This page is still under construction.

Parts of this page are still being built. What you see may change.

Running Laps

Time limit1sMemory limit128 MB

Summary
Count how many times a faster cow overtakes a slower cow, counting ordered pairs, before the fastest cow finishes L laps on a track of length C.
Level

Medium7 of 10

Topics
Sorting, Math, Binary search, Array
Solved
No attempts yet

Problem

Farmer John decides to investigate whether cow racing could work as a sport. He lines up his NN cows (1≤N≤100,0001 \le N \le 100{,}000) to run a race of LL laps around a circular track of length CC. All cows start at the same point and each runs at its own constant speed. The race ends the moment the fastest cow has covered the full distance L⋅CL \cdot C.

During the race one cow may pass another. A crossing event is defined by an ordered pair of cows (x,y)(x, y) and a time tt (no later than the moment the race ends) at which cow xx moves ahead of cow yy. Count the total number of crossing events that occur during the entire race.

Input

  • Line 1: three space-separated integers NN, LL, and CC (1≤L,C≤25,0001 \le L, C \le 25{,}000).
  • Lines 2 to N+1N+1: line i+1i+1 contains the speed of cow ii, an integer between 11 and 1,000,0001{,}000{,}000.

Output

  • A single line with the total number of crossing events during the entire race.

Explanation

Consider 4 cows running 2 laps on a track of length 100 with speeds 20, 100, 70, and 1. The race lasts until the fastest cow (speed 100) finishes its 2 laps. During that time there are 4 crossing events: the speed-100 cow passes the speed-20 and speed-1 cows, and the speed-70 cow also passes the speed-20 and speed-1 cows.

Examples1

  1. Example 1

    Input
    4 2 100
    20
    100
    70
    1
    
    Expected output
    4