Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=math.gcd(math.gcd(i,j),k)
print(ans)

Fixed submission:
import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        for k in range(j,n+1):
            if(i==j and j==k and i==k):ans+=math.gcd(math.gcd(i,j),k)
            elif(i!=j and j!=k and i!=k):ans+=math.gcd(math.gcd(i,j),k)*6
            else:ans+=math.gcd(math.gcd(i,j),k)*3
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r=s.count("R")
g=s.count("G")
b=s.count("B")

ans=r*g*b
for i in range(1,n):
    for j in range(n):
        if(j+i*2>=n):continue
        d1,d2,d3=s[j],s[j+i],s[j+i*2]
        if(not(d1==d2 or d2==d3 or d1==d3)):ans-=1
print(ans)

Fixed submission:
n=int(input())
s=input()

r=s.count("R")
g=s.count("G")
b=n-r-g

ans=r*g*b
for i in range(1,n):
    for j in range(n):
        if(j+i*2>=n):break
        d1,d2,d3=s[j],s[j+i],s[j+i*2]
        if(not(d1==d2 or d2==d3 or d1==d3)):ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
q=[i for i in range(1,10)]
ans=0
for i in range(k):
    ans=q.pop(0)
    p=10*ans+int(str(ans)[-1])
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)

print(ans)

Fixed submission:
k=int(input())
q=[i for i in range(1,10)]
ans=0
c=0
for i in range(k):
    ans=q.pop(0)
    p=10*ans+int(str(ans)[-1])
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)
    if(i+len(q)>k):break
    c+=1
for i in range(k-c-1):
    ans=q.pop(0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

n=int(input())
a=list(map(int,input().split()))
s=0
m={}
for i in set(a):
    c=a.count(i)
    m[i]=c
    s+=c*(c-1)//2
for i in a:
    print(s-m[i]+1)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
s=0
m=Counter(a)
for i in m.values():
    s+=i*(i-1)//2
for i in a:
    print(s-m[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):

n=int(input())
a=list(map(int,input().split()))
s=0
for i in set(a):
    m=a.count(i)
    s+=m*(m-1)//2
for i in a:
    print(s-a.count(i)+1)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
s=0
m=Counter(a)
for i in m.values():
    s+=i*(i-1)//2
for i in a:
    print(s-m[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
t=True
a=str()
b=str()
for i in range(n):
    q=input().split()
    if(len(q)==1):
        t=not t
        a=a[::-1]
        b=b[::-1]
        continue
    if(int(q[1])==1):
        if(t):a=q[2]+a
        else:b=q[2]+b
    if(int(q[1])==2):
        if(t):b=b+q[2]
        else:a=a+q[2]
if(t):print(a+s+b)
else:print(b+s[::-1]+a)

Fixed submission:
s=input()
n=int(input())
t=True
a=str()
b=str()
for i in range(n):
    q=input().split()
    if(len(q)==1):
        t=not t
        continue
    if(int(q[1])==1):
        if(t):a=q[2]+a
        else:b=b+q[2]
    if(int(q[1])==2):
        if(t):b=b+q[2]
        else:a=q[2]+a
if(t):print(a+s+b)
else:print(b[::-1]+s[::-1]+a[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
for i in range(n):
    q=input().split()
    if(len(q)==1):
        s=s[::-1]
        continue
    if(int(q[1])==1):s=q[2]+s
    if(int(q[1])==2):s=s+q[2]
print(s)

Fixed submission:
s=input()
n=int(input())
t=True
a=str()
b=str()
for i in range(n):
    q=input().split()
    if(len(q)==1):
        t=not t
        continue
    if(int(q[1])==1):
        if(t):a=q[2]+a
        else:b=b+q[2]
    if(int(q[1])==2):
        if(t):b=b+q[2]
        else:a=q[2]+a
if(t):print(a+s+b)
else:print(b[::-1]+s[::-1]+a[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[]
m={}
for i in range(n):
    st=input()
    if(st in s):m[st]+=1
    else:m[st]=1
    s.append(st)
mx=max(m.values())
ans=[]
for i in m:
    if(m[i]==mx):ans.append(i)
ans=sorted(ans)
for i in ans:
    print(i)

Fixed submission:
n=int(input())
s=[]
m={}
for i in range(n):
    st=input()
    if(st in m):m[st]+=1
    else:m[st]=1
mx=max(m.values())
ans=[]
for i in m:
    if(m[i]==mx):ans.append(i)
ans=sorted(ans)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[]
for i in range(n):
    s.append(input())
s=sorted(s)
ss=sorted(list(set(s)))
m=0
t=[]
for i in ss:
    tm=s.count(i)
    t.append(tm)
    m=max(m,tm)

for i in ss:
    if(m==s.count(i)):print(i)

Fixed submission:
n=int(input())
s=[]
m={}
for i in range(n):
    st=input()
    if(st in m):m[st]+=1
    else:m[st]=1
mx=max(m.values())
ans=[]
for i in m:
    if(m[i]==mx):ans.append(i)
ans=sorted(ans)
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
pp=list(map(f,p))
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+pp[i]

for i in range(n-k+1):
    ans=max(ans,t[i+k]-t[i])
print(ans)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
pp=list(map(f,p))
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+pp[i]
ans=0
for i in range(n-k+1):
    ans=max(ans,t[i+k]-t[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
p=list(map(f,p))
ans=0.
for i in range(n-k+1):
    ans=max(ans,sum(p[i:i+k]))
print(ans)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
pp=list(map(f,p))
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+pp[i]
ans=0
for i in range(n-k+1):
    ans=max(ans,t[i+k]-t[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

l=[0 for i in range(n)]
t=""
w=0
ww=0
a=0
for i in range(m):
    p,s=input().split()
    if(l[int(p)-1]==1):continue
    if(s=="WA"):
        w+=1
        ww+=1
    if(s=="AC"):
        ww=0
        a+=1
        l[int(p-1)]=1
print(a,w-ww)

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

l=[0 for i in range(n)]
ll=[0 for i in range(n)]
w=0
a=0
for i in range(m):
    p,s=input().split()
    if(l[int(p)-1]==1):continue
    if(s=="WA"):ll[int(p)-1]+=1
    if(s=="AC"):
        l[int(p)-1]=1
        w+=ll[int(p)-1]
        a+=1
print(a,w)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
 
dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))
 
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
h=list(map(int,input().split()))

# dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])


Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
h=list(map(int,input().split()))

# dp=[int(10e8)]*n
dp=np.full(n,10e8,dtype=np.int64)
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])


Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=np.array([int(10e8)]*n)

dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])


Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n

dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])


Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    ww,vv=map(int,input().split())
    w.append(ww)
    v.append(vv)

dp=[[0 for i in range(W+10)] for j in range(N+10)]

for i in range(N):
    for j in range(W+1):
        if(j-w[i]>=0):
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

Fixed submission:
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    ww,vv=map(int,input().split())
    w.append(ww)
    v.append(vv)

dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if(j-w[i]>=0):
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = input().split()
A_MAP = {}
for i in range(N):
    A_MAP[str(i+1)] = A[i]

route_hash = {'1': 0}
current_pos = '1'
next_pos = ''
counter = 0
while counter <= K:
    next_pos = A_MAP[current_pos]
    counter+=1
    if next_pos in route_hash:
        break
    route_hash[next_pos] = counter # たどり着くまでにかかった回数
    current_pos = next_pos

remain = K - counter
counter -= route_hash[next_pos]
remain = remain % counter

current_pos = next_pos
for i in range(remain):
    next_pos = A_MAP[current_pos]
    route_hash[next_pos] = counter # たどり着くまでにかかった回数
    current_pos = next_pos
print(current_pos)


Fixed submission:
N, K = map(int, input().split())
A = input().split()
A_MAP = {}
for i in range(N):
    A_MAP[str(i+1)] = A[i]

route_hash = {'1': 0}
current_pos = '1'
next_pos = ''
counter = 0
breaked = False
while counter < K:
    next_pos = A_MAP[current_pos]
    counter+=1
    if next_pos in route_hash:
        breaked = True
        break
    route_hash[next_pos] = counter # たどり着くまでにかかった回数
    current_pos = next_pos

if not breaked:
    print(current_pos)
    exit()

remain = K - counter
counter -= route_hash[next_pos]
remain = remain % counter

current_pos = next_pos
for i in range(remain):
    next_pos = A_MAP[current_pos]
    route_hash[next_pos] = counter # たどり着くまでにかかった回数
    current_pos = next_pos
print(current_pos)
Buggy python submission (verdict: Runtime Error):
n, x, y = map(int, input().split())
x = x-1
y = y-1

result = [0] * n
for i in range(n):
    for j in range(i, n, 1):
        if i == j:
            continue
        minij = min([(j - i - 1), ((x - i + 1) + (y - j) - 1)])
        result[minij] += 1
for i in range(n-1):
    print(result[i])



Fixed submission:
n, x, y = map(int, input().split())
result = [0] * n
for i in range(1,n):
    for j in range(i+1, n+1):
        result[min([(j - i), (abs(i - x) + 1 + abs(j - y))])] += 1

for i in range(1,n):
    print(result[i])

Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if (d[i][k] == 0 or d[k][j] == 0):
                    continue
                if (i == j):
                    continue
                if (d[i][j] == 0):
                    d[i][j] = d[i][k] + d[k][j]
                else:
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])

n, x, y = map(int, input().split())

result = [[0] * n for i in range(n)]
for i in range(n):
    if (i-1 >= 0):
        result[i][i-1] = 1
    if (i+1 < n):
        result[i][i+1] = 1
result[x-1][y-1] = 1
result[y-1][x-1] = 1

warshall_floyd(result, n)

result_hash = [0] * (n-1)
for i in range(n):
    for j in range(n):
        if result[i][j] == 0:
            continue
        result_hash[result[i][j] - 1] += 1

for i in range(n-1):
    print(int(result_hash[i] / 2))


Fixed submission:
n, x, y = map(int, input().split())
result = [0] * n
for i in range(1,n):
    for j in range(i+1, n+1):
        result[min([(j - i), (abs(i - x) + 1 + abs(j - y))])] += 1

for i in range(1,n):
    print(result[i])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(input().split())

for i in range(len(a)):
    n = n - int(a[i])

if n >= 0:
    print(n)
else:
    print(-1)


Fixed submission:
def isKaibun(str):
    for i in range(len(str)):
        if str[i] != str[len(str)-i-1]:
            return False
    return True

s = input()

if not isKaibun(s):
    print("No")
elif not isKaibun(s[0:int((len(s) - 1) / 2)]):
    print("No")
elif not isKaibun(s[int((len(s) + 3) / 2)-1:len(s)]):
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
s = str(input())

def check(text):
    n = len(text)
    if n == 1:
        return True

    left = int((n-1)/2)
    right = int((n+3)/2 - 1)

    print(text[0:left], text[right:n])
    if len(text[0:left]) == len(text[right:n]):
        if text[0:left] == text[right:n] and check(text[0:left]):
            return True
    else:
        if text[0:left] == text[right+1:n] and check(text[0:left]):
            return True
    return False

if check(s):
    print("Yes")
else:
    print("No")


Fixed submission:
def isKaibun(str):
    for i in range(len(str)):
        if str[i] != str[len(str)-i-1]:
            return False
    return True

s = input()

if not isKaibun(s):
    print("No")
elif not isKaibun(s[0:int((len(s) - 1) / 2)]):
    print("No")
elif not isKaibun(s[int((len(s) + 3) / 2)-1:len(s)]):
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
s = str(input())

def check(text):
    n = len(text)
    if n == 1:
        return True

    left = int((n-1)/2)
    right = int((n+3)/2 - 1)

    print(text[0:left], text[right:n])
    if len(text[0:left]) == len(text[right:n]):
        if text[0:left] == text[right:n] and check(text[0:left]):
            return True
    else:
        if text[0:left] == text[right+1:n] and check(text[0:left]):
            return True
    return False

if check(s):
    print("Yes")
else:
    print("No")


Fixed submission:
def isKaibun(str):
    for i in range(len(str)):
        if str[i] != str[len(str)-i-1]:
            return False
    return True

s = input()

if not isKaibun(s):
    print("No")
elif not isKaibun(s[0:int((len(s) - 1) / 2)]):
    print("No")
elif not isKaibun(s[int((len(s) + 3) / 2)-1:len(s)]):
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
loop = int(input())

rev = 0
for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        rev = (rev+1) % 2
    else:
        type = int(queries[1])
        c = str(queries[2])
        if (type + rev) % 2 == 1:
            s = c + s
        else:
            s = s + c
if rev == 1:
    s = s[::-1]
print(s)



Fixed submission:
from collections import deque

s = deque((str(input())))
loop = int(input())

rev = 0
for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        rev = (rev+1) % 2
    else:
        type = int(queries[1])
        c = str(queries[2])
        if (type + rev) % 2 == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev == 1:
    print("".join(reversed(list(s))))
else:
    print("".join(list(s)))

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
loop = int(input())

for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        s = s[::-1]
    else:
        type = int(queries[1])
        c = str(queries[2])
        if type == 1:
            s = c + s
        else:
            s = s + c
print(s)



Fixed submission:
from collections import deque

s = deque((str(input())))
loop = int(input())

rev = 0
for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        rev = (rev+1) % 2
    else:
        type = int(queries[1])
        c = str(queries[2])
        if (type + rev) % 2 == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev == 1:
    print("".join(reversed(list(s))))
else:
    print("".join(list(s)))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

fail = False
result = {}
for i in range(0, m):
    s, c = map(int, input().split())
    key = n-s
    if key in result and result[key] != c:
        fail = True
        break
    result[key] = c

if not(n-1 in result) or result[n-1] == 0:
   fail = True

if fail:
    print(-1)
else:
    res = 0
    for i in range(0, n):
        if i in result:
            res += 10 ** i * result[i]
    print(res)


Fixed submission:
n = int(input())
print(int((n+1)/2))
Buggy python submission (verdict: Runtime Error):
A = []
p = 10**18
for i in range(18,1,-1):
  l = max(0,10**(i-2) - 1)
  m = 10**(i-2)
  for j in range(99,0,-1):
    c = l+m*j
    s = c/sum(map(int,str(c)))
    if s <= p:
      A.append(c)
      p = s

A = A[::-1]
X = int(input())
for i in range(X):print(A[i])

Fixed submission:
A = []
p = 10**18
for i in range(15,2,-1):
  l = max(0,10**(i-3) - 1)
  m = 10**(i-3)
  for j in range(999,9,-1):
    c = l+m*j
    s = c/sum(map(int,str(c)))
    if s-p <= 1e-7:
      A.append(c)
      p = s

for i in range(9,0,-1):A.append(10*i+9)
for i in range(9,0,-1):A.append(i)
A = A[::-1]
A = list(set(A))
A.sort() 


X = int(input())
for i in range(X):print(A[i])
Buggy python submission (verdict: Runtime Error):
in = [int(i) for i in input().split(' ')]
A,B,C = in[0],in[1],in[2]
if (A+B+C - max(A,B,C)) % 2 == 0:
  print((3*max(A,B,C) - A - B - C)/2)
else:
  print((3*max(A,B,C) - A - B - C - 1)/2) + 2

Fixed submission:
tin = [int(i) for i in input().split(' ') ]
A,B,C = tin[0],tin[1],tin[2]
if (A+B+C - max(A,B,C)) % 2 == 0:
  print(int((3*max(A,B,C) - A - B - C)/2))
else:
  print( int( (3*max(A,B,C) - A - B - C - 1)/2 + 2 ) )
Buggy python submission (verdict: Runtime Error):
n = int(input())

print(a + a*a + a*a*a)

Fixed submission:
a = int(input())

print(a + a*a + a*a*a)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = ['']

quo = n
rem = 0

while True:
    rem = quo%26
    quo = quo//26
    if rem == 0:
        ans.insert(0, 'z')
        if quo < 2:
            break
    else:
    
    if quo == 0:
        break

print(*ans, sep="")

Fixed submission:
n = int(input())
ans = ''
check = 'abcdefghijklmnopqrstuvwxyz'

while n != 0:
    n -= 1
    ans += check[n%26]
    n = n//26

print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())
q = int(input())
ans = []

for _ in range(q):
    b, c = input().split()
    atmp = " ".join(a)
    atmp = atmp.replace(b, c)
    a = atmp.split(" ")
    anew = [int(x) for x in a]
    ans.append(sum(anew))
    
print(*ans, sep='\n')

Fixed submission:
import collections

n = int(input())
arr = list(map(int, input().split()))
cnt = collections.defaultdict(int)

for val in arr:
    cnt[val] += 1

sums = sum(arr)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    diff = (c-b)*(cnt[b])
    sums += diff
    print(sums)
    cnt[c] += cnt[b]
    cnt[b] = 0
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(1, 101):
    if i not in p:
        tmp = abs(x-i)  
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(1, 101):
    if i not in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))

for i in range(1, 101):
    if not i in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))

for i in range(1, 101):
    if not i in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()