N,K=map(int,input().split()) P=list(map(int,input().split())) mod=N P2=P[-1:]+P[:-1] NEXT=[[0]*N for i in range(31)] DIS=[[0]*N for i in range(31)] for i in range(N): DIS[0][i]=P2[i] NEXT[0][i]=(i+DIS[0][i])%mod for j in range(1,31): for i in range(N): DIS[j][i]=DIS[j-1][i]+DIS[j-1][NEXT[j-1][i]] NEXT[j][i]=(i+DIS[j][i])%mod A=[] for i in range(N): NOW=i ANS=0 U=K while U: b=U.bit_length()-1 ANS+=DIS[b][NOW] NOW=NEXT[b][NOW] U-=(1<