#P3054. Counting Cow Crossing Events

    ID: 16312 Type: Default 1000ms 256MiB

Counting Cow Crossing Events

Counting Cow Crossing Events

Farmer John is experimenting with cow racing. In his race, n cows run L laps on a circular track of circumference C. All cows start at the same point but run at different speeds. The race ends as soon as the fastest cow completes the full distance of L×C.

Whenever one cow overtakes another (i.e. crosses from behind to in front) during the race, a crossing event is said to have occurred. Formally, for any pair of cows (x, y) with speeds s_x > s_y, a crossing event occurs each time cow x catches up to cow y (which happens when the distance difference reaches a multiple of the track length) before or at the moment the race ends.

Let the speeds of the cows be si (1 ≤ i ≤ n) and let smax denote the maximum speed. The race finishing time is \[ T = \frac{L \cdot C}{s_{max}}, \] and for any pair of cows with s_x > s_y the number of crossing events is \[ \left\lfloor \frac{L\,(s_x - s_y)}{s_{max}} \right\rfloor. \]

Your task is to count the total number of crossing events over all pairs of cows. Note that if two cows have the same speed, no crossing event occurs between them.

Example: Suppose n=3, L=3, and the speeds are 5, 3 and 2. Then smax=5 and the crossing events occur as follows:

  • For the pair (5, 3): \(\lfloor 3(5-3)/5 \rfloor = \lfloor 6/5 \rfloor = 1\) crossing.
  • For the pair (5, 2): \(\lfloor 3(5-2)/5 \rfloor = \lfloor 9/5 \rfloor = 1\) crossing.
  • For the pair (3, 2): \(\lfloor 3(3-2)/5 \rfloor = \lfloor 3/5 \rfloor = 0\) crossings.

The total is 1 + 1 + 0 = 2.

inputFormat

The first line contains three integers n, L and C where 1 ≤ n ≤ 100,000. The next n lines each contain a single integer representing the speed si of the i-th cow. It is guaranteed that all speeds are positive integers.

outputFormat

Output a single integer which is the total number of crossing events that occur during the race.

sample

2 2 100
3
2
0