Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, X, T = map(int, input().split())

if X==1:
  ans == N*T
else:
  if N > X:
    ans = (N//X)*T
    ans = ans+T
  elif N < X:
    ans = T

print(ans)


Fixed submission:
N, X, T = map(int, input().split())
i=0
ans=0

if X==1:
  ans= N*T
else:
  if N<=X:
    ans = T
  else:
    while i<N :
      i = i+X
      ans = ans+T 
print(ans)

Buggy python submission (verdict: Runtime Error):
N, X, T = map(int, input().split())
if N > X:
  ans = (N//X)*T
  ans = ans+T
elif N < X:
  ans = T
elif X==1:
  ans == N*T
print(ans)


Fixed submission:
N, X, T = map(int, input().split())
i=0
ans=0

if X==1:
  ans= N*T
else:
  if N<=X:
    ans = T
  else:
    while i<N :
      i = i+X
      ans = ans+T 
print(ans)
Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
flg = 0
if n[0]==7:
  flg = 1
if n[1]==7:
  flg = 1
if n[2]==7:
  flg = 1

if flg == 1:
  print('Yes')
else:
  print('No')


Fixed submission:
n = list(map(int, input()))
flg = 0
if n[0]==7:
  flg = 1
if n[1]==7:
  flg = 1
if n[2]==7:
  flg = 1

if flg == 1:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
n = int(input())

for i in range(1,n)
  if i%15==0:
    print('FizzBuzz')
  elif i%5==0:
    print('Buzz')
  elif i%3==0:
    print('Fizz')
  else:
    print(i)


Fixed submission:
n = list(map(int, input()))
flg = 0
if n[0]==7:
  flg = 1
if n[1]==7:
  flg = 1
if n[2]==7:
  flg = 1

if flg == 1:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
a, b = int(input().split(" "))

quotinent = a // b

res = max(a - b * quotinent, abs( a- b * (quotinent + 1)))
print(res)

Fixed submission:
a, b = map(int, input().split(" "))

quotinent = a // b

res = min(a - b * quotinent,  abs(a- b * (quotinent + 1)))
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

N, X, D = map(int, read().split())

if D == 0:
    if X == 0:
        print(1)
    else:
        print(N+1)
    exit()

g = gcd(X, D)
X //= g; D //= g
if D < 0:
    X, D = -X, -D

def F(d):
    event = []
    for n in range(d, N+1, D):
        
        low = X * n // D + n * (n-1) // 2 # 右の項は総和の式から
        high = X * n // D + n * (N+N-n-1) // 2
        event.append((low, 0))
        event.append((high, 1))
    event.sort()
    overlap = 0
    cnt = 0
    for x, t in event:
        if not t:
            if not overlap:
                left_end = x
            overlap += 1
        else:
            overlap -= 1
            if not overlap:
                cnt += x - left_end + 1
    return cnt
#min(D,N+1)
answer = sum(F(d) for d in range(D))
print(answer)



Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

N, X, D = map(int, read().split())

if D == 0:
    if X == 0:
        print(1)
    else:
        print(N+1)
    exit()

g = gcd(X, D)
X //= g; D //= g
if D < 0:
    X, D = -X, -D

def F(d):
    event = []
    for n in range(d, N+1, D):
        
        low = X * n // D + n * (n-1) // 2 # 右の項は総和の式から
        high = X * n // D + n * (N+N-n-1) // 2
        event.append((low, 0))
        event.append((high, 1))
    event.sort()
    overlap = 0
    cnt = 0
    for x, t in event:
        if not t:
            if not overlap:
                left_end = x
            overlap += 1
        else:
            overlap -= 1
            if not overlap:
                cnt += x - left_end + 1
    return cnt

answer = sum(F(d) for d in range(min(D,N+1)))
print(answer)
Buggy python submission (verdict: Runtime Error):
from math import gcd 


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

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(gcd(gcd_l[i], A[i]))
    gcd_r.append(gcd(gcd_r[i], A[-(i+1)]))

gcd_r = gcd_r[::-1]

ans = []
for i in range(N):
    ans.append(gcd(gcd_l[i], gcd_r[i+1]))

print(max(ans))

Fixed submission:
from fractions import gcd


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

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(gcd(gcd_l[i], A[i]))
    gcd_r.append(gcd(gcd_r[i], A[-(i+1)]))

gcd_r = gcd_r[::-1]

ans = []
for i in range(N):
    ans.append(gcd(gcd_l[i], gcd_r[i+1]))

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a= list(map(int, input().split()))

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10 ** 18:
    ans = -1

print(ans)

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

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit(0)

ans = 1
for i in range(0, n):
    ans = ans * a[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int,input().split())
print(max(A)-min(A))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
print(max(A)-min(A))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int,input().split())
print(max(A)-min(A))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
print(max(A)-min(A))
Buggy python submission (verdict: Runtime Error):
alp = input()
if str.isupper(alp) == True:
  print("A")
else:
  pritn("a")

Fixed submission:
alp = input()
if str.isupper(alp) == True:
  print('A')
else:
  print('a')
Buggy python submission (verdict: Runtime Error):
number = int(input())
flag = False
for i in range(len(number)):
	if int(number[i])==7:
		flag = True
		break
if(flag):
	print("Yes")
else:
	print("No")
























Fixed submission:
number = str(input())
flag = False
for i in range(len(number)):
	if int(number[i])==7:
		flag = True
		break
if(flag):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
n , m = map(int,input().split())
arr = list(map(int,input().split()))
add = sum(arr)
miniVotes = int(add*(1/(4*m)))
cnt = 0
for i in range(len(arr)):
	if arr[i]>=miniVotes:
		cnt+=1
if(cnt>=m):
	print("Yes")
else:
	print("No")

Fixed submission:
x ,y ,z = map(int,input().split())
print(z,x,y)

Buggy python submission (verdict: Runtime Error):
x ,y ,z = map(int,intput().split())
print(z,x,y)


Fixed submission:
x ,y ,z = map(int,input().split())
print(z,x,y)
Buggy python submission (verdict: Runtime Error):
def check(string):
	N = len(string)
	rev = string[::-1]
	for i in range(N//2+1):
		if(rev[i]!=string[i]):
			break
			return False
	return True


string = input()
n = len(string)
n-=1
str1 = string[0:((n-1)//2)]
str2 = string[((n+3)//2):n]
if check(str1) and check(str2):
	print("Yes")
else:
	print("No")

Fixed submission:
def check(string2):
	N = len(string2)
	rev = string2[::-1]
	for i in range((N//2)+1):
		if(rev[i]!=string2[i]):
			return False
	return True


string = input()
n = len(string)
n-=1
str1 = string[0:int((n)/2)]
# print(str1)
str2 = string[int((n)/2)+1:n+1]
# print(str2)
if check(str1) and check(str2) and check(string):
	print("Yes")
else:
	print("No")

Buggy python submission (verdict: Runtime Error):
def check(string):
	N = len(string):
	rev = string[::-1]
	for i in range(N//2+1):
		if(rev[i]!=string[i]):
			break
			return False
	return True


string = input()
n = len(string)
n-=1
str1 = string[0:((n-1)/2)]
str2 = string[((n+3)/2):n]
if check(str1) and check(str2):
	print("Yes")
else:
	print("No")

Fixed submission:
def check(string2):
	N = len(string2)
	rev = string2[::-1]
	for i in range((N//2)+1):
		if(rev[i]!=string2[i]):
			return False
	return True


string = input()
n = len(string)
n-=1
str1 = string[0:int((n)/2)]
# print(str1)
str2 = string[int((n)/2)+1:n+1]
# print(str2)
if check(str1) and check(str2) and check(string):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
n , m = map(int,input().split())
dp = [-1 for _ in range(n)]
flag = True 
for _ in range(m):
	i , val =  map(int,input().split())
	if dp[i-1] == -1:
		dp[i-1]=val
	elif dp[i-1]!=val:
		flag = False
		# print(dp[i-1])
		break
if dp[0]==0:
	flag = False
if flag:
	for i in range(n):
		if dp[i]==-1:
			dp[i]=0
	if dp[0]==0:
		dp[0]=1
	for x in dp:
		print(str(x),end="")
else:
	print("-1")

Fixed submission:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
grid = []
for _ in range(3):
	temp = []
	temp = list(map(int,input().split()))
	grid.append(temp)
N = int(input())
b = []
for _ in range(N):
	b.append(int(input()))
for x in b:
	for i in range(3):
		for j in range(3):
			if grid[i][j]==x:
				grid[i][j]= -(grid[i][j])
ans = -1
# if not (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):	
for i in range(3):
	if grid[i][0]<0 and grid[i][1]<0 and grid[i][2]<0:
		ans  = 1
		break
	elif(grid[0][i]<0 and grid[1][i]<0 and grid[2][i]<0):
		ans = 1
		break
if ans!=1:
	if (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):
		ans = 1
	if( grid[0][2]<0 and grid[1][1]<0 and grid[2][0]<0):
		ans =1  
if(ans ==1):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
        break

if ans:
	print("NO")
else:
	print("YES")




Fixed submission:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
		break

if ans:
	print("NO")
else:
	print("YES")

Buggy python submission (verdict: Runtime Error):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
        break

if ans:
	print("NO")
else:
	print("YES")




Fixed submission:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
		break

if ans:
	print("NO")
else:
	print("YES")

Buggy python submission (verdict: Runtime Error):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
        break

if ans:
	print("No")
else:
	print("Yes")




Fixed submission:
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(N-1):
	if arr[i]==arr[i+1]:
		ans = 1
		break

if ans:
	print("NO")
else:
	print("YES")
Buggy python submission (verdict: Runtime Error):
N = int(input())
string1 = str(input())
string2 = str(input())
res = ''
j = 0
k = 0
for i in range((2*N)):
	if(i%2!=0):
		res+=string1[j]
		j+=1
	else:
		res+=string2[k]
		k+=1
print(res)

Fixed submission:
N = int(input())
string1 , string2 = map(str,input().split())
res = ''
j = 0
k = 0
for i in range((2*N)):
	if(i%2==0):
		res+=string1[j]
		j+=1
	else:
		res+=string2[k]
		k+=1
print(res)
Buggy python submission (verdict: Runtime Error):
def main():
	n = int(input())
	arr = list(map(int,input().split()))
	for i in range(len(arr)-1):
		if arr[i]-1>(arr[i-1]-1):
			# print(i)
			print("No")
			return
	print("Yes")
	return


main()

Fixed submission:
def main():
	n = int(input())
	cnt = 0
	for i in range(1,n+1):
		string = str(i)
		if len(string)%2==1:
			cnt+=1
	print(cnt)




main()
Buggy python submission (verdict: Runtime Error):
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()


Fixed submission:
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()

Buggy python submission (verdict: Runtime Error):
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()


Fixed submission:
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()
Buggy python submission (verdict: Runtime Error):
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    maxRow = 0
    maxCol = 0
    mR = 0
    mC = 0
    for i in row:
        if row[i]>mR:
            mR = row[i]
            maxRow = i
    for i in col:
        if col[i]>mC:
            mC = col[i]
            maxCol = i
    rd = {}
    cd = {}
    for i in row:
        if row[i] == mR:
            rd.add(i)
    for i in col:
        if row[i] == mC:
            cd.add(i)
    diff = rd.difference(cd)
    s = mR+mC
    if len(diff) == 0:
        s-=1
        print(s)
        return
    print(s)
    return

x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)


Fixed submission:
from math import ceil
N,X,T = list(map(int,input().split(' ')))
p = ceil(N/X)
print(p*T)

Buggy python submission (verdict: Runtime Error):
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    a = max(row.values())
    b = max(col.values())
    print(a+b-1)


x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)


Fixed submission:
from math import ceil
N,X,T = list(map(int,input().split(' ')))
p = ceil(N/X)
print(p*T)
Buggy python submission (verdict: Runtime Error):
    k = input()
    l = list(map(int,input().split(' ')))
    c = 0
    for i in range(len(l)-1):
      x = l[i+1]-lis[i]
      if x<0:
        l[i+1]+=abs(x)
      	c+=abs(x)
    print(c)

Fixed submission:
try:
    k = int(input())
    l = list(map(int,input().split(' ')))
    c = 0
    for i in range(len(l)-1):
      x = l[i+1]-l[i]
      if x<0:
        l[i+1]+=abs(x)
        c+=abs(x)
    print(c)
except:
    pass

Buggy python submission (verdict: Runtime Error):
k = input()
l = list(map(int,input()))
c = 0
for i in range(len(l)-1):
  x = l[i+1]-lis[i]
  if x<0:
    l[i+1]+=abs(x)
  	c+=abs(x)
print(c)

Fixed submission:
try:
    k = int(input())
    l = list(map(int,input().split(' ')))
    c = 0
    for i in range(len(l)-1):
      x = l[i+1]-l[i]
      if x<0:
        l[i+1]+=abs(x)
        c+=abs(x)
    print(c)
except:
    pass
Buggy python submission (verdict: Runtime Error):
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        costs.append(min(x+costs[-1]),min(x+costs[-2]))
    print(costs)
    return costs[-1]
input()
lis = list(map(int,input().split(' ')))
print(sol(lis))

Fixed submission:
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        costs.append(min(x+costs[-1],y+costs[-2]))
    return costs[-1]
input()
lis = list(map(int,input().split(' ')))
print(sol(lis))
Buggy python submission (verdict: Time Limit Exceeded):
def sol(lis,K):
    import sys
    dp = [sys.maxsize]*len(lis)
    dp[0] = 0
    for i in range(len(lis)):
        for j in range(i+1,i+K+1):
            if j<len(lis):
                dp[j] = min(dp[j],dp[i]+abs(lis[j]-lis[i]))
    print(dp[-1])
n,k = list(map(int,input().split(' ')))
lis = list(map(int,input().split(' ')))
sol(lis,k)

Fixed submission:
def sol(lis,K):
    import sys
    dp = [sys.maxsize]*len(lis)
    dp[0] = 0
    for i in range(len(lis)):
        for j in range(i+1,i+K+1):
            if j<len(lis):
                dp[j] = min(dp[j],dp[i]+abs(lis[j]-lis[i]))
    print(dp[-1])
n,k = list(map(int,input().split(' ')))
lis = list(map(int,input().split(' ')))
sol(lis,k)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

s = 0

m = 1000000007

for i in range(n):

    if i == n-1:
        pass
    else:
        for j in range(i+1, n):
            s += a[i] * a[j]

s = s % m

print(s)


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

m = 1000000007

s = sum(a)
ans = 0
for i in range(n):
    aa = a[i]
    ans += aa * (s - aa)

ans = ans//2
ans = ans % m

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

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

h.sort()
h.reverse()

en = []
ans = 0

for i, j in enumerate(h):
    # en.append(j)
    # print([h[0],h[0]])
    if i == 0:
        en.append((h[0],h[0]))
    else:
        mintmp = min(en[0])
        maxtmp = max(en[0])
        ans += mintmp
        en.append((maxtmp, h[i]))
        en.append((mintmp, h[i]))
        en.pop(0)

    # print(en)

print(ans)

Fixed submission:
from collections import deque

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

h.sort()
h.reverse()

en = deque()
ans = 0

for i, j in enumerate(h):
    if i == 0:
        en.append((j,j))
    else:
        maxtmp, mintmp = en.popleft()
        ans += mintmp
        en.append((maxtmp, j))
        en.append((mintmp, j))

print(ans)
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()))

print(a)
print(b)

read = 0
time_ = 0
ai = 0
bi = 0

max_read = 0

def readbook(time, read, ai, bi, isa):
    
    if isa:
        if ai < n:
            time += a[ai]
        else:
            return
    else:
        if bi < m:
            time += b[bi]
        else:
            return
    if time > k:
        return
    else:
        # readable
        read += 1
        global max_read
        if read > max_read:
            max_read = read

        readbook(time, read, ai + 1, bi, True)
        readbook(time, read, ai, bi + 1, False)


readbook(time_, read, ai, bi, True)
read = 0
time_ = 0
ai = 0
bi = 0
readbook(time_, read, ai, bi, False)

if max_read !=0:
    max_read += 1
print(max_read)

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])
# print(a)
# print(b)

ans, j = 0, m

# 
for i in range(n+1):
    if a[i] > k:
        break

    # bのパイルから何冊読めない？
    while b[j] > k -a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())

i = 0
idx = n
if n > 26:
    while n > 0:
        idx = n
        i += 1
        n = n - 26**i
        # print(i, n)

else:
    print(alpha[n-1])
    sys.exit()

# letter len : i, idx 

def getstr(i, idx):

    if i == 0:
        return ""
    elif i == 1:
        return alpha[idx-1]
    else:
        # number in the range
        t = 26**i

        # number  of bin
        b = int(26 * idx / t)
        idx -= b * int(t/26) 
        i -= 1

        return alpha[b] + getstr(i, idx)

print(getstr(i,idx))


Fixed submission:
import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())

i = 0
idx = n
if n > 26:
    while n > 0:
        idx = n
        i += 1
        n = n - 26**i
        # print(i, n)

else:
    print(alpha[n-1])
    sys.exit()

# letter len : i, idx 

def getstr(i, idx):

    if i == 0:
        return ""
    elif i == 1:
        return alpha[idx-1]
    else:
        # number in the range
        t = 26**i

        # number  of bin
        b = int(26 * idx / t)

        bb = 0
        tmp = idx
        while tmp > 0:
            tmp -= int(t/26)
            bb += 1

        b = bb - 1
        idx -= b * int(t/26) 
        i -= 1
        
        return alpha[b] + getstr(i, idx)

print(getstr(i,idx))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

bc = [list(map(int, input().split())) for i in range(q)]

a.sort()
uni = list(set(a))

kosu = [a.count(i) for i in uni]

for i in bc:
    b = i[0]
    c = i[1]

    if b in uni:
        # remove original
        tar = uni.index(b)
        uni.pop(tar)
        num = kosu.pop(tar)
        
        # add new
        if c in uni:
            idx = uni.index(c)
            kosu[idx] += num
        else:
            uni.append(c)
            kosu.append(num)

    ans = 0
    for ii in range(len(uni)):
        ans += uni[ii] * kosu[ii]

    print(ans)

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

bc = [list(map(int, input().split())) for i in range(q)]

cnt = [0] * 100005 

for i in range(n):
    cnt[a[i]] += 1
    
tot = 0
for j in range(len(cnt)):
    tot += j * cnt[j]

# print(tot)

for k in range(q):
    b = bc[k][0]
    c = bc[k][1]
    tot -= b*cnt[b]
    tot -= c*cnt[c]
    cnt[c] += cnt[b]
    cnt[b] = 0
    tot += b*cnt[b]
    tot += c*cnt[c]
    print(tot)