Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += 3**cnt
        A %= mod
    elif S[i] == "B":
        AB += A
        AB %= mod
    elif S[i] == "C":
        ABC += AB
        ABC %= mod
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + 3**cnt) % mod
        cnt += 1
        
        
print(ABC)

Fixed submission:
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += pow(3, cnt, mod)
        A %= mod
    elif S[i] == "B":
        AB += A
        AB %= mod
    elif S[i] == "C":
        ABC += AB
        ABC %= mod
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + pow(3, cnt, mod)) % mod
        cnt += 1
        
        
print(ABC)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += 3**cnt
        A %= mod
    elif S[i] == "B":
        AB += A
        AB %= mod
    elif S[i] == "C":
        ABC += AB
        ABC %= mod
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + 3**cnt) % mod
        cnt += 1
        
        
print(ABC)

Fixed submission:
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += pow(3, cnt, mod)
        A %= mod
    elif S[i] == "B":
        AB += A
        AB %= mod
    elif S[i] == "C":
        ABC += AB
        ABC %= mod
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + pow(3, cnt, mod)) % mod
        cnt += 1
        
        
print(ABC)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += 3**cnt
    elif S[i] == "B":
        AB += A
    elif S[i] == "C":
        ABC += AB
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + 3**cnt) % mod
        cnt += 1
        
        
print(ABC%mod)

Fixed submission:
S = input()

mod = 10**9+7
A = 0
AB = 0
ABC = 0
cnt = 0
for i in range(len(S)):
    if S[i] == "A":
        A += pow(3, cnt, mod)
        A %= mod
    elif S[i] == "B":
        AB += A
        AB %= mod
    elif S[i] == "C":
        ABC += AB
        ABC %= mod
    else:
        ABC = (3*ABC + AB) % mod
        AB = (3*AB + A) % mod
        A = (3*A + pow(3, cnt, mod)) % mod
        cnt += 1
        
        
print(ABC)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = []
for i in range(9):
    x = ((N - (N % (10**i))) / (10**i)) % 10
    L.append(x)
if N % sum(L) == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
L = []
for i in range(10):
    x = ((N - (N % (10**i))) / (10**i)) % 10
    L.append(x)
sn = int(sum(L))
if N % sn == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in range(N):
    num = num*A[j]
while num % 2 == 0:
    ans = ans + 1
    num = num / 2
print(ans)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in range(N):
    while A[j] % 2 == 0:
        ans += 1
        A[j] /= 2
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in A:
    num *= j
while num % 2 == 0:
    ans += 1
    num *= 0.5
print(ans)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
num = 1
ans = 0
for j in range(N):
    while A[j] % 2 == 0:
        ans += 1
        A[j] /= 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

ans = N
i = 0
while i < N-1:
    cnt = 0
    sum_plus = A[i]
    sum_xor = A[i]
    for j in range(i+1, N):
        sum_plus += A[j]
        sum_xor ^= A[j]
        if sum_plus == sum_xor:
            cnt += 1
        else:
            break
    i += 1
    ans += cnt
    
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

ans = 0
j = 1
k = 0
sum_plus = A[0]
sum_xor = A[0]
while j <= N and k < j:
    if sum_plus == sum_xor:
        ans += j-k
        if j < N:
            sum_plus += A[j]
            sum_xor ^= A[j]
        j += 1
    else:
        sum_plus -= A[k]
        sum_xor ^= A[k]
        k += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(H)]
Q = int(input())

L = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i, j]
        
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    while l < r:
        ans += abs(L[l+D][0]-L[l][0])+abs(L[l+D][1]-L[l][1])
        l += D
    print(ans)

Fixed submission:
H,W,D = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(H)]
Q = int(input())

L = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i, j]
        
E = [0]*(H*W+1)
for i in range(D+1, H*W+1):
    E[i] = E[i-D] + abs(L[i][0]-L[i-D][0])+abs(L[i][1]-L[i-D][1])
    
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    ans = E[r] - E[l]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(H)]
Q = int(input())

L = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i, j]
        
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    while l < r:
        ans += abs(L[l+D][0]-L[l][0])+abs(L[l+D][1]-L[l][1])
        l += D
    print(ans)

Fixed submission:
H,W,D = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(H)]
Q = int(input())

L = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i, j]
        
E = [0]*(H*W+1)
for i in range(D+1, H*W+1):
    E[i] = E[i-D] + abs(L[i][0]-L[i-D][0])+abs(L[i][1]-L[i-D][1])
    
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    ans = E[r] - E[l]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,C = map(int, input().split())
L = [[int(a) for a in input().split()] for _ in range(N)]

ans = [[0, 0] for _ in range(C)]
L.sort()
for i in range(N):
    j = 0
    while j < C:
        if ans[j][0] == L[i][0] and ans[j][1] == L[i][2]:
            ans[j][0] = L[i][1]
            j = C
        elif ans[j][0] < L[i][0]:
            ans[j][0] = L[i][1]
            ans[j][1] = L[i][2]
            j = C
        j += 1
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i][0] > 0:
        num += 1
        
print(num)

Fixed submission:
N,C = map(int, input().split())
L = [[int(a) for a in input().split()] for _ in range(N)]

ans = [0]*C
chan = [0]*C
L.sort()
for i in range(N):
    for j in range(C):
        if ans[j] == L[i][0] and chan[j] == L[i][2]:
            ans[j] = L[i][1]
            break
        elif ans[j] < L[i][0]:
            ans[j] = L[i][1]
            chan[j] = L[i][2]
            break
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i] > 0:
        num += 1
        
print(num)
Buggy python submission (verdict: Runtime Error):
n=int(input)
ans = 1
while pow(ans,2) <= n:
  ans += 1
print(pow(ans-1,2))

Fixed submission:
n=int(input())
ans = 1
while ans**2 <= n:
  ans += 1
ans -= 1
print(ans**2)

Buggy python submission (verdict: Runtime Error):
n=int(input)
ans = 1
while ans**2 <= n:
  ans += 1
ans -= 1
print(ans**2)

Fixed submission:
n=int(input())
ans = 1
while ans**2 <= n:
  ans += 1
ans -= 1
print(ans**2)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
while True:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Fixed submission:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
while N > 1:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
s = set()
while len(s) != 1:
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)

Fixed submission:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = sorted(A)
while N > 1:
    s = set()
    for i in range(len(L)-1):
        s.add(L[i+1]-L[i])
    L = list(s)
    L.sort()
    if L[0] == 1 or len(L) == 1:
        break

if K > max(A):
    ans = "IMPOSSIBLE"
elif K in A or L[0] == 1:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
    for a in A:
        if a-K < 0:
            continue
        if (a-K)%L[0] == 0:
            ans = "POSSIBLE"
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(N)]

L = [0]*(M+1)
I = [0]*N
ans = N
flag = True
while flag:
    cnt = [0]*(M+1)
    for i in range(N):
        while I[i] < N and L[A[i][I[i]]] == 1:
            I[i] += 1
        if I[i] == N:
            flag = False
            break
        cnt[A[i][I[i]]] += 1
        I[i] += 1
    num = max(cnt)
    ans = min(ans, num)
    for i in range(1, M+1):
        if cnt[i] == num:
            L[i] = 1
    if sum(L) == M:
        flag = False

print(ans)

Fixed submission:
N,M = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(N)]

L = [0]*(M+1) #L[i]:0ならスポーツiを含める、1なら含めない
I = [0]*N #A[i][I[i]]:人iが参加するスポーツ
ans = N
flag = True
while flag:
    cnt = [0]*(M+1)
    for i in range(N):
        while I[i] < N and L[A[i][I[i]]] == 1:
            I[i] += 1
        if I[i] == N:
            flag = False
            break
        cnt[A[i][I[i]]] += 1
    if flag:
        num = max(cnt)
        ans = min(ans, num)
        for i in range(1, M+1):
            if cnt[i] == num:
                L[i] = 1
    if sum(L) == M:
        flag = False

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt == A[0] and cnt < N-1:
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

ans = "No"
if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt == A[0] and cnt < N-1:
        ans = "Yes"
    elif cnt < A[0] and N-cnt >= 2*(A[0]-cnt+1):
        ans = "Yes"
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, -c))
    
    
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出

def BellmanFord(E, N, M, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #M:辺の数
    #source:始点
    #グラフの初期化
    inf = 10**15
    d = [inf for i in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(M):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and j == N-1: return -1
    
    return d

dist = BellmanFord(E, N, M, 0)
if dist == -1:
    print("inf")
else:
    print(-dist[N-1])

Fixed submission:
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, -c))
    
    
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出

def BellmanFord(E, N, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #source:始点
    #グラフの初期化
    inf = 10**20
    d = [inf for _ in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(N):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and edge[0] == N-1:
                        return -1
    
    return d

dist = BellmanFord(E, N, 0)
if dist == -1:
    print("inf")
else:
    print(-dist[N-1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
mod = 10**9+7

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
Xd[1] = 2*Xd[0] + 2*Xd[1]
for i in range(n-3):
    Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
    Xd[i+2] %= mod
    
Yd[1] = 2*Yd[0] + 2*Yd[1]
for i in range(m-3):
    Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
    Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)

Fixed submission:
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
mod = 10**9+7

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
if n > 2:
    Xd[1] = 2*Xd[0] + 2*Xd[1]
    for i in range(n-3):
        Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
        Xd[i+2] %= mod
        
if m > 2:
    Yd[1] = 2*Yd[0] + 2*Yd[1]
    for i in range(m-3):
        Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
        Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)
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)

INF = 4001
Na = sum(A)
Nb = sum(B)
dp = [[[INF]*(Nb+1) for _ in range(Na+1)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for j in range(Na+1):
        for k in range(Nb+1):
            if j < A[i] or k < B[i]:
                dp[i+1][j][k] = dp[i][j][k]
            else:
                dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-A[i]][k-B[i]]+C[i])
            
ans = INF
for i in range(1, N+1):
    for j in range(1, Na+1):
        for k in range(1, Nb+1):
            if j*Mb == k*Ma:
                ans = min(ans, dp[i][j][k])
                
if ans == INF:
    ans = -1
    
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)

INF = 4001
Na = sum(A)
Nb = sum(B)
dp = [[[INF]*(Nb+1) for _ in range(Na+1)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for j in range(Na+1):
        for k in range(Nb+1):
            if j < A[i] or k < B[i]:
                dp[i+1][j][k] = dp[i][j][k]
            else:
                dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-A[i]][k-B[i]]+C[i])
            
ans = INF
for i in range(1, N+1):
    for j in range(1, Na+1):
        for k in range(1, Nb+1):
            if j*Mb == k*Ma:
                ans = min(ans, dp[i][j][k])
                
if ans == INF:
    ans = -1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = 1
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)

Fixed submission:
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = max(T//t, A//a, 1)
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = 1
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)

Fixed submission:
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = max(T//t, A//a, 1)
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)
Buggy python submission (verdict: Time Limit Exceeded):
N,A = map(int, input().split())
X = [int(x) for x in input().split()]

M = sum(X)
dp = [[[0]*(N+1) for _ in range(M+1)] for _ in range(N+1)]
    
for i in range(N+1):
    dp[i][0][0] = 1
    
for i in range(N):
    for j in range(M+1):
        for k in range(1, N+1):
            if j >= X[i]:
                dp[i+1][j][k] = dp[i][j][k] + dp[i][j-X[i]][k-1]
            else:
                dp[i+1][j][k] = dp[i][j][k]
        
ans = 0
for k in range(1, N+1):
    if k*A <= M:
        ans += dp[N][k*A][k]
            
print(ans)

Fixed submission:
N,A = map(int, input().split())
X = [int(x) for x in input().split()]

M = sum(X)
dp = [[[0]*(N+1) for _ in range(M+1)] for _ in range(N+1)]
    
for i in range(N+1):
    dp[i][0][0] = 1
    
for i in range(N):
    for j in range(M+1):
        for k in range(1, N+1):
            if j >= X[i]:
                dp[i+1][j][k] = dp[i][j][k] + dp[i][j-X[i]][k-1]
            else:
                dp[i+1][j][k] = dp[i][j][k]
        
ans = 0
for k in range(1, N+1):
    if k*A <= M:
        ans += dp[N][k*A][k]
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

answer = 0
for c in range(1, N):
    target = N - c
    count = 0
    for i in range(1, target+1):
        if target % i == 0:
            count += 1
    answer += count

print(answer)


Fixed submission:
N = int(input())

answer = 0
for a in range(1, N):
    answer += (N-1) // a

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()

max_count = 0
for start_t in range(len(T)):
    for start_s in range(start_t, len(S)):
        if len(S) - start_s < len(T) - start_t:
            break
        if T[start_t] == S[start_s]:
            count = 0

            for i in range(len(T) - start_t):
                if T[start_t+i] == S[start_s+i]:
                    count += 1
            
            max_count = max(max_count, count)

answer = len(T) - max_count
print(answer)



Fixed submission:
S = input()
T = input()

max_count = 0
for start_t in range(len(T)):
    for start_s in range(start_t, len(S)):
        if len(S) - start_s < len(T) - start_t:
            break
        if T[start_t] == S[start_s]:
            count = 0

            for i in range(len(T) - start_t):
                if T[start_t+i] == S[start_s+i]:
                    count += 1
            
            max_count = max(max_count, count)

answer = len(T) - max_count
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9 + 7

    answer = 0
    for i in range(N):
        answer = answer % mod +  A[i] % mod * sum(A[i+1:]) % mod

    print(answer)

main()



Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)
Buggy python submission (verdict: Runtime Error):
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] = 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1:
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Fixed submission:
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] += 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

flag = 0 # 0をpairwise coprime

for i in range(N): 
    for j in range(i+1, N):
        if math.gcd(A[i], A[j]) != 1:
            flag = 1 #1はpairwise coprimeではない
            break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Fixed submission:
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] += 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

flag = 0 # 0をpairwise coprime

for i in range(N): 
    for j in range(i+1, N):
        if math.gcd(A[i], A[j]) != 1:
            flag = 1 #1はpairwise coprimeではない
            break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)

Fixed submission:
import math
L = 10**6 + 1

N = int(input())
A = list(map(int, input().split()))
memo = [0] * L
flag = 0 # 0をpairwise coprime

for a in A:
    memo[a] += 1

for i in range(2, L):
    if sum(memo[i::i]) > 1:
        flag = 1
        break

g = 0
for i in range(N):
    g = math.gcd(g, A[i])

if flag == 0:
    answer = 'pairwise coprime'
elif flag == 1 and g == 1:
    answer = 'setwise coprime'
else:
    answer = 'not coprime'

print(answer)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

print(A*B)

Fixed submission:
A, B = map(int, input().split())

print(A*B)
Buggy python submission (verdict: Runtime Error):
S = input()

if S = 'ABC':
    print('ARC')
else:
    print('ABC')

Fixed submission:
S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))

count_list = []
for a in A_list:
    count = 0
    for i in range(N):
        if a == A_list[i]:
            count += 1
    count_list.append(count)

if max(count_list) == 1:
    print('YES')
else:
    print('NO')

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
A_set = set(A_list)

if len(A_list) == len(A_set):
    print('YES')
else:
    print('NO')