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

n = int(input())
s = []
c = []
s_dash = []
ans = 0

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

s_dash.sort()
for i in range(n):
	for j in range(i+1,n):
		if s_dash[i] == s_dash[j]:
			ans += 1
		else:
			break

print(ans)


### FIXED CODE ###

def cmb(n, r):
	if n < r: return 0
	if r == 0: return 1
	if r == 1: return n
	if n - r < r: r = n - r

	numerator = [n - r + k + 1 for k in range(r)]
	denominator = [k + 1 for k in range(r)]

	for p in range(2,r+1):
		pivot = denominator[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p-1,r,p):
				numerator[k - offset] /= pivot
				denominator[k] /= pivot

	result = 1
	for k in range(r):
		if numerator[k] > 1:
			result *= int(numerator[k])

	return result

n = int(input())
s = []
for _ in range(n):
	tmp = list(input())
	tmp.sort()
	s.append(tmp)

s.sort()

count = 1
ans = 0
for i in range(n-1):
	if s[i] == s[i+1]:
		count += 1
	else:
		ans += cmb(count,2)
		count = 1

if count != 1:
	ans += cmb(count,2)

print(ans)
### BUGGY CODE ###

n=int(input())
L=tuple(map(int,input().split()))
for i in range(1,n+1):
    print(L.count(i))


### FIXED CODE ###

from collections import Counter
n = int(input())
a = tuple(map(int, input().split()))
All = Counter(a)
for i in range(1,n+1):
    try:
        print(All[i])
    except:
        print(0)
### BUGGY CODE ###

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

a=[]

ans = 0

for i in P:
  a.append(i)
  if min(a) >= i:
    ans+=1
    
print(ans)
    
    

### FIXED CODE ###

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

a = P[0]
ans = 0

for i in range(N):
  if P[i] <= a:
    a = P[i]
    ans += 1
    
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
t=[]
for i in range(N):
    for j in t:
        if A[i]==j+i:
            ans+=1
    t.append(-A[i]-i)
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
t=dict()
for i in range(N):
    if A[i]-i in t:
        ans+=t[A[i]-i]
    t.setdefault(-A[i]-i,0)
    t[-A[i]-i]+=1
print(ans)
### BUGGY CODE ###

#n=int(input())
n,m=map(int,input().split())
#a=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]

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

for i in range(m):
    ll[l[i][0]-1].append(l[i][1])
    ll[l[i][1]-1].append(l[i][0])

lt=[0 for i in range(n)]
lll=[1]
for i in range(n):
    for j in ll[lll[i]-1]:
        lll.append(j)
        if (j!=1 and lt[j-1]==0):
            lt[j-1]=lll[i]
    lll=list(dict.fromkeys(lll))

print("Yes")
for i in range(1,n):
    print(lt[i])


### FIXED CODE ###

#n=int(input())
n,m=map(int,input().split())
#a=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]

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

for i in range(m):
    ll[l[i][0]-1].append(l[i][1])
    ll[l[i][1]-1].append(l[i][0])

lt=[0 for i in range(n)]
lll=[1]
for i in range(n):
    for j in ll[lll[i]-1]:
        if (j!=1 and lt[j-1]==0):
            lll.append(j)
            lt[j-1]=lll[i]

print("Yes")
for i in range(1,n):
    print(lt[i])
### BUGGY CODE ###

def D():
    s = input()
    sketa = len(s)
    ans = 0
    for keta in range(4, sketa):
        for j in range(sketa-keta+1):
            if int(s[j: j+keta])%2019==0:
                ans += 1
    print(ans)
D()

### FIXED CODE ###

def D():
    s = input()
    mods = [0]*2019
    mods[0] = 1
    mod = 0
    for i, element in enumerate(s[::-1]):
        mod += int(element)*pow(10,i,2019)
        mods[mod%2019] += 1
    print(sum(map(lambda x:int(x*(x-1)/2), mods)))
D()
### BUGGY CODE ###

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

for i in range(1,n+1):
    print(A.count(i))


### FIXED CODE ###

n=int(input())
A=list(map(int, input().split()))
B = [0]*n

for i in range(n-1):
    B[A[i]-1] += 1

for j in range(n):
    print(B[j])
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
edges = [[] for i in range(n)]
edges_r = [[] for i in range(n)]
for i in range(n+m-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges_r[b].append(a)
ns = [(len(e),i) for i, e in enumerate(edges_r)]
ns.sort()
s = ns[0][1]

INF = 1 << 60
ks = [-1] * n
parents = [-1] * n
q = deque([s])
ks[s] = 0
# 同じ深さのもの同士をつなぐのはありえないので
# 根の部分から徐々に掘り下げながら、真の親を探す
while len(q) > 0:
    u = q.popleft()
    for v in edges[u]:
        if ks[u] >= ks[v]:
            ks[v] = ks[u] + 1
            parents[v] = u
            q.appendleft(v)

for p in parents:
    print(p+1)

### FIXED CODE ###

"""
子孫に向かって有向辺が伸びる
⇨ ループなし
⇨ トポロジカルソート通りに並べると親がわかる
"""
from collections import deque
from collections import defaultdict
n, m = map(int, input().split())

edges = [[] for _ in range(n)]
ps = [[] for _ in range(n)]
for i in range(n+m-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    ps[b].append(a)

def topo(G):
    cut_in = defaultdict(int)
    for vs in G:
        for v in vs:
            cut_in[v] += 1
    res = []
    # 入次数が0のものを洗い出し
    zeros = [i for i in range(n) if cut_in[i] == 0]
    q = deque(zeros)
    # すべての入次数が0になるまでくりかえす
    while len(q) > 0:
        v = q.popleft()
        res.append(v)
        for u in G[v]:
            cut_in[u] -= 1
            if cut_in[u] == 0:
                q.append(u)
    return res

ss = topo(edges)
# print(ss,ps)
ss = {s:i for i,s in enumerate(ss)}

for i in range(n):
    mn = -1
    parent = 0
    if len(ps[i]) == 0:
        print(0)
        continue
    for p in ps[i]:
        if mn < ss[p]:
            mn = ss[p]   
            parent = p
    print(parent+1)
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = {}
    for i in range(n):
        ans[a[i]-1] = i+1
    ans_str =""
    for i in range(n):
        if ans_str =="":
            ans_str = str(ans[i])
        else:
            ans_str = ans_str+" "+str(ans[i])
    print(ans_str)

### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = [0]*n
    for i in range(n):
        ans[a[i]-1] = i+1
    ans_list = map(str, ans)  # mapで要素すべてを文字列に
    ans_str =' '.join(ans_list)
    print(ans_str)
### BUGGY CODE ###

import itertools
n=int(input())
A=list(map(int,input().split()))
AC=list(itertools.combinations(A,2))
x=0
for i in range(n*(n-1)//2):
  x+=AC[i][0]*AC[i][1]%(10**9+7)
print(x%(10**9+7))

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
sumA=sum(A)
x=0
for i in range(n-1):
  sumA-=A[i]
  x+=A[i]*sumA
print(x%(10**9+7))
### BUGGY CODE ###

from itertools import product
from functools import reduce
from math import gcd
k = int(input())
ans = 0
for abc in product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)
print(ans)


### FIXED CODE ###

import itertools
from functools import reduce


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


k = int(input())
ans = 0
for abc in itertools.product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)

print(ans)
### BUGGY CODE ###

"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *P = map(int, read().split())

ans = 0
for i in range(N - K + 1):
    L = P[i:i + K]
    s = (sum(L) + K) / 2
    ans = max(s, ans)
print('{:.10f}'.format(ans))


### FIXED CODE ###

"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

import itertools

# import math
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *P = map(int, read().split())
R = list(itertools.accumulate(P))
ans = 0
for i in range(K - 1, N):
    if i - K >= 0:
        s = ((R[i] - R[i - K]) + K) / 2
    else:
        s = (R[i] + K) / 2
    ans = max(s, ans)
print('{:.6f}'.format(ans))
### BUGGY CODE ###

#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
maxscore = sum([row[3] for row in matrix])
for i in itertools.product(range(1,M+1), repeat=N):
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore
    if ansscore == maxscore:
        break
print(ansscore)

### FIXED CODE ###

#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(itertools.combinations_with_replacement(range(1,M+1),N))
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)
### BUGGY CODE ###

K,S=input().split()
K=int(K)
S=int(S)
ans=0
for l in range(K+1):
    for m in range(K+1):
        for n in range(K+1):
            if l+m+n==S:
                ans=ans+1
print(ans)

### FIXED CODE ###

K,S=input().split()
K=int(K)
S=int(S)
ans=0
for l in range(K+1):
    for m in range(K+1):
        if l+m<=S and l+m+K>=S:
            ans=ans+1
print(ans)
### BUGGY CODE ###

# D - Powerful Discount Tickets
n,m= map(int, input().split())

list = [int(s) for s in input().split()]

list.sort(reverse=True)

i = 0
while (m != 0):
    list[i] = (int)(list[i] / 2)
    m = m - 1
    if len(list) == 0:
        continue
    else:
        list.sort(reverse=True)

print(sum(list))

### FIXED CODE ###

# D - Powerful Discount Tickets
import heapq
n,m= map(int, input().split())

a = [int(s) for s in input().split()]
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍

heapq.heapify(a)

while (m != 0):
    heapq.heappush(a, (int)(heapq.heappop(a) / 2))
    m = m - 1

print(-sum(a))
### BUGGY CODE ###

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

lis = []

Ans = 0

for i in range(b - a + 1):
	lis.append(b)
	b -= 1

for i in range(len(lis)):
	if lis[i] % x == 0:
		Ans += 1

print(Ans)
	

### FIXED CODE ###

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

print(b//x - ( a - 1 )//x)
### BUGGY CODE ###

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

ba = B - A 
if A % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if B % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a = A
b = B
a2 = ""
b2 = ""

if a == 0:
	a2 = "0"
else:
	while True:
		if a % 2 == 0:
			a2 += "0"
		else:
			a2 += "1"
		a = int(a // 2)
		if a == 1:
			a2 += "1"
			break
if b == 0:
	b2 = "0"
else:
	while True:
		if b % 2 == 0:
			b2 += "0"
		else:
			b2 += "1"
		b = int(b // 2)
		if b == 1:
			b2 += "1"
			break

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 1:
		c2 += 2 ** i

print(c2)


### FIXED CODE ###

a, b = list(map(int, input().split()))
ba = b - a
if a % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if b % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a2 = format(a, "b")
b2 = format(b, "b")
a2 = str(a2[::-1])
b2 = str(b2[::-1])

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 1:
		c2 += 2 ** i

print(c2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
import numpy as np

def main():
	h,w,k=MI()
	G=[]
	for i in range(h):
		A=input().rstrip()
		A=list(map(int,A))
		G.append(A)
	G=np.array(G)
	#G=np.cumsum(G,axis=1)
	#print(G)

	an=10**10

	for i in range(1<<h-1):
		ans=h-1
		B=np.copy(G)
		for j in range(h):
			if 1&(i>>j):
				ans-=1
				B[j+1]+=B[j]
				B[j]=[0]*w
		C=np.zeros(h)
		#print(B)

		for i in range(w):
			C+=B[:,i]
			#print(C)
			if np.max(C)>k:
				ans+=1
				C=B[:,i]
		an=min(an,ans)
		#print(ans)
	print(an)
















if __name__ == "__main__":
	main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

def main():
	h,w,k=MI()
	G=[]
	for i in range(h):
		A=list(map(int,input().rstrip().decode()))
		G.append(A)
	#print(G)

	for i in range(h):
		for j in range(w):
			if i!=0:
				G[i][j]+=G[i-1][j]
			if j!=0:
				G[i][j]+=G[i][j-1]
			if i!=0 and j!=0:
				G[i][j]-=G[i-1][j-1]
	#print(G)

	B=[]
	for i in range(2**(h-1)):
		C=[0,h-1]
		for j in range(h):
			if i&(1<<j):
				C.append(j)
				C.append(j+1)
		C.sort()
		B.append(C)

	#print(B)

	ans=10**10

	def check(x1,y1,x2,y2):
		ret=G[x2][y2]
		if x1 != 0:
			ret -= G[x1-1][y2]
		if y1 != 0:
			ret -= G[x2][y1-1]
		if x1 != 0 and y1 != 0:
			ret += G[x1-1][y1-1]
		return ret

	for D in B:
		#print(d)
		cnt=len(D)//2-1
		l=0
		ww=0
		f=0
		while ww<w and f==0:
			for i,j in zip(D[0::2],D[1::2]):
				#print(i,j)
				if check(i,l,j,ww)>k:
					#print(i,l,j,ww,check(i,l,j,ww))
					if l==ww:
						f=1
					else:
						cnt+=1
						l=ww
					break
			ww+=1
			#print(w,ww,cnt)
		#print(D,cnt)
		if f==0:
			ans=min(ans,cnt)
	print(ans)














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

_a, _b = map(int, input().split())
_common_divisors = []
_min = min([_a, _b])

def isprime(num):
  for i in range(2, num):
    if num % i == 0:
      return False
  return True

for _i in range(_min):
  _num = _i + 1
  if _a % _num == 0 and _b % _num == 0:
    _common_divisors.append(_num)
_count = 0
for _divisor in _common_divisors:
  if isprime(_divisor):
    _count = _count + 1
print(_count)

### FIXED CODE ###

from collections import Counter

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
_a, _b = map(int, input().split())
_a_set = set(prime(_a))
_b_set = set(prime(_b))
_common_prime = _a_set & _b_set
print(len(_common_prime) + 1)
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = ans * (((2*i) - (count*2))%m)
    count += 1
  if S[2*i + 1] == "B":
    ans = ans * (((2*i + 1) - (count*2))%m)
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)

### FIXED CODE ###

N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = ans * ((2*i) - (count*2))%m
    count += 1
  if S[2*i + 1] == "B":
    ans = ans * ((2*i + 1) - (count*2))%m
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,a,b = map(int, input().split())
    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = 0

    for i in range(1, n+1):
        if i==a or i==b:
            continue
        res += nCr(n, i, mod)
        res %= mod

    print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,a,b = map(int, input().split())
    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = (2**n - 1)%mod
    x = nCr(n, a, mod)
    y = nCr(n, b, mod)
    print((res-x-y)%mod)

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):
      if s[i][j]=='#':
        continue

      _ans=0
      for a in range(i)[::-1]:
        if s[a][j]=='.':
          _ans+=1
        else:
          break
      for a in range(i+1,h):
        if s[a][j]=='.':
          _ans+=1
        else:
          break
      for a in range(j)[::-1]:
        if s[i][a]=='.':
          _ans+=1
        else:
          break
      for a in range(j,w):
        if s[i][a]=='.':
          _ans+=1
        else:
          break

      ans=max(ans,_ans)
  return ans

# main()
print(main())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  L=[[0 for _ in range(w)]for __ in range(h)]
  R=[[0 for _ in range(w)]for __ in range(h)]
  D=[[0 for _ in range(w)]for __ in range(h)]
  U=[[0 for _ in range(w)]for __ in range(h)]

  for i in range(h):
    for j in range(w):
      if s[i][j]=='#':
        L[i][j]=0
        U[i][j]=0
        continue

      if i==0:
        U[i][j]=1
      else:
        U[i][j]=U[i-1][j]+1

      if j==0:
        L[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if s[i][j]=='#':
        R[i][j]=0
        D[i][j]=0
        continue

      if i==h-1:
        D[i][j]=1
      else:
        D[i][j]=D[i+1][j]+1

      if j==w-1:
        R[i][j]=1
      else:
        R[i][j]=R[i][j+1]+1

  ans=0
  # print(R,L,D,U)
  for i in range(h):
    for j in range(w):
      ans=max(ans,R[i][j]+L[i][j]+U[i][j]+D[i][j]-3)

  return ans

# main()
print(main())
### BUGGY CODE ###

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

s = [0]*n
for i in range(m):
  l,r = map(int,input().split())
  for j in range(l-1,r):
    s[j] += 1

print(s.count(m))

### FIXED CODE ###

n,m=map(int,input().split())
L=[0]*m
R=[0]*m
table=[0]*(n+2)
for i in range(m):
   L[i],R[i]=map(int,input().split())
   table[L[i]]+=1
   table[R[i]+1]-=1
s=[0]*(n+2)#累積和をするリスト
for i in range(1,n+2):
   s[i]=s[i-1]+table[i]
print(s.count(m))
### BUGGY CODE ###

s = input()
q = int(input())

query = [""]*q

rev=1

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        rev*=-1
    else:
        r = query[i].split()
        if rev==1:
            if r[1]=="1":
                s = r[2]+s
            else:
                s += r[2]
        else:
            if r[1]=="2":
                s = r[2]+s
            else:
                s += r[2]

if rev==-1:
    s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)
### BUGGY CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
c = [0 for i in range(n)]
cc = 0
f = False
for i in range(n):
    t = s[0:i+1]
    c[i] = t.count("AC")
for i in range(q):
    print(c[l[i][1]-1]-c[l[i][0]-1])

### FIXED CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
c = [0 for i in range(n)]
cc = 0
f = False
for i in range(n):
    if f:
        f = False
        if s[i] == "C":
            cc += 1
    if s[i] == "A":
        f = True
    c[i] = cc
for i in range(q):
    print(c[l[i][1]-1]-c[l[i][0]-1])
### BUGGY CODE ###

s=list(input())

c=0
for i in range(len(s)):
    j=i
    while s[j:j+3]==["A","B","C"]:
        s[j:j+3]=["B","C","A"]
        c+=1
        j-=1
        if j==-1:
            break

print(c)


### FIXED CODE ###

s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())

si = [[0]for i in range(n+1)]
a = []


import bisect

for i in range(m):
    p,y = map(int,input().split())
    a.append([p,y])
    bisect.insort_left(si[p],y)




for i in range(m):
    ans = bisect.bisect_right(si[a[i][0]],a[i][1]) - 1
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0]) + '0'*(6-len(str(ans))) + str(ans))
    

    


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split()))for i in range(m)]
pypy = py[::]
from operator import itemgetter
import bisect
py.sort(key = itemgetter(1))
dic = {}
for i in range(m):
    if py[i][0] not in dic:
        dic[py[i][0]] = []
    dic[py[i][0]].append(py[i][1])


anslist = [0]*m

for i in range(m):
    anslist[i] = str(pypy[i][0]).zfill(6) + str(bisect.bisect_left(dic[pypy[i][0]],pypy[i][1]) + 1).zfill(6)

for ans in anslist:
    print(ans)