Harryxun/stf_run huggingface dataset:
#import numpy as np
import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))

    def check(x):
        return N+K >= sum(map(lambda a: math.ceil(a/x), A))

    s = max(A)//2
    h = s//2
    c = check(s)
    while h > 0 or not c:
        if c:
            s -= h
        else:
            s += max(1,h)
        h //= 2
        c = check(s)
    print(s)

main()


### FIXED CODE ###

#import numpy as np
import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))

    def check(x):
        if x <= 0:
            return False
        else:
            return N+K >= sum(map(lambda a: math.ceil(a/x), A))

    s = max(A)//2
    h = s//2
    c = check(s)
    last = c
    while True:
        if c:
            s -= max(1,h)
        else:
            s += max(1,h)
        h //= 2
        last = c
        c = check(s)
        if h <= 0 and last != c:
            if last:
                s += 1
            break
    print(s)

main()
from scipy.special import comb 

def cmb(n,r):
    return comb(n, r, exact=True)

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()


### FIXED CODE ###

import math
def cmb(n, r):
    if n<2:
        return 0

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()
def f(l, a, hist):
    if(a in hist):
        return -1
    if(a == 1):
        return len(hist)
    hist.append(a)
    return f(l,l[a]-1,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0]-1,[0]))

if(__name__ == "__main__"):
    solve()


### FIXED CODE ###

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())
a, b = map(int, input().split())
A = list(str(a) * b)
B = list(str(b) * a)
if A[0] >= b[0]:
    print(str(a)*b)
else:
    print(str(b)*a)

### FIXED CODE ###

a, b = map(int, input().split())

l = ['{}'.format(a)*b, '{}'.format(b)*a]
l.sort()
print(l[0])
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline

n, m, q = [int(i) for i in input().split()]
abcd = []
canditates = []
ans = 0


for _ in range(q):
    abcd.append([int(i) for i in input().split()])


def helper(_min, _max, cur, res):
    if res == 0:
        canditates.append(list(cur))
    else:
        for i in range(_min, _max):
            cur.append(i)
            helper(i, _max, cur, res - 1)
            cur.pop()


helper(1, m + 1, [], m)

for A in canditates:
    _temp = 0
    for a, b, c, d in abcd:
        if A[b - 1] - A[a - 1] == c:
            _temp += d
    ans = max(ans, _temp)

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline

n, m, q = [int(i) for i in input().strip().split()]
abcd = []
canditates = []
ans = 0


for _ in range(q):
    abcd.append([int(i) for i in input().strip().split()])


def helper(_min, _max, cur, res):
    if res == 0:
        canditates.append(list(cur))
    else:
        for i in range(_min, _max):
            cur.append(i)
            helper(i, _max, cur, res - 1)
            cur.pop()


helper(1, m + 1, [], n)

for A in canditates:
    _temp = 0
    for a, b, c, d in abcd:
        if A[b - 1] - A[a - 1] == c:
            _temp += d

    ans = max(ans, _temp)

print(ans)
import sys
sys.setrecursionlimit(20)
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
startwithone=[i for i in number if i[0]==1]
notstartwithone=[i for i in number if i[0]!=1]
ans=0
flag2=0
def find(x):
  if root[x]==x:
    return x
  return find(root[x])
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  if find(1)==find(x):
    root[y]=x
  else:
    root[x]=y
def dfs(i,flag):
  global ans
  global root
  global flag2
  flag2=flag
  if bin(flag)[2:].count("1")!=n-2 or len(notstartwithone)<i:
    if len(notstartwithone)<i:
      return 0
    dfs(i+1,flag|2**i)
    dfs(i+1,flag)
  root=[i for i in defroot]
  rank=[i for i in defrank]
  for j in range(len(notstartwithone)):
    if flag&2**j>0:
      union(notstartwithone[j][0],notstartwithone[j][1])
  for j in range(1,n):
    if check(j,j+1)==False:
      return 0
  if len(set(root))==n:
    ans+=1
for i in startwithone:
  root=[i for i in range(n+1)]
  rank=[0]*(n+1)
  union(i[0],i[1])
  defroot=[i for i in root]
  defrank=[i for i in rank]
  dfs(0,0)
print(ans)

### FIXED CODE ###

import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
visit[1]=1
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].append(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in node[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)
n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))

def hoge(index, index1):
	if(index == 0 and index1 == 0):
		return min([enemy[0], beat[0]])
	elif(index >= 0 and index1 - index == 1):
		return min([enemy[index1], beat[index] - hoge(index, index)])
	elif(index >= 1 and index1 == index):
		return min([enemy[index] - hoge(index - 1, index), beat[index] ])
	else:
      print(index, index1)
res = 0
for i in range(n):
	res += hoge(i, i) + hoge(i, i+1)
print(res)


### FIXED CODE ###

n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))
ans = 0 
for i in range(n):
  #左を全力で倒す
  left = min([enemy[i], beat[i]])
  ans += left
  enemy[i] -= left
  beat[i] -= left
  
  right = min([enemy[i+1], beat[i]])
  ans += right
  enemy[i + 1] -= right
  beat[i] -= right
  
print(ans)
n = int(input())
A = list(map(int, input().split()))

rgb = [0, 0, 0]
ans = 1
for a in A:
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1

print(ans)


### FIXED CODE ###

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

rgb = [0, 0, 0]
ans = 1
for a in A:
    if a not in rgb:
        print(0)
        break
    ans = (ans * rgb.count(a)) % 1000000007
    idx = rgb.index(a)
    rgb[idx] += 1
else:
    print(ans)
N = int(input())
M = int(input())
total = 0

for i in range(M):
    A = int(input())
    total = total+A

if total <= N:
    print (N - total)
else:
    print (-1)


### FIXED CODE ###

import math

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

if (n-sum(a)) < 0:
    print(-1)
else:
    print(n-sum(a))
n = input()

for i,v in enumerate(n):
  if v == '9':
    n[i] = '1'
  elif v == '1':
    n[i] = '9'
    
print(n)

### FIXED CODE ###

n = input()

ans = ''
for i, v in enumerate(n):
    if v == '9':
        ans += '1'
    elif v == '1':
        ans += '9'
    else:
        ans += v

print(ans)
Beta
  paiza.IO
新規コード
一覧
ウェブ開発  
New!
日本語  サインアップ ログイン
Python3 Split Button!	
Enter a title here
Main.py 
Success  

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
s=input()
x,y = [int(i) for i in input().split()]
#print(s)
susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)
#print(susumu)
syokiti = susumu.pop(0)
susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]
x -= syokiti
  実行 (Ctrl-Enter) Split Button!             
出力
入力
コメント 0
(0.04 sec)
 
No

### FIXED CODE ###

import numpy as np

s=input()
x,y = [int(i) for i in input().split()]

#print(s)

susumu = [0]
for moji in s:
    if moji == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu[0]

susumu_NS = [i for i in susumu[1::2] if i!=0]
susumu_EW = [i for i in susumu[2::2] if i!=0]

x -= syokiti

#print(susumu)
#print(susumu_NS)
#print(susumu_EW)
# ＥＷの部分和でx? NSの部分和でy？

LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_NS)):
    dpleft =np.r_[dp[susumu_NS[j]:],np.zeros(susumu_NS[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_NS[j], dtype=bool),dp[:-susumu_NS[j]]]
    dp = dpleft|dpright
#    print(dp)

can_y = 0
if dp[y+LL] != False:
    can_y = 1
#print(dp)
#print(susumu_NS)

#########################################
LL = len(s)+2
dp = np.zeros(LL*2, dtype=bool)
dp[LL] = 1
for j in range(len(susumu_EW)):
    dpleft =np.r_[dp[susumu_EW[j]:],np.zeros(susumu_EW[j], dtype=bool)]
    dpright=np.r_[np.zeros(susumu_EW[j], dtype=bool),dp[:-susumu_EW[j]]]
    dp = dpleft|dpright
#    print(dp)

can_x = 0
if dp[x+LL] != False:
    can_x = 1

#print(dp)
#print(susumu_EW)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')
X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(1,101))
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

### FIXED CODE ###

X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(0,102))
answer = 0
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(list[K+1])

### FIXED CODE ###

K=int(input())
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(list[K-1])
strings = raw_input.split(',')
  new_strings = []
  for string in strings:
    if string.islower():
      new_strings.append(string.upper())
    else:
      new_strings.append(string.lower())
  for new_string in new_strings:
    print new_string + ',',

### FIXED CODE ###

print raw_input().swapcase()
n, m = map(int, input().split())
print(1900*m + 100(n - m) * 2**m)

### FIXED CODE ###

n, m = map(int, input().split())
print((1900*m + 100*(n - m)) * 2**m)
N = input()
if "7" in S:
    print("yes")
else:
    print("no")

### FIXED CODE ###

S = input()
if "7" in S:
    print("Yes")
else:
    print("No")
a = input()
	print(a + a ** 2 + a ** 3)


### FIXED CODE ###

a = int(input())
print(a + a**2 + a**3)
#!/usr/bin/env python3
import math

a, b = map(int, input().split())
x = math.floor((a-1)/0.08)
y = math.floor((a+1)/0.08)
z = math.floor((b-1)/0.1)
w = math.floor((b+1)/0.1)

if y<z:
    print(-1)
    exit(0)

ans = []
for i in range(min(x,z), min(y,w)):
    if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
        ans.append(i)

print(min(ans))


### FIXED CODE ###

#!/usr/bin/env python3
import math

a, b = map(int, input().split())
x = math.floor((a-1)/0.08)
y = math.floor((a+1)/0.08)
z = math.floor((b-1)/0.1)
w = math.floor((b+1)/0.1)

if y<z:
    print(-1)
    exit(0)

ans = []
for i in range(min(x,z), min(y,w)):
    if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
        ans.append(i)

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))
S = input()
T = input()
flg = True
for i in range(0,len(S)):
    if S == T:
        print('Yes')
        break
    else:
        T = T[len(T)]+T[1:]
else:
    print('No')


### FIXED CODE ###

S = input()
T = input()

for i in range(0,len(S)):
    if S == T:
        print('Yes')
        break
    else:
        T = T[len(T)-1]+T[0:len(T)-1]
else:
    print('No')
n=int(input())
h=list(map(int,input().split()))
h.reverse()
i=0
while h[i]<h[i+1]:
  i+=1
  
print(i+1)
  

### FIXED CODE ###

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

ans = 0
c = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        c += 1
    else:
        ans = max(ans, c)
        c = 0
print(max(ans, c))
S = str(input())
N = len(S)

counter = 0
for i in range(N-3):
    for j in  range(i+3,N):
        s = int(S[i:j+1])
        m = s % 2019
        if m == 0:
            counter += 1

print(counter)







### FIXED CODE ###

inputs = str(input())
S = int(inputs.split()[0])
W = int(inputs.split()[1])
if S <= W:
    print("unsafe")
else:
    print("safe")
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]
while 0 in li:
    li.remove(0)

ans = ans + min(li) - 10
    
print(ans)

### FIXED CODE ###

import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

    
li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]

if li == [0, 0, 0, 0, 0]:
    ans = ans + min(li)
    print(ans)
    
else:
    for j in li:
        if j==0:
            li.remove(0)
    ans = ans + min(li) - 10
    print(ans)
N = int(input())
A = [[0] + list(map(int, input())) + [0] for _ in range(2)]

R1 = [0] * (N+1)
R2 = [0] * (N+2)

for i in range(1, N+1):
  R1[i] = R[i-1]+A[0][i]
  R2[i] = R[i+1]+A[1][i]

ans = 0
for i in range(1, N+1):
  ans = max(ans, R1[i]+R2[i])
print(ans)

### FIXED CODE ###

N = int(input())
A = [[0] + list(map(int, input().split())) + [0] for _ in range(2)]

R1 = [0] * (N+1)
R2 = [0] * (N+2)

for i in range(1, N+1):
  R1[i] = R1[i-1]+A[0][i]
  R2[N-i+1] = R2[N-i+2]+A[1][N-i+1]

ans = 0
for i in range(1, N+1):
  ans = max(ans, R1[i]+R2[i])
print(ans)
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    t1,t2 = map(int,input().split())
    p.append(t1)
    x.append(t2)
sum_t = sum(t)
for i in range(m):
    print(sum_t - (t[i] -x[i]))

### FIXED CODE ###

n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    t1,t2 = map(int,input().split())
    p.append(t1)
    x.append(t2)
sum_t = sum(t)
for i in range(m):
    sa = t[p[i] - 1] - x[i]
    print(sum_t-sa)
a, b = map(int, input().split())
print(ceil((a + b) / 2))

### FIXED CODE ###

import math

a, b = map(int, input().split())
print(math.ceil((a + b) / 2))
K=int(input())
S=int(input())
cnt= 0

for x in range(0,K+1):
    for y in range(0,K+1):
        for z in range(0,K+1):
            if ((x + y + z )== S):
                cnt += 1

print(cnt)

### FIXED CODE ###

K,S = map(int,input().split())
cnt= 0

for x in range(0,K+1):
    for y in range(0,K+1):
        if(0 <= S - x - y and S - x - y <= K):
            cnt += 1

print(cnt)
N = int(input())

for i in range(N):
	sides = map(int, input().split())
	longestSide = max(sides)
	sides.remove(longestSide)
	if (longestSide ** 2) == (sides[0] ** 2 + sides[1] ** 2):
		print('YES')
	else:
		print('NO')

### FIXED CODE ###

N = int(input())

for i in range(N):
	sides = list(map(int, input().split()))
	longestSide = max(sides)
	sides.remove(longestSide)
	if (longestSide ** 2) == (sides[0] ** 2 + sides[1] ** 2):
		print('YES')
	else:
		print('NO')
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
A = list(map(int, inputs[1].split()))

B = list(map(lambda x: x[1]-x[0], enumerate(A, 1)))
b = floor(sum(B) / n)
C = list(map(lambda x: abs(x-b), B))
print(sum(C))

### FIXED CODE ###

import sys
from statistics import median_low
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))

B = list(map(lambda x: x[1]-x[0], enumerate(A, 1)))
b = median_low(B)
C = list(map(lambda x: abs(x-b), B))
print(sum(C))
N = input()
S = input()
count = 0
if(int(N)>=3 and int(N)<=50):
    for i in range(1, int(N)-1):
        if S[i-1]+S[i]+S[i+1] == "ABC":
            count += 1
    print(count)
Seen by Sokhom Sovichea at 19:59

### FIXED CODE ###

n = int(input())
s = str(input())
print(s.count("ABC"))
import math
a,b=map(int,input().split())
c=a*b//math.gcd(a,b)
print(c)

### FIXED CODE ###

from fractions import gcd
a,b=map(int,input().split())
c=int(a*b//gcd(a,b))
print(c)
dp = [[-1 for i in range(6005)] for j in range(6005)]

def f(idx, time):
    if time >= T:
        return 0
    if idx >= N:
        return 0
    if dp[idx][time] != -1:
        return dp[idx][time]
    dp[idx][time] = max(f(idx+1, time), B[idx]+f(idx+1, time+A[idx]))
    return dp[idx][time]

N, T = [int(i) for i in input().split()]
data = []
A, B = [], []

for i in range(N):
    a, b = [int(j) for j in input().split()]
    data.append([a,b])
    A.append(a)
    B.append(b)

data.sort()
A, B = [], []
for i, j in data:
    A.append(i)
    B.append(j)

print(f(0, 0))


### FIXED CODE ###

dp = [[-1 for i in range(6005)] for j in range(6005)]


def f(idx, time):
    if time >= T:
        return 0
    if idx >= N:
        return 0
    if dp[idx][time] != -1:
        return dp[idx][time]
    dp[idx][time] = max(f(idx+1, time), B[idx]+f(idx+1, time+A[idx]))
    return dp[idx][time]

N, T = [int(i) for i in input().split()]
data = []
A, B = [], []

for i in range(N):
    a, b = [int(j) for j in input().split()]
    data.append([a,b])
    A.append(a)
    B.append(b)

data.sort()
A, B = [], []
for i, j in data:
    A.append(i)
    B.append(j)

for idx in range(N, -1, -1):
    for time in range(T, -1, -1):
        if time == T:
            dp[idx][time] = 0
            continue
        if idx == N:
            dp[idx][time] = 0
            continue
        if A[idx]+time >= T:
            fval = 0
        else:
            fval = dp[idx+1][time+A[idx]]
        dp[idx][time] = max(dp[idx+1][time], B[idx] + fval)

print(dp[0][0])
import math
n = input()
c = 0

for i in range(n):
    x = input()
    if x == 1:
        x = 0
    for j in range(2,math.floor(math.sqrt(x))+ 1):
        if x % j == 0:
            x = 0
            break
        if x != 0:
            c += 1	
print(c)

### FIXED CODE ###

import math
n = int(input())
count = 0
for i in range(n):
    a = int(input())
    for j in range(2,int(math.sqrt(a) + 1)):
        if a % j == 0:
            break
    else:
        count += 1  
print(count)
r = int(input())
g = int(input())
b = int(input())
if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

r, g, b = map(int, input().split())
if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")
A=int(input())
B=chr(A+1)
print("" + B)

### FIXED CODE ###

A=ord(input())
print(chr(A+1))
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,W-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i-1][min(j+1,H-1)]!='#':
        ans='No'
        break
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,H-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i][min(j+1,W-1)]!='#':
        ans='No'
        break
print(ans)
n = int(input())
hp_list = list(map(int, input().split()))
i = min(hp_list)
while True:
    dividable = True
    for j in hp_list:
        if j % i != 0:
            dividable = False
    if dividable:
        break
    else:
        for j in range(2, i + 1):
            if i % j == 0:
                i /= j
                break
print(int(i))

### FIXED CODE ###

from fractions import gcd

input()
a = list(map(int, input().split()))
l = a[0]
for i in a[1:]:
    l = gcd(l,i)
print(l)
h,w = map(int,input().split())
l = list(list(input()) for i in range(h))
for i in l:
  if i.count('.') ==w:
    i.clear()
    l.remove([])
t = len(l)
#print(l)
for i in range(w):
  if all (l[q][i]=="." for q in range(t)):
    for q in range(t):
      l[q][i] =""
for z in range(t):
  l[z].remove("")
print(l)
  

### FIXED CODE ###

h,w = map(int,input().split())
l = list(list(input()) for i in range(h))
for i in l:
  if i.count('.') ==w:
    i.clear()
l= [i for i in l if i!=[]]
#print(l)
t = len(l)
for i in range(w):
  if all (l[q][i]=="." for q in range(t)):
    for q in range(t):
      l[q][i] =""
if "" in l:
  for z in l:
    z.remove("")
for m in l:
  print("".join(m))
#M num of prefecture
#N num of city
N, M = map(int,input().split())
#P pref
#Y year
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)
    except:
        break

sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)):
    pref_n =prefs.index(sort_city[i][0])
    address=str(pref_n+1).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])



### FIXED CODE ###

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
a=0
for i in range(m):
    if s[i][1][0]==0:
       a=1     
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
    s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])
# coding: utf-8


if __name__ == '__main__':
  x = input()

  print(x ** 3)

### FIXED CODE ###

x = int(input())
print(x ** 3)
while 1:
????????r, c = map(int, raw_input().split())
????????if r == 0: break
????????old = [raw_input().split() for i in range(r)]
????????old = map(list, zip(*old))
????????new = [int("".join(lst),2) for lst in old]
????????ans = 0
????????for i in range(1<<(r)):
????????????????ret = 0
????????????????for j in new:
????????????????????????cnt = bin(i^j).count('1')
????????????????????????ret += cnt if cnt > r/2 else r-cnt
????????????????ans = max(ans, ret)
????????print ans

### FIXED CODE ###

while 1:
    r, c = map(int, raw_input().split())
    if r == 0: break
    old = [raw_input().split() for i in range(r)]
    old = map(list, zip(*old))
    new = [int("".join(lst),2) for lst in old]
    ans = 0
    for i in range(1<<(r-1)):
        ret = 0
        for j in new:
            cnt = bin(i^j).count('1')
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print ans
import fractions
N = int(input())
tokei = [int(input()) for _ in range(N)]
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
ans = lcm(tokei[0],tokei[1])
for i in range(2,N):
    ans = lcm(ans,tokei[i])
print(ans)

### FIXED CODE ###

import fractions
N = int(input())
tokei = [int(input()) for _ in range(N)]
if N == 1:
    print(tokei[0])
    exit()
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
ans = lcm(tokei[0],tokei[1])
for i in range(2,N):
    ans = lcm(ans,tokei[i])
print(ans)
R = int(input())

if R < 1200:
    print('ABC')
elif R < 2800
    print('ARC')
else:
    print('AGC')

### FIXED CODE ###

R = int(input())

if R < 1200:
    print('ABC')
elif R < 2800:
    print('ARC')
else:
    print('AGC')