Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

Fixed submission:
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

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

n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

ans = 0
for i in itertools.combinations(range(n),m):
    v = 0
    for l in range(3):
        u = 0
        for j in i:
            u += a[j][l]
        v += abs(u)
    ans = max(ans,v)

print(ans)

Fixed submission:
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

ans = 0
for i,j,k in itertools.combinations(range(n),m):
    u = 0
    for l in range(3):
        u += abs(a[i][l] + a[j][l] + a[k][l])
    ans = max(ans,u)

print(ans)

Fixed submission:
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

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

ans = 0
for i,j,k in itertools.combinations(range(n),m):
    u = 0
    for l in range(3):
        u += abs(a[i][l] + a[j][l] + a[k][l])
    ans = max(ans,u)

print(ans)


Fixed submission:
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)
Buggy python submission (verdict: Runtime Error):
#https://agc023.contest.atcoder.jp/submissions/2429958
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
  
def main():
    n,x = LI()
    m = [I() for _ in range(n)]
    r = (x - m[0] - m[1] - m[2]) // (min(m))

    return r
 
print(main())

Fixed submission:
n,x = (int(i) for i in input().split()) 
m = [int(input()) for i in range(n)] 
count_donut = 0 
for m_i in m:
    x = x - m_i
    count_donut +=1
count_donut += x // min(m)
print(count_donut)
Buggy python submission (verdict: Runtime Error):
n = long(input())
x = [long(i) for i in input().split()]
sortx = sorted(x)

mid_left = sortx[(n//2)-1]
mid_right = sortx[(n//2)]

for i in range(n):
    if sortx[i] <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

Fixed submission:
n = int(input())
x = [int(i) for i in input().split()]
sortx = sorted(x)

mid_left = sortx[(n//2)-1]
mid_right = sortx[(n//2)]

for i in range(n):
    if x[i] <= mid_left:
        print(mid_right)
    else:
        print(mid_left)
Buggy python submission (verdict: Runtime Error):
a = sorted(int(i) for i in input().split()) 
print((a[1] - a[0]+1) // 2 + a[2] - a[1] + (a[1] - a[0]) % 2)

Fixed submission:
a = input()
if a in ["abc","acb","bac","bca","cab","cba"]: #== ("abc" or "acb" or "bac" or "bca" or "cab" or "cba"):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A, B, K = (int(i) for i in input().split()) 
low = range(A,A+K)
high = range(B,B-K,-1)
t = sorted(list(set(low) | set(high)))
for s in t:
    if s >= A and s <= B:
        print(s)

Fixed submission:
a = input()
if a in ["abc","acb","bac","bca","cab","cba"]: #== ("abc" or "acb" or "bac" or "bca" or "cab" or "cba"):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j]-a[j+1])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))
    

Fixed submission:
a = [int(input()) for i in range(2)]
b = [int(input()) for i in range(2)]
print(min(a)+min(b))

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * mins(abs(a[j]-a[j-1]),abs(a[j]-a[j+1])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))
    

Fixed submission:
a = [int(input()) for i in range(2)]
b = [int(input()) for i in range(2)]
print(min(a)+min(b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j]-a[j+1])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))
    

Fixed submission:
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_ = [[int(i) for i in input()] for j in range(n)]
a = set([_ for _ in a_])
print(len(a))

Fixed submission:
#8th
n = int(input())
a = set(float(input()) for i in range(n))
# a_ = [[int(i) for i in input()] for j in range(n)]
# a = set(_[0] for _ in a_)
print(len(a))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_ = [[int(i) for i in input()] for j in range(n)]
a = set([_[0][0] for _ in a_])
print(len(a))

Fixed submission:
#8th
n = int(input())
a = set(float(input()) for i in range(n))
# a_ = [[int(i) for i in input()] for j in range(n)]
# a = set(_[0] for _ in a_)
print(len(a))

Buggy python submission (verdict: Runtime Error):
a = set(float(input()) for i in range(n))
print(len(a))

Fixed submission:
#8th
n = int(input())
a = set(float(input()) for i in range(n))
# a_ = [[int(i) for i in input()] for j in range(n)]
# a = set(_[0] for _ in a_)
print(len(a))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = list(map(int, input().split()))
first = True
for i in range(K):
  s = 0
  
  for j in l:
    s += i ^ j
    
  if first:
    m = s
    first = False
  else:
    if m < s:
      m = s
print(m)

Fixed submission:
N, K = map(int, input().split())
a = list(map(int, input().split()))

max_bit = 40
ans = 0
for i in range(max_bit, -1, -1):
  bit = 2 ** i
  c = len([1 for j in a if j&bit > 0])
  if 2*c < N and bit <= K:
    c = N - c
    K -= bit
  ans += bit * c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
l = list(map(int, input().split()))
first = True
for i in range(K+1):
  s = 0
  
  for j in l:
    s += i ^ j
    
  if first:
    m = s
    first = False
  else:
    if m < s:
      m = s
print(m)

Fixed submission:
N, K = map(int, input().split())
a = list(map(int, input().split()))

max_bit = 40
ans = 0
for i in range(max_bit, -1, -1):
  bit = 2 ** i
  c = len([1 for j in a if j&bit > 0])
  if 2*c < N and bit <= K:
    c = N - c
    K -= bit
  ans += bit * c
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
return a*b/2

Fixed submission:
a, b, c = map(int, input().split())
sum_ = a * b / 2
print(int(sum_))
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst_a = [int(i) for i in input().split()]
lst_b = [int(i) for i in input().split()]
j = 0
for i in range(n):
  if lst_a[i] != lst_b[i]:
    continue
  else:
    flag = False
    while j != n:
      if lst_a[i] != lst_b[j]:
        lst_b[i], lst_b[j] = lst_b[j], lst_b[i]
        flag = True
        break
      j += 1
    if not flag:
      break
if not flag:
  print('No')
else:
  print('Yes')
  lst_b = [str(i) for i in lst_b]
  print(' '.join(lst_b))

Fixed submission:
n = int(input())
lst_a = [int(i) for i in input().split()]
lst_b = [int(i) for i in input().split()]
j = 0
flag = True
for i in range(n):
  if i > 0:
    if lst_a[i] != lst_a[i - 1]:
      j = 0
  if lst_a[i] != lst_b[i]:
    continue
  else:
    flag = False
    while j != n:
      if lst_a[i] != lst_b[j] and lst_a[j] != lst_b[i]:
        lst_b[i], lst_b[j] = lst_b[j], lst_b[i]
        flag = True
        break
      j += 1
    if not flag:
      break
if not flag:
  print('No')
else:
  print('Yes')
  lst_b = [str(i) for i in lst_b]
  print(' '.join(lst_b))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
lst = [int(i) for i in input().split()]
sum_list = [0]
total = 0
for i in range(n):
  total += lst[i]
  sum_list.append(total)
for _ in range(q):
  t, a, b = map(int, input().split())
  if t == 0:
    for i in range(a + 1, n + 1):
      sum_list[i] += b
  else:
    print(sum_list[b] - sum_list[a])
    

Fixed submission:
class bit:
  def __init__(self, n):
    self.size = n
    self.bit = [0] * (n + 1)
  
  def make(self, lst):
    self.bit = [0] + lst[:]
    for i in range(1, self.size + 1):
      if i + (i & -i) > self.size:
        continue
      self.bit[i + (i & -i)] += self.bit[i]
  
  def add(self, a, b):
    i = a + 1
    while i <= self.size:
      self.bit[i] += b
      i += i & -i
  
  def sum(self, a):
    i = a
    ret = 0
    while i > 0:
      ret += self.bit[i]
      i -= i & -i
    return ret
  
  def sub(self, a, b):
    return self.sum(b) - self.sum(a)

n, q = map(int, input().split())
lst = [int(i) for i in input().split()]
l = bit(n)
l.make(lst)
for _ in range(q):
  t, a, b = map(int, input().split())
  if t == 0:
    l.add(a, b)
  else:
    print(l.sub(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
fri_dic = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in fri_dic:
    fri_dic[a] = set()
  if b not in fri_dic[a]:
    fri_dic[a].add(b)
  if b not in fri_dic:
    fri_dic[b] = set()
  if a not in fri_dic[b]:
    fri_dic[b].add(a)
visited = set()
max_count = 0
count = 0
for i in range(1, n + 1):
  #print(visited)
  if i in visited:
    continue
  queue = [i]
  con_visited = set()
  while queue:
    p = queue.pop(0)
    if p in visited:
      continue
    visited.add(p)
    con_visited.add(p)
    if p not in fri_dic:
      continue
    for j in fri_dic[p]:
      queue.append(j)
  if len(con_visited) > max_count:
    max_count = len(con_visited)
  count += len(con_visited)
  if max_count >= n - count:
    break
print(max_count)


Fixed submission:
n, m = map(int, input().split())
fri_dic = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in fri_dic:
    fri_dic[a] = set()
  if b not in fri_dic[a]:
    fri_dic[a].add(b)
  if b not in fri_dic:
    fri_dic[b] = set()
  if a not in fri_dic[b]:
    fri_dic[b].add(a)
visited = set()
max_count = 0
for i in range(1, n + 1):
  #print(visited)
  if i in visited:
    continue
  stack = [i]
  con_visited = set()
  while stack:
    p = stack.pop()
    if p in visited:
      continue
    visited.add(p)
    con_visited.add(p)
    if p not in fri_dic:
      continue
    for j in fri_dic[p]:
      stack.append(j)
  if len(con_visited) > max_count:
    max_count = len(con_visited)
print(max_count)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
fri_dic = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in fri_dic:
    fri_dic[a] = set()
  if b not in fri_dic[a]:
    fri_dic[a].add(b)
  if b not in fri_dic:
    fri_dic[b] = set()
  if a not in fri_dic[b]:
    fri_dic[b].add(a)
visited = set()
max_count = 0
for i in range(1, n + 1):
  #print(visited)
  if i in visited:
    continue
  queue = [i]
  con_visited = set()
  while queue:
    p = queue.pop(0)
    if p in visited:
      continue
    visited.add(p)
    con_visited.add(p)
    if p not in fri_dic:
      continue
    for j in fri_dic[p]:
      queue.append(j)
  if len(con_visited) > max_count:
    max_count = len(con_visited)
print(max_count)


Fixed submission:
n, m = map(int, input().split())
fri_dic = {}
for _ in range(m):
  a, b = map(int, input().split())
  if a not in fri_dic:
    fri_dic[a] = set()
  if b not in fri_dic[a]:
    fri_dic[a].add(b)
  if b not in fri_dic:
    fri_dic[b] = set()
  if a not in fri_dic[b]:
    fri_dic[b].add(a)
visited = set()
max_count = 0
for i in range(1, n + 1):
  #print(visited)
  if i in visited:
    continue
  stack = [i]
  con_visited = set()
  while stack:
    p = stack.pop()
    if p in visited:
      continue
    visited.add(p)
    con_visited.add(p)
    if p not in fri_dic:
      continue
    for j in fri_dic[p]:
      stack.append(j)
  if len(con_visited) > max_count:
    max_count = len(con_visited)
print(max_count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1, n + 1):
  count = 0
  # x <= y <= zとして考える
  if i >= 6:
    for x in range(1, i + 1):
      if 6 * x ** 2 > i:
        break
      a = i - x ** 2
      for y in range(x, i + 1):
        if 3 * y ** 2 + 2 * x * y > a:
          break
        for z in range(y , i + 1):
          if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x == i:
            if x == y:
              if y == z:
                count += 1
              else:
                count += 3
            else:
              if y == z:
                count += 3
              else:
                count += 6
            break
          if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x > i:
            break
  print(count)

Fixed submission:
ans = [0] * 10000
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      k = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      if k > 10000:
        break
      ans[k - 1] += 1

n = int(input())
for i in range(n):
  print(ans[i])

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

for i in range(1, n + 1):
  count = 0
  # x <= y <= zとして考える
  if i >= 6:
    for x in range(1, i // 6 + 1):
      for y in range(x, i + 1):
        for z in range(y , i + 1):
          if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x == i:
            if x == y:
              if y == z:
                count += 1
              else:
                count += 3
            else:
              if y == z:
                count += 3
              else:
                count += 6
  print(count)

Fixed submission:
ans = [0] * 10000
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      k = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      if k > 10000:
        break
      ans[k - 1] += 1

n = int(input())
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

#print(a_books)
data = ['a'] * n + ['b'] * m
all_lists = set()
for list in itertools.permutations(data):
  if list not in all_lists:
    all_lists.add(list)
#print(all_lists)
max_count = 0
for list in all_lists:
  count = 0
  a = 0
  b = 0
  time = 0
  for i in range(n+m):
    if list[i] == 'a':
      time += a_books[a]
      if time > k:
        break
      count += 1
      a += 1
    if list[i] == 'b':
      time += b_books[b]
      if time > k:
        break
      count += 1
      b += 1
  if count > max_count:
    max_count = count
  if max_count == n + m:
    break
print(max_count)


Fixed submission:
n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

time = 0
count = 0
for i in range(n):
  time += a_books[i]
  if time > k:
    time -= a_books[i]
    i -= 1
    break
  count += 1
for j in range(m):
  time += b_books[j]
  if time > k:
    time -= b_books[j]
    j -= 1
    break
  count += 1
max_count = count
#print(max_count, time)
while j < m and i >= 0:
  time -= a_books[i]
  i -= 1
  count -= 1
  j += 1
  while j < m:
    time += b_books[j]
    if time > k:
      time -= b_books[j]
      j -= 1
      break
    count += 1
    j += 1
  if count > max_count:
    max_count = count
  #print(count, time)
  #print(max_count)
print(max_count)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, k = map(int, input().split())
lst = [int(i) for i in input().split()]

lists = list(itertools.combinations(range(n), k))
#print(lists)
min_price = float('inf')
for each in lists:
  total = 0
  for index in each:
    total += lst[index]
  if total < min_price:
    min_price = total
print(min_price)

Fixed submission:
n, k = map(int, input().split())
lst = [int(i) for i in input().split()]

count = 0
min_price = 0
while count < k:
  #print(count)
  total = min_price
  for i in range(len(lst)):
    total += lst[i]
    #print(total)
    if i == 0:
      min_price = total
      min_index = i
    elif total < min_price:
      min_price = total
      min_index = i
    total -= lst[i]
  lst.pop(min_index)
  count += 1
print(min_price)
Buggy python submission (verdict: Runtime Error):
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
sum = 0
for key, value in dic.items():
  sum += key * value

m = int(input())
for _ in range(m):
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    sum += lst_s[1] * number
    sum -= lst_s[0] * number
    dic.pop(lst_s[0])
  print(sum)

Fixed submission:
n = int(input())
lst = [int(i) for i in input().split()]
dic = {}
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
sum = 0
for key, value in dic.items():
  sum += key * value

m = int(input())
for _ in range(m):
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    sum += lst_s[1] * number
    sum -= lst_s[0] * number
    dic.pop(lst_s[0])
  print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = [int(i) for i in input().split()]
dic = {}
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
m = int(input())
for _ in range(m):
  sum = 0
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    dic.pop(lst_s[0])
  for key, value in dic.items():
    sum += key * value
  print(sum)

Fixed submission:
n = int(input())
lst = [int(i) for i in input().split()]
dic = {}
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
sum = 0
for key, value in dic.items():
  sum += key * value

m = int(input())
for _ in range(m):
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    sum += lst_s[1] * number
    sum -= lst_s[0] * number
    dic.pop(lst_s[0])
  print(sum)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Fixed submission:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_num = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_num:
    min_num = l
    nums.append(i)
  elif l > min_num:
    break
print(nums[-1])

Fixed submission:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in k.split()]

nums = []
min_num = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_num:
    min_num = l
    nums.append(i)
  elif l > min_num:
    break
print(nums[-1])

Fixed submission:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)