Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):

    BM = [[] for _ in range(20)]
    for j, a in enumerate(A):
        n = a
        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                BM[i].append(j)

    error_print('-----')

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            ri = bisect.bisect_left(bm, i)
            if len(bm) == 0 or len(bm) == ri or len(bm) == ri + 1:
                r = N - 1
            else:
                r = bm[ri + 1] - 1
            min_r = min_r if min_r < r else r
        ans += min_r - i
    return ans


def main():
    N = read_int()
    A = read_int_n()
    N = int(2 * 1e+5)
    A = [random.randint(0, 2**20 - 1) for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

    def solve(self, n, arr):
        sum = 0
        bitcount = [0]*64
        for num in arr:
            b = reversed(bin(num)[2:])
            for i, s in enumerate(b):
                if i != "0":
                    bitcount[i] += int(s)
        for i, b in enumerate(bitcount):
            if b == 0:
                continue
            sum += b * (n-b) * 2**i
        return sum % (10**9 + 7)


def main():
    N = int(input())
    A_l = [int(i) for i in input().split()]
    solver = Solver()
    print(solver.solve(N, A_l))
    sys.exit()


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def solve(n, arr):
    sum = 0
    bitcount = [0]*100
    for num in arr:
        b = reversed(bin(num)[2:])
        for i, s in enumerate(b):
            if i != "0":
                bitcount[i] += int(s)
    for i, b in enumerate(bitcount):
        sum += b * (n-b) * 2**i
    return sum % (10**9 + 7)


def main():
    N = int(input())
    A_l = [int(i) for i in input().split()]
    print(solve(N, A_l))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

res = [0]*(1000001)
for i in a: res[i] += 1


def check(N,P):
    if N == 1:
        if P[1]==1: return True
        else: return False
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    
    for i in res:
        if i!=N and P[i] >= 1: return False
        if i==N and P[i] >= 2: return False
    return True    

ans = 0
for N in a:
    if check(N,res): ans += 1

print(ans)



### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

d = {}
for i in a:
    if i in d: d[i] += 1
    else: d[i] = 1

M = 10**6+1
sieve = [0]*(M)
for k,v in d.items():
    for i in range(k,M,k):
        sieve[i] += v


ans = 0
for ai in a:
    if sieve[ai] == 1:
        ans += 1

print(ans)
### BUGGY CODE ###

# @author 

import sys

class EVirusTree2:

    def solve(self):
        from collections import defaultdict
        import sys
        sys.setrecursionlimit(10 ** 5 + 5)

        MOD = 10 ** 9 + 7
        n, k  = [int(_) for _ in input().split()]
        adj = defaultdict(list)
        for i in range(n - 1):
            a, b = [int(_) for _ in input().split()]
            a -= 1
            b -= 1
            adj[a].append(b)
            adj[b].append(a)
        done = [0] * n
        def dfs(s, rem):
            done[s] = 1
            if rem < 0:
                return 0
            res = 1
            for x in adj[s]:
                if done[x]:
                    continue
                if rem <= 0:
                    return 0
                res = (res * rem) % MOD
                res = (res * dfs(x, k - 2)) % MOD
                rem -= 1
                if res == 0:
                    return 0
            return res

        print((dfs(0, k - 1) * k) % MOD)




solver = EVirusTree2()
input = sys.stdin.readline

solver.solve()


### FIXED CODE ###

# @author 

import sys

class EVirusTree2:

    def solve(self):
        from collections import defaultdict
        import sys
        sys.setrecursionlimit(10 ** 5 + 5)

        MOD = 10 ** 9 + 7
        n, k  = [int(_) for _ in input().split()]
        adj = defaultdict(list)
        for i in range(n - 1):
            a, b = [int(_) for _ in input().split()]
            a -= 1
            b -= 1
            adj[a].append(b)
            adj[b].append(a)
        done = [0] * n
        def dfs(s, rem):
            done[s] = 1
            if rem < 0:
                return 0
            res = 1
            for x in adj[s]:
                if done[x]:
                    continue
                if rem <= 0:
                    return 0
                res = (res * rem) % MOD
                res = (res * dfs(x, k - 2)) % MOD
                rem -= 1
                if res == 0:
                    return 0
            return res

        print((dfs(0, k - 1) * k) % MOD)




solver = EVirusTree2()
input = sys.stdin.readline

solver.solve()
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]

    V = {(i,j):0 for i in range(N) for j in range(i+1,N)}
    Ef = {(i,j):[] for i in range(N) for j in range(i+1,N)}
    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0) if i<a0 else (a0,i)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1) if i<a1 else (a1,i)
            Ef[k0].append(k1)
            V[k1] += 1

    q = [k for k in V if V[k] == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for k in q:
            for k2 in Ef[k]:
                V[k2] -= 1
                rmv += 1
                if V[k2] == 0 : qq.append(k2)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()


### FIXED CODE ###

#"""
import sys
input = sys.stdin.readline
#"""
def main():
    def get_key(i,j):
        if i<j: i,j = j,i
        return i*N+j
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]
    V = [-1]*(N*N)
    for i in range(N):
        for j in range(i+1,N):
            V[get_key(i,j)] = 0
    Ef = [[] for _ in V]

    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1)
            Ef[get_key(*k0)].append(get_key(*k1))
            V[get_key(*k1)] += 1

    q = [i for i,v in enumerate(V) if v == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for i in q:
            for j in Ef[i]:
                V[j] -= 1
                rmv += 1
                if V[j] == 0 : qq.append(j)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()
### BUGGY CODE ###

import sys
# input処理を高速化する
input = sys.stdin.readline
# 入力
S = input()
T = input()

def lcs(s, t):
    dp = [[0 for i in range(len(T)+1)] for j in range(len(S)+1)]
    for i in range(len(S)):
        for j in range(len(T)):
            if S[i] == T[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                if dp[i][j+1] > dp[i+1][j]:
                    dp[i+1][j+1] = dp[i][j+1]
                else:
                    dp[i+1][j+1] = dp[i+1][j]

    ans = ''
    i = len(S)
    j = len(T)
    while (i>0  and j>0):
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans += s[i-1] 
            i -= 1
            j -= 1
    
    print(ans[::-1])
        
lcs(S, T)

### FIXED CODE ###

import sys

# input処理を高速化する
input = sys.stdin.readline

# 入力
S = input()
T = input()

def chmax(a, b):
    if a >= b:
        return a
    else:
        return b


def lcs(s, t):
    dp = [[0 for i in range(len(T)+1)] for j in range(len(S)+1)]
    for i in range(len(S)):
        for j in range(len(T)):
            if S[i] == T[j]:
                dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i][j+1])

    ans = ''
    i = len(S)
    j = len(T)
    while (i>0  and j>0):
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans += s[i-1] 
            i -= 1
            j -= 1
    
    print(ans[::-1])

        
lcs(S, T)
### BUGGY CODE ###

S = input()
Q = int(input())
query = []
for i in range(Q):
    query.append(list(map(str, input().split())))


def start(S, x, flg):
    if flg == True:
        S = x + S
    else:
        S = S + x
    return S


def end(S, x, flg):
    if flg == True:
        S = S + x
    else:
        S = x + S
    return S


flg = True
for q in query:
    if len(q) == 1:
        flg = not flg
    else:
        if int(q[1]) == 1:
            S = start(S, q[2], flg)
        else:
            S = end(S, q[2], flg)
else:
    if flg == True:
        print(S)
    else:
        print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
query = []
for i in range(Q):
    query.append(list(map(str, input().split())))


def start(S, x):
    S = x + S
    return S


def end(S, x):
    S = S + x
    return S


front = ''
back = ''
flg = True
for q in query:
    if len(q) == 1:
        flg = not flg
    else:
        if flg == True:
            if q[1] == '1':
                front = start(front, q[2])
            else:
                back = end(back, q[2])
        else:
            if q[1] == '1':
                back = end(back, q[2])
            else:
                front = start(front, q[2])
else:
    if flg == True:
        print(front + S + back)
    else:
        print(back[::-1] + S[::-1] + front[::-1])
### BUGGY CODE ###

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

a=1
for i in range(N):
    if i>= K:
        prev = a 
        cur = a * A[i] // A[i-K]
        if prev >= cur:
            print('No')
        else :
            print('Yes')
        a//=A[i-K]
    a*=A[i]


### FIXED CODE ###

N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

for i in range(N):
    if i>= K:
        prev = A[i-K] 
        cur = A[i]
        if prev >= cur:
            print('No')
        else :
            print('Yes')
### BUGGY CODE ###

from collections import deque

N,M=map(int,input().split())
PY=[]
pY=[[] for i in range(N+1)]
for i in range(M):
    P,Y=map(int,input().split())
    PY.append([P,Y])
    pY[P].append(Y)
"""
N=2
M=3
PY=[[1,32],[2,63],[1,12]]
pY=[[],
   [32,12],
   [63]]
"""
py=[[]]
for i in range(1,len(pY)):
    pY[i].sort()
    py.append(pY[i])
for P in PY:
    for i in range(len(py[P[0]])):
        if py[P[0]][i]==P[1]:
            print(str(P[0]).zfill(6)+str(i+1).zfill(6))
            break


### FIXED CODE ###

from bisect import bisect_right
N,M=map(int,input().split())
PY=[]
record=[[] for i in range(N+1)]
for i in range(M):
    P,Y=map(int,input().split())
    PY.append([P,Y])
    record[P].append(Y)
for i in range(1,N+1):
    record[i].sort()
for i in range(M):
    p,y=PY[i][0],PY[i][1]
    order=bisect_right(record[p],y)
    print(str(p).zfill(6)+str(order).zfill(6))
### BUGGY CODE ###

s = input()
n = int(input())

rev = 0
for i in range(n):
    q = input().split()
    if q[0] == '1':
        rev = (rev + 1) % 2
    else:
        head = int(q[1]) % 2
        if head ^ rev:
            s = q[2] + s
        else:
            s += q[2]
            
print(s[::-1]) if rev else print(s)

### FIXED CODE ###

s = input()
n = int(input())

rev = 0
sh = ''
for i in range(n):
    q = input().split()
    if q[0] == '1':
        rev = (rev + 1) % 2
    else:
        head = int(q[1]) % 2
        if head ^ rev:
            sh += q[2]
            # print('sh', sh)
        else:
            s += q[2]
            # print('s', s)
ans = sh[::-1] + s
print(ans[::-1]) if rev else print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

ans = set(list(range(1, N + 1)))
for lr in LR:
    l, r = lr
    ans = ans & set(list(range(l, r + 1)))
print(len(list(ans)))

### FIXED CODE ###

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

A, B = 1, N
for lr in LR:
    L, R = lr
    if R < A or B < L:
        print(0)
        exit()

    if A <= L <= R <= B:
        A, B = L, R
    elif L <= A <= R <= B:
        B = R
    elif A <= L <= B <= R:
        A = L
print(B - A + 1)
### BUGGY CODE ###

N, C = map(int, input().split())
Xi = [list(map(int, input().split())) for _ in range(N)]

# 真上に0があると考える。下から⇢にいくか←にいくかで区別

#右方向に進んだときの累積Caloryと累積max
R_cal = [0 for i in range(N)]
R_max = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        R_cal[i] = Xi[i][1] - Xi[i][0]
        R_max[i] = max(R_cal[i], 0)
    else:
        d = Xi[i][0] - Xi[i - 1][0]
        R_cal[i] = R_cal[i - 1] + Xi[i][1] - d
        R_max[i] = max(R_cal[i], R_max[i - 1])

#右方向に進んだときの累積max
L_cal = [0 for i in range(N)]
L_max = [0 for i in range(N)]
for i in range(N - 1, -1, -1):
    if i == N - 1:
        L_cal[i] = Xi[i][1] - (C - Xi[i][0])
        L_max[i] = max(L_cal[i], 0)
    else:
        d = Xi[i + 1][0] - Xi[i][0]
        L_cal[i] = L_cal[i + 1] + Xi[i][1] - d
        L_max[i] = max(L_cal[i], L_max[i + 1])

#右方向にとにかくすすむ
max_value = 0
for i in range(N):
    cal = R_cal[i]
    l_cal = 0
    if i < N - 1:
        l_cal = max(L_max[i + 1:]) - Xi[i][0]
    if l_cal > 0:
        cal += l_cal
    max_value = max(cal, max_value)
#左にとにかくすすむ
for i in range(N - 1, -1, -1):
    cal = L_cal[i]
    r_cal = 0
    if i > 0:
        r_cal = max(R_max[:i]) - (C - Xi[i][0])
    if r_cal > 0:
        cal += r_cal
    max_value = max(cal, max_value)
print(max_value)

### FIXED CODE ###

N, C = map(int, input().split())
Xi = [list(map(int, input().split())) for _ in range(N)]

#両端に(0,0)があると考えると楽なので追加
Xi.insert(0, [0, 0])
Xi.append([C, 0])

# 真上に0があると考える。下から⇢にいくか←にいくかで区別
#右方向に進んだときの累積Caloryと累積max
total = 0
R_max = [0 for i in range(N + 2)]
for i in range(1, N + 1):
    total += Xi[i][1] - (Xi[i][0] - Xi[i - 1][0])
    R_max[i] = max(total, R_max[i - 1])

#右方向に進んだときの累積max
total = 0
L_max = [0 for i in range(N + 2)]
for i in range(N, 0, -1):
    total += Xi[i][1] - (Xi[i + 1][0] - Xi[i][0])
    L_max[i] = max(total, L_max[i + 1])

max_value = 0
for i in range(0, N + 1):
    i2 = N - i - 1
    #右方向にとにかくすすむ
    cal = R_max[i] + L_max[i + 1] - Xi[i][0]
    max_value = max(cal, max_value)

    #左にとにかくすすむ
    cal = R_max[i] + L_max[i + 1] - (C - Xi[i + 1][0])
    max_value = max(cal, max_value)
print(max_value)
### BUGGY CODE ###

from collections import defaultdict as dd

def main():
    a = dd(int)
    n, m = [int(i) for i in input().split()]
    for i in input().split():
        a[int(i)] += 1

    for _ in range(m):
        b, c = [int(i) for i in input().split()]
        for _ in range(b):
            a[c]+=1
    res = 0
    cnt = 0
    for k in sorted(list(a.keys()))[::-1]:
        v = a[k]
        if cnt + v <= n:
            num = v
        else:
            num = n - cnt
        res += num * k
        cnt += num
        if cnt >= n:
            break
    print(res) 

if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    
    bc = []
    for _ in range(m):
        b, c = map(int, input().split())
        bc.append((b, c))

    total = 0
    for num, v in sorted(bc, key=lambda x: -x[1]):
        total += num
        a.extend([v]*num)
        if total >= n:
            break
    print(sum(sorted(a)[-n:]))

if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main():
    s = input()
    t = input()

    dp = [[0]*(len(t)+1) for i in range(len(s)+1)]


    check = 0
    for i in range(len(s)):
        
        for j in range(len(t)):
            if s[i]==t[j]:
                dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
        
    i = len(s)
    j = len(t)
    ans = ""
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans = s[i-1] + ans
            i -= 1
            j -= 1
    print(ans)        
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s = input()
    t = input()

    dp = [[0]*(len(t)+1) for i in range(len(s)+1)]


    check = 0
    for i in range(len(s)):
        
        for j in range(len(t)):
            if s[i]==t[j]:
                dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
        
    i = len(s)
    j = len(t)
    ans = ""
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans = s[i-1] + ans
            i -= 1
            j -= 1
    print(ans)        
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def comb(n,k):
  p=1000000007
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a,b,c=factorial(n) %p,factorial(k) %p,factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":res=(res*a) %p
  return res

n= int(input())
a= list(map(int,input().split()))
check= [0]*(n+1)
r=jn=-1
for i in range(n+1):
    check[a[i]-1]+=1
    if check[a[i]-1]==2:
        jn,r= a[i],i
        break
st=a.index(jn)+n-r
for k in range(1,n+2):print(comb(n+1,k)-comb(st,k-1) if st>=k-1 else comb(n+1,k))

### FIXED CODE ###

mod = 1000000007
n= int(input())
a= list(map(int,input().split()))
check = [0]*(n+1)
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+1+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)
def cmb2(n,r):
    mod = 1000000007
    if (r<0 or r>n ):return 0
    r = min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%mod
r=-1
jn=-1
for i in range(n+1):
    check[a[i]-1]+=1
    if check[a[i]-1]==2:
        jn,r=a[i],i
        break
l=a.index(jn)
s = min(l,n-r)
t = max(l,n-r)
print(n)
for p in range(2,n+1):
  w2=cmb2(n+1,p)
  y2=cmb2(s+t,p-1)
  print(((w2+mod)-y2) % mod)
print(1)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))

for i in range(1,N+1):
    print(A.count(i))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*N

for i in A:
    B[i-1]+=1

for i in B:
    print(i)
### BUGGY CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N):
  l, r = 0, 0
  for j in range(N):
    k = i - j
    if(A[j] < B[i]):
      l += 1
    if(B[i] < C[k]):
      r += 1
  cnt += l*r
print(cnt)


### FIXED CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

a = 0
c = 0
ans = 0
for b in B:
  while a < N and A[a] < b:
    a += 1
  while c < N and C[c] <= b:
    c += 1
  ans += a * (N - c)
print(ans)
### BUGGY CODE ###

import numpy as np

def count_num_light(a):
  ret = np.array([0 for _ in range(len(a))])
  for i in range(len(a)):
    start = max(0, i-a[i])
    ret[start:i+a[i]+1] += 1
  
  return ret
                  
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
num_light = count_num_light(a)

for i in range(k-1):
  num_light = count_num_light(num_light)
  if np.sum(num_light) == n**2:
    break

print(*num_light)


### FIXED CODE ###

def count_num_light(a):
  ret = [0 for _ in range(len(a))]
  n = len(a)
  for i in range(n):
    start = max(0, i-a[i])
    end = min(n-1, i+a[i])
    ret[start] += 1
    if end+1 < n:
      ret[end+1] -= 1
  for i in range(1,n):
    ret[i] += ret[i-1]
  
  return ret
                  
n, k = map(int, input().split())
a = list(map(int, input().split()))
num_light = count_num_light(a)
 
for i in range(k-1):
  num_light = count_num_light(num_light)
  if sum(num_light) == n**2:
    break
    
print(*num_light)
### BUGGY CODE ###

import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

l = [1]
i = 0
while (True):
    if a[l[i]-1] in l:
        p = l.index(a[l[i]-1])
        break

    l.append(a[l[i]-1])
    i += 1

if k < p:
    print(l[k])
else:
    k -= p
    x = k % (len(l)-p)
    print(l[x+p])



### FIXED CODE ###

import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

q = [0 for i in range(n)]
l = [1]
i = 0
while (True):
    if q[a[l[i]-1]-1] == 1:
        p = l.index(a[l[i]-1])
        break
    
    q[a[l[i]-1]-1] = 1
    l.append(a[l[i]-1])
    i += 1

if k < p:
    print(l[k])
else:
    k -= p
    x = k % (len(l)-p)
    print(l[x+p])