Optimization: Fence and Distance Problems