#C11854. Distinct Shortest Paths

    ID: 41216 Type: Default 1000ms 256MiB

Distinct Shortest Paths

Distinct Shortest Paths

You are given two points in a 2D plane: the starting point \((x_0, y_0)\) and the target point \((x_t, y_t)\). Your task is to compute the number of distinct shortest paths from the starting point to the target point when only unit horizontal and vertical moves are allowed.

The shortest path from \((x_0, y_0)\) to \((x_t, y_t)\) requires moving \(dx = |x_t - x_0|\) steps in the horizontal direction and \(dy = |y_t - y_0|\) steps in the vertical direction. The total number of moves is \(dx + dy\), and the number of distinct ways to arrange these moves is given by the binomial coefficient:

(dx+dydx)\binom{dx+dy}{dx}

For example, from \((0, 0)\) to \((2, 2)\), we have \(dx = 2\) and \(dy = 2\), so the number of distinct shortest paths is \(\binom{4}{2} = 6\).

Note: The points may include negative coordinates, but the computation is based on the absolute differences in their coordinates.

inputFormat

The input consists of a single line containing four space-separated integers: \(x_0\), \(y_0\), \(x_t\), and \(y_t\), representing the coordinates of the starting point and the target point, respectively.

outputFormat

Output a single integer representing the number of distinct shortest paths from the starting point to the target point.

## sample
0 0 2 2
6

</p>