Equations involving distance and cost