Harryxun/stf_run huggingface dataset:
n=int(input())  
l=[] 
for i in range(len(str(n))): 
  l.append(int(n[i])) 
if((sum(l)%9)==0): 
  print("Yes") 
else: 
  print("No") 
  

### FIXED CODE ###

n=input() 
l=[] 
for i in range(len(str(n))): 
  l.append(int(n[i])) 
if((sum(l)%9)==0): 
  print("Yes") 
else: 
  print("No")
print(count(input(), '1'))

### FIXED CODE ###

print(input().count('1'))
n=int(raw_input())
last=n % 10
hon=[2,4,5,7,9]
pon=[0,1,6,8]
bon=[3]
if last in hon:
  print("hon")
if last in pon:
  print("pon")
if last in bon:
  print("bon")

### FIXED CODE ###

n=int(input())
last=n % 10
hon=[2,4,5,7,9]
pon=[0,1,6,8]
bon=[3]
if last in hon:
  print("hon")
if last in pon:
  print("pon")
if last in bon:
  print("bon")
N = int(input())
S = list(map(int,input().split()))
if len(set(S)) == 4:
    print('Four')
elif len(set(S)) == 3:
    print('Three')

### FIXED CODE ###

N = int(input())
S = list(map(str,input().split()))
if len(set(S)) == 4:
    print('Four')
elif len(set(S)) == 3:
    print('Three')
x, y, a, b, c = list(map(int, input().split(' ')))
p_list = sorted(list(map(int, input().split(' '))), reverse=True)
q_list = sorted(list(map(int, input().split(' '))), reverse=True)
r_list = sorted(list(map(int, input().split(' '))), reverse=True)

xy_list = sorted(p_list[:x] + q_list[:y])

i = 0
for r in range(c):
    if r_list[r] > xy_list[0]:
        i += 1
    else:
        break

if i == 0:
    print(sum(xy_list))
else:
    print(sum(xy_list[i:] + r_list[:i]))


### FIXED CODE ###

s = input()

s_list = [i for i in s]

if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
mapper={}
for i in range(H):
    for j in range(W):
        mapper[A[i][j]]=(i,j)

Q=int(input().strip())
L=[]
R=[]
dist={}
def search(l,r):
    if l==r:
        return 0
    if (l,r) in dist:
        return dist[l,r]
    else:
        if l+D==r:
            posl=mapper[l]
            posr=mapper[r]
            val= abs(posl[0]-posr[0])+abs(posl[1]-posr[1])
            dist[(l,l+D)]=val
            return val
        else:
            val=search(l,l+D)+search(l+D,r)
            dist[l,r]=val
            return val
for i in range(Q):
    cst=0
    l,r=map(int,input().split())
    print(search(l,r))

### FIXED CODE ###

# 解説読後
import sys
sys.setrecursionlimit(100000)
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
mapper={}
for i in range(H):
    for j in range(W):
        mapper[A[i][j]]=(i,j)

Q=int(input().strip())
dist=[0]*(H*W+1)
for i in range(1,H*W+1):
    if i<=D:
        dist[i] = 0
    else:
        pos1=mapper[i]
        pos2=mapper[i-D]
        dist[i]=dist[i-D]+abs(pos1[0]-pos2[0])+abs(pos1[1]-pos2[1])
for i in range(Q):
    cst=0
    l,r=map(int,input().split())
    print(dist[r]-dist[l])
n = int(input())
if n % 2 == 1:
    print(0)
else:
    count = 0
    n //= 2
    while n > 0:
        n//= 5
        count += n
	print(count)
        

### FIXED CODE ###

n = int(input())
if n % 2 == 1:
    print(0)
else:
    count = 0
    n //= 2
    while n > 0:
        n //= 5
        count += n
    print(count)
import math

N = int(input())
x = math.factorial(N)

ans=1
for i in range(2, 1+int(x**(1/2))):
    cnt = 1
    if x%i == 0:
        x = x//i
        cnt += 1
    else:
        break
    ans *= cnt
                
print(1 if N == 1 else ans*2%(10**9+7))

### FIXED CODE ###

import math

N = int(input())
x = math.factorial(N)

ans = 1
i = 2
while i <= x:
    cnt = 1
    while x%i == 0:
        x //= i
        cnt += 1
    ans *= cnt
    i += 1
                
print(ans%(10**9+7))
def main():
    n, k = list(map(int, input().split()))
    p = list(map(int, input().split()))
    
    s = []
    for i in range(len(p)-k):
        s.append((sum(p[i:i+k])+k)/2)    
    print(max(s))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import itertools as iter

def main():
    n, k = list(map(int, input().split()))
    p = [0]
    p.extend(list(iter.accumulate([(1+int(x))/2 for x in input().split()])))
    #print(p)
    
    s = []
    for i in range(n-k+1):
        s.append(p[i+k]-p[i])
    #print(s)
    print(max(s))
    
if __name__ == '__main__':
    main()
from collections import defaultdict

MOD = 998244353


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.sort(reverse=True)
    total = sum(A)
    half = -(-total//2)
    dp1 = [defaultdict(lambda: 0) for _ in range(2)]
    dp1[0][0] = 1
    dp2 = [defaultdict(lambda: 0) for _ in range(2)]
    dp2[0][0] = 1
    for i in range(N):
        dp1[(i+1) & 1] = defaultdict(lambda: 0)
        dp2[(i+1) & 1] = defaultdict(lambda: 0)
        for j in dp1[i & 1]:
            nj = min(j+A[i], half+1)
            dp1[(i+1) & 1][j] = (dp1[(i+1) & 1][j] + dp1[i & 1][j] * 2) % MOD
            dp1[(i+1) & 1][nj] = (dp1[(i+1) & 1][nj] + dp1[i & 1][j]) % MOD
            dp2[(i+1) & 1][j] = (dp2[(i+1) & 1][j] + dp2[i & 1][j]) % MOD
            dp2[(i+1) & 1][nj] = (dp2[(i+1) & 1][nj] + dp2[i & 1][j]) % MOD
    ans = (3**N) % MOD
    for t in dp1[N & 1]:
        if t >= half:
            ans = (ans - dp1[N & 1][t] * 3) % MOD
            if total % 2 == 0 and t == half:
                ans = (ans + dp2[N & 1][t] * 3) % MOD
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import math


def main():
    N = int(input())
    x = math.floor(math.sqrt(N*2))
    if x * (x+1) != N*2:
        print("No")
        return
    print("Yes")
    print(x+1)
    s = [[] for _ in range(x+1)]
    counter = 1
    for i in range(x+1):
        for j in range(i+1, x+1):
            s[i].append(counter)
            s[j].append(counter)
            counter += 1
    for i in range(x+1):
        print(len(s[i]), *s[i])


if __name__ == "__main__":
    main()
from bisect import bisect_right
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())))
cnt = M*V
B = [[A[i],i] for i in range(N)]
for i in range(N):
    if cnt>=M:
        B[i][0] += M
        cnt -= M
    else:break
B = sorted(B,key=lambda x:x[1],reverse=True)
B = sorted(B,key=lambda x:x[0],reverse=True)
ind = B[P-1][1]
cur = P-1
while True:
    if B[cur+1][0]==B[cur][0]:
        ind = B[cur+1][1]
        cur += 1
    else:break
low = -1
high = ind
while high-low>1:
    mid = (high+low)//2
    cnt = M*V
    B = A[:]
    for i in range(mid+1):
        B[i] += M
        cnt -= M
    b = B[mid]
    for i in range(mid+1,N):
        if B[i]<b and cnt>=b-B[i]:
            B[i] += b-B[i]
            cnt -= b-B[i]
        else:break
    for i in range(N-1,-1,-1):
        if cnt>=M:
            B[i] += M
            cnt -= M
        elif 0<cnt<M:
            B[i] += cnt
            break
    ind = bisect_right(B,b)
    if N-ind<P:
        high = mid
    else:
        low = mid
print(N-high)

### FIXED CODE ###

from bisect import bisect_left,bisect_right
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())))
low = -1
high = A[-1]+M
while high-low>1:
    mid = (low+high)//2
    indL = bisect_left(A,mid-M)
    indR = bisect_right(A,mid)
    if indL>N-P:
        high = mid
        continue
    if indR<N-P+1:
        low = mid
        continue
    tot = M*V
    i = indL
    while i<N-P+1:
        if tot-(mid-A[i])<0:break
        tot -= mid-A[i]
        i += 1
    if i<N-P+1 or 0<=tot<=M*(P-1+indL):
        high = mid
    else:
        low = mid
ind = bisect_left(A,high-M)
print(N-ind)
s = input()
q = int(input())
for _ in range(q):
  t = input()
  if t[0]=='1':
    s = s[::-1]
  else:
    if t[2]=='1':
      s = t[4:] + s
    else:
      s = s + t[4:]
print(s)

### FIXED CODE ###

def main():
  a,b=map(int, input().split())
  for i in range(1251):
    if int(i*0.08)==a and int(i*0.1)==b:
      return i
  return -1
  
if __name__ == '__main__':
  print(main())
A = list(map(int,input().split()))

LCM = A[0]
for i in range(0,N-1,1):
    #LCM = LCM*A[i+1]/math.gcd(A[i+1],LCM)
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]=(LCM*pow(A[i],MOD-2,MOD))%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i]%MOD + ans%MOD)%MOD

print(ans)

### FIXED CODE ###

def lcm(X,Y):
    x=X
    y=Y
    if y>x:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return X*Y//y

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

LCM = A[0]
for i in range(0,N-1,1):
    LCM = lcm(LCM,A[i+1])
B = [0 for i in range(0,N,1)]
for i in range(0,N,1):
    B[i]= (LCM%MOD)*pow(A[i],MOD-2,MOD)%MOD

ans = 0
for i in range(0,N,1):
    ans = (B[i] + ans)%MOD

print(ans)
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
mxlba=0
for i in xrange(n):
    mxlba=max(mxlba,len(bin(a[i])[2:]))
cnt=[0]*mxlba
for i in xrange(n):
    bit=bin(a[i])[2:]
    lb=len(bit)
    for j in xrange(lb-1,-1,-1):
        if bit[j]=="1":
            cnt[lb-1-j]+=1
            break

axor=0
for i in xrange(n):
    axor^=a[i]

axor=bin(axor)[2:]
ans=0
i=-1
while i<mxlba:
    i+=1
    if axor[i]=="1":
        if cnt[i]==0:
            print(-1)
            exit()
        else:
            ans+=1
            cnt[i]-=1
            if mxlba-i-1==0:
                break
            tmp=int("1"*(mxlba-i-1),2)
            axor=int(axor,2)^tmp
            axor=bin(axor)[2:]
print(ans)


### FIXED CODE ###

n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
mxlba=0
for i in xrange(n):
    mxlba=max(mxlba,len(bin(a[i])[2:]))

exist=[False]*(mxlba+1000)
for i in xrange(n):
    bit=bin(a[i])[2:]
    lb=len(bit)
    for j in xrange(lb-1,-1,-1):
        if bit[j]=="1":
            exist[lb-1-j]=True
            break

axor=0
for i in xrange(n):
    axor^=a[i]
if axor==0:
    print(0)
    exit()
axor=bin(axor)[2:]
la=len(axor)
ans=0
i=0
while i<la:
    if axor[i]=="1":
        if not exist[la-i-1]:
            print(-1)
            exit()
        else:
            ans+=1
            if la-i-1==0:
                break
            tmp=int("1"*(la-i-1),2)
            axor=int(axor,2)^tmp
            axor=bin(axor)[2:]
    i+=1

print(ans)
a = int(input())
b = int(input())
c = int(input())
d = int(input())

ab_count = a + b
cd_count = c + d

if ab_count > cd_count:
	print('left')
else if ab_count == cd_count:
	print('balanced')
elif:
	print('light')

### FIXED CODE ###

a,b,c,d = map(int,input().split(" "))

if a+b > c+d:
	print("Left")
elif a+b == c+d:
	print("Balanced")
else:
	print("Right")
#include<stdio.h>
int main(void){long n;scanf("%ld",&n);printf("%ld\n",n*(n-1)/2);}

### FIXED CODE ###

n=int(input());print(n*(n-1)//2)
def gcd(a, b):
  if b==0:
    return a
  return gcd(b, a%b)

def main():
  a,b = map(int, input().split())
  g = gcd(a,b)
  N = int(g**0.5)
  ans = 1
  for i in range(2, N+1):
    if g%i==0:
	  ans += 1
    while(g%i==0):
      g /= i
  if g != 1:
    ans += 1
  print(ans)

main()

### FIXED CODE ###

def gcd(a, b):
  if b==0:
    return a
  return gcd(b, a%b)

a,b = map(int, input().split())
g = gcd(a,b)
N = int(g**0.5)
ans = 1
for i in range(2, N+1):
  if g%i==0:
    ans += 1
  while(g%i==0):
    g /= i
if g != 1:
  ans += 1
print(ans)
import numpy as np
p = 998244353

N,S = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
dp = np.zeros(S+1)
dp[0] = 1
for a in A:
  if S < a:
    dp = 2*dp
    continue
  tmp = 2*dp
  dp = np.append(np.zeros(a),dp[:S-a+1])
  dp += tmp
  dp %= p
print(int(dp[S]))

### FIXED CODE ###

import numpy as np
p = 998244353

N,S = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
dp = np.zeros(S+1)
dp[0] = 1
for a in A:
  if S < a:
    dp *= 2
    dp %= p
    continue
  tmp = 2*dp
  dp = np.append(np.zeros(a),dp[:S-a+1])
  dp += tmp
  dp %= p
print(int(dp[S]))
a, b = input().split('\n')
x = [int(i) for i in b.split()]
print(min(x), max(x), sum(x))


### FIXED CODE ###

n = int(input())
x = [int(v) for v in input().split()]
print(min(x), max(x), sum(x))
def main():
    A, B = map(int, input())
    if A == B:
        M = A + B
    elif A > B:
        M = A + (A - 1)
    else:
        M = B + (B - 1)
    print(M)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    A, B = map(int, input().split())
    if A == B:
        M = A + B
    elif A > B:
        M = A + (A - 1)
    else:
        M = B + (B - 1)
    print(M)

if __name__ == "__main__":
    main()
# D - Match Matching

N, M = map(int, input().split())
A = list(int(x) for x in input().split())
match_list = [(0, 6), (1, 2), (2, 5), (3, 5), (4, 4), (5, 5), (6, 6), (7, 3), (8, 7), (9, 6)]
MA = []
for a in A:
    MA.append(MATCH[a])
MA.sort(key=lambda x: x[1])

def dfs(tmp, s):
    global ans
    if s == N:
        ans = max(ans, tmp)    
    for ma in MA:
        if s+ma[1] <= N:
            tmp = tmp*10 + ma[0]
            dfs(tmp, s + ma[1])
            tmp //= 10

tmp = 0
ans = 0
dfs(tmp, 0)
print(ans)

### FIXED CODE ###

# D - Match Matching

N, M = map(int, input().split())
A = list(int(x) for x in input().split())
match_list = [('0', 6), ('1', 2), ('2', 5), ('3', 5), ('4', 4), ('5', 5), ('6', 6), ('7', 3), ('8', 7), ('9', 6)]
MA = []
for a in A:
    MA.append(match_list[a])
MA.sort(key=lambda x: x[0], reverse=True)

# dp[i] := i本のマッチを使って作れる最大桁数
dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
    for j in range(M):
        if i-MA[j][1] >= 0:
            dp[i] = max(dp[i], dp[i-MA[j][1]] + 1)

remain_keta = dp[N]
remain_match = N
ans = ''
for i in range(dp[N]):
    for ma in MA:
        # 大きい数字から一桁使った時に、
        # 残り桁がちょうど一桁減っている場合
        if remain_match >= ma[1] and dp[remain_match - ma[1]] == remain_keta - 1:
            ans +=  ma[0]
            remain_keta -= 1
            remain_match -= ma[1]
            break

print(ans)
upperbase,bottom,high = map(int,input().split())
print((upperbase + bottom) * high /　2)

### FIXED CODE ###

lis = [int(input()) for i in range(3)]
print((lis[0]+lis[1]) * lis[2] // 2)
for i in range(3000):
  a = input().split()
  x = int(a[0])
  y = int(a[1])
  if x == y:
    print(x,y)
  elif x < y:
    print(x,y)
  else:
    print(y,x)



### FIXED CODE ###

for i in range(3000):
  a = input().split()
  x = int(a[0])
  y = int(a[1])
  if x + y == 0:
    break
  elif x < y:
    print(x,y)
  elif y < x:
    print(y,x)
  else:
    print(x,y)
a = [input() for i in range(2)]

text = a[0]
iter = int(a[1])

text_list = list(text)
ren = []
start = text_list[0]
a = 0
for i in range(1,len(text_list)):
  if text_list[i] == start:
    a += 1
    if i == len(text_list)-1:
      ren.append(a)
  else:
    start = text_list[i]
    ren.append(a)
    a = 0

for i in range(len(ren)):
  ren[i] += 1

ans = 0
if text_list[0] == text_list[-1]:
  if ren[0] % 2 == 1 and ren[-1] % 2 == 1:
    for r in ren:
      ans += (r//2)
    ans *= iter
    ans += iter-1
  else:
    for r in ren:
      ans += (r//2)
    ans *= iter    
else:
  for r in ren:
    ans += (r//2)
  ans *= iter

print(ans)
    
  

### FIXED CODE ###

a = [input() for i in range(2)]

text = a[0]
iter = int(a[1])

text_list = list(text)
ren = []
start = text_list[0]
a = 0
for i in range(1,len(text_list)):
  if text_list[i] == start:
    a += 1
    if i == len(text_list)-1:
      ren.append(a)
  else:
    start = text_list[i]
    ren.append(a)
    a = 0

for i in range(len(ren)):
  ren[i] += 1

if ren == []:
  ren = [1]
  
ans = 0
if len(ren) == 1:
  ans = ren[0] * iter // 2
elif text_list[0] == text_list[-1]:
  if ren[0] % 2 == 1 and ren[-1] % 2 == 1:
    for r in ren:
      ans += (r//2)
    ans *= iter
    ans += iter-1
  else:
    for r in ren:
      ans += (r//2)
    ans *= iter    
else:
  for r in ren:
    ans += (r//2)
  ans *= iter

print(ans)
K, N = map(int,input().split())
A = list(map(int, input().split()))
sub = [A[0]+K-A[N-1]]
for _ in range(N-1):
    p = A.pop()
    sub.append(K-p)
    K = p
sub.remove(max(sub))
print(sum(sub))

### FIXED CODE ###

S = input()
ans = 'No'
if S[2] == S[3] and S[4] == S[5]:
   ans = 'Yes'
print(ans)
N = int(input())
A = input().split()
for i in range(N):
  count=0
  for j in range(N-1):
	if i+1==int(A[j]):
	  count+=1
  print(count)

### FIXED CODE ###

N = int(input())
A =[int(n) for n in input().split()]
b = [0]*N
for i in A:
  b[i-1]+=1
for i in range(N):
  print(b[i])
import bisect
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    S = list(input())

    a_ord = ord('a')
    z_ord = ord('z')

    set_list = [[] for _ in range(z_ord+1)]
    for i in range(N):
        s = S[i]
        set_list[ord(s)].append(i)

    Q = int(input())
    for q in range(Q):
        ipt = input().split()
        if ipt[0] == "1":
            i,c = int(ipt[1]), ipt[2]
            j = ord(S[i-1])

            if j == ord(c): continue
            set_list[j].remove(i-1)
            bisect.insort_left(set_list[ord(c)],i-1)
            S[i-1] = c
            # print(set_list[])

        else:
            l,r = int(ipt[1]), int(ipt[2])
            ans = 0
            # if l == r:
            #     print(1)
            #     continue

            for i in range(a_ord,z_ord+1):
                st = set_list[i]
                if not len(st) > 0: continue

                # print(i,set_list[i])
                l_p = bisect.bisect_left(st,l-1)
                r_p = bisect.bisect_right(st,r-1)

                # print(l-1,r-1,l_p,r_p)
                if l_p < r_p:
                    ans += 1

            # print(ans,"____")
            print(ans)



if __name__ == "__main__":
  main()


### FIXED CODE ###

import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    print(math.ceil(N/2))

if __name__ == "__main__":
  main()
N,Y = input().split()
N = int(N)
Y_k=int(Y)/1000

for i in range(N+1):
    for j in range(N+1 - i):
        k = N-i-j
        if 10*i + 5*j + 1*k == Y_k:
            answer = [i,j,k]

print(answer[0],answer[1],answer[2])


### FIXED CODE ###

N,Y = input().split()
N = int(N)
Y_k=int(Y)/1000

answer = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1 - i):
        k = N-i-j
        if 10*i + 5*j + 1*k == Y_k:
            answer = [i,j,k]

print(answer[0],answer[1],answer[2])
data = list(map(int(),input().split()))
a = data[0]
b = data[1]
c = data[2]
d = data[3]
 
print(min(a,b)+min(c,d))

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a,b)+min(c,d))
k,n=map(int,input().split())
a=[map(int,input().split()]
j=[k-a[n-1]]
for i in range(n-1):
    j.append(a[i+1]-a[i])
print(k-max(j))


### FIXED CODE ###

k,n=map(int,input().split())
a=list(map(int,input().split()))
j=[int(k+a[0]-a[-1])]
for i in range(n-1):
    j.append(a[i+1]-a[i])
print(k-max(j))
N=int(input())
A=list(map(int,input().split()))
c=0
for i in N:
  c+=1/A[N]
c=1/c
print(c)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
c=[1/i for i in A]
print(1/sum(c))
n=int(input())
tako=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(1,n+1):
        ans+=tako[i]*tako[j]
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
if a-b*2>0:
    print(a-b*2)
else:
    print(0)
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

print(gcd_list(A))


### FIXED CODE ###

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

print(gcd_list(A))
n = int(input())
l = [input() for i in range(n)]

l = set(l)
l = list(l)
print(sum(l))

### FIXED CODE ###

n = int(input())
l = [input() for i in range(n)]
 
l = set(l)
l = list(l)
print(len(l))
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = -10**18

for i in range(N):
    tmp_score = 0
    pos = i
    # ループになるまで移動
    for j in range(1, N+1):
        pos = P[pos]-1
        if K >= j:
            tmp_score += C[pos]
            ans = max(ans,tmp_score)
        if pos == i:
            break
    
    div = K // j
    mod = K % j

        if K >= j:
        tmp_score *= div
        ans = max(ans,tmp_score)
        # 端数ぶん移動
        # mod=0 のときは移動しない
        for _ in range(1, mod+1):
            pos = P[pos]-1
            tmp_score += C[pos]
            ans = max(ans,tmp_score)

print(ans)

### FIXED CODE ###

S = input()
ans = 0
if "RRR" in S:
    ans = 3
elif "RR" in S:
    ans = 2
elif "R" in S:
    ans = 1
else:
    ans = 0
print(ans)
n, m = map(int, input().split())

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



def solve():
    global n, m, sc
    ans = [None] * n
    for s, c in sc:
        if s > n:
            return -1
        if ans[s-1] is None:
            ans[s-1] = c
            continue
        if ans[s-1] != c:
            return -1
        if s+1 == n and c == 0:
            return -1
    ans = [x or 0 for x in ans]
    ans = list(map(str, ans))
    return ''.join(ans)

print(solve())

### FIXED CODE ###

n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())
D = int(input())
# with open("sample1.in") as f:

last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = 0
# opened = []  #開催したやつを保存
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
        # スコア計算
    score_max = 0
    score_index = 0
    for j in range(26):

        if j == 0:
            score_max = s[i][j]+(i + 1 - last[j]) * \
                c[j]  # - (i - last[j]) * c[j]
            for k in range(26):
                score_max -= (i + 1 - last[k]) * c[k]
            score_index = 0
        else:
            score = s[i][j]+(i+1 - last[j]) * c[j]
            for k in range(26):
                score -= (i + 1 - last[k]) * c[k]

            if score_max < score:
                score_max = score
                score_index = j
            #print(i, j, score)
    result.append(score_index)
    #print(score_index, score)
    last[score_index] = i + 1
    toral += score
    # print(a.index(max(a)))
# print(total)
for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i]+1)


### FIXED CODE ###

# coding: utf-8
# Your code here!

D = int(input())
# with open("sample1.in") as f:

#c = [0 for i in range(26)]
s = [[0 for j in range(27)] for i in range(D)]
c = list(map(int, input().split(" ")))
result=[]
# for i in range(26):
#    c[i] = int(input())
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
    result.append(a.index(max(a))+1)
    #print(a.index(max(a)))

for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i])
n,k=map(int,input().split())
p=[int(i)-1for i in input().split()]
c=list(map(int,input().split()))
ans=-10**9
for i in range(n):
    start=i
    cycle=[0]
    for _ in range(n):
        i=p[i]
        cycle+=[cycle[-1]+c[i]]
        if i==start:break
    S,L=cycle[-1],len(cycle)-1
    if S<0:ans=max(ans,max(cycle[1:k%L+1]))
    else:ans=max(ans,k//L*S+max(cycle[:k%L+1]))
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
p=[int(i)-1for i in input().split()]
c=list(map(int,input().split()))
ans=-10**9
for i in range(n):
    start=i
    cycle=[0]
    for _ in range(n):
        i=p[i]
        cycle+=[cycle[-1]+c[i]]
        if i==start:break
    S,L=cycle[-1],len(cycle)-1
    if S<=0:ans=max(ans,max(cycle[1:k+1]))
    else:
        if k>L:ans=max(ans,(k//L-1)*S+max(max(cycle),max(cycle[:k%L+1])+S)) 
        else:ans=max(ans,max(cycle[:k+1]))
print(ans)
n=int(input())
t=[int(i)for i in input().split()]
m=int(input())
T=sum(t)
for i in' '*m:p,x=LI();print(T+x-t[p-1])

### FIXED CODE ###

I=input
I()
t=[int(i)for i in I().split()]
for i in' '*int(input()):p,x=map(int,I().split());print(sum(t)+x-t[p-1])