#C6814. Counting Landmark Pairs

    ID: 50616 Type: Default 1000ms 256MiB

Counting Landmark Pairs

Counting Landmark Pairs

You are given n landmarks placed sequentially along a straight road, each one unit apart. Your task is to compute the number of pairs of landmarks such that the distance between them is exactly d meters.

Formally, if the landmarks are numbered from 0 to n-1, then for any pair (i, j) with i < j, the distance between them is j - i. You are required to count the number of pairs satisfying the condition:

$$j - i = d$$

It can be shown that when \(0 \le d < n\), the answer is \(n-d\). If \(d \ge n\), then no such pairs exist and the answer is 0.

Note: The input is read from standard input and the result should be printed to standard output.

inputFormat

The input consists of a single line containing two space-separated integers:

  • n (the number of landmarks)
  • d (the required distance between landmarks)

Constraints:

  • \(1 \le n \le 10^{12}\)
  • \(0 \le d \le 10^{12}\)

outputFormat

Output a single integer, the number of pairs of landmarks that have a distance exactly equal to d.

## sample
10 3
7