N, K = map(int, input().split()) P = list(map(int, input().split())) d = [0]*N for i in range(N): d[i] = (P[i]+i) % N M = 40 step = [[0]*(M+1) for _ in range(N)] step2 = [[0]*(M+1) for _ in range(N)] for i in range(N): step[i][0] = d[i] step2[i][0] = int(d[i]<=i) for i in range(1, M+1): for j in range(N): step[j][i] = step[step[j][i-1]][i-1] step2[j][i] = step2[j][i-1] + step2[step[j][i-1]][i-1] #print(step2[0]) for i in range(N): tmp = K c = i cy = 0 for j in range(M+1): if tmp % 2: cy += step2[c][j] c = step[c][j] # print(i, c, cy) tmp //= 2 print(c+1+cy*N)