Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    base = sum(a)
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        offset = c -b
        cnt = 0
        for i, aaa in enumerate(a):
            if aaa == b:
                a[i] = c
                cnt += 1
        base = base + offset*cnt
        print(base)
        

if __name__ == "__main__":
    main()

Fixed submission:
from sys import stdin

mapping = [0] * 100001

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    base = sum(a)
    for aaa in a:
        mapping[aaa] += 1
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        offset = c - b
        kazu = mapping[b]
        base = base + kazu*offset
        mapping[b] = 0
        mapping[c] += kazu
        
        print(base)
        

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        a = [c if x == b else x for x in a]
        print(sum(a))

if __name__ == "__main__":
    main()

Fixed submission:
from sys import stdin

mapping = [0] * 100001

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    base = sum(a)
    for aaa in a:
        mapping[aaa] += 1
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        offset = c - b
        kazu = mapping[b]
        base = base + kazu*offset
        mapping[b] = 0
        mapping[c] += kazu
        
        print(base)
        

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

memos = [False] * 102

for p in P:
    memos[p] = True

tgt = x
offset = 1
look_down = True
while True:

    if memos[tgt] == False:
        break
    if look_down:
        look_down = False
        tgt = tgt-offset
    else:
        look_down = True
        tgt = offset + offset
        offset += 1

print(tgt)


Fixed submission:
from sys import stdin

a = [int(x) for x in stdin.readline().rstrip().split()]


for i, x in enumerate(a):
    i += 1
    if x == 0:
        print(i)

Buggy python submission (verdict: Runtime Error):
from sys import stdin

x, y = [int(x) for x in stdin.readline().rstrip().split()]


if y < 2*x or 4*x < y:
    print('No')
else:
    if (4*x-y) % 2 == 0:
        print('Yes')
    else:
        print('No')


Fixed submission:
from sys import stdin

a = [int(x) for x in stdin.readline().rstrip().split()]


for i, x in enumerate(a):
    i += 1
    if x == 0:
        print(i)

Buggy python submission (verdict: Runtime Error):
from sys import stdin

x, y = [int(x) for x in stdin.readline().rstrip().split()]


if y < 2*x and 4*x < y:
    print('No')
else:
    if (4*x-y) % 2 == 0:
        print('Yes')
    else:
        print('No')


Fixed submission:
from sys import stdin

a = [int(x) for x in stdin.readline().rstrip().split()]


for i, x in enumerate(a):
    i += 1
    if x == 0:
        print(i)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

memos = [False] * 102

for p in P:
    memos[p] = True

tgt = x
offset = 1
look_down = True
while True:

    if memos[tgt] == False:
        break
    if look_down:
        look_down = False
        tgt = tgt-offset
    else:
        look_down = True
        tgt = offset + offset
        offset += 1

print(tgt)


Fixed submission:
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

    memos = [False] * 102

    for p in P:
        memos[p] = True

    tgt = x
    offset = 1
    look_down = True
    while True:

        if memos[tgt] == False:
            break
        if look_down:
            look_down = False
            tgt = x-offset
        else:
            look_down = True
            tgt = tgt + offset + offset
            offset += 1

    print(tgt)
else:
    print(x)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]

rest_lists = []

P.sort()

def return_filtered(div, rl):
    new = []
    protect = True
    for tgt in rl:
        if protect and tgt == div:
            new.append(tgt)
            protect = False
        elif tgt == div and len(new) >0:
            new.pop()
        elif not tgt % div == 0:
            new.append(tgt)
    print(new)
    return new

new_list = P
k = 0
while True:
    if len(new_list) == 0:
        break
    k += 1
    if 1+k > len(new_list):
        break
    new_list = return_filtered(new_list[1+k], new_list)

print(len(new_list))

Fixed submission:
from sys import stdin

n = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

# 使わなくて良い
# def get_sieve_of_eratosthenes_new(n):
#     import math
#     if not isinstance(n, int):
#         raise TypeError('n is int type.')
#     if n < 2:
#         raise ValueError('n is more than 2')
#     prime = []
#     limit = math.sqrt(n)
#     data = [i + 1 for i in range(1, n)]
#     while True:
#         p = data[0]
#         if limit <= p:
#             return prime + data
#         prime.append(p)
#         data = [e for e in data if e % p != 0]

# 倍数はOUTという判定を行ってく

# その前に複数あるものはのぞく

cnt = [0] * ((10**6)+1)
for elem in a:
    cnt[elem] += 1

filtered = []

for i in range((10**6)+1):
    if cnt[i] == 1:
        filtered.append(i)

# 倍数かどうかチェック用カウンタ
cnt = [0] * ((10**6)+1)

# 重複のない要素それぞれで倍数を見ていく（上限まで）
a = list(set(a))
for elem in a:
    # 自分自身はカウントしない
    # elemずつ増えるので、倍数という意味になる
    for i in range(elem*2, (10**6)+1, elem):
        cnt[i] += 1

ans = 0
# filteredのうち何らかの倍数になっていないものの数が答え
for i in filtered:
    if cnt[i] == 0:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters = [0]
dd = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters.extend(dd)

max_intense = False
additional = 0
if k >= n-1:
    print(" ".join(list(map(str, [n]*n))))
else:
    for times in range(k):
        counter = 0
        new_intense_counters = [0] * (n+1)
        add_all = 0
        for i, intense in enumerate(intense_counters):
            if i == 0:
                continue
            intense += additional

            if intense == n-1:
                counter += 1
                add_all += 1
            else:
                min = i - intense
                if min < 1:
                    min = 1
                max = i + intense
                if max > n:
                    max = n

                if min == 1 and max == n:
                    add_all += 1
                else:
                    for lighted_position in range(min, max+1):
                        new_intense_counters[lighted_position] += 1
        if counter == n:
            max_intense = True
            break
        intense_counters = new_intense_counters
        additional = add_all

    if max_intense:
        print(" ".join(list(map(str, [n]*n))))
    else:
        print(" ".join(list(map(str, intense_counters[1:]))))


Fixed submission:
n = input()

print(n[:3])

Buggy python submission (verdict: Runtime Error):
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters = [0]
dd = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters.extend(dd)


for times in range(k):
    lighted_positions = []
    for i, intense in enumerate(intense_counters):
        if i == 0:
            continue

        min = i - intense
        max = i + intense

        for lighted_position in range(min, max+1):
            if 0 < lighted_position and lighted_position <= n:
                lighted_positions.append(lighted_position)

    intense_counters = [0] * (n+1)
    for lp in lighted_positions:
        intense_counters[lp] += 1

print(" ".join(list(map(str, intense_counters[1:]))))


Fixed submission:
n = input()

print(n[:3])
Buggy python submission (verdict: Runtime Error):
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7)
solve()

Fixed submission:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans % (10**9+7)
  ans = ans**2
  ans = ans % (10**9+7)
  for a in AA:
    aa = (a**2) % (10**9+7)
    ans -= a**2
    while ans<0:
      ans += 10**9+7
  ans = ans % (10**9+7)
  print(int(ans/2))
solve()

Fixed submission:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  N = int(input())
  AA = list(map(int,input().split()))

  ans = 0
  for a in AA:
    ans += a
  ans = ans % (10**9+7)
  ans = ans**2
  ans = ans % (10**9+7)
  for a in AA:
    ans -= a**2
    while ans<0:
      ans += 10**9+7
  ans = ans % (10**9+7)
  print(int(ans/2))
solve()

Fixed submission:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AA = list(map(int,input().split()))

ans = 0
for a in AA:
  ans += a
ans = ans % (10**9+7)
ans = ans**2
for a in AA:
  ans -= a**2
  while ans<0:
    ans += 10**9+7
  ans = (ans) % (10**9+7)
ans = ans % (10**9+7)
print(int(ans/2))

Fixed submission:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  N, M, K = map(int,input().split())
  AA = list(map(int,input().split()))
  BB = list(map(int,input().split()))
  A_max = 0
  AAs = [0]*N
  AAs[0] = AA[0]
  if K>=AAs[0]:
    A_max = 1
  for i in range(1,N):
    AAs[i] = AAs[i-1] + AA[i]
    if K>=AAs[i]:
      A_max+=1
  BBs = [0]*M
  BBs[0] = BB[0]
  for i in range(1,M):
    BBs[i] = BBs[i-1] + BB[i]
  Book_max = 0
  for i in range(A_max+1):
    b_max = i
    if i == 0:
      B_time = K
    else:
      B_time = K - AAs[i-1]
    for j in range(M):
      if B_time>=BBs[j]:
        b_max +=1
    if Book_max<b_max:
      Book_max = b_max
  print(Book_max) 
solve()

Fixed submission:
def solve():
  N, M, K = map(int,input().split())
  AA = list(map(int,input().split()))
  BB = list(map(int,input().split()))
  A_max = 0
  AAs = [0]*N
  AAs[0] = AA[0]
  if K>=AAs[0]:
    A_max = 1
  for i in range(1,N):
    AAs[i] = AAs[i-1] + AA[i]
    if K>=AAs[i]:
      A_max+=1
  BBs = [0]*M
  BBs[0] = BB[0]
  BM = M
  for i in range(1,M):
    BBs[i] = BBs[i-1] + BB[i]
  Book_max = 0
  for i in range(A_max+1):
    b_max = 0
    if i == 0:
      B_time = K
    else:
      B_time = K - AAs[i-1]
    for j in range(BM-1,-1,-1):
      #print(i,j,A_max,b_max,B_time,BM)
      if B_time>=BBs[j]:
        b_max = j+1
        BM = b_max
        break
    if Book_max<b_max+i:
      Book_max = b_max+i
  print(Book_max) 
solve()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AA = list(map(int,input().split()))
res = AA[0]
for a in AA[1:]:
    res = res*a
if res>1e18:
  print('-1')
else:         
  print(res)

Fixed submission:
N = int(input())
AA = list(map(int,input().split()))
res = AA[0]
if 0 in AA:
  print(0)
else:
  for a in AA[1:]:
    res = res*a
    if res>1e18:
      print('-1')
      exit()
  print(res)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())
Smx = 0
if B<N:
    N = B
for i in range(N+1):
    S = int((A*(i % B) - ((A*i) % B))/B)
    if Smx<S:
        Smx = S
print(Smx)

Fixed submission:
A, B, N = map(int, input().split())
Smx = 0
if B<N:
    N = B
for i in range(N,0,-1):
    if i<N-A:
        break
    S = int((A*(i % B) - ((A*i) % B))/B)
    if Smx<S:
        Smx = S
print(Smx)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
NN = [[0 for i in range(N)] for j in range(N)]
NN2 = [[0 for i in range(N)] for j in range(N)]
 
  
for i in range(N):
  for j in range(i,N):
    NN[i][j] = j-i
for i in range(N):
  for j in range(i+1,N):
    NN2[i][j] = abs(i-X)+abs(j-Y)+1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    if NN[i][j]>NN2[i][j]:
      CNT[NN2[i][j]] += 1
    else:
      CNT[NN[i][j]] += 1
for i in range(1,N):
  print(CNT[i])

Fixed submission:
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
NN = np.array([np.zeros(N,dtype='int')]*N)
NN2 = np.array([np.zeros(N,dtype='int')]*N)

  
for i in range(N):
  for j in range(i,N):
    NN[i][j] = j-i
for i in range(N):
  for j in range(i+1,N):
    NN2[i][j] = abs(i-X)+abs(j-Y)+1
#print(NN)
#print(NN2)
NN_max = np.minimum(NN, NN2)
#print(NN_max)
for i in range(1,N):
  print(len(np.where(NN_max==i)[0]))

Fixed submission:
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, X, Y = map(int,input().split())

NN = np.array([np.zeros(N,dtype='bool')]*N)
count = 0
#initialize
for i in range(N-1):
  NN[i][i+1] = True
NN[X-1][Y-1] = True
print(N)
for _ in range(N-2):
  NN2 = np.array(NN)
  for i in range(N):
    for j in range(i+1,N):
      if NN[i][j] == True:
        #top
        if i !=0:
          if (not NN[i-1][j]) and (i-1<j):
            NN2[i-1][j] = True
        #bottom
        if i != N-1:
          if (not NN[i+1][j]) and (i+1<j):
            NN2[i+1][j] = True
            count += 1
        #left
        if j != 0:
          if (not NN[i][j-1]) and (i<j-1):
            NN2[i][j-1] = True
        #right
        if j != N-1:
          if (not NN[i][j+1]) and (i<j+1):
            NN2[i][j+1] = True
  count = np.sum(NN2)-np.sum(NN)
  if count==0:
    NN = NN2
    print(0)
  else:
    NN = NN2
    print(count)
          


Fixed submission:
N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
 
alpha_map = {chr(i):i for i in range(97,123)}
alpha_map_inv = {i:chr(i) for i in range(97,123)}
a = [0] * len(S)
for i, s in enumerate(S):
  a[i] = alpha_map[s]

reversed = False

for _ in range(Q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    if reversed:
      reversed = False
    else:
      reversed = True
  else:
    if (query[1] == '1')&(not reversed):
      a.insert(0,alpha_map[query[2]])
    elif (query[1] == '2')&(reversed):
      a.insert(0,alpha_map[query[2]])
    else:
      a.append(alpha_map[query[2]])
ss = [''] * len(a)
for i, aa in enumerate(a):
  ss[i] = alpha_map_inv[aa]
if reversed:
  ss.reverse()
print(''.join(ss))

Fixed submission:
from collections import deque
S = input()
Q = int(input())
 
alpha_map = {chr(i):i for i in range(97,123)}
alpha_map_inv = {i:chr(i) for i in range(97,123)}
a = deque()
for s in S:
  a.append(s)
reversed = False
 
for _ in range(Q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    if reversed:
      reversed = False
    else:
      reversed = True
  else:
    if (query[1] == '1')&(not reversed):
      a.appendleft(query[2])
    elif (query[1] == '2')&(reversed):
      a.appendleft(query[2])
    else:
      a.append(query[2])
if reversed:
  a.reverse()
print(''.join(list(a)))
Buggy python submission (verdict: Runtime Error):
if A==B:
  if A!=C:
    print('Yes')
  else:
    print('No')
else:
  if A==C:
    print('Yes')
  elif B==C:
    print('Yes')
  else:
    print('No')

Fixed submission:
nums = input().rstrip().split(" ")
n1 = int(nums[0])
n2 = int(nums[1])
n3 = int(nums[2])
if n1 == n2 and n2 == n3 and n1 == n3:
  print("No")
elif n1 != n2 and n2 != n3 and n1 != n3:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n=input()
s=0
for i in n:
  s+=int(i)
  s=s%9
if s%9==0:
  print(Yes)
else:
  print("No")
  

Fixed submission:
import math
n,x,t=list(map(int,input().split()))
print(math.ceil(n/x)*t)
Buggy python submission (verdict: Runtime Error):
n=input()
s=0
for i in n:
  s+=int(i)
  s=s%9
if s%9==0:
  print(Yes)
else:
  print("No")
  

Fixed submission:
n=input()
s=0
for i in n:
  s+=int(i)
  s=s%9
if s%9==0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n=input()
s=0
for i in n:
  s+=int(i)
if s%9==0:
  print(Yes)
else:
  print("No")
  

Fixed submission:
n=input()
s=0
for i in n:
  s+=int(i)
  s=s%9
if s%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
sum=0
for i in range(1,n):
  m=max(l[:i])
  if l[i]<m:
    sum+=m-l[i]
print(sum)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
sum=0
m=l[0]
for i in range(1,n):
  m=max(m,l[i])
  sum+=m-l[i]
print(sum)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
attack = True
win = True

while a < 0 | c < 0:
	if attack:
		c -= b
		attack = False
	else:
		a -= d
		attack = True
		if a < 0:
			win = False
            
print("Yes") if win else print('No')


Fixed submission:
s, w = map(int, input().split())

print("unsafe") if (s <= w) else print("safe")

Buggy python submission (verdict: Runtime Error):
a, b, c ,d = map(int, input().split())
attack = True
win = True

while True:
	if attack:
		c -= b
		attack = False
		if c < 0:
			break
	else:
		a -= d
		attack = True
		if a < 0:
			win = False 
			break


print("Yes") if win else print('No')


Fixed submission:
s, w = map(int, input().split())

print("unsafe") if (s <= w) else print("safe")

Buggy python submission (verdict: Runtime Error):
a, b, c ,d = map(int, input().split())
attack = True
win = True

while True:
	if attack:
		c -= b
		attack = False
		if c < 0:
			break
	else:
		a -= d
		attack = True
		if a < 0:
			win = False 
			break


print("Yes") if win else print('No')



Fixed submission:
s, w = map(int, input().split())

print("unsafe") if (s <= w) else print("safe")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
m = n
while m > 0:
  n = min(abs(n - k), n)
  if m > n:
      m = n
  else:
      print(m)
      break

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

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
m = n
while m > 0:
  n = min(abs(n - k), n)
  if m > n:
      m = n
  else:
      print(n)
      break

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

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
m = n
while m > 0:
  n = min(abs(n - k), m)
  if m > n:
      m = n
  else:
      print(n)
      break

Fixed submission:
a, b, c = map(int, input().split())
print(c, a, b)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
from collections import Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N = int(stdin.readline().rstrip())
A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
attack = 0
menber = 0

while attack < N and menber < N:
    attack += 1
    ans = A.count(attack)
    print(ans)
    menber += ans
    
if attack < N:
    print('0\n'*(N-attack))

Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
from collections import Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N = int(stdin.readline().rstrip())
A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))

A_ = Counter(A)

for i in range(1,N+1):
    print(A_[i])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(stdin.readline().rstrip())
ans = 0

for c in range(2,K+1):
    for b in range(2,K+1):
        for a in range(2,K+1):
            ans += gcd(a,b,c)
            
print(ans+(K**3-(K-1)**3))

Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(stdin.readline().rstrip())
ans = 0
for_c = []

for b in range(1,K+1):
    for a in range(1,K+1):
        if math.gcd(a,b) == 1:
            ans += K
        else:
            for_c.append(math.gcd(a,b))

for c in range(1,K+1):
    for ab in range(len(for_c)):
        ans += math.gcd(for_c[ab],c)

print(ans)