| BSUIR Open XII: Student Final |
|---|
| Finished |
Due to the rapid development of humanity in the space sphere, the fairy tales that parents tell their children have become distorted. They have ceased to be interesting or funny and have turned into computer science problems. For example, Martian children are told the following problem at night.
Once upon a time, there were three friends — Sasha, Kirill, and Yuri. At some point, they ran out of money. Therefore, they decided to build a casino and started to come up with rules:
Playing the same game all the time is boring, and there is no element of randomness. Therefore, the friends decided to clarify the rules:
The friends also decided to assess the profitability of their scheme, but they couldn't manage it. Therefore, they ask you to help them calculate the number of pairs $$$(l, r)$$$, for which the casino wins the game.
The first line contains the numbers $$$n$$$ and $$$k$$$ — the number of slot machines and the maximum number of stones that can be taken in one move.
The second line contains the numbers $$$a_1, \ldots, a_n$$$ — the initial number of stones in each of the machines.
$$$$$$1 \le n \le 1\,000\,000$$$$$$ $$$$$$2 \le k \le 100$$$$$$ $$$$$$1 \le a_i \le 10^{18}$$$$$$
Output a single number — the answer to the problem.
3 21 2 3
3
2 10308 693
3
Consider the first example:
Out of all possible pairs $$$(l, r)$$$, $$$3$$$ pairs $$$(3,3)$$$, $$$(1,2)$$$, $$$(1,3)$$$ are suitable for us, so the answer is $$$3$$$.
| Name |
|---|


