Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03006 (python)

Fixed submission:
n = int(input())
if n == 1:
    print(1)
    exit()

l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append([x, y])

res = 10 ** 100
for i in range(n):
    for j in range(i + 1, n):
        sa = []
        invalid = False
        for p,q in zip(l[i], l[j]):
            sa.append(p - q)

        cnt = 0
        flag = [False] * n
        for p in range(n):
            if not flag[p]:
                cnt += 1
            flag[p] = True
            nxt = [l[p][0] + sa[0], l[p][1] + sa[1]]
            for q in range(n):
                if l[q] == nxt:
                    if flag[q]:
                        cnt -= 1
                    else:
                        flag[q] = True
        
        # cnt = 0
        # flag = [False] * n
        # for p in range(n):
        #     if flag[p]:
        #         continue
        #     cnt += 1
        #     flag[p] = True
        #     for q in range(p + 1, n):
        #         if flag[q]:
        #             continue
        #         sb = []
        #         for a,b in zip(l[p], l[q]):
        #             sb.append(a - b)
                
        #         if sa[0] == 0:
        #             if sb[0] == 0 and sb[1] % sa[1] == 0:
        #                 flag[q] = True
        #         elif sa[1] == 0:
        #             if sb[1] == 0 and sb[0] % sa[0] == 0:
        #                 flag[q] = True
        #         else:
        #             if sb[0] % sa[0] == 0 and sb[1] % sa[1] == 0:
        #                 if sb[0] // sa[0] == sb[1] // sa[1]:
        #                     flag[q] = True
        res = min(res, cnt)
print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd
# from fractions import gcd

n = int(input())
if n == 1:
    print(1)
    exit()

l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append([x, y])

res = 10 ** 100
for i in range(n):
    for j in range(i + 1, n):
        sa = []
        invalid = False
        for p,q in zip(l[i], l[j]):
            sa.append(p - q)

        # if not invalid:
        #     g = gcd(sa[0], sa[1])
        #     sa[0] //= g
        #     sa[1] //= g
        
        cnt = 0
        flag = [False] * n
        for p in range(n):
            if flag[p]:
                continue
            cnt += 1
            flag[p] = True
            for q in range(p + 1, n):
                if flag[q]:
                    continue
                sb = []
                for a,b in zip(l[p], l[q]):
                    sb.append(a - b)
                
                if sa[0] == 0:
                    if sb[0] == 0 and sb[1] % sa[1] == 0:
                        flag[q] = True
                elif sa[1] == 0:
                    if sb[1] == 0 and sb[0] % sa[0] == 0:
                        flag[q] = True
                else:
                    if sb[0] % sa[0] == 0 and sb[1] % sa[1] == 0:
                        if sb[0] // sa[0] == sb[1] // sa[1]:
                            flag[q] = True
        res = min(res, cnt)
print(res)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

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

p = [a[0]]
for i in range(1, n):
    p.append(gcd(p[i - 1], a[i]))

q = [a[-1]]
for i in range(n - 1):
    q.append(gcd(q[i], a[n - 2 - i]))
q = q[::-1]

res = 1
for i in range(n):
    if i - 1 < 0:
        res = max(res, q[i + 1])
    elif i + 1 >= n:
        res = max(res, p[i - 1])
    else:
        res = max(res, gcd(p[i - 1], q[i + 1]))

print(res)

Buggy submission (verdict: Runtime Error):
from fraction import gcd

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

p = [a[0]]
for i in range(1, n):
    p.append(gcd(p[i - 1], a[i]))

q = [a[-1]]
for i in range(n - 1):
    q.append(gcd(q[i], a[n - 2 - i]))
q = q[::-1]

res = 1
for i in range(n):
    if i - 1 < 0:
        res = max(res, q[i + 1])
    elif i + 1 >= n:
        res = max(res, p[i - 1])
    else:
        res = max(res, gcd(p[i - 1], q[i + 1]))

print(res)

Buggy submission (verdict: Runtime Error):
from math import gcd

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

p = [a[0]]
for i in range(1, n):
    p.append(gcd(p[i - 1], a[i]))

q = [a[-1]]
for i in range(n - 1):
    q.append(gcd(q[i], a[n - 2 - i]))
q = q[::-1]

res = 1
for i in range(n):
    if i - 1 < 0:
        res = max(res, q[i + 1])
    elif i + 1 >= n:
        res = max(res, p[i - 1])
    else:
        res = max(res, gcd(p[i - 1], q[i + 1]))

print(res)
Problem p03062 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    if pos == []:
      print(-sum(neg[:-1])+neg[-1])
      exit()
    else:
      b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)
Problem p03064 (python)

Fixed submission:
M,z,s=998244353,1,0
N,*A=map(int,open(0))
d=[1]+[0]*7**6
e=[1]+[0]*7**6
for a in A:
 i=s;s+=a;z*=3
 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print((z+~s%2*e[s//2]*3)%M)

Buggy submission (verdict: Runtime Error):
M,z,s=998244353,1,0
N,*A=map(int,open(0))
d=[1]+[0]*7**6
e=d.copy()
for a in A:
 i=s;s+=a;z*=3
 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print((z+~s%2*e[s//2]*3)%M)
Problem p03090 (python)

Fixed submission:
n = int(input())
res = []
if n%2 == 0:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n + 1:
                continue
            res.append([i, j])
elif n % 2 == 1:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n:
                continue
            res.append([i, j])
print(len(res))
for (i,j) in res:
    print(i, j)

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,m = map(int,input().split())
cnt = [0] * n
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    cnt[a] += 1
    cnt[b] += 1
cnt = sorted(cnt, reverse = True)

odd = 0
even = 0
two = 0

g = gb(cnt)
for k,v in g:
    vv = len(list(v))
    if k == 2:
        two += 1
        continue
    if vv % 2 == 0:
        even += 1
    else:
        odd += 1
        
if two > even + odd:
    print('No')
elif odd == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,m = map(int,input().split())
cnt = [0] * n
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    cnt[a] += 1
    cnt[b] += 1
cnt = sorted(cnt, reverse = True)

odd = 0
even = 0
two = 0
g = gb(cnt)
for k,v in g:
    vv =len(list(v))
    if k == 2:
        two += 1
        continue
    if vv % 2 == 0:
        even += 1
    else:
        odd += 1
if odd == 1:
    print('Yes')
else:
    print('No')
Problem p03231 (python)

Fixed submission:
from fractions import gcd

n,m = map(int,input().split())
s = input()
t = input()
if n==m:
    if s!=t:
        print('-1')
        exit()
    else:
        print(n)
        exit()
elif n<m:
    n,m = m,n
    s,t = t,s
# n>m
if n%m==0:
    k = n//m
    if s[::k]==t:
        print(n)
        exit()
    else:
        print('-1')
        exit()
else:
    g = gcd(n,m)
    if s[::n//g]==t[::m//g]:
        print(n*m//gcd(n,m))
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
import fractions as f
g=f.gcd(list(map(int,input().split())));print(-1if input()[::n//g]!=input()[::m//g]else n*m//g)

Buggy submission (verdict: Runtime Error):
import fractions as f
g=f.gcd(map(int,input().split()));print(-1if input()[::n//g]!=input()[::m//g]else n*m//g)
Problem p03244 (python)

Fixed submission:
from collections import Counter as C
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2], v[1::2]
a1 = C(v1).most_common()
a2 = C(v2).most_common()

if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
    exit()

res = n//2
if len(a2)!=1:
    res = a1[0][1] + a2[1][1]
if len(a1)!=1:
    res = max(res, a1[1][1] + a2[0][1])
print(n-res)

Buggy submission (verdict: Runtime Error):
import itertools
n,*l=map(int,open(0).read().split())
f=lambda g:sorted([[len(list(v)),k]for k,v in itertools.groupby(g)])[-9:]
print(n-max(n//2,max(a+c for c,d in f(l[1::2])for a,b in f(l[::2])if b-d)))
Problem p03254 (python)

Fixed submission:
n,x = map(int,input().split())
a = sorted(list(map(int,input().split())))

res = 0
sum = 0
for i in a:
    res += 1
    sum += i
    if sum>=x:
        break
if sum==x:
    print(res)
else:
    print(res-1)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)[::-1]
res = 0
p = 0
for i in a:
    x -= i
    if x < 0:
        x += i
        break
    res += 1
    p += 1
else:
    if x > 0:
        res -= 1
#print(p, a[p:])
print(res + (x in a[p:]))
t
Problem p03262 (python)

Fixed submission:
from fractions import gcd

n,m = map(int,input().split())
x = [abs(int(i)-m) for i in input().split()]

res = x[0]

for i in x:
    res = gcd(res,i)

print(res)

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')



n,x = map(int,input().split())
a = list(map(int,input().split()))
p = []
for i in a:
    p.append(abs(i - x))
g = p[0]
for i in p:
    g = gcd(i, g)
print(g)y
Problem p03288 (python)

Fixed submission:
r=int(input())
if r<1200:
  print("ABC")
elif r<2800:
  print("ARC")
else:
  print("AGC")

Buggy submission (verdict: Runtime Error):
r=input()
if r<1200:
  print("ABC")
elif r<2800:
  print("ARC")
else:
  print("AGC")
Problem p03309 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l = len(a)
b = [a[i]-(i+1) for i in range(n)]
b = sorted(b)
mid = b[l//2]
sum = 0
for i in range(n):
    sum+=abs(a[i]-(mid+(i+1)))
print(sum)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
l = len(a)
b = [a[i]-(i+1) for i in range(n)]
b = sorted(b)
if l%2==1:
    mid = b[l//2+1]
    sum = 0
    for i in range(n):
        sum += abs(a[i] - mid - (i+1))
else:
    mid = (b[l//2] + b[l//2+1]) / 2
    sum1 = 0
    sum2 = 0
    for i in range(n):
        sum1 += abs(a[i] - math.floor(mid) - (i+1))
        sum2 += abs(a[i] - math.ceil(mid) - (i+1))
    sum = min(sum1, sum2)
print(sum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
l = len(a)
b = [a[i]-(i+1) for i in range(n)]
b = sorted(b)
if l%2==1:
    mid = b[l//2+1]
else:
    mid = (b[l//2] + b[l//2+1]) // 2
sum = 0
for i in range(n):
    sum += abs(a[i] - mid - (i+1))
print(sum)
Problem p03318 (python)

Fixed submission:
res = []
for digit in range(1,16):
    if digit<=3:
        for i in range(2,11):
            res.append(10**(digit-1)*i-1)
    elif 4<=digit<=12:
        for i in range(11,(digit-2)*10):
            res.append(i*10**(digit-2)-1)
        for i in range(digit-2,11):
            res.append(i*10**(digit-1)-1)
    elif digit==15:
        for i in range(101,110):
            res.append(i*10**(digit-3)-1)
        for i in range(11,101):
            res.append(i*10**(digit-2)-1)
    else:
        for i in range(11,101):
            res.append(i*10**(digit-2)-1)
for i in range(int(input())):
    print(res[i])

Buggy submission (verdict: Runtime Error):
res = []
for digit in range(1,16):
    if digit<=3:
        for i in range(2,11):
            res.append(10**(digit-1)*i-1)
    elif 4<=digit<=12:
        for i in range(11,(digit-2)*10):
            res.append(i*10**(digit-2)-1)
        for i in range(digit-2,11):
            res.append(i*10**(digit-1)-1)
    else:
        for i in range(11,101):
            res.append(i*10**(digit-2)-1)
for i in range(int(input())):
    print(res[i])
Problem p03323 (python)

Fixed submission:
A,B=list(map(int,input().split()))
if A>8 or B>8:
	print(':(')
else:
	print('Yay!')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A>8 or B>8:
	print(':(')
else:
	print('Yay!')
Problem p03361 (python)

Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]

def countSharp(x,y):
    res = 0
    if x!=0:
        res += s[x-1][y]=='#'
    if y!=0:
        res += s[x][y-1]=='#'
    if x!=h-1:
        res += s[x+1][y]=='#'
    if y!=w-1:
        res += s[x][y+1]=='#'
    return res

flag = [[False for _ in range(w)] for oijqd in range(h)]
for i,l in enumerate(s):
    for j,c in enumerate(l):
        if c=='.':
            flag[i][j] = True

for i in range(h):
    for j in range(w):
        if s[i][j]=='#' and countSharp(i,j)>0:
            flag[i][j] = True
            if i!=0:
                flag[i-1][j] = True
            if j!=0:
                flag[i][j-1] = True
            if i!=h-1:
                flag[i+1][j] = True
            if j!=w-1:
                flag[i][j+1] = True

res = True
for l in flag:
    if False in l:
        res = False
        break

print('Yes' if res else 'No')

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[]

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(H+2))
A.append(K*(H+2))
for i in range(1,H):
    for j in range(1,W):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[]

for i in range(W):
    S='.'+input()+'.'
    A.append(S)
K='.'
A.insert(0,K*(H+2))
A.append(K*(H+2))
for j in range(1,H+1):
    for i in range(1,W+1):
        if A[i][j]=='#':
            if A[i+1][j]=='.' and A[i-1][j]=='.' and A[i][j+1]=='.' and A[i][j-1]=='.':
                print('No')
                exit(0)

print('Yes')
Problem p03480 (python)

Fixed submission:
s = input()
n = len(s)
if s[0]*n==s:
    print(n)
    exit()
res = []
for i,(a,b) in enumerate(zip(s,s[1:])):
    if a != b:
        res.append(max(i+1,n-1-i))
print(min(res))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
res = []
for i,(a,b) in enumerate(zip(s,s[1:])):
    if a != b:
        res.append(max(i+1,n-1-i))
print(min(res))
Problem p03575 (python)

Fixed submission:
n,m = map(int,input().split())

# 0-indexed
visited = [False]*n
aa = []
bb = []
edge = []
for i in range(51):
    edge.append([False]*51)
"""
edge = [[False]*7]*7
"""

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    aa.append(a)
    bb.append(b)
    edge[a][b] = True
    edge[b][a] = True
    """
    for l in edge:
        print(l)
    print('')
    """

def dfs(vertex):
    visited[vertex] = True
    for i in range(n):
        if edge[vertex][i] and not visited[i]:
            #print(i, end=' ')
            dfs(i)

res = 0
for i in range(m):
    visited = [False]*n
    edge[aa[i]][bb[i]] = False
    edge[bb[i]][aa[i]] = False
    dfs(0)
    if not visited==[True]*n:
        res += 1
    #print(visited)
    edge[aa[i]][bb[i]] = True
    edge[bb[i]][aa[i]] = True

print(res)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

# 0-indexed
visited = [False]*n
aa = []
bb = []
edge = []
for i in range(7):
    edge.append([False]*7)
"""
edge = [[False]*7]*7
"""

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    aa.append(a)
    bb.append(b)
    edge[a][b] = True
    edge[b][a] = True
    """
    for l in edge:
        print(l)
    print('')
    """

def dfs(vertex):
    visited[vertex] = True
    for i in range(n):
        if edge[vertex][i] and not visited[i]:
            #print(i, end=' ')
            dfs(i)

res = 0
for i in range(m):
    visited = [False]*n
    edge[aa[i]][bb[i]] = False
    edge[bb[i]][aa[i]] = False
    dfs(0)
    if not visited==[True]*n:
        res += 1
    #print(visited)
    edge[aa[i]][bb[i]] = True
    edge[bb[i]][aa[i]] = True

print(res)
Problem p03651 (python)

Fixed submission:
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
G = a[0]
for i in a:
    G = gcd(G,i)
if k<=max(a) and k%G==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
from math import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
G = a[0]
for i in a:
    G = gcd(G,i)
if k<=max(a) and k%G==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03729 (python)

Fixed submission:
a,b,c=input().split()
print('YES' if a[-1]==b[0] and b[-1]==c[0] else 'NO')

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=input()
if a[-1]==b[0] and b[-1]==c[0]:
  print('YES')
else:
  print('NO')
Problem p03937 (python)

Fixed submission:
h,w=map(int,input().split())
r=0
for _ in range(h):r+=input().count('#')
print('Possible'if r==h+w-1else'Impossible')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[i*30000+1 for i in range(n)]
b=[30000**2-i for i in a]
p=list(map(int,input().split()))
for i in range(n):
  a[p[i]-1]+=i
  b[p[i]-1]+=i
print(*a)
print(*b)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[i*40000 for i in range(n)]
b=[40000**2-i for i in a]
p=list(map(int,input().split()))
for i in range(n):
  a[p[i]]+=i
  b[p[i]]+=i
print(*a)
print(*b)
Problem p03938 (python)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
A = [45678 * i for i in range(1, N + 1)]
B = A[::-1]
for i, p in enumerate(P):
    A[p - 1] += i
    B[p - 1] += i
print(*A)
print(*B)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[i*40000 for i in range(n)]
b=[i*40000 for i in range(n-1,-1,-1)]
p=list(map(int,input().split()))
for i in range(n):
  a[p[i]]+=i
  b[p[i]]+=i
print(*a)
print(*b)
Problem p03992 (python)

Fixed submission:
s=input()
print(s[:4]+' '+s[4:])

Buggy submission (verdict: Runtime Error):
input();*a,=map(int,input().split());print(sum(a[a[i]-1]==i+1for i in range(len(a)))>>1)
Problem p04043 (python)

Fixed submission:
A=input()
print(['NO','YES'][(A.count('5')==2)*(A.count('7')==1)])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split());d=input().split()
while 1:
    for c in str(n):
        if c in d:break
    else:
        print(n)
        exit()
    n += 1

Buggy submission (verdict: Runtime Error):
l = sort(list(map(int,input().split())))
if l==[5,5,7]:
    print('YES')
else:
    print('NO')
Problem p02608 (python)

Fixed submission:
n=int(input())
import math
for i in range(1,n+1):
    t=0
    for x in range(1,101):
        if (x**2)*6>i:
            break
        for y in range(x,101):
            if x**2+3*(y**2)+2*x*y>i:
                break
            B=(x+y)
            C=x**2+y**2+x*y-i
            r=(B**2-4*C)**0.5
            z1=(-B+r)/2
            z2=(-B-r)/2
            if z1.is_integer() and z1>0:
                if x==y and y==z1:
                    t+=1
                elif x!=y and y!=z1 and z1!=x:
                    t+=6
                else:
                    t+=3
            if z2.is_integer() and z2>0:
                if x==y and y==z2:
                    t+=1
                elif x!=y and y!=z2 and z2!=x:
                    t+=6
                else:
                    t+=3
    print(t)

Buggy submission (verdict: Runtime Error):
n=int(input())
import math
a=math.floor(math.sqrt(n/6))+1
for i in range(1,n+1):
    t=0
    for x in range(1,a):
        b=math.floor(math.sqrt((i-x**2)/3))+1
        for y in range(x,b):
            c=math.floor(math.sqrt(i-x**2-y**2-x*y))+1
            for z in range(y,c):
                if x**2+y**2+z**2+x*y+y*z+z*x==i:
                    if x==y and y==z:
                        t+=1
                    elif x!=y and y!=z and z!=x:
                        t+=6
                    else:
                        t+=3
    print(t)
Problem p02630 (python)

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())
N=[0]*(10**5)
s=0
for i in range(n):
    N[a[i]-1]+=1
    s+=a[i]
for i in range(q):
    s+=(c[i]-b[i])*N[b[i]-1]
    N[c[i]-1]+=N[b[i]-1]
    N[b[i]-1]=0
    print(s)

Buggy submission (verdict: Runtime Error):
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())
N=[0]*(10**3+10)
s=0
for i in range(n):
    N[a[i]-1]+=1
    s+=a[i]
for i in range(q):
    s+=(c[i]-b[i])*N[b[i]-1]
    N[c[i]-1]+=N[b[i]-1]
    N[b[i]-1]=0
    print(s)
Problem p02812 (python)

Fixed submission:
n=int(input())
s=list(input())
t=0
for i in range(n-2):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        t+=1
print(t)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
t=0
for i in range(n):
    if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
        t+=1
print(t)
Problem p02555 (python)

Fixed submission:
S = int(input())
a = [0 for _ in range(S+1)]
if S < 3:
  print(a[S])
  exit()
a[3] = 1


for n in range(4, S+1):
  sm = 0
  for i in range(3, S):
    sm += a[n-i]
  a[n] = sm+1

print(a[S] % ((10**9) + 7))

Buggy submission (verdict: Runtime Error):
S = int(input())
a = [0 for _ in range(S+1)]
a[3] = 1
for n in range(4, S+1):
  sm = 0
  for i in range(3, S):
    sm += a[n-i]
  a[n] = sm+1

print(a[S] % ((10**9) + 7))
Problem p02555 (python)

Fixed submission:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
s = int(input())
a = s//3
if a == 0:
    print(0)
else:
    m = 10**9+7
    cnt = 1
    for i in range(2, a+1):
        cnt += comb(s-2*i-1, i-1)
    print(cnt%m)

Buggy submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
s = int(input())
a = s//3
if a == 0:
    print(0)
else:
    m = 10**9+7
    cnt = 1
    for i in range(2, a+1):
        cnt += comb(s-2*i-1, i-1)
print(cnt%m)
Problem p02613 (python)

Fixed submission:
n = int(input())
count_ac, count_wa, count_tle, count_re = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == "AC":
        count_ac += 1
    if s == "WA":
        count_wa += 1
    if s == "TLE":
        count_tle += 1
    if s == "RE":
        count_re += 1

print("AC x", count_ac)
print("WA x", count_wa)
print("TLE x", count_tle)
print("RE x", count_re)

Buggy submission (verdict: Runtime Error):
n = int(input())
c0, c1, c2, c3 = 0
for _ in range(n):
    if _ == "AC":
        c0 += 1
    if _ == "WA":
        c1 += 1
    if _ == "TLE":
        c2 += 1
    if _ == "RE":
        c3 += 1
print("AC x", c0)
print("WA x", c1)
print("TLE x", c2)
print("RE x", c3)