Harryxun/stf_run huggingface dataset:
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p, x = [], []
for i in range(m):
  q, y = map(int, input().split())
  p[i] = q
  x[i] = y
s = sum(t)
for j in range(m):
  print(s - t[p[j]] + x[j])

### FIXED CODE ###

n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = []
x = []
for i in range(m):
  q, y = map(int, input().split())
  p.append(q)
  x.append(y)
  
s = sum(t)
for j in range(m):
  print(s - t[p[j]-1] + x[j])
# coding: utf-8
import math

n = int(input())
h_list = list(map(int, input().split()))

inf = math.inf
ans_list = [inf for _ in range(n)]
# ans_list = [0, 1, 2,..., n-1]
# h_list = [0, 1, 2,..., n-1]

def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans_list[0] = 0
ans_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    ans_list[i] = cmin(ans_list[i], ans_list[i-1]+abs(h_list[i]-h_list[i-1]))
    ans_list[i] = cmin(ans_list[i], ans_list[i-2]+abs(h_list[i]-h_list[i-2]))

print(ans_list[-1])

### FIXED CODE ###

# coding: utf-8

n = int(input())
h_list = list(map(int, input().split()))

inf = float('inf')
ans_list = [inf for _ in range(n)]
# ans_list = [0, 1, 2,..., n-1]
# h_list = [0, 1, 2,..., n-1]

def cmin(a, b):
    if a<b:
        return a
    else:
        return b

ans_list[0] = 0
ans_list[1] = abs(h_list[1] - h_list[0])
for i in range(2, n):
    ans_list[i] = cmin(ans_list[i], ans_list[i-1]+abs(h_list[i]-h_list[i-1]))
    ans_list[i] = cmin(ans_list[i], ans_list[i-2]+abs(h_list[i]-h_list[i-2]))

print(ans_list[-1])
X,N = map(int,input().split())
P = list(map(int,input().split()))

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(-100,100)]
    for i in P:
        list.remove(i)
    min = 100
    for i in list:
        if min > abs(X-i):
            min = abs(X - i)
            result = i

print(result)

### FIXED CODE ###

X,N = map(int,input().split())
P = list(map(int,input().split()))

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(201)]
    for i in P:
        list.remove(i)
    if len(list) == 0:
        result = 0
    else:
        min = 100
        for i in list:
            if min > abs(X-i):
                min = abs(X - i)
                result = i
print(result)
a = [input() for _ in range(int(input())]
print("AC x {0}".format(a.count("AC"))
print("WA x {0}".format(a.count("WA"))
print("TLE x {0}".format(a.count("TLE"))      
print("RE x {0}".format(a.count("RE"))

### FIXED CODE ###

a = [input() for _ in range(int(input()))]
print("AC x {}".format(a.count("AC")))
print("WA x {}".format(a.count("WA")))
print("TLE x {}".format(a.count("TLE")))
print("RE x {}".format(a.count("RE")))
def main():
    S=input()
    res=""

    for i in range(len(S)):
        if S[i]=="?":
            if i==0:
                if S[i+1]=="?":
                    res+="P"
                else:
                    res=+"D"
            elif i==len(S)-1:
                res+="D"
            else:
                if res[i-1]=="P":
                    res+="D"
                elif S[i+1]=="?":
                    res+="P"
                else:
                    res+="D"
        else:
            res+=S[i]
    print(res)

if __name__=="__main__":
    main()


### FIXED CODE ###

def main():
    S=input()
    res=""

    for i in range(len(S)):
        if S[i]=="?":
            if len(S)==1:
                res+="D"
                continue
            if i==0:
                if S[i+1]=="?":
                    res+="P"
                else:
                    res+="D"
            elif i==len(S)-1:
                res+="D"
            else:
                if res[i-1]=="P":
                    res+="D"
                elif S[i+1]=="?":
                    res+="P"
                else:
                    res+="D"
        else:
            res+=S[i]
    print(res)

if __name__=="__main__":
    main()
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,K=rl()

td_1 = [0]*N
td_rem = []
for _ in range(N):
    t,d = rl()
    t -= 1
    if td_1[t] == 0:
        td_1[t] = d
    else:
        if d <= td_1[t]:
            td_rem += [d]
        else:
            td_rem += [td_1[t]]
            td_1[t] = d


td_1.sort(reverse=True)
td_rem.sort(reverse=True)
#print(td_1)
#print(td_rem)
import numpy as np
td_1 = np.cumsum([0] + td_1[:td_1.index(0)])
td_rem = np.cumsum([0]+td_rem)

ans = [0 for _ in range(K+1)]
sum_l = 0
for i in range(1,K+1):
    if len(td_1)-1 >= i and len(td_rem)-1>=K-i:
        ans[i] = i*i + td_1[i] + td_rem[K-i]

#print(td_1)
#print(td_rem)
#print(ans)
print(max(ans))


### FIXED CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,K=rl()
td = [rl() for _ in range(N)]

from operator import itemgetter
key0 = itemgetter(0)
key1 = itemgetter(1)
td.sort(key=key1,reverse=True)

netas = set()
dup = []

for t,d in td[:K]:
    if t in netas:
        dup.append(d)
    else:
        netas.add(t)

score = len(netas)**2 + sum(map(key1,td[:K]))
ans = score
for t,d in td[K:]:
    if t not in netas and dup != []:
        netas.add(t)
        dup_ = dup.pop(-1)
        score += 2*len(netas)-1 + d - dup_
        ans = max(ans,score)
print(ans)
import math

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

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

min=v[A]


C=v[0:A].count(min)#最低個数
D=v[0:A].count(min)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(min)#最小の人たちの個数
q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))


### FIXED CODE ###

import math

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

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

mini=v[A]
C=v[0:A].count(mini)#最低個数
D=v[0:A].count(mini)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(mini)#最小の人たちの個数
D=min(D,p)

q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = []
for i in range(N):
    a = A.pop(0)
    B.append(0)
    B.append(0)
ans = 0
for i in range(N-1):
    a = B.pop(0)
    ans += b
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
k = N - 2
a = A.pop()
ans = a
n = k // 2
for i in range(n):
    a = A.pop()
    ans += 2*a
if k - 2*n == 1:
    ans += A[-1]

print(ans)
from collections import deque
h, w = map(int, input().split())
sy, sx = list(map(int, input().split()))
sy -= 1
sx -= 1
gy, gx = list(map(int, input().split()))
gy -= 1
gx -= 1
s = [input() for _ in range(h)]
inf = float("inf")
meiro = [[inf]*w for _ in range(h)]
d = deque()
d.append([sy, sx])
meiro[sy][sx] = 0
move1 = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while d:
    py, px = d.popleft()
    #move1 bfs
    for dy, dx in move1:
        if 0 <= py + dy < w and 0 <= px + dx < h:
            childy = py + dy
            childx = px + dx
            if s[childy][childx] == "." and meiro[childy][childx] > meiro[py][px]:
                meiro[childy][childx] = meiro[py][px]
                d.appendleft([childy, childx])
                # move1のbfsを優先的に探索したいからd.appendleftする

    #warp
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            if 0<=warpx<w and 0<=warpy<h:
                warpx = px + dx
                warpy = py + dy
                if s[warpy][warpx] == "." and meiro[warpy][warpx] > meiro[py][px]:
                    meiro[warpy][warpx] = meiro[py][px] + 1
                    d.append([warpy, warpx])


ans = meiro[gy][gx] if meiro[gy][gx] != inf else -1
print(ans)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
sy, sx = list(map(int, input().split()))
sy -= 1
sx -= 1
gy, gx = list(map(int, input().split()))
gy -= 1
gx -= 1
s = [input() for _ in range(h)]
inf = float("inf")
meiro = [[inf]*w for _ in range(h)]
d = deque()
d.append([sy, sx])
meiro[sy][sx] = 0
move1 = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while d:
    py, px = d.popleft()
    #move1 bfs
    for dy, dx in move1:
        if 0 <= px+dx < w and 0 <= py+dy < h:
            childy = py + dy
            childx = px + dx
            if s[childy][childx] == "." and meiro[childy][childx] > meiro[py][px]:
                meiro[childy][childx] = meiro[py][px]
                d.appendleft([childy, childx])
                # move1のbfsを優先的に探索したいからd.appendleftする

    #warp
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            if 0 <= px+dx < w and 0 <= py+dy < h:
                warpx = px + dx
                warpy = py + dy
                if s[warpy][warpx] == "." and meiro[warpy][warpx] == inf:
                    meiro[warpy][warpx] = meiro[py][px] + 1
                    d.append([warpy, warpx])


ans = meiro[gy][gx] if meiro[gy][gx] != inf else -1
print(ans)
X = int(input())
a = X // 500
X -= a * 500
b = X // 5
print(a,b)
print(a*1000+5*

### FIXED CODE ###

X = int(input())
a = X // 500
X -= a * 500
b = X // 5
print(a*1000+5*b)
from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    global N
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0
floyd_warshall(distant)
# warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(ans)


### FIXED CODE ###

# from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0

warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(ans)
if A+B>=C:
    print ("Yes")
else:
    print ("No")

### FIXED CODE ###

A, B, C = map(int, input().split())
if A+B>=C:
    print ("Yes")
else:
    print ("No")
import collections
x,n=map(int,input().split())
l=list(map(int,input().split()))
v=collections.Counter(l)
if n==0:
    print(x)
else:
    for i in  range(101):
        if x not in v:
            ans=x
            break
            
        if x+1 not in v:
            ans=x+1
            break
        if x-1 not in v:
            ans=x-1
            break
    print(ans)
        

        

### FIXED CODE ###

import collections
x,n=map(int,input().split())
if n!=0:
    l=list(map(int,input().split()))
    v=collections.Counter(l)
if n==0:
    print(x)
else:
    for i in  range(101):
        if x not in v:
            ans=x
            break
            
        if x-i not in v:
            ans=x-i
            break
        if x+i not in v:
            ans=x+i
            break
    print(ans)
text_list = input().split()
n = 0
for i in range(str(text_list[3])):
  if i >= int(text_list[0]):
    n += 1
  elif i >= int(text_list[0]) + int(text_list[1]):
    pass
  elif i >= int(test_list[0]) + int(text_list[1]) + int(text_list[2]):
    n -= 1
    
print(n)


### FIXED CODE ###

a, b, c, d = map(int, input().split())
if d <= a:
  print(d)
elif d <= a + b:
  print(a)
else:
  print(a-(d-(a+b)))
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]
ans%=mod
print(ans-1)


### FIXED CODE ###

N=int(input())
from collections import defaultdict
dic=defaultdict(int)
dic[(0,0)]=dic[(0,1)]=0
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]-1
ans%=mod
print(ans)
def find_root(edges, root, group, before, now):
    group.append(now)
    children = edges[now]
    for child in children:
        if child != before and child not in group:
            root, group = find_root(edges, root, group, now, child)
    return root, group
    
if __name__ == '__main__':
    N, K, L = map(int, input().split())
    roads = [[] for _ in range(N)]
    rails = [[] for _ in range(N)]
    road_roots = [None]*N
    rail_roots = [None]*N
    answer = [1]*N
        
    for i in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        roads[p].append(q)
        roads[q].append(p)
    
    for i in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        rails[r].append(s)
        rails[s].append(r)
    
    for i, r in enumerate(road_roots):
        if r is None:
            root, group = find_root(roads, i, [], -1, i)
            for g in group:
                road_roots[g] = root

    for i, r in enumerate(rail_roots):
        if r is None:
            root, group = find_root(rails, i, [], -1, i)
            for g in group:
                rail_roots[g] = root
    railroads=[[rail, road] for rail, road in zip(road_roots, rail_roots)]

    for n in range(N):
        for d in range(1, N-n):
            if railroads[n] == railroads[n+d]:
                answer[n] += 1 
                answer[n+d] += 1
    print(' '.join(list(map(str, answer))))

### FIXED CODE ###

from collections import defaultdict
def build_tree(N, edges):
    root_list = [i for i in range(N)]
    for p, q in edges:
        p -= 1
        q -= 1
        root_p = get_root(root_list, p)
        root_q = get_root(root_list, q)
        root_now = min(root_p, root_q, p)
        root_list[p] = root_now
        root_list[q] = root_now
        root_list[root_p] = root_now
        root_list[root_q] = root_now
    return root_list

def get_root(root_list, city):
    if root_list[city] == city:
        return city
    else: 
        root_list[city] = get_root(root_list, root_list[city])
        return root_list[city]

if __name__ == '__main__':
    N, K, L = map(int, input().split())
    roads = [None]*K
    rails = [None]*L
    for k in range(K):
        roads[k] = list(map(int, input().split()))
    for l in range(L):
        rails[l] = list(map(int, input().split()))
    
    
    '''N = 2*10**5
    L = int(N/2)
    K = int(N/2)
    roads = [None]*K
    rails = [None]*L
    for i in range(L):
        roads[i] = [2*i, 2*i+1]
    for i in range(K):
        rails[i] = [2*i, 2*i+1]'''
    
    road_roots = build_tree(N, roads)
    rail_roots = build_tree(N, rails)
    
    railroads = defaultdict(int)
    RR = []
    for n in range(N):
        rr = (get_root(road_roots, n), get_root(rail_roots, n))
        RR.append(rr)
        railroads[rr] += 1
    answer = [railroads[key] for key in RR]
    print(' '.join(map(str, answer)))
N = int(input())

import numpy as np

sum = 0

for n in range(1, int(np.sqrt(N))+1):
    x = (N - n ) // n
    if (N - n) % n == 0 and n**2 < N:
        sum += x

print(sum)

### FIXED CODE ###

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

print(N-K+1)
N = int(input())
import math
print(int(math.ceil(N / 1000) * 1000 - N)


### FIXED CODE ###

N = int(input())
import math
print(int(math.ceil(N / 1000) * 1000 - N))
n = int(input())
nums = [list(map(int,input().split()))for i in range(n)]


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(*key, record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True

    for i in range(101):
        for j in range(101):
            if (i, j) not in record:
                print(i, j, 1)
                exit()



### FIXED CODE ###

n = int(input())
nums = [list(map(int,input().split())) for i in range(n)]


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(key[0],key[1], record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True
    ndone = True
    for i in range(101):
        for j in range(101):
            if (i, j) not in record and ndone:
                print(i, j, 1)
                ndone = False
import math

def main():
    a, b, c = map(int, input().split())
    
    top = max([a, b, c])
    bot = min([a, b, c])
    global mid
    for x in [a, b, c]:
        if top != x and bot != x:
            mid = x
    count = 0
    
    count = top - mid
    bot += count
    mid += count
    
    if (top - bot) % 2 == 0:
        count += (top - bot) / 2 
    else:
        count += math.ceil((top - bot) / 2)+1
        
    print(int(count), end="")
    print()

if __name__ == '__main__':
    main()


### FIXED CODE ###

import math

def main():
    a, b, c = map(int, input().split())
    
    li = [a, b, c]
    top = max(li)
    top_index = li.index(top)
    bot = min(li)
    bot_index = li.index(bot)
    mid_index = calc_mid_index(top_index, bot_index)
    mid = li[mid_index]
    count = 0
    
    count = top - mid
    bot += count
    mid += count
    
    if (top - bot) % 2 == 0:
        count += (top - bot) / 2 
    else:
        count += math.ceil((top - bot) / 2) + 1
        
    print(int(count))

def calc_mid_index(top_index, bot_index):
    for i in range(3):
        if i != top_index and i != bot_index:
            return i



if __name__ == '__main__':
    main()
list = [a,b,c,d,e]
flag = 0

for first_num in list:
    for second_num in list:
        if (first_num - second_num) > abs(k):
          flag = 1
 
if flag == 0:
  print('Yay!')  
else:
  print(':(')
   

### FIXED CODE ###

a = input()
b = input()
c = input()
d = input()
e = input()
k = input()


list = [a,b,c,d,e]
flag = 0


for first_num in list:
    for second_num in list:
        if (int(first_num) - int(second_num)) > abs(int(k)):
          flag = 1

if flag == 0:
  print('Yay!')
else:
  print(':(')
#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

flag = 0
done = [0] * (N + 1)

root = []
ind = 0

ind = A[0]
root = [1]
done[1] = 1

while True:

    if done[ind]:
        flag = 1
        break
    done[ind] = 1

    root += [ind]
    ind = A[ind-1]

print("rootlen : ", len(root))
print("flag : ", flag)

if flag:
    if len(root) < K:
        left = root.index(ind) - 1
        loopcnt = len(root) - (root.index(ind))

        root2 = root[left+1:]
        print(root2[(K-(left+1)) % loopcnt])
    else:
        print(root[K])
else:
    print(root[K])


### FIXED CODE ###

#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

flag = 0
done = [0] * (N + 1)

root = []
ind = 0

ind = A[0]
root = [1]
done[1] = 1

while True:

    if done[ind]:
        flag = 1
        break
    done[ind] = 1

    root += [ind]
    ind = A[ind-1]

if flag:
    if len(root) <= K:
        left = root.index(ind) - 1
        loopcnt = len(root) - (root.index(ind))

        root2 = root[left+1:]
        print(root2[(K-(left+1)) % loopcnt])
    else:
        print(root[K])
else:
    print(root[K-1])
S = list(input())
ans = []
for i in range(1, len(S)-1):
    if S[i]=="A":
        ans.append(i)
        break
T = S[::-1]
for i in range(len(T)):
    if T[i]=="Z":
        ans.append(i)
        break
print((len(S)-ans[0])-ans[1])

### FIXED CODE ###

S = list(input())
ans = []
for i in range(len(S)):
    if S[i]=="A":
        ans.append(i)
        break
T = S[::-1]
for i in range(len(T)):
    if T[i]=="Z":
        ans.append(i)
        break
print((len(S)-ans[0])-ans[1])
N = int(input())
A = list(map(int, input().split()))

dp = [0]*N

cum = A[0]
for i in range(N):
    if i == 0:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = max(A[0],A[1])
        continue
    if i%2==0: #奇数の時
        cum += A[i]
        dp[i] = max(dp[i−1],dp[i-2]+A[i])

    if i%2==1: #偶数の時
        dp[i] = max(dp[i-2]+A[i],cum)

ans = dp[-1]


print(ans)
#print(*ans, sep='\n')

### FIXED CODE ###

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

dp = [0]*N

cum = A[0]
for i in range(N):
    if i == 0:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = max(A[0],A[1])
        continue
    if i%2==0: #奇数の時
        cum += A[i]
        dp[i] = max(dp[i-1],dp[i-2]+A[i])

    if i%2==1: #偶数の時
        dp[i] = max(dp[i-2]+A[i],cum)

ans = dp[-1]


print(ans)
#print(*ans, sep='\n')