Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]


def main():
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            for k in range(N):
                if i == k or j == k:
                    continue
                if A[i][j] > A[i][k] + A[k][j]:
                    print(-1)
                    return
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            for k in range(N):
                if i == k or j == k:
                    continue
                if A[i][k] >= A[i][j] + A[k][j]:
                    A[i][k] = float('INF')
    ans = 0
    for i in range(N):
        for j in range(N):
            if A[i][j] == float('INF'):
                continue
            ans += A[i][j]
            A[j][i] = 0
    print(ans)


main()


Fixed submission:
def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        A[i][i] = float('INF')
    for i in range(N):
        for j in range(i):
            if i == j:
                A[i][j] = float('INF')
                continue
            b = min(map(sum, zip(A[i], A[j])))
            if A[i][j] > b:
                print(-1)
                return
            if b > A[i][j]:
                ans += A[i][j]
    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    print(d[0] * d[1])


main()


Fixed submission:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    if (len(d) == 2):
        print(d[0] * d[1])
    else:
        print(0)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    b1 = 0
    b2 = 0
    b4 = 0
    for a in A:
        if a == 2:
            b2 += 1
            continue
        if a // 2 > 1 and a % 2 == 0:
            b4 += 1
            continue
        b1 += 1
    if b2 > 0:
        if b4 >= b1:
            print('Yes')
            return
    else:
        if b4 + 1 >= b1:
            print('Yes')
            return
    print('No')


main()


Fixed submission:
def main():
    H, W = map(int, input().split())
    N = int(input())
    A = list(map(int, input().split()))
    ans = [[0] * W for _ in range(H)]
    i = 0
    j = 0
    d = 1
    for n in range(N):
        for _ in range(A[n]):
            ans[i][j] = str(n + 1)
            if (0 > d and j == 0) or (d > 0 and j == W - 1):
                i += 1
                d *= -1
                continue
            j += d
    for r in ans:
        print(' '.join(r))


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    i = 1
    c = 0
    v = [0]
    while A[i - 1] not in v:
        if A[i - 1] == 2:
            print(c + 1)
            return
        v.append(i)
        i = A[i - 1]
        c += 1
    print(-1)


main()


Fixed submission:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    i = 1
    c = 0
    v = [0] * (N + 1)
    while v[i] == 0:
        if A[i - 1] == 2:
            print(c + 1)
            return
        v[i] = 1
        i = A[i - 1]
        c += 1
    print(-1)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [False] * (4800 // 400 - 1)
    d = [0] * (4800 // 400 - 1)
    for a in A:
        c[a // 400] = True
        d[a // 400] += 1
    mn = 1 if c[:8].count(True) == 0 else c[:8].count(True)
    mx = c[:8].count(True) + sum(d[8:])
    print(mn, mx)


main()


Fixed submission:
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [False] * (4800 // 400 + 1)
    d = [0] * (4800 // 400 + 1)
    for a in A:
        c[a // 400] = True
        d[a // 400] += 1
    mn = 1 if c[:8].count(True) == 0 else c[:8].count(True)
    mx = c[:8].count(True) + sum(d[8:])
    print(mn, mx)


main()

Buggy python submission (verdict: Runtime Error):
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [0] * (4800 // 400)
    mx = 0
    for a in A:
        c[a // 400] = True
        if a >= 3200:
            mx += 1
    print(max(c[:3200 // 400].count(True), mx),
          c[:3200 // 400].count(True) + mx)


main()


Fixed submission:
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [False] * (4800 // 400 + 1)
    d = [0] * (4800 // 400 + 1)
    for a in A:
        c[a // 400] = True
        d[a // 400] += 1
    mn = 1 if c[:8].count(True) == 0 else c[:8].count(True)
    mx = c[:8].count(True) + sum(d[8:])
    print(mn, mx)


main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range(N):
        for j in range(N):
            f = True
            for k in range(M):
                for l in range(M):
                    if A[i + k][j + l] != B[k][l]:
                        f = False
                        break
                if f is False:
                    break
            if f is True:
                print('Yes')
                exit()
    print('No')


main()


Fixed submission:
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range(N):
        for j in range(N):
            f = True
            for k in range(M):
                for l in range(M):
                    if i + k >= N or j + l >= N:
                        f = False
                        break
                    if A[i + k][j + l] != B[k][l]:
                        f = False
                        break
                if f is False:
                    break
            if f is True:
                print('Yes')
                exit()
    print('No')


main()
Buggy python submission (verdict: Time Limit Exceeded):
N, Ma, Mb = map(int, input().split())
A = []
B = []
C = []
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
M = 401
dp = [[[float('INF') for _ in range(M)]
       for _ in range(M)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(M):
        for k in range(M):
            if dp[i][j][k] == float('INF'):
                continue
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
            dp[i + 1][j + A[i]][k + B[i]
                                ] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i])
ans = float('INF')
for j in range(1, M):
    for k in range(1, M):
        if j * Mb == k * Ma:
            ans = min(ans, dp[N][j][k])
if ans == float('INF'):
    print(-1)
else:
    print(ans)


Fixed submission:
N, Ma, Mb = map(int, input().split())
A = []
B = []
C = []
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
M = 401
dp = [[[float('INF') for _ in range(M)]
       for _ in range(M)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(M):
        for k in range(M):
            if dp[i][j][k] == float('INF'):
                continue
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
            dp[i + 1][j + A[i]][k + B[i]
                                ] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i])
ans = float('INF')
for j in range(1, M):
    for k in range(1, M):
        if j * Mb == k * Ma:
            ans = min(ans, dp[N][j][k])
if ans == float('INF'):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for i in range(len(s)):
    if s[i] != 'A':
        continue
    for j in range(i + 1, len(s)):
        if s[j] == 'Z':
            ans = max(ans, j + 1 - i)
print(ans)


Fixed submission:
s = input()
n = len(s)
a = float('INF')
z = 0
for i in range(n):
    if s[i] == 'A':
        a = min(a, i)
    elif s[i] == 'Z':
        z = max(z, i)
print(z + 1 - a)
Buggy python submission (verdict: Time Limit Exceeded):
sx, sy, tx, ty = map(int, input().split())
gp = []


def fn(q, gx, gy):
    while len(q) > 0:
        x, y, d, p = q.pop(0)
        for xx, yy, dd in [(x + 1, y, 'R'), (x - 1, y, 'L'), (x, y + 1, 'U'), (x, y - 1, 'D')]:
            if (xx, yy) == (gx, gy):
                gp.extend(p + [(xx, yy)])
                return d + dd
            if -1000 <= xx <= 1000 and -1000 <= yy <= 1000 and (xx, yy) not in p:
                q.append((xx, yy, d + dd, p + [(xx, yy)]))


print(fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy) +
      fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy))


Fixed submission:
sx, sy, tx, ty = map(int, input().split())

ans = ''
ans += 'R' * (tx - sx)
ans += 'U' * (ty - sy)
ans += 'L' * (tx - sx)
ans += 'D' * (ty - sy)
ans += 'D' + 'R' * (tx - sx + 1)
ans += 'U' * (ty - sy + 1) + 'L'
ans += 'U' + 'L' * (tx - sx + 1)
ans += 'D' * (ty - sy + 1) + 'R'

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
sx, sy, tx, ty = map(int, input().split())
gp = []


def fn(q, gx, gy):
    while len(q) > 0:
        x, y, d, p = q.pop(0)
        for xx, yy, dd in [(x + 1, y, 'R'), (x - 1, y, 'L'), (x, y + 1, 'U'), (x, y - 1, 'D')]:
            if (xx, yy) == (gx, gy):
                gp.extend(p + [(xx, yy)])
                return d + dd
            if -1000 <= xx <= 1000 and -1000 <= yy <= 1000 and (xx, yy) not in p:
                q.append((xx, yy, d + dd, p + [(xx, yy)]))


print(fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy) +
      fn([(sx, sy, '', gp)], tx, ty) + fn([(tx, ty, '', gp)], sx, sy))


Fixed submission:
sx, sy, tx, ty = map(int, input().split())

ans = ''
ans += 'R' * (tx - sx)
ans += 'U' * (ty - sy)
ans += 'L' * (tx - sx)
ans += 'D' * (ty - sy)
ans += 'D' + 'R' * (tx - sx + 1)
ans += 'U' * (ty - sy + 1) + 'L'
ans += 'U' + 'L' * (tx - sx + 1)
ans += 'D' * (ty - sy + 1) + 'R'

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2))
else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** (N // 2))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
C = [0] * N
for a in A:
    C[a] += 1
if N % 2 == 1:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2) % 1000000007)
else:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** (N // 2) % 1000000007)
Buggy python submission (verdict: Runtime Error):
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']


def fn(i):
    if i == 0:
        print('YES')
        exit()
    for tg in targets:
        if S[i - len(tg):i][::-1] == tg[::-1]:
            fn(i - len(tg))
    print('No')
    exit()


fn(len(S))


Fixed submission:
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']

i = len(S)
while True:
    if i == 0:
        print('YES')
        exit()
    for tg in targets:
        if S[i - len(tg):i][::-1] == tg[::-1]:
            i -= len(tg)
            break
    else:
        print('NO')
        exit()

Buggy python submission (verdict: Runtime Error):
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']


def fn(i):
    if len(S) == i:
        print('YES')
        exit()
    for tg in targets:
        if S[i: i + len(tg)] == tg:
            fn(i + len(tg))


fn(0)
print('No')


Fixed submission:
S = input()
targets = ['dream', 'dreamer', 'erase', 'eraser']

i = len(S)
while True:
    if i == 0:
        print('YES')
        exit()
    for tg in targets:
        if S[i - len(tg):i][::-1] == tg[::-1]:
            i -= len(tg)
            break
    else:
        print('NO')
        exit()
Buggy python submission (verdict: Runtime Error):
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret/2) % mod))

Fixed submission:
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret//2) % mod)

Buggy python submission (verdict: Runtime Error):
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret/2) % mod))

Fixed submission:
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret//2) % mod)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, K = map(np.int64, input().split())
A = list(map(np.int64, input().split()))
B = list(map(np.int64, input().split()))

time0 = 0
cnt = 0
while(time0<=K):
    if len(A) == 0 and len(B) != 0:
        time0 += B.pop(0)
        cnt += 1
    elif len(B) == 0 and len(A) != 0:
        time0 += A.pop(0)
        cnt += 1
    elif len(A) == 0 and len(B) == 0:
        cnt += 1
        break
    else:
        if A[0] < B[0]:
            time0 += A.pop(0)
            cnt += 1
        elif A[0] > B[0]:
            time0 += B.pop(0)
            cnt += 1
        else:
            if A[1]<=B[1]:
                time0 += A.pop(0)
                cnt+=1
            else:
                time0 += B.pop(0)
                cnt+=1
            
cnt -= 1

print(cnt)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
aa = 0
for i in range(1,N+1):
    aa += A[i-1]
    a.append(aa)
    
b = [0]
bb = 0
for i in range(1,M+1):
    bb += B[i-1]
    b.append(bb)
    
time0 = 1
ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    else:
        while(j >= 0):
            if b[j] <= K - a[i]:
                ans = max(ans, i+j)
                break
            else:
                j -= 1
        
        
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for i in range(1,N+1):
    y = int(N/i)
    ans += int(1/2*y*(y+1)*i)
    
print(ans)


Fixed submission:
N = int(input())

ans = 0
for i in range(1,N+1):
    y = N//i
    ans += y*(y+1)*i//2
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i], C[i] = map(int,input().split())

S = [0]*Q
for i in range(Q):
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]
    S[i] = sum(A)

for i in range(Q):
    print(S[i])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i], C[i] = map(int,input().split())
    
num = [0]*100000
for i in range(len(A)):
    num[A[i]-1] += 1
    
S =[sum(A)]
for i in range(Q):
    S.append(S[i]+(C[i]-B[i])*num[B[i]-1])
    num[C[i]-1] += num[B[i]-1]
    num[B[i]-1] = 0
 
S.pop(0)    
for i in range(Q):
    print(S[i])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

p.sort()

p0 = []
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break

p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])

Fixed submission:
import numpy as np
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

p.sort()

p0 = [0]
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break
p0.append(101)
p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

p.sort()

p0 = []
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break

p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])


Fixed submission:
import numpy as np
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

p.sort()

p0 = [0]
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break
p0.append(101)
p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

AA = [0]*1000000

for i in range(N):
    ma = 1000000//A[i]
    for j in range(1,ma+1):
        AA[j*A[i]-1]+=1

ans = 0

for i in range(N):
    if AA[A[i]-1] == 1:
        ans += 1
        
print(ans)

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
M = max(A)
cnt = [0 for i in range(M)]
for i in range(N):
    if cnt[A[i]-1] != 0:
        cnt[A[i]-1] = 2
    else:
        j = A[i]-1
        while j<M:
            cnt[j] += 1
            j += A[i]

ans = 0
for i in range(N):
    if cnt[A[i]-1] == 1:
        ans += 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

AA = [0]*1000000

for i in range(N):
    j = 1
    while (j*A[i]<=1000000):
        AA[j*A[i]-1] += 1
        j += 1

ans = 0

for i in range(N):
    if AA[A[i]-1] == 1:
        ans += 1
        
print(ans)

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
M = max(A)
cnt = [0 for i in range(M)]
for i in range(N):
    if cnt[A[i]-1] != 0:
        cnt[A[i]-1] = 2
    else:
        j = A[i]-1
        while j<M:
            cnt[j] += 1
            j += A[i]

ans = 0
for i in range(N):
    if cnt[A[i]-1] == 1:
        ans += 1
        
print(ans)

Buggy python submission (verdict: Runtime Error):
for i in range(1e6):
  i**2
  

Fixed submission:
import math
N = int(input())
A = list(map(int,input().split()))
M = max(A)
cnt = [0 for i in range(M)]
for i in range(N):
    if cnt[A[i]-1] != 0:
        cnt[A[i]-1] = 2
    else:
        j = A[i]-1
        while j<M:
            cnt[j] += 1
            j += A[i]

ans = 0
for i in range(N):
    if cnt[A[i]-1] == 1:
        ans += 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

def fuctrization(n):
    arr = []
    tmp = n
    for i in range(2,math.ceil(n**(1/2))+1):
        if tmp%i==0:
            j = 0
            while tmp%i==0:
                j += 1
                tmp //= i
            arr.append([i,j])
    if tmp != 1:
        arr.append([tmp,1])
    if arr:
        pass
    else:
        arr.append([n,1])
            
    return arr
            
        
        
n = int(input())
if n == 1:
    print(0)
else:
    arr = fuctrization(n)
    nn = 0
    for i in range(len(arr)):
        k = arr[i][1]
        nnn = 1
        while k-nnn>0:
            k -= nnn
            nnn += 1
            if k-nnn == 0:
                pass
            elif nnn != 1:
                nnn -= 1
        nn += nnn
print(nn)


Fixed submission:
import numpy as np
import math

def fuctrization(n):
    arr = []
    tmp = n
    for i in range(2,math.ceil(n**(1/2))+1):
        if tmp%i==0:
            j = 0
            while tmp%i==0:
                j += 1
                tmp //= i
            arr.append([i,j])
    if tmp != 1:
        arr.append([tmp,1])
    if arr:
        pass
    else:
        arr.append([n,1])
            
    return arr
            
        
        
n = int(input())
if n == 1:
    print(0)
else:
    arr = fuctrization(n)
    nn = 0
    for i in range(len(arr)):
        k = arr[i][1]
        nnn = 1
        while k-nnn>=0:
            k -= nnn
            nnn += 1
            nn +=1
    print(nn)
Buggy python submission (verdict: Runtime Error):
N=input()
if len(n)>1:
  N=N[1]
  
if N in ["2","4","5","7","9"]:
  print("hon")
elif N == "3":
  print("bon")
else:
  print("pon")

Fixed submission:
N=str(input())
N=N[-1]
  
if N in ["2","4","5","7","9"]:
  print("hon")
elif N == "3":
  print("bon")
else:
  print("pon")
Buggy python submission (verdict: Runtime Error):
K=input()
S=input()

if len(S)>=K:
  print(s)
else:
  print(s[:K]+"...")

Fixed submission:
K=int(input())
S=input()

if len(S)<=K:
  print(S)
else:
  print(S[:K]+"...")
Buggy python submission (verdict: Runtime Error):
import sys
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline()
ans = 0
for i in s:
  ans += int(i)
  ans %= 9

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

Fixed submission:
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline().rstrip()
ans = 0
for i in s:
	ans += int(i)
	ans %= 9

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

Buggy python submission (verdict: Runtime Error):
import sys
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline()
ans = 0
for i in s:
  ans += int(i)
  ans %= 9

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


Fixed submission:
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline().rstrip()
ans = 0
for i in s:
	ans += int(i)
	ans %= 9

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

Buggy python submission (verdict: Runtime Error):
import sys
import math
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline()
ans = 0
for i in s:
  ans += int(i)
  ans %= 9

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

Fixed submission:
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

s = sys.stdin.readline().rstrip()
ans = 0
for i in s:
	ans += int(i)
	ans %= 9

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