Streets and Avenues in Berhattan

CodeForces - 1070J