atcoder#ABC241E. [ABC241E] Putting Candies

[ABC241E] Putting Candies

Score : 500500 points

Problem Statement

You are given a sequence A=(A0,A1,,AN1)A=(A_0,A_1,\ldots,A_{N-1}) of length NN. There is an initially empty dish. Takahashi is going to repeat the following operation KK times.

  • Let XX be the number of candies on the dish. He puts A(XmodN)A_{(X\bmod N)} more candies on the dish. Here, XmodNX\bmod N denotes the remainder when XX is divided by NN.

Find how many candies are on the dish after the KK operations.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1K10121 \leq K \leq 10^{12}
  • 1Ai1061 \leq A_i\leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A0A_0 A1A_1 \ldots AN1A_{N-1}

Output

Print the answer.

5 3
2 1 6 3 1
11

The number of candies on the dish transitions as follows.

  • In the 11-st operation, we have X=0X=0, so A(0mod5)=A0=2A_{(0\mod 5)}=A_0=2 more candies will be put on the dish.
  • In the 22-nd operation, we have X=2X=2, so A(2mod5)=A2=6A_{(2\mod 5)}=A_2=6 more candies will be put on the dish.
  • In the 33-rd operation, we have X=8X=8, so A(8mod5)=A3=3A_{(8\mod 5)}=A_3=3 more candies will be put on the dish.

Thus, after the 33 operations, there will be 1111 candies on the dish. Note that you must not print the remainder divided by NN.

10 1000000000000
260522 914575 436426 979445 648772 690081 933447 190629 703497 47202
826617499998784056

The answer may not fit into a 3232-bit integer type.