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

from itertools import accumulate

def max_from_acc(A, b):
    r = -10**9-1
    acc = [0] + list(accumulate(A + A[:b]))
    for i in range(len(A)):
        for j in range(1, b+1):
            r = max(r, acc[i+j]-acc[i])
    return r

n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [p - 1 for p in P]

checked = [False] * n
loops = []
for i in range(n):
    if checked[i]:
        continue
    checked[i] = True
    tmp = [i]
    next = P[i]
    while next != i:
        tmp.append(next)
        checked[next] = True
        next = P[next]
    loops.append(tmp)

# print(loops)

ans = -10**9-1
for loop in loops:
    t =len(loop)
    div, mod = divmod(k, t)
    if mod == 0:
        mod = t
        div -= 1
    C_loop = [C[p] for p in loop]
    loop_score = sum(C_loop)

    if t >=k:
        ans = max(ans, max_from_acc(C_loop, k))
    else:
        if loop_score > 0:
            ans = max(ans, max_from_acc(C_loop, mod)+loop_score*div)
        else:
            ans = max(ans, max_from_acc(C_loop, t))

print(ans)

### FIXED CODE ###

from itertools import accumulate

n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [p - 1 for p in P]

check = [False] * n
loops = []

for i in range(n):
    if check[i]:
        continue
    check[i] = True
    next = P[i]
    tmp = [i]
    while next != i:
        check[next] = True
        tmp.append(next)
        next = P[next]
    loops.append(tmp)

ans = int(-1e9)

for loop in loops:

    num = len(loop)
    div = k // num
    r = k % num
    if r == 0:
        r = num
        div -= 1
    L = [C[p] for p in loop]
    ans_tmp = int(-1e9)
    sumL = sum(L)
    by_loop = max(sumL, 0) * div
    if k > num and sumL <= 0:
        r = num
    L += L[:r]
    ACC = [0] + list(accumulate(L))

    for i in range(num):
        for j in range(i + 1, i + r + 1):
            ans_tmp = max(ans_tmp, ACC[j] - ACC[i] + by_loop)

    ans = max(ans, ans_tmp)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2*(10**5)+1)
def make_tree(node):
    for i in tree_list[node]:
        if i != tree_dic[node]["p"]:
            tree_dic[node]["c"].append(i)
            tree_dic[i]["p"] = node
            make_tree(i)

n, q = map(int, input().split())
tree_list = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    tree_list[a-1].append(b-1)
    tree_list[b-1].append(a-1)

tree_dic = {} #tree_dic = {i:{p:j, c:[k, l]}}
for i in range(n):
    tree_dic[i] = {"p": None, "c": [], "x": 0}

make_tree(0)

for i in range(q):
    p, x = map(int, input().split())
    tree_dic[p-1]["x"] += x
# print(tree_dic)

x_list = [0 for _ in range(n)]

import queue
next_visit = queue.Queue()
next_visit.put(0)
while not next_visit.empty():
    i = next_visit.get()
    tmp = tree_dic[i]["x"]
    if i != 0:
        tmp += x_list[tree_dic[i]["p"]]
    x_list[i] = tmp
    for j in tree_dic[i]["c"]:
        next_visit.put(j)

for i in x_list:
    print(i, end=" ")

### FIXED CODE ###

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

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree_candidate[a].append(b)
    tree_candidate[b].append(a)

tree = [[] for _ in range(n)]

app = set([0])

import queue
next = queue.Queue()
next.put(0)
# print(tree_candidate)
while not next.empty():
    i = next.get()
    for j in tree_candidate[i]:
        if not j in app:
            tree[i].append(j)
            app.add(j)
            next.put(j)

cnts = [0 for _ in range(n)]
for i in range(q):
    p, x = map(int, input().split())
    cnts[p-1] += x
    # print(x, p, tree[p-1], cnts)

next = queue.Queue()
next.put(0)

while not next.empty():
    i = next.get()
    for j in tree[i]:
        cnts[j] += cnts[i]
        next.put(j)

for i in cnts:
    print(i, end=' ')
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)
useA = [a.pop(0)]
useB = [b.pop(0)]
useC = [c.pop(0)]
if len(a) == 0:
  a.append(0)
if len(b) == 0:
  b.append(0)
if len(c) == 0:
  c.append(0)
while True:
  if a[0] == b[0] == c[0] == 0:
    break
  if a[0] >= b[0] and a[0] >= c[0]:
    useA.append(a.pop(0))
    if len(a) == 0:
      a.append(0)
  elif b[0] >= a[0] and b[0] >= c[0]:
    useB.append(b.pop(0))
    if len(b) == 0:
      b.append(0)
  elif c[0] >= b[0] and c[0] >= a[0]:
    useC.append(c.pop(0))
    if len(c) == 0:
      c.append(0)
#  print( len(useA) * len(useB) * len(useC))
  if 1000*k**2 <= len(useA) * len(useB) * len(useC):
    break
ans = []
#print(useA, useB, useC)
for i in range(len(useA)):
  for j in range(len(useB)):
    for m in range(len(useC)):
      ans.append(useA[i] + useB[j] + useC[m])
ans.sort(reverse = True)
for i in range(k):
  print(ans[i])

### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)
def search(a, b):
  ret = []
  al = len(a)
  bl = len(b)
  for i in range(min(al, k)):
    for j in range(min(bl, k-i)):
      ret.append(a[i] + b[j])
  ret.sort(reverse = True)
  return ret
d = search(a, b)      
e = search(c, d)    

for i in range(k):
  print(e[i])
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    tmp = input()
    if tmp not in S:
        S.append(tmp)

print(len(S))

### FIXED CODE ###

N = int(input())
S = set()
for i in range(N):
    S.add(input())

print(len(S))
### BUGGY CODE ###

import math

N = int(input())
a = sorted(list(map(int,input().split())))

count = 0



while(a!=[]):
    temp = a[-1]
    a.pop(-1)
    b=2**math.floor(math.log2(temp))
    if a ==[]:
        break
    if 2*b-temp in a:
        count += 1
        a.pop(a.index(2*b-temp))
    
print(count)



### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
b = {}
for i in range(len(a)):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1
twins = []
now = 1
while now <= a[-1]:
    now *= 2
    twins.append(now)
for i in range(len(a) - 1, -1, -1):
    tmpa = 0
    if  b[a[i]] == 0:
        continue
    for j in range(len(twins) - 1, -1, -1):
        if twins[j] <= a[i]:
            break
        tmpa = twins[j] - a[i]
    if tmpa == a[i]:
        if b[tmpa] >= 2:
            b[tmpa] -= 2
    elif tmpa in b and b[tmpa] != 0:
        b[tmpa] -= 1
        b[a[i]] -= 1
countb = 0
for i in b:
    countb += b[i]
print((n - countb) // 2)
### BUGGY CODE ###

n,m = map(int, input().split())
l = [int(input()) for i in range(m)]
ll = [0]*(n+2)
ll[1] = 1
for i in range(2,n+2):
    if not i-1 in l:
        ll[i] = ll[i-1] + ll[i - 2]
print(ll[-1] % 1000000007)


### FIXED CODE ###

n,m = map(int, input().split())
u = [0]*(n+1)
for i in range(m):
    u[int(input())] = 1
ll = [0]*(n+2)
ll[1] = 1
for i in range(2,n+2):
    if not u[i-1]:
        ll[i] = ll[i-1] + ll[i - 2]
print(ll[-1] % 1000000007)
### BUGGY CODE ###

#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools


def input_int_list_with_length(length=None):
    if length == None:
        length = int(input())
    return list(map(int, input().split()))[:length]


def solve(N, A):
    ans = 0
    for i in range(N):
        for j in range(i, N):
            if j-i == A[i]+A[j]:
                ans += 1
    print(ans)


def main():
    A = input_int_list_with_length()
    solve(len(A), A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools


def input_int_list_with_length(length=None):
    if length == None:
        length = int(input())
    return list(map(int, input().split()))[:length]


def solve(N, A):
    ans = 0
    L = {}
    for i in range(N):
        l = i+A[i]
        if l in L:
            L[l] += 1
        else:
            L[l] = 1
    for i in range(N):
        r = i-A[i]
        if r in L:
            ans += L[r]

    print(ans)


def main():
    A = input_int_list_with_length()
    solve(len(A), A)


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

H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

dp = [0]*(H+1)

for i in range(1,H+1):
    dp[i] = min(dp[max(0,i-a)]+b for a,b in AB)
    
print(dp[H])

### FIXED CODE ###

H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
h,w,k = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

from itertools import *
ans=10**10
import copy
for tmp in list(product([True,False], repeat=h-1)):
    num_sp = sum(tmp)+1
    cnt=[0]*num_sp
    nxt_cnt=[0]*num_sp
    last_spl=-1
    ok=True

 #   print(tmp)
    cur_ans=sum(tmp)
    for i in range(w):
        for j in range(h):
            spl = sum(tmp[:j])
            nxt_cnt[spl] += int(l[j][i])
            cnt[spl] += int(l[j][i])

        if max(cnt) > k:
#            print("split",i,cnt)
            cur_ans+=1
            cnt=copy.deepcopy(nxt_cnt)
            if last_spl+1 == i or max(nxt_cnt)>k:
                ok=False
                break
            last_spl=i-1
        nxt_cnt=[0]*num_sp
        if not ok:
            break
    if ok:
        ans=min(ans,cur_ans)

#    print("  ",cur_ans,ok)
print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline
h,w,k = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

from itertools import *
ans=10**10
import copy
for tmp in list(product([True,False], repeat=h-1)):
    num_sp = sum(tmp)+1
    cnt=[0]*num_sp
    nxt_cnt=[0]*num_sp
    last_spl=-1
    ok=True

    spl_l=[]
    for aaa in range(h):
        spl_l.append(sum(tmp[:aaa]))
    cur_ans=sum(tmp)
    for i in range(w):
        for j in range(h):
            spl = spl_l[j]
            nxt_cnt[spl] += int(l[j][i])
            cnt[spl] += int(l[j][i])

        if max(cnt) > k:
            cur_ans+=1
            cnt=copy.copy(nxt_cnt)
            if last_spl+1 == i or max(nxt_cnt)>k:
                ok=False
                break
            last_spl=i-1
        nxt_cnt=[0]*num_sp
        if not ok:
            break
    if ok:
        ans=min(ans,cur_ans)

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

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
if X<Y and X<Z:
  X,Z=Z,X
  A,C=C,A
elif Y<X and Y<Z:
  Y,Z=Z,Y
  B,C=C,Y
C=sorted(C,reverse=True)
k=min(K,X*Y)
AB=sorted([a+b for a in A for b in B],reverse=True)[:k]
ABC=sorted([ab+c for ab in AB for c in C[:K]],reverse=True)[:K]
for x in ABC:
  print(x)


### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
ans=[]
for i in range(X):
  if i+1>K:
    break
  for j in range(Y):
    if (i+1)*(j+1)>K:
      break
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)>K:
        break
      ans.append(A[i]+B[j]+C[k])
ans=sorted(ans,reverse=True)
for a in ans[:K]:
  print(a)
### BUGGY CODE ###

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

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    si.strip("G")
    si.strip("T")
    cntli.append(si.count("AC"))

for p in cntli:
    print(p)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

d,g = map(int,input().split())

p = []

for i in range(d):
    p.append(list(map(int,input().split())))

nums = []

from itertools import permutations
from math import ceil

for perm in permutations(range(d)):
    s = g
    num = 0
    for i in range(d):
        j = perm[i]
        if s > 100*(j+1)*p[j][0] + p[j][1]:
            s -= 100*(j+1)*p[j][0] + p[j][1]
            num += p[j][0]
        else:
            if s <= 100*(j+1)*(p[j][0] - 1):
                num += ceil(s / (100*(j+1)))
            else:
                num += p[j][0]
            s=0
        if s<=0:
            break
    nums.append(num)

print(min(nums))

### FIXED CODE ###

d,g = map(int,input().split())

p = []

for i in range(d):
    p.append(list(map(int,input().split())))

from itertools import product
from math import ceil

ans = 1e09

for c in product([0,1],repeat=d):
    score = 0
    num = 0
    ind = 0
    for i in range(d):
        if c[i] == 1:
            score += p[i][0]*100*(i+1) + p[i][1]
            num += p[i][0]
        else:
            ind = max(i,ind)
    
    if g - score <= 0:
        ans = min(ans,num)
    elif g - score <= (p[ind][0]-1)*100*(ind+1):
        num += ceil((g-score)/(100*(ind+1)))
        ans = min(ans,num)
print(ans)
### BUGGY CODE ###

N = int(input())
ans = 1

for i in range(2,N+1):
	ans *= i
print(ans % (10 ** 9 + 7))

### FIXED CODE ###

N = int(input())
ans = 1
for i in range(2,N+1):
  ans = ans * i % (10 ** 9 + 7)

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

from collections import Counter
s = input()

ans = 0
mods = []
x = int(s)%2019
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)%2019
    a = x%2019
    mods.append(a)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

### FIXED CODE ###

from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)
### BUGGY CODE ###

S = input()
ans = 0
for i in range(len(S)):
    s = S[i]
    for j in range(i+1,len(S)):
        s += S[j]
        #print(s)
        if int(s)%2019==0:
            ans += 1
print(ans)

### FIXED CODE ###

S = input()
dp = [0 for i in range(2019)]
dp[0] = 1

num = 0
for i,j in enumerate(S[::-1]):
    num += int(j)*(pow(10,i,2019))
    dp[num%2019] += 1

ans = 0
for m in dp:
    if m >= 2:
        ans += int(m*(m-1)/2)
print(ans)
### BUGGY CODE ###

def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    inf = 1 << 30
    L = 30

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

    ps = []
    coef_0 = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a == 0:
            coef_0.append(b + 1)
        else:
            ps.append((a / (b + 1), a, b))  # namedtupleやめた,sort_key,coef,const

    ps.sort(key=itemgetter(0), reverse=True)
    coef_0.sort()

    dp = [inf] * (L + 1)
    dp[0] = 0
    for _, coef, const in ps:
        for visited in reversed(range(L)):
            dp[visited + 1] = min(
                dp[visited + 1],
                (dp[visited] + 1) * (coef + 1) + const
            )

    def accumulate(a):
        s = 0
        yield s  # start=x->0
        for x in a:
            s += x
            yield s

    *acc, = accumulate(coef_0)

    ans = max(k for k in range(L + 1) if dp[k] <= T)
    cnt = len(acc) - 1
    for visited, consumption_time in enumerate(dp):
        rest = T - consumption_time
        if rest < 0: continue  # le->lt
        while cnt >= 0 and acc[cnt] > rest:  # bisect_right->しゃくとり
            cnt -= 1
        if cnt == 0:
            break  # 途中で離脱するようにした
        ans = max(ans, visited + cnt)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/hitachi2020/submissions/10704509

def main():
    import sys
    input = sys.stdin.readline

    inf = 1 << 30
    L = 30

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

    ps = []
    coef_0 = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a == 0:
            coef_0.append(b + 1)
        else:
            ps.append((a, b))  # namedtupleやめた,coef,const

    ps.sort(key=lambda p: p[0] / (p[1] + 1), reverse=True)
    coef_0.sort()

    dp = [inf] * (L + 1)
    dp[0] = 0
    for coef, const in ps:
        for visited in reversed(range(L)):
            dp[visited + 1] = min(
                dp[visited + 1],
                (dp[visited] + 1) * (coef + 1) + const
            )

    def accumulate(a):
        s = 0
        yield s  # start=x->0
        for x in a:
            s += x
            yield s

    *acc, = accumulate(coef_0)

    ans = {0}
    cnt = len(acc) - 1
    for visited, consumption_time in enumerate(dp):
        rest = T - consumption_time
        if rest < 0: break  # le->lt,continue->break,restは狭義単調減少
        while cnt > 0 and acc[cnt] > rest:  # bisect_right->しゃくとり
            cnt -= 1
        ans.add(visited + cnt)
    print(max(ans))


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

n, q = map(int, input().split())
s = str(input())

for i in range(q):
  l, r = map(int, input().split()) 
  sp = s[l-1:r]
  print(sp.count('AC'))


    

### FIXED CODE ###

n, q = map(int, input().split())
s = str(input())

cum = [0]*n
current = 0

flag = 0

for i in range(1, len(s)):
  if s[i-1] == 'A' and s[i] =='C':
    current += 1
  cum[i] = current

for i in range(q):
  l, r = map(int, input().split())
  print(cum[r-1]-cum[l-1])
### BUGGY CODE ###

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

a = []

for i in range(0,Q):
    x = int(input())
    a.append(x)

l = [K] * N

for i in a:
    for n in range(0,N):
        if n == (i-1):
            pass
        else:
            l[n] -= 1

for n in range(0, N):
    if l[n] <= 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

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

a = []

for i in range(0,Q):
    x = int(input())
    a.append(x)

l = [0] * N

for i in a:
    l[i-1] += 1

for n in range(0, N):
    if l[n] >= (Q-K+1):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n,a,b = map(int, input().split())

mod = 1000000007

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = n
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

print(pow(2,n,mod)-1-(cmb(n,a,mod)+cmb(n,b,mod)))

### FIXED CODE ###

n, a, b = map(int, input().split())
mod = 7+10**9
def comb(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod
c_a = comb(n,a,mod)
c_b = comb(n,b,mod)
print((pow(2,n,mod)-1 -(c_a+c_b))%mod)
### BUGGY CODE ###

n, k = map(int,input().split())
a = list(map(int,input().split()))
from collections import deque

ans = deque()
ans.appendleft(1)
count = 1
s = -1

while True:
    if a[count-1] in ans:
        s = a[count-1]
        break
    else:
        ans.append(a[count-1])
        count = a[count-1]

ans = list(ans)
if s == -1:
    print(ans[k])
else:
    t = ans.index(s)
    if t >= k:
        print(ans[k])
    else:
        ans = ans[t:]
        print(ans[(k-t)%len(ans)])

### FIXED CODE ###

n, k = map(int,input().split())
a = list(map(int,input().split()))
from collections import deque

ans = deque()
ans.appendleft(1)
count = 1
s = -1
zeros = [0]*n

while True:
    if zeros[a[count-1]-1] == 1:
        s = a[count-1]
        break
    else:
        ans.append(a[count-1])
        zeros[count-1]=1
        count = a[count-1]

ans = list(ans)
if s == -1:
    print(ans[k])
else:
    t = ans.index(s)
    if t >= k:
        print(ans[k])
    else:
        ans = ans[t:]
        print(ans[(k-t)%len(ans)])
### BUGGY CODE ###

N = int(input())
S = input()

counts = []

for n in range(N):
    count = 0
    for s in S[0:n]:
        if s == "W":
            count += 1
    for s in S[n+1:]:
        if s == "E":
            count += 1
    counts.append(count)

print(min(counts))

### FIXED CODE ###

N=int(input())
S=input()
cnt=S.count("E")
m=cnt
for i in S:
    if i=="E":
        cnt-=1
    else:
        cnt+=1
    m=min(m,cnt)
print(m)
### BUGGY CODE ###

n, *a = map(int, open(0).read().split())
a.sort()
key = [0]*n
for i in range(n-1):
  if key[i]: continue
  for j in range(i+1, n):
    if a[i]==a[j]:
      key[i] = 1
      key[j] = 1
    elif a[j]%a[i]==0:
      key[j] = 1
print(key.count(0))

### FIXED CODE ###

N, *A = map(int, open(0).read().split())
A.sort()
dp = [True]*3*int(1e6)
x = -1
for a in A:
  if a == -1: continue
  x = a
  while x <= A[-1]:
    x += a
    dp[x] = False
  x = a

res = 0
for i, a in enumerate(A):
  if i > 0 and a == A[i-1]: continue
  if i < N-1 and a == A[i+1]: continue
  if dp[a]: res += 1
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = []
wa = {}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if p not in ac:
        if s == "AC":
            ac.append(p)
            ok += 1
        else:
            if p in wa.keys():
                wa[p] += 1
            else:
                wa[p] = 1

for i in ac:
    if i in wa.keys():
        ng += wa[i]

print(ok, ng)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = {str(i): 0 for i in range(n+1)}
wa = {str(i): 0 for i in range(n+1)}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if ac[p] == 0:
        if s == "AC":
            ac[p] += 1
            ok += 1
            if wa[p] > 0:
                ng += wa[p]
        else:
            wa[p] += 1

print(ok, ng)
### BUGGY CODE ###

import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, W = map(int, input().split())
    items = [0] * N

    for i in range(N):
        w, v = map(int, input().split())
        items[i] = (v, w)

    dp = [0] * (W + 1)

    for value, weight in items:
        for w in range(W + 1)[:: -1]:
            if w - weight >= 0:
                dp[w] = max(dp[w], dp[w - weight] + value)

    print(dp[W])

sol()

### FIXED CODE ###

import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, W = map(int, input().split())
    items = [0] * N

    for i in range(N):
        w, v = map(int, input().split())
        items[i] = (v, w)

    dp = [0] * (W + 1)

    for value, weight in items:
        for w in range(W + 1)[:: -1]:
            if w - weight >= 0:
                dp[w] = max(dp[w], dp[w - weight] + value)

    print(dp[W])

sol()
### BUGGY CODE ###

import numpy as np

def main():
    
    N = int(input())
    A = []
    for i in range(N):
        A.append(input())

    A = np.array(A)

    for i in range(N):
        print(max(np.delete(A, [i], axis=0)))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    a = int(input())
    lists= [int(input()) for _ in range(a)]
 
    temp = lists.copy()
    first = max(temp)
    temp.remove(first)
    second = max(temp)
 
    for i in range(a):
        if lists[i] == first:
            print(second)
        else:
             print(first)
 
if __name__ == '__main__' :
    main()
### BUGGY CODE ###

# B

N = int(input())
solve = []

while N > 0:
    solve.append(N % 10)
    N //= 10

ans = 0
for i in range(len(solve)):
    ans += solve[i]

if ans % 9 == 0:
    print('Yes')
if ans % 9 != 0:
    print('No')

### FIXED CODE ###

N = int(input())

k = N % 9

if k == 0:
    print('Yes')
    
if k != 0:
    print('No')