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

Fixed submission:
n = int(input())
for t in range(1,10):
    if n <= t*100 + t*10 + t:
        res = t*100 + t*10 + t
        break 

print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1,10):
    t = 10-i
    if n > t*100 + t*10 + t:
        res = (t+1)*100 + (t+1)*10 + t+1
        break

print(res)
Problem p03260 (python)

Fixed submission:
ab = input()
a,b = ab.split()
a = int(a)
b = int(b)
 
if a%2 == 1 and b%2 == 1:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
ab = input()
a,b = ab.split()
a = int(a)
b = int(b)
 
if a%2 == 1 and b%2 == 1:
  print(Yes)
else:
  print(No)
Problem p03264 (python)

Fixed submission:
k = int(input())
print(int((k/2)**2)) if k%2 == 0 else print(int((k/2)**2 - 1/4))

Buggy submission (verdict: Runtime Error):
k = int(input())
print(int((k/2)**2)) if k%2 == 0 else print(int(k/2)**2 - 1/4))
Problem p03308 (python)

Fixed submission:
n = input()
an = input()
an = an.split()
list = []

for i in an:
    i = int(i)
    list.append(i)
min_an = min(list)
max_an = max(list)

print(max_an - min_an)

Buggy submission (verdict: Runtime Error):
n = int(input())
an = input()
an = an.split()

dif = 999999999

for i in range(n-1):
    for r in range(i+1, n):
        a = int(an[i])
        b = int(an[r])

        abs = abs(a-b)
        if abs < dif:
            dif = abs

print(dif)

Buggy submission (verdict: Runtime Error):
n = int(input())
an = input()
an = an.split()

dif = 10000000000

for i in range(n-1):
    for r in range(i+1, n):
        a = int(an[i])
        b = int(an[r])

        abs = abs(a-b)
        if abs < dif:
            dif = abs

print(dif)
Problem p03323 (python)

Fixed submission:
ab = input()
a, b = ab.split()
A = int(a)
B = int (b)
if A > 8 or B > 8:
    res = ':('

else:
    res = 'Yay!'

print(res)

Buggy submission (verdict: Runtime Error):
A = int(input ())
B = int (input ())
if A > 8 or B > 8: 
    res = ‘: (‘
 
else:
    res = ‘Yay!’
 
print(res)

Buggy submission (verdict: Runtime Error):
A = int(input ())
B = int (input ())
if A > 8 or B > 8: 
    res = ‘: (‘

else:
    res = ‘Yay!’

print(res)
Problem p03324 (python)

Fixed submission:
d,n = map(int, input().split())
if n == 100:
    print(100**d * 101)
else:
    print(100**d * n)

Buggy submission (verdict: Runtime Error):
dn = input()
d, n = dn.split()
d = int(d)
n = int(n)
list = []
for i in range(1, 1000001):
    if i% 100**d:
        list.append(i)

print(list[n+1])

Buggy submission (verdict: Runtime Error):
n = int(input())
line = input()
liststr = line.split()
list = []

for i in liststr:
    i = int(i)
    list.append(i)


cc = 0
for r in list:
    while r%2 == 0:
        r = r / 2
        cc = cc + 1


print(cc)
Problem p03455 (python)

Fixed submission:
ab_str = input()
a_str, b_str = ab_str.split()
a = int(a_str)
b = int(b_str)
if a%2 == 0 or b%2 == 0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
ab_str = input()
a_str, b_str = ab_str.split()
a = int(a_str)
b = int(b_str)
if a%2 == 0 or b%2 == 0:
  print(Even)
else:
  print(Odd)
Problem p03470 (python)

Fixed submission:
n = input()
n = int(n)
s = set([])

for i in range(1, n+1):
    a = input()
    a = int(a)
    s.add(a)

print(len(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
print(len(list(set(map(int, input() for i in range(n))))))

Buggy submission (verdict: Runtime Error):
n = int(input())
list = input().split()
print(list(set(list)))
Problem p03478 (python)

Fixed submission:
n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
    if a <= sum(list(map(int, list(str(i))))) <= b:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n+1):
    sum = sum(list(map(int, list(str(i)))))
    if a<= sum <=b:
        ans+=i

print(ans)
Problem p03544 (python)

Fixed submission:
n = int(input())
l0 = 2
l1 = 1
for i in range(n-1):
    l = l0 + l1
    l0 = l1
    l1 = l
if n == 1:
    print(l1)
else:
    print(l)

Buggy submission (verdict: Runtime Error):
n = int(input())
l0 = 2
l1 = 1
for i in range(n-1):
    l = l0 + l1
    l0 = l1
    l1 = l

print(l)
Problem p02743 (python)

Fixed submission:
a,b,c = map(int,input().split())
d = 4 * a * b
e = (c - a - b) * (c - a - b)
if d < e and 0 < (c - a - b):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
d = 4 * a * b
e = (c - a - b) * (c - a - b)
if d < e && 0 < (c - a - b):
  print("Yes")
else:
  print("No")
Problem p02767 (python)

Fixed submission:
import math


def inp():
    return(int(input()))


def invr():
    return(map(int, input().split()))


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = 100000000000
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)

Buggy submission (verdict: Runtime Error):
import math


def inp():
    return(int(input()))


def invr():
    return(map(int, input().split()))


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = math.inf
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)

Buggy submission (verdict: Runtime Error):
import math


def inp():
    return(int(input()))


def invr():
    return(map(int, input().split()))


n = inp()
arr = invr()
arr = sorted(arr)
max = arr[n-1]
min = arr[0]

cost = math.inf
for p in range(min, max+1):
    temp_cost = 0
    for xi in arr:
        temp_cost += (xi-p)**2
    if temp_cost < cost:
        cost = temp_cost
print(cost)
Problem p03282 (python)

Fixed submission:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
k = inp()
i = 0
while i < len(a) and a[i] == '1':
    i += 1

if i >= k:
    print(1)
elif len(a) == i:
    print(1)
else:
    print(a[i])

Buggy submission (verdict: Runtime Error):
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
k = inp()
i = 0
while a[i] == '1':
    i += 1

if i >= k:
    print(1)
elif len(a) == i:
    print(1)
else:
    print(a[i])
Problem p03720 (python)

Fixed submission:
N, M = map(int, input().split())
R = list()
for i in range(N):
  R.append(0)
for i in range(M):
  c1, c2 = map(int, input().split())
  R[c1-1] += 1
  R[c2-1] += 1
for i in range(N):
  print(R[i])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
R = list()
for i in range(N):
  R.append(0)
for i in range(M):
  c1, c2 = map(int, input().split())
  R[c1] += 1
  R[c2] += 1
for i in range(N):
  print(R[i])
Problem p04033 (python)

Fixed submission:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a, b = invr()
res = "Negative"

if 0 < a and a <= b:
    res = "Positive"
if a <= b and b < 0:
    temp = (b-a)+1
    if temp % 2 == 0:
        res = "Positive"
    else:
        res = "Negative"
if a <= 0 and b >= 0:
    res = "Zero"

print(res)

Buggy submission (verdict: Runtime Error):
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a, b = invr()
res = "Negative"


if a > 0 and b > 0:
    res = "Positive"
if a < 0 and b < 0:
    temp = abs(abs(a)-abs(b)) + 1
    if temp % 2 == 0:
        res = "positive"
    else:
        res = "Negative"
if a == b:
    res = "Positive"
if a <= 0 and b = > 0:
    res = "Zero"

print(res)
Problem p02713 (python)

Fixed submission:
import math

k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)
Problem p03162 (python)

Fixed submission:
def solve(a):
    dp = [[0]*3 for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
    return max(dp[-1])
  
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(a))

Buggy submission (verdict: Runtime Error):
def solve(a):
    dp = [[0]*3 for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
    return max(dp[-1])
  
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(a))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)

def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            dp[f] = 0
            for c in g[f]:
                dp[f] = max(dp[f], 1 + _solve(c))
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    # print(dp)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))

Buggy submission (verdict: Runtime Error):
def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            dp[f] = 0
            for c in g[f]:
                dp[f] = max(dp[f], 1 + _solve(c))
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    # print(dp)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))

Buggy submission (verdict: Runtime Error):
def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            sol = 0
            for c in g[f]:
                sol = max(sol, 1 + _solve(c))
            dp[f] = sol
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))

Buggy submission (verdict: Runtime Error):
def solve(g):
    dp = [-1]*len(g)
    def _solve(f):
        if dp[f] == -1:
            for c in g[f]:
                dp[f] = max(dp[f], 1 + _solve(c))
            dp[f] = max(dp[f], 0)
        return dp[f]
    for f in range(len(g)):
        _solve(f)
    # print(dp)
    return max(dp)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    f, t = map(int, input().split())
    g[f-1].append(t-1)

print(solve(g))
Problem p02675 (python)

Fixed submission:
numero = int(input())

digito_1 = numero % 10

if digito_1 == 2 or digito_1 == 4 or digito_1 == 5 or digito_1 == 7 or digito_1 == 9:
    print("hon")
elif digito_1 == 0 or digito_1 == 1 or digito_1 == 6 or digito_1 == 8:
    print("pon")
elif digito_1 == 3:
    print("bon")

Buggy submission (verdict: Runtime Error):
from queue import Queue

n,m = map(int,input().split())

grafo = [[] for i in range(n)]

for x in range(m):
    a,b = map(int,input().split())
    grafo[a-1].append(b)
    grafo[b-1].append(a)


placas = [0] * (n)

def bfs(a):
    q = Queue(maxsize = n)
    placas[0] = 1
    q.put(a)
    while not q.empty():
        popado = q.get()
        for adj in grafo[popado-1]:
            if not placas[adj-1]:
                placas[adj-1] = popado
                q.put(adj)

    if placas.count(0) == 0:
        print("Yes")
        for x in placas[1::]:
            print(x)
    else:
        print("No")

bfs(1)

Buggy submission (verdict: Runtime Error):
import math

A,B,H,M = map(int,input().split())


if M == 0 and H == 6:

    print(A+B)

elif M == 0 and H == 0:

    print(abs(A-B))

else:

    angulo = abs(11 * M - 60 * H)/2

    angulo = math.radians(angulo)

    print(abs(math.sqrt((A**2 + B ** 2) -  (2 * A * B * math.cos(angulo)))))
Problem p02677 (python)

Fixed submission:
import math

A,B,H,M = map(int,input().split())


if M == 0 and H == 6:

    print(A+B)

elif M == 0 and H == 0:

    print(abs(A-B))

else:
    angulo = abs(11 * M - 60 * H)/2

    angulo = math.radians(angulo)

    print(abs(math.sqrt((A**2 + B ** 2) -  (2 * A * B * math.cos(angulo)))))

Buggy submission (verdict: Runtime Error):
import math

A,B,H,M = map(int,input().split())


if M == 0 and H == 6:

    print(A+B)

elif M == 0 and H == 0:

    print(abs(A-B))

else:

    angulo = abs(11 * M - 60 * H)/2

    angulo = math.radians(angulo)

    print(abs(math.sqrt((A**2 + B ** 2) -  (2 * A * B * math.cos(angulo)))))
~
Problem p02681 (python)

Fixed submission:
s = input()
t = input()

string = s + t[-1]

if string == t:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

if s + t[-1] == t:
    print("Yes")
else:
    print("No")
~
Problem p02718 (python)

Fixed submission:
N,M = map(int,input().split())

votos = list(map(int,input().split()))

qtd_votos = sum(votos)

minimo = qtd_votos/(4*M)

votos.sort(reverse = True)

if votos[M-1] >= minimo:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())

votos = list(map(int,input().split()))

qtd_votos = sum(votos)

minimo = qtd_votos/(4*M)

votos.sort(reverse = True)

if votos[M-1] >= minimo:
    print("Yes")
else:
    print("No")
トすることで判定できます。
Problem p02642 (python)

Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
maxA = A[len(A)-1]
valid = [True] * maxA

for i in range(len(A)):
    if valid[A[i]-1] == False:
        continue
    if i != 0 and A[i-1] == A[i]:
        valid[A[i]-1] = False
    else:
        for j in range(A[i]*2, maxA+1, A[i]):
            valid[j-1] = False

count = 0
for i in range(len(A)):
    if valid[A[i]-1] == True:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
maxA = A[len(A) - 1]
valid = [True] * (maxA + 1)
for i in range(1, len(valid)):
    if valid[i] == False or not i in A:
        continue
    else:
        for j in range(2, maxA // i + 1):
            valid[j * i] = False
count = 0
for i in range(len(A)):
    if i == 0 and A[i] == A[i+1]:
        continue
    if i != 0 and A[i-1] == A[i]:
        continue
    if valid[A[i]]:
        count += 1
print(count)
Problem p02760 (python)

Fixed submission:
b = list(map(int, input().split()))
tmp1 = list(map(int, input().split()))
tmp2 = list(map(int, input().split()))
b.extend(tmp1)
b.extend(tmp2)
answer = [False]*9
N = int(input())
for i in range(N):
    num = int(input())
    if num in b:
        answer[b.index(num)] = True
if (answer[0] and answer[1] and answer[2]) or (answer[3] and answer[4] and answer[5]) or (answer[6] and answer[7] and answer[8]) or (answer[1-1] and answer[4-1] and answer[7-1]) or (answer[2-1] and answer[5-1] and answer[8-1]) or (answer[3-1] and answer[6-1] and answer[9-1]) or (answer[1-1] and answer[5-1] and answer[9-1]) or (answer[3-1] and answer[5-1] and [7-1]):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
b = list(map(int, input().split()))
tmp1 = list(map(int, input().split()))
tmp2 = list(map(int, input().split()))
b.extend(tmp1)
b.extend(tmp2)
answer = [False]*9
N = int(input())
for i in range(N):
    num = int(input())
    if num in b:
        answer[b.index(num)] = True
if (answer[0] and answer[1] and answer[2]) or (answer[3] and answer[4] and answer[5]) or (answer[6] and answer[7] and answer[8]) or (answer[1-1] and answer[4-1] and answer[7-1]) or (answer[2-1] and answer[5-1] and answer[8-1]) or (answer[3-1] and answer[6-1] and answer[9-1]) or (answer[1-1] and answer[5-1] and answer[9-1]) or (answer[3-1] and answer[5-1] and [b7]):
    print("Yes")
else:
    print("No")
Problem p02921 (python)

Fixed submission:
S = input()
T = input()
count = 0
for (s, t) in zip(S, T):
    if s == t:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
print(math.floor(1 / 2 * N * (N - 1)))
Problem p03023 (python)

Fixed submission:
N = int(input())
print(180 * (N - 2))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(180 * (n - 2))
Problem p02584 (python)

Fixed submission:
X, K, D = map(int, input().split())
s = 0
g = K

def d(h):
    return X + (h - (K-h))*D

if d(s) >= 0:
    ans = d(s)
elif d(g) <= 0:
    ans = abs(d(g))
else:
    half = (s + g)//2
    while s < half:
        if d(half) < 0:
            s = half
        else:
            g = half
        half = (s + g)//2

    ans = min(abs(d(s)) , abs(d(g)) )
print(ans)

Buggy submission (verdict: Runtime Error):
X, K, D = map(int, input().split())
s = 0
g = K

def d(h):
    return X + (h - (K-h))*D

if d(s) >= 0:
    ans = d(s)
elif d(g) <= 0:
    ans = g(g)
else:
    half = (s + g)//2
    while s < half:
        if d(half) < 0:
            s = half
        else:
            g = half
        half = (s + g)//2

    ans = min(abs(d(s)) , abs(d(g)) )
print(ans)
Problem p02609 (python)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y=sum(map(int, X_2))+1
z=y-2

a = X_10%y
b = X_10%z

for i in range(N):
    if X_2[i]=='0':
        c = (2**(N-1-i))%y
        x = (a+c)%y
    elif sum(map(int, X_2[0:i]+X_2[i+1:]))==0:
        print(0)
        continue
    else:
        c = (2**(N-1-i))%z
        x = (b-c)%z
    
    count = 1
    while x != 0:
        x = x%sum(map(int, bin(x)[2:]))
        count+=1
    print(count)

Buggy submission (verdict: Runtime Error):
from itertools import product
from math import log2

N = int(input())
X = input()
m = sum(list(map(int, X)))+1
n = int(log2(m)+1)
f = [0]

i = 0
for p in product([0,1], repeat=n):
    if i>0:
        a = sum(p)
        f.append(f[i%a]+1)
    i += 1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
        a = m-2
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
        a = m
    print(f[x%a]+1)

Buggy submission (verdict: Runtime Error):
from itertools import product
from math import log2

N = int(input())
X = input()
f = [0]*(N+1)
m = sum(list(map(int, X)))+1
n = int(log2(m)+1)

i = 0
for p in product([0,1], repeat=n):
    if i>0:
        a = sum(p)
        f[i] = f[i%a]+1
    i += 1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
        a = m-2
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
        a = m
    print(f[x%a]+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = input()
f = [0]*(N+1)
for i in range(1, N):
    a = sum(list(map(int, bin(i)[2:])))
    f[i] = f[i%a]+1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
    a = sum(list(map(int, bin(x)[2:])))
    print(f[x%a]+1)
Problem p02630 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
X = [0] * (10**5)

for i in range(N):
    X[A[i]-1] += 1

ans = sum(A)

for j in range(Q):
    b, c = map(int, input().split())
    a = X[b-1]
    X[b-1] = 0
    X[c-1] += a
    ans = ans - a*b + c*a
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())

for i in range(Q):
    b, c = map(int, input().split())
    s = 0
    e = N
    h = int((s+e)/2)
    while A[h] != b and s != h :
        if A[h] < b:
            s = h
            h = int((s+e)/2)
        elif A[h] > b:
            e = h
            h = int((s+e)/2)
    X = []
    for j in range(s, e):
        if A[j] == b:
            X.append(j)
            A[j] = c
    print(sum(A))
    if len(X) > 0:
        A = A[:X[0]] + A[X[-1]:]
        s = 0
        e = len(A)
        h = int((s+e)/2)
        while A[h] != c and s != h :
            if A[h] < c:
                s = h
                h = int((s+e)/2)
            elif A[h] > c:
                e = h
                h = int((s+e)/2)
        A = A[:h] + [c]*len(X) + A[h+1:]

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())

for i in range(Q):
    b, c = map(int, input().split())
    s = 0
    e = N
    h = int((s+e)/2)
    while A[h] != b and s != h :
        if A[h] < b:
            s = h
            h = int((s+e)/2)
        elif A[h] > b:
            e = h
            h = int((s+e)/2)
    X = []
    for j in range(s, e):
        if A[j] == b:
            X.append(j)
            A[j] = c
    print(sum(A))
    if len(X) > 0:
        A = A[:X[0]] + A[X[-1]:]
        s = 0
        e = len(A)
        h = int((s+e)/2)
        while A[h] != c and s != h :
            if A[h] < c:
                s = h
                h = int((s+e)/2)
            elif A[h] > c:
                e = h
                h = int((s+e)/2)
        A = A[:h] + [c]*len(X) + A[h+1:]