Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
 
n, x, y = map(int, input().split())
x -= 1
y -= 1
 
def calc(i, j, x, y):
    mindist = abs(j - i)
    mindist = min(mindist, abs(x - i) + 1 + abs(y - j))
    mindist = min(mindist, abs(y - i) + 1 + abs(x - j))
    return mindist
 
result = [0 for i in range(n)]
for i in range(n):
    for j in range(n):
        if i == j :
            continue
        k = calc(i, j, x, y)       
        result[k] += 1
 
for i in range(1, n):
    print(result[i] // 2)

### FIXED CODE ###

import sys

n, x, y = map(int, input().split())
x -= 1
y -= 1

def calc(i, j, x, y):
    mindist = abs(j - i)
    mindist = min(mindist, abs(x - i) + 1 + abs(y - j))
    mindist = min(mindist, abs(y - i) + 1 + abs(x - j))
    return mindist

result = [0 for i in range(n)]
for i in range(n):
    for j in range(n):
        if i == j :
            continue
        k = calc(i, j, x, y)       
        result[k] += 1

for i in range(1, n):
    print(result[i] // 2)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
S = input()
judge = [0] * 1
tmp = ''
ans = 0
m = ''

for n in range(0, len(S)):
	m += S[n]
	judge[0] = m

	if ans > len(S) - len(m) + 1:
		break
	#print(judge)

	for i in range(len(m), len(S)):
		tmp += S[i]
		
		for j in range(len(judge) - 1, len(judge)):
			if judge[j] == tmp:
				break

		else:
			judge.append(tmp)
			tmp = ''
	
	else:
		ans = max(ans, len(judge))
		judge = [0] * 1

print(ans)

### FIXED CODE ###

S = input()
dp = [0] * (len(S) + 1)
dp[1] = 1

if S[0] == S[1]:
	dp[2] = 1
else:
	dp[2] = 2

for i in range(3, len(S) + 1):
	if S[i - 1] != S[i - 2]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 3] + 2

print(dp[-1])
### BUGGY CODE ###

def expect(x):
    return sum(list(range(1,x+1)))/x
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    table = []
    for i in range(n-k+1):
        w = 0
        for j in range(k):
            w += expect(p[i+j])
        table.append(w)
    print(max(table))
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
n, k = map(int,input().split())
p = list(map(int, input().split()))
p = [(1+i)/2 for i in p]
# 累積和の配列sを作成する
s = [0] * (n+1)
for i in range(1,n+1):
    s[i] = s[i-1] + p[i-1]
max = -1 * float("inf")
for i in range(n-k+1):
    sum = s[k+i] - s[i]
    if max <= sum:
        max = sum
print(max)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
N, M = map(int, sys.stdin.readline().split())
G = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, sys.stdin.readline().split())
    l, r = l - 1, r - 1
    G[l].append((r, d))
    G[r].append((l, -d))

R = [None] * N


def dfs(u):
    global R, G
    for w, d in G[u]:
        if R[w] is None:
            R[w] = R[u] + d
            if not dfs(w):
                return False
        else:
            if R[w] != R[u] + d:
                return False
    return True


flag = True
for i in range(N):
    if R[i] is None:
        R[i] = 0
        flag &= dfs(i)

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

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
N, M = map(int, sys.stdin.readline().split())
G = [[] for i in range(N)]
for i in range(M):
    l, r, q = map(int, sys.stdin.readline().split())
    G[l - 1].append((r - 1, q))
    G[r - 1].append((l - 1, -q))

R = [None] * N


def dfs(u):
    global R, G
    for w, d in G[u]:
        if R[w] is None:
            R[w] = R[u] + d
            if not dfs(w):
                return False
        else:
            if R[w] != R[u] + d:
                return False
    return True


flag = True
for i in range(N):
    if R[i] is None:
        R[i] = 0
        flag &= dfs(i)

if flag:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

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

L_list = sorted(L_list)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L_list[i] + L_list[j] > L_list[k]:
                count += 1
            else:
                break

print(count)

### FIXED CODE ###

import bisect

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

L_list = sorted(L_list)

total = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        total += bisect.bisect_left(L_list, L_list[i] + L_list[j]) - j -1

print(total)
### BUGGY CODE ###

n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = list(map(int, input().split()))
    index = [i for i, x in enumerate(a_list) if x == b]
    for i in index:
        a_list[i] = c
    print(sum(a_list))

### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
sum_a = sum(a_list)
num_a = [0]*(10**5)
for i in a_list:
    num_a[i-1] += 1
    
q = int(input())
for _ in range(q):
    b, c = list(map(int, input().split()))
    sum_a = sum_a + c * num_a[b-1] - b *num_a[b-1]
    num_a[c-1] += num_a[b-1]
    num_a[b-1] = 0
    print(sum_a)
### BUGGY CODE ###

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

sum_A = [0]*N
sum_A_k = 1
for i in range(K):
  sum_A_k = sum_A_k*A[i]
sum_A[K-1] = sum_A_k

for i in range(N-K):
  sum_A[K+i] = sum_A[K-1+i]*A[K+i]/A[i]
  if sum_A[K+i] > sum_A[K-1+i]:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

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

for i in range(N-K):
  if A[K+i]/A[i] > 1:
    print('Yes')
  else:
    print('No')

# sum_A = [0]*N
# sum_A_k = 1
# for i in range(K):
#   sum_A_k = sum_A_k*A[i]
# sum_A[K-1] = sum_A_k

# for i in range(N-K):
#   sum_A[K+i] = sum_A[K-1+i]*A[K+i]/A[i]
#   if sum_A[K+i] > sum_A[K-1+i]:
#     print('Yes')
#   else:
#     print('No')
### BUGGY CODE ###

import sys
import math
input = lambda: sys.stdin.readline().rstrip()


def solve():
    A, B = map(int, input().split())

    ans = 1
    max_n = min(A, B) + 1

    for n in range(2, max_n):
        if A == 1 or B == 1:
            break

        if A % n == 0 and B % n == 0:
            ans += 1

            while True:
                if A % n == 0 and B % n == 0:
                    A = A // n
                    B = B // n
                else:
                    break

    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import math
input = lambda: sys.stdin.readline().rstrip()


def factorize(n):
    b = 2
    fct = set()
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct |= set([b])
        b = b + 1
    if n > 1:
        fct |= set([n])
    return fct


def solve():
    A, B = map(int, input().split())
    ap = factorize(A)
    bp = factorize(B)
    ans = 1 + len(ap & bp)
    print(ans)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

import math

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

s = 0

for i in range(k+1):
    s += (math.factorial(n-1) // (math.factorial(n-1-i) * math.factorial(i)) ) * m * ((m-1) ** (n-i-1))

print(s % 998244353)


### FIXED CODE ###

import math

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

MOD=998244353

fact = [0] * (n+1)
inv = [0] * (n+1)
factinv = [0] * (n+1)

fact[0]=fact[1]=1
inv[1]=1
factinv[0]=factinv[1]=1

for i in range(2,n+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
    factinv[i] = factinv[i-1] * inv[i] % MOD

def cbn(n, k, fact, factinv, MOD):
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power(x * x % MOD, n // 2, MOD) % MOD

s = 0
for i in range(k+1):
    s += cbn(n-1, i, fact, factinv, MOD) * m * power(m-1, n-1-i, MOD)

print(s % MOD)
### BUGGY CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    img = tuple(tuple(map(int, line.split())) for line in file_input)
    
    acc_row = tuple(tuple(accumulate(line)) + (0,) for line in img)
    acc_col = tuple(tuple(accumulate(line)) + (0,) for line in zip(*img))
    
    ans = 0
    for i, tpl_1 in enumerate(zip(img, acc_row)):
        img_i, acc_row_i = tpl_1
        for j, img_j in enumerate(img[i:], start=i):
            if acc_row_i[j] - acc_row_i[i - 1] > ans:
                ans = acc_row_i[j] - acc_row_i[i - 1]
                
            if i == j:
                continue
            
            col = acc_col[0]
            col_max = col[j] - col[i - 1]
            
            for acc_col_k, img_i_k, img_j_k in zip(acc_col[1:], img_i[1:], img_j[1:]):
                col = acc_col_k[j] - acc_col_k[i - 1]
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + img_i_k + img_j_k
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()


### FIXED CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    G = tuple(tuple(map(int, line.split())) for line in file_input)
    G1 = tuple(t[1:] for t in G)
    
    # accumulated rows
    ar = ((0,) + tuple(accumulate(line)) for line in G)
    
    # accumulated columns
    ac = ((0,) + tuple(accumulate(line)) for line in zip(*G))
    ac_1 = next(ac)
    ac = tuple(zip(*ac))
    
    ans = 0
    for i, t1 in enumerate(zip(G1, ar, ac, ac_1)):
        G_i, ar_i, ac_i, ac_1i = t1
        ar_ii = ar_i[i]
        for j, t2 in enumerate(zip(G1[i:], ar_i[i+1:], ac[i+1:], ac_1[i+1:]), start=i):
            G_j, ar_ij, ac_j, ac_1j = t2
            single_row = ar_ij - ar_ii
            if single_row > ans:
                ans = single_row
                
            if i == j:
                continue
            
            col_max = ac_1j - ac_1i
            
            for ac_jk, ac_ik, G_ik, G_jk in zip(ac_j, ac_i, G_i, G_j):
                col = ac_jk - ac_ik
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + G_ik + G_jk
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()
### BUGGY CODE ###

N=int(input())
S=input()
R=S.count("R")
G=S.count("G")

ans=R*G*(N-(R+G))

for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k<=N-1:
      if S[j]!=S[i] and S[j]!=S[k] and S[k]!=S[i]:
          ans-=1
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")

for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k<=N-1:
      if S[j]!=S[i] and S[j]!=S[k] and S[k]!=S[i]:
          ans-=1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from itertools import accumulate

class Segtree:
    def __init__(self, original, func, element):
        self.n = len(original)
        self.element = element
        self.func = func
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [element]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = func(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            y = self.seg[i ^ 1]
            i >>= 1
            x = self.func(x, y)
            self.seg[i] = x
                
    def add(self, i, d):
        self.update(i, self.get(i)+d)
        
    def query(self, l, r):
        l += self.N0
        r += self.N0
        nl = self.element
        nr = self.element
        while l < r:
            if l & 1:
                nl = self.func(nl, self.seg[l])
                l += 1
            if r & 1:
                nr = self.func(nr, self.seg[r-1])
            l >>= 1
            r >>= 1
     
        return self.func(nl, nr)

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  A = [0]*(m+2)
  for l, r in LR:
    A[l] += 1
    A[r+1] -= 1
  L = Segtree(A, lambda x, y:x+y, 0)
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  A = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      L.add(l, -1)
      L.add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += L.query(0, j+1)
    A.append(res)
  print(*A[::-1], sep="\n")

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()
### BUGGY CODE ###

N,X,Y = map(int,input().split())
ans = [0]*(N-1)
X , Y = X-1 , Y-1#配列の場所に合わせる

for i in range(N):
  for k in range(N):
    if i == k:
      pass
    else:
      if i < k:
        ans_ = min(abs(k-i),abs(X-i)+abs(Y-k)+1)
        ans[ans_-1] += 1
      else:
        ans_ = min(abs(k-i),abs(X-k)+abs(Y-i)+1)
        ans[ans_-1] += 1

ans = [int(i/2) for i in ans]

for i in ans:
  print(i)

### FIXED CODE ###

n,x,y=map(int,input().split())
c=[0]*~-n
for i in range(n):
  for j in range(i):
    c[min(~j+i,abs(~j+x)+abs(~i+y))]+=1
for i in c:
  print(i)
### BUGGY CODE ###

from collections import defaultdict
R,C,K = map(int,input().split())
dp = [0 for _ in range(3001)]
ddc = defaultdict(lambda:0)

for i in range(K):
	r,c,v = map(int,input().split())
	ddc[(r, c)] = v

for j in range(1, 3001):
	sol = []
	for i in range(1, 3001):
		dp[i] = max(dp[i-1], dp[i])
		if ddc[(j, i)] >= 1:
			targ = ddc[(j, i)]
			#print(len(sol))
			if len(sol) < 3:
				dp[i] += targ
				sol.append(targ)
			else:
				if min(sol) < targ:
					#print(sol)
					dp[i] += targ-min(sol)
					sol.remove(min(sol))
					sol.append(targ)

print(dp[3000])

### FIXED CODE ###

R,C,K = map(int,input().split())
dp0 = [[0 for _ in range(C+1)] for f in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for f in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for f in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for f in range(R+1)]
vl = [[0 for _ in range(C+1)] for f in range(R+1)]

for i in range(K):
	r,c,v = map(int,input().split())
	vl[r][c] = v

for i in range(1, R+1):
	for j in range(1, C+1):
		dp0[i][j] = max(dp0[i][j], dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
		dp3[i][j] = max(dp3[i][j], dp3[i][j-1], dp2[i][j-1]+vl[i][j], dp2[i][j]+vl[i][j])
		dp2[i][j] = max(dp2[i][j], dp2[i][j-1], dp1[i][j-1]+vl[i][j], dp1[i][j]+vl[i][j])
		dp1[i][j] = max(dp1[i][j], dp1[i][j-1], dp0[i][j-1]+vl[i][j], dp0[i][j]+vl[i][j])

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))
### BUGGY CODE ###

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

ans = 0
flag = True
while flag:
  flag = False
  for i in range(n-1, -1, -1):
    if not flag and a[i]%2 == 0:
      flag = True
      ans += 1
      a[i] //= 2
    else: a[i] *= 3
print(ans)

### FIXED CODE ###

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

ans = 0
for i in a:
  while i%2==0:
    i//=2
    ans+= 1
print(ans)
### BUGGY CODE ###

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
 
 
N, Q = list(map(int, input().split()))
STX=[]
D=[]
for i in range(N):
    STX.append(list(map(int, input().split())))
STX.sort(key=lambda x: x[2])
 
kensaku = dict()
for i in range(Q):
    D.append(int(input()))
    kensaku[D[-1]] = i
 
dist = [10000000000000 for i in range(Q)]
 
for i in range(N):
    s = STX[i][0] - STX[i][2]
    t = STX[i][1] - STX[i][2] - 1
    a = bisect.bisect_left(D, s)
    b = bisect.bisect_right(D, t)
    #print(D)
    for j in range(a, b):
        dist[kensaku[D[j]]] = min(dist[kensaku[D[j]]], STX[i][2])
    del D[a:b]
 
 
for i in range(Q):
    if dist[i] > 100000000000:
        print(-1)
    else:
        print(dist[i])

### FIXED CODE ###

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


N, Q = list(map(int, input().split()))
STX=[]
D=[]
for i in range(N):
    S, T, X = list(map(int, input().split()))
    STX.append((X, S, T))
STX = sorted(STX, key=lambda x: x[0])

for i in range(Q):
    D.append(int(input()))

skip = [-1]*Q

dist = [-1]*Q

for X, S, T in STX:
    s = S - X
    t = T - X - 1
    a = bisect.bisect_left(D, s)
    b = bisect.bisect_right(D, t)
    #print(D)
    j = a
    while j < b:
        if skip[j] == -1:
            skip[j] = b
            dist[j] = X
            j+=1
        else:
            j=skip[j]


for i in range(Q):
    print(dist[i])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N, M = map(int, input().split(" "))
	#N = int(input())
	#S = input()

	A = input().split(" ")
	A = list(A)
	#A = A[:-1]
	A = [int(s) for s in A]

	BC = []
	for i in range(M):
		b, c = map(int, input().split(" "))
		BC.append((b, c))

	for i in BC:
		A.sort()
		b, c = i

		tmp = bisect_left(A, c)
		if tmp <= b:
			A[:tmp] = [c] * tmp
		elif tmp > b:
			A[:b] = [c] * b


	ans = 0
	for i in A:
		ans += i
	print(ans)


if __name__ == "__main__":
	main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

def main():
	N, M = map(int, input().split(" "))
	#N = int(input())
	#S = input()

	A = input().split(" ")
	A = list(A)
	#A = A[:-1]
	A = [(int(s) * (-1), 1) for s in A]
	heapq.heapify(A)

	for i in range(M):
		b, c = map(int, input().split(" "))
		heapq.heappush(A, (c * (-1), b))
	
	ans = []
	for i in range(N):
		t, con = heapq.heappop(A)
		for _ in range(con):
			if len(ans) == N:
				print(sum(ans))
				sys.exit()
			ans.append(t * (-1))
	print(sum(ans))


if __name__ == "__main__":
	main()
### BUGGY CODE ###

K, S = list(map(int, input().split()))
ok_list = []
for x in range(K + 1):
    if S - x > K:
        y_max = K + 1
    else:
        y_max = S - x + 1

    for y in range(y_max):
        if S - x - y > K:
            z_max = K + 1
        else:
            z_max = S - x - y + 1
        for z in range(z_max):
            # print((x, y, z))
            if x + y + z == S:
                # print((x, y, z))
                ok_list.append((x, y, z))

print(len(ok_list))

### FIXED CODE ###

K, S = list(map(int, input().split()))
# ok_list = []
cnt = 0
for x in range(K + 1):
    if S - x > K:
        y_max = K + 1
    else:
        y_max = S - x + 1

    if S - x > 2 * K:
        continue
    else:
        # print(y_max, end=" ")
        pass

    for y in range(y_max):

        if S - (x + y) <= K:
            cnt += 1
print(cnt)
### BUGGY CODE ###

l,r=map(int,input().split())
mi=2018
res1=l%2019
for i in range(r-l):
  res2=(i+l+1)%2019
  for j in range(r-l-i):
    if (res1*res2)%2019<mi:
      mi=(res1*res2)%2019
    res2+=1
  res1+=1
print(mi)

### FIXED CODE ###

l,r=map(int,input().split())
if(r-l>=2018):
  print(0)
else:
  mi=2018
  res1=l%2019
  for i in range(r-l):
    res2=(i+l+1)%2019
    for j in range(r-l-i):
      if (res1*res2)%2019<mi:
        mi=(res1*res2)%2019
      res2+=1
    res1+=1
  print(mi)
### BUGGY CODE ###

n = int(input())

def calc(b, e):
    # 等差数列の和
    cnt = e // b
    return (b + e) * cnt // 2

ans = 0

for i in range(1, n+1):
    ans += calc(i, n//i * i)

print(ans)

### FIXED CODE ###

n=int(input())

ans_tmp = sum(range(n+1)) * 2 -1

from itertools import accumulate
sum_list = list(accumulate(range(1, n)))

ans_tmp_2 = 0

for i in range(2, n+1//2+1):
    if n // i > 1:
        count_tmp = n // i
        ans_tmp_2 += i * sum_list[count_tmp - 1] - i

print(ans_tmp + ans_tmp_2)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    # print(a)
    b, c = map(int, input().split())
    d = min(b, len(list(filter(lambda x: x<c, a))))
    a[0:d] = [c]*d
    a.sort()
print(sum(a))


### FIXED CODE ###

from heapq import heappush, heappop

n, m = map(int, input().split())
a = list(map(int, input().split()))
card = [list(map(int, input().split())) for _ in range(m)]
card = sorted(card, key=lambda x:-x[1])

hq = []
for i in range(n):
    heappush(hq, a[i])

ans = sum(a)
for i in range(m):
    for j in range(card[i][0]):
        if hq == []:
            break
        num = heappop(hq)
        if num >= card[i][1]:
            heappush(hq, num)
            break
        else:
            ans += card[i][1]-num
print(ans)
### BUGGY CODE ###

n, a, b = map(int, input().split())
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
            if len(l) == n:
                break
        flag = False
    else:
        for y in range(b):
            l += "r"
            if len(l) == n:
                break
        flag = True

    if len(l) >= n:
        break

         
for c in l:
    if c == "b":
        count += 1

print(count)


### FIXED CODE ###

N, A, B = map(int, input().split())
ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
### BUGGY CODE ###

import sys
def solve(n,m,a,b):
    ans = ""
    #b = [[] for i in range(n)]
    #for s1,s2 in a:
    #    b[s1-1].append(s2)
    for i in range(len(b)):
        b[i].sort()
    for i in range(m):
        ans += str(a[i][0]).zfill(6) + str(b[a[i][0]-1].index(a[i][1])+1).zfill(6) + "\n"
    return ans

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = []
    ls_b = [[] for i in range(N)]
    for i in range(M):
        p,y = map(int, sys.stdin.readline().strip().split())
        ls_PY.append([p,y])
        ls_b[p-1].append(y)
    #ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY, ls_b)

def main():
    N, M, ls_PY, ls_b = readQuestion()
    answer = solve(N, M, ls_PY, ls_b)
    print(answer)

if __name__ == '__main__':
    main()

### FIXED CODE ###

N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了
 
PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M
 
for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for i in range(M):
  	print(w[i])