#K35312. Minimum Streets and Avenues

    ID: 25504 Type: Default 1000ms 256MiB

Minimum Streets and Avenues

Minimum Streets and Avenues

This problem requires you to compute the minimum number of streets and avenues needed to travel between two intersections in a city laid out in a grid pattern. The grid is an n x n matrix and the intersections are determined by their coordinates.

The distance between two points \((x_1, y_1)\) and \((x_2, y_2)\) is calculated using the Manhattan distance formula:

\( |x_1 - x_2| + |y_1 - y_2| \)

Your task is to implement a solution that reads the grid size and the coordinates for the starting and destination intersections, and then outputs the computed Manhattan distance as the minimum number of streets and avenues that must be traversed.

inputFormat

The input is given via standard input as a single line containing five space-separated integers:

  • n: the size of the grid (n x n)
  • x1, y1: the coordinates of the starting intersection
  • x2, y2: the coordinates of the destination intersection

For example: 10 3 2 7 8

outputFormat

Output a single integer, which is the minimum number of streets and avenues needed to travel between the two intersections. The result should be printed to standard output.

## sample
5 0 0 4 4
8

</p>