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

import sys

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    pass
  else:
    dic[a] = []
  
  dic[a].append(b)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

lst = []
for i in range(1,m+1):
  if i in dic.keys():
    lst.extend(dic[i])
    lst = sorted(lst, reverse=True)

  if len(lst) != 0:
    count += lst.pop(0)
  

print(count)

### FIXED CODE ###

import heapq

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    pass
  else:
    dic[a] = []
  
  dic[a].append(-b)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

lst = []
for i in range(1,m+1):
  if i in dic.keys():
    for num in dic[i]:
      heapq.heappush(lst, num)
  if len(lst) != 0:
    tmp = heapq.heappop(lst)
    count -= tmp
  

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

k,s=map(int,input().split())

val=list(range(0, k+1))[::-1]
n=len(val)
ans=0

for i in range(n):
    if val[i]>s:
        continue
    for j in range(n):
        if val[i]+val[j]>s:
            continue
        for k in range(n):
            if val[i]+val[j]+val[k]==s:
                ans+=1
                break
print(ans)


### FIXED CODE ###

k, s=map(int, input().split())

ans=0
for x in range(0, k+1):
    if x>s:
        break
    for y in range(0, k+1):
        if x+y>s:
            break
        z=s-x-y
        if 0<=z and z<=k:
            ans+=1
            continue
print(ans)
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
A = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

ans = 0
for i in range(N-1, -1, -1):
    b = defaultdict(int)

    b[ A[i] % M ]  += 1
    for dkey in d.keys():
        b[ (A[i] + dkey)%M ] +=   d[dkey] # b[A[i]] + d[dkey] 
    ans += b[0]

    d = b

#print("ans: ", ans)
# print(d)
print(ans)
    
    


### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
A = list(map(int, input().split()))

from collections import defaultdict
# d = defaultdict(int)
d = defaultdict(list)
# d = defaultdict(set)
# d = {}


B = [0] * (N+1)
B[0] = 0 
# B[1] = A[0]
for i in range(0,N):
    B[i+1] = A[i]
    B[i+1] += B[i]

# print(B)


for i in range(0,N+1):
    d[ B[i] % M] += [i]
    # d[ B[i] % M] |= set([i])
# print(d)
# exit(0)

from bisect import bisect_left

ans = 0
for i in range(0,N+1):
    m = B[i] % M 
    # print(d[m])
    ans += bisect_left( d[m], i)
    # print("{i:3d}: d[{m}]: {d}  bisect({i}): {bi}".format(m=m, d=d[m], i=i, bi=bisect_left(d[m], i)))

    
    
# for i in range(N-1, -1, -1):

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

N = int(input())
l = []
for i in range(N):
	num = int(input())
	if num in l:
		l.remove(num)
	else:
		l.append(num)

print(len(l))

### FIXED CODE ###

N = int(input())
alist = sorted([int(input()) for x in range(N)])

tmpNum = alist[0]
cnt = 1
ans = 0
for i in range(1, N):
	num = alist[i]
	if tmpNum == num:
		cnt = cnt + 1
		if i == N-1 and cnt % 2 != 0:
			ans = ans + 1
	else:
		if cnt % 2 != 0:
			ans = ans + 1
		tmpNum = num
		cnt = 1
		if i == N-1:
			ans = ans + 1

if len(alist) == 1:
	ans = ans + 1


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

h,w=map(int, input().split())
ch,cw=map(int, input().split())
ch-=1
cw-=1
dh,dw=map(int, input().split())
dh-=1
dw-=1
grid=[]
for i in range(h):
    s=list(input())
    news=[-1 if x=='#' else 0 for x in s]
    grid.append(news)
dif=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
col=0
for i in range(h):
    for j in range(w):
        if grid[i][j]==0:
            col+=1
            stack=deque([(i,j)])
            while stack:
                nowi,nowj=stack.popleft()
                grid[nowi][nowj]=col
                for di,dj in dif:
                    if 0<=nowi+di<h and 0<=nowj+dj<w and grid[nowi+di][nowj+dj]==0:
                        stack.append((nowi+di,nowj+dj))

es=[set([]) for _ in range(col)]
visited=[-1]*col
for i in range(h):
    for j in range(w):
        now=grid[i][j]
        if now!=-1: 
            for x in range(-2, 3):
                for y in range(-2, 3):
                    if (x,y) in dif:
                        continue
                    if 0<=i+x<h and 0<=j+y<w:
                        nex=grid[i+x][j+y]
                        if nex!=-1 and now!=nex:
                            es[now-1].add(nex-1)

start=grid[ch][cw]-1
end=grid[dh][dw]-1
if start==end:
    print(0)
    exit()

stack=deque([start])
visited[start]=0
while stack:
    now=stack.popleft()
    for e in es[now]:
        if visited[e]==-1:
            visited[e]=visited[now]+1
            stack.append(e)
#print(grid)
print(visited[end])


### FIXED CODE ###

h,w=map(int, input().split())
ch,cw=map(int, input().split())
ch-=1
cw-=1
dh,dw=map(int, input().split())
dh-=1
dw-=1
grid=[]
for i in range(h):
    s=list(input())
    news=[-1 if x=='#' else 0 for x in s]
    grid.append(news)
dif=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
col=0
for i in range(h):
    for j in range(w):
        if grid[i][j]==0:
            col+=1
            stack=deque([(i,j)])
            grid[i][j]=col
            while stack:
                nowi,nowj=stack.popleft()
                for di,dj in dif:
                    if 0<=nowi+di<h and 0<=nowj+dj<w and grid[nowi+di][nowj+dj]==0:
                        stack.append((nowi+di,nowj+dj))
                        grid[nowi+di][nowj+dj]=col
start=grid[ch][cw]-1
end=grid[dh][dw]-1
if start==end:
    print(0)
    exit()
es=[set([]) for _ in range(col)]
visited=[-1]*col

for i in range(h):
    for j in range(w):
        now=grid[i][j]
        if now!=-1: 
            for x in range(-2, 3):
                for y in range(-2, 3):
                    if 0<=i+x<h and 0<=j+y<w:
                        nex=grid[i+x][j+y]
                        if nex!=-1 and now!=nex:
                            es[now-1].add(nex-1)

stack=deque([start])
visited[start]=0
while stack:
    now=stack.popleft()
    for e in es[now]:
        if visited[e]==-1:
            visited[e]=visited[now]+1
            stack.append(e)
#print(grid)
print(visited[end])
### BUGGY CODE ###

n = int(input())
a = tuple(map(int, input().split()))
ans = 0
lim = max(a)
amount = [0]*lim
for i in range(lim):
    amount[i] = a.count(i+1)
    ans += amount[i]*(amount[i]-1)//2
for j in range(n):
    print(ans - amount[a[j]-1] + 1)

### FIXED CODE ###

import numpy as np
def main():
    from collections import Counter
    n = int(input())
    a = tuple(map(int, input().split()))
    ans = 0
    c = Counter(a)
    for i in range(n):
        ans += c[i+1]*(c[i+1]-1)//2
    for j in range(n):
        print(ans - c[a[j]] + 1)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = str(input())
T = S
flag = True
while(flag):
    flag = False
    for i in range(1, len(T)):
        if int(T[i-1]) ^ int(T[i]):
            flag = True
            T = T[:i-1]+T[i+1:]
            break
print(len(S)-len(T))


### FIXED CODE ###

S = str(input())
print(len(S)-abs(S.count('0')-S.count('1')))
### BUGGY CODE ###

L,R=map(int,input().split())

min=2019
for i in range(L,R):
    for j in range(i+1,R+1):
        mod = (i*j) % 2019
#        print(str(i)+' '+str(j)+' '+str(mod))
        if mod == 0:
            min = 0
            break
        if mod < min:
            min = mod
print(min)



### FIXED CODE ###

L,R=map(int,input().split())

ans=2019
for i in range(L,min(R,L+2018)):
    for j in range(i+1,min(R+1,L+2019)):
        mod = (i*j) % 2019
#        print(str(i)+' '+str(j)+' '+str(mod))
        if mod == 0:
            ans = 0
            break
        if mod < ans:
            ans = mod
print(ans)
### BUGGY CODE ###

class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):  # グループの要素
        root = self.find(x)
        return set(i for i in range(self.N) if self.find(i) == root)

    def roots(self):  # 根のリスト
        return set(i for i, x in enumerate(self.parents) if x < 0)

    def all_group_members(self):  # グループごとの辞書
        return {r: self.members(r) for r in self.roots()}


n, m = map(int, input().split())
minusone = lambda x: int(x) - 1
p = list(map(minusone, input().split()))
xy = [list(map(minusone, input().split())) for _ in range(m)]

uf = Unionfind(n)
for x, y in xy:
    uf.union(x, y)

ans = 0
for lst in uf.all_group_members().values():
    ans += sum((p[num] in lst) for num in lst)
print(ans)


### FIXED CODE ###

class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def all_group_members(self):  # グループごとの辞書
        members_dict = {i: set([i]) for i, x in enumerate(self.parents) if x < 0}
        for i, x in enumerate(self.parents):
            if x >= 0:
                members_dict[self.find(x)].add(i)
        return members_dict


n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

uf = Unionfind(n)
for x, y in xy:
    uf.union(x - 1, y - 1)

ans = 0
for lst in uf.all_group_members().values():
    ans += sum((p[num] - 1 in lst) for num in lst)
print(ans)
### BUGGY CODE ###

n = int(input())
P = [int(input()) for _ in range(n)]

seen = [0] * (n + 1)
i = 0
counter = 0
while i < n:
    if seen[i]:
        i += 1
        continue

    p = P[i]
    seen[i] = 1
    cnt = 1
    for j in range(i+1, n):
        if P[j] == p + 1:
            seen[j] = 1
            cnt += 1
            p += 1
    i += 1
    counter = max(counter, cnt)

ans = n - counter
print(ans)


### FIXED CODE ###

n = int(input())
order = [0] * (n+1)
for i in range(n):
    p = int(input())
    order[p] = i+1
order[0] = 10**9

cnt = 0
ans = 0
for x, y in zip(order[:-1], order[1:]):
    if x > y:
        ans = max(cnt, ans)
        cnt = 0
    else:
        cnt += 1
ans = max(cnt, ans)

answer = n - ans - 1
print(answer)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

from operator import itemgetter
import itertools
import bisect

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

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

BC = [(0, 0)]*M
for m in range(M):
    BC[m] = tuple(map(int, input().split()))
BC.sort(key=itemgetter(1), reverse = True)

def main(): 
    #print(BC)
    res = 0
    num = 0
    for i in range(M):
        idx = 0         
        idx = bisect.bisect_left(A[num:], BC[i][1])
        if idx == 0:
            break
        else:
            less =min(idx, BC[i][0]) 
            num += less
            res += BC[i][1]*less
            
    print(res+sum(A[num:]))
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019
 
@author: Owner
"""
 
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019
 
@author: Owner
"""
 
from operator import itemgetter
import itertools
import collections
import bisect
 
N, M = list(map(int, input().split()))
 
A = list(map(int, input().split()))
A.sort()

A = collections.deque(A)

BC = [(0, 0)]*M
for m in range(M):
    BC[m] = tuple(map(int, input().split()))
BC.sort(key=itemgetter(1), reverse = True)
 
def main(): 
    #print(BC)
    res = 0
    for i in range(M):
        idx = 0         
        idx = bisect.bisect_left(A, BC[i][1])
        if idx == 0:
            break
        else:
            less =min(idx, BC[i][0])
            for n in range(less):
                A.popleft()
            res += BC[i][1]*less
 
    print(res+sum(A))
                
                
                
            
            
                
 
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.buffer.readline
n,m,k=map(int,input().split())
link=[[] for _ in range(n)]
block=[[]  for _ in range(n)]
ans=[0]*n
s=[]
for i in range(m):
    a,b=map(int,input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)
for i in range(k):
  a,b=map(int,input().split())
  block[a-1].append(b-1)
  block[b-1].append(a-1)
for i in range(n):#スタートの選び方
    u=[0]*n
    q=deque([i])
    while len(q)>0:
        x=q.pop()
        u[x]=1
        for j in link[x]:
            if u[j]==1:
              continue
            elif j in q:
              continue
            else:q.append(j)
    s.append(u)
    ans[i]=sum(u)-1
for i in range(n):
  for j in link[i]:
    if s[i][j]==1:
      ans[i]-=1
  for k in block[i]:
    if s[i][k]==1:
      ans[k]-=1
print(*ans)

### FIXED CODE ###

class UnionFind():
    def __init__(self,n):
      self.n=n
      self.root=[-1]*(n+1)
      self.rank=[0]*(n+1)
      
    def find(self,x):
      if self.root[x]<0:
        return x
      else:
        self.root[x]=self.find(self.root[x])
        return self.root[x]
    
    def unite(self,x,y):
      x=self.find(x)
      y=self.find(y)
      if x==y:
        return 0
      elif self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      else:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
          
    def Same(self,x,y):
      return self.find(x)==self.find(y)
    
    def size(self,x):
      return -self.root[self.find(x)]
import sys
input=sys.stdin.buffer.readline
n,m,k=map(int,input().split())
link=UnionFind(n)
f=[0]*n
block=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    link.unite(a,b)
    f[a]+=1
    f[b]+=1
for _ in range(k):
    a,b=map(int,input().split())
    block[a-1].append(b-1)
    block[b-1].append(a-1)
ans=[]
for i in range(n):
  ret=link.size(i)-f[i]-1
  for j in block[i]:
    if link.Same(i,j):
      ret-=1
  ans.append(ret)
print(*ans)
### BUGGY CODE ###

s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

### FIXED CODE ###

s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])
### BUGGY CODE ###

import numpy as np
n, k, q = map(int, input().split())
point = np.array([k for _ in range(n)])


def judge(point):
    ans = []
    if k > q:
        return(['Yes' for _ in range(n)])
    for _ in range(q):
        a = int(input())
        point -= 1
        point[a-1] += 1
    for i in range(n):
        if point[i] > 0:
            ans.append('Yes')
        else:
            ans.append('No')
    return(ans)
            

ans = judge(point)
print(*ans)

### FIXED CODE ###

n, k, q = map(int, input().split())
def judge():
    val = {}
    for _ in range(q):
        a = int(input())
        val[a-1] = val.get(a-1,0) + 1
    #print(val)
    for i in range(n):
        if val.get(i,k-q) + (k - q) > 0:
            print('Yes')
        else:
            print('No')
if k > q:
    print(*['Yes' for _ in range(n)])
else:
    ans = judge()
### BUGGY CODE ###

N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
ans=[i+1 for i in range(N)]
for i in range(M):
  for j in range(LR[i][0]):
    if j in ans:
      ans.remove(j)
  for k in range(LR[i][1]+1,N+1):
    if k in ans:
      ans.remove(k)
print(len(ans))

### FIXED CODE ###

N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
l,r=LR[0][0],LR[0][1]
for i in range(M):
  if LR[i][1]<=r:
    r=LR[i][1]
  if l<=LR[i][0]:
    l=LR[i][0]
ans=r-l+1
if ans>0:
  print(ans)
else:
  print(0)
### BUGGY CODE ###

from scipy.special import comb
n, m, k = map(int, input().split())
ans = 0
for i in range(k + 1):
    ans += pow(m - 1, n - i - 1) * comb(n - 1, i, exact=True) * m
    ans %= 998244353
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
mod = 998244353
ans = 0
x = 1
for i in range(k + 1):
    ans += (((m * pow(m - 1, n - i - 1, mod)) % mod) * x) % mod
    ans %= mod
    x = (x * (n - i - 1) * pow(i + 1, mod - 2, mod)) % mod
print(ans % mod)
### BUGGY CODE ###

MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def nPr(n, r, mod=MOD):
    return f[n] * pow(f[n-r], mod-2, mod) % mod

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    # tmp = pow(nPr(m-k, n-k), 2, MOD) * nPr(m, k) * nCr(n,k) % MOD
    tmp = nPr(m-k, n-k) * nPr(m, n) * nCr(n,k) % MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans = (ans + MOD) % MOD
print(ans)


### FIXED CODE ###

MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def nPr(n, r, mod=MOD):
    return f[n] * pow(f[n-r], mod-2, mod) % mod

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    tmp = nPr(m-k, n-k)
    tmp *= tmp
    tmp %= MOD
    tmp *= nPr(m, k)
    tmp %= MOD
    tmp *= nCr(n,k)
    tmp %= MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans += MOD
ans %= MOD
print(ans)
### BUGGY CODE ###

from collections import deque

def bfs(maze, h, w, si, sj, gi, gj):
    memo = [[0] * w for i in range(h)]
    q = deque([[si, sj]])
    score = [[0] * w for i in range(h)]

    pattern = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while len(q) > 0:
        i, j = q.popleft()
        if i == gi and j == gj:
            return score[gi][gj]
        for move in pattern:
            ni, nj= i + move[0], j + move[1]
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue
            p = maze[ni][nj]
            if p == '#':
                continue
            if p == '.' and not score[ni][nj]:
                score[ni][nj] = score[i][j] + 1
                q.append([ni, nj])

h, w = map(int, input().split())
maze = [input() for i in range(h)]
memo = []
scores = []
for si in range(h):
    for sj in range(w):
        if maze[si][sj] == "#":
            continue
        for gi in range(h):
            for gj in range(w):
                if maze[gi][gj] == "#" or (si == gi and sj == gj) or (gi, gj) in memo:
                    continue
                scores.append(bfs(maze, h, w, si, sj, gi, gj))
print(max(scores))

### FIXED CODE ###

from collections import deque

def bfs(maze, h, w, si, sj):
    q = deque([[si, sj]])
    score = [[-1] * w for i in range(h)]
    score[si][sj] = 0
    pattern = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while len(q) > 0:
        i, j = q.popleft()
        for move in pattern:
            ni, nj= i + move[0], j + move[1]
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue
            p = maze[ni][nj]
            if p == '#':
                continue
            if p == '.' and score[ni][nj] == -1:
                score[ni][nj] = score[i][j] + 1
                q.append([ni, nj])
    return max(map(max, score))

h, w = map(int, input().split())
maze = [input() for i in range(h)]
scores = []
for si in range(h):
    for sj in range(w):
        if maze[si][sj] == "#":
            continue
        scores.append(bfs(maze, h, w, si, sj))
print(max(scores))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
a = [0] * (N+1)

for i in range(1,N+1):
    a[i] = a[i-1] + A[i-1]

a.sort()
#print(a)

b = list(set(a))

count = []

for i in range(len(b)):
    tmp = a.count(b[i])
    if tmp >= 2:
        count.append(tmp)

#print(count)

ans = 0

for i in range(len(count)):
    tmp = count[i]*(count[i]-1) //2
    ans += tmp

print(ans) 



### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
a = [0] * (N+1)

for i in range(1,N+1):
    a[i] = a[i-1] + A[i-1]

a.sort()
#print(a)

ans = 0
s = 0

for i in range(N+1):
    if i == 0:
        s += 1
    elif 1 <= i <= N -1:
        if a[i] == a[i-1]:
            s += 1
        else:
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
            s = 1
    elif i == N :
        if a[i] == a[i-1]:
            s += 1
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
        else:
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
            s = 1
#    print(ans, s)






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

import sys

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY_dict = {}
    for _ in range(M):
        p, y = map(int, sys.stdin.readline().split())
        PY_input.append((p, y))
        PY_dict.setdefault(p, []).append(y)

    for i in PY_dict.values():
        i.sort()

    for p, y in PY_input:
        print("{:06}{:06}".format(p, PY_dict[p].index(y)+1))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import bisect
input = sys.stdin.readline

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY_dict = {}
    for _ in range(M):
        p, y = map(int, input().split())
        PY_input.append((p, y))
        PY_dict.setdefault(p, []).append(y)

    for i in PY_dict.values():
        i.sort()

    for p, y in PY_input:
        print("{:06}{:06}".format(p, bisect.bisect_right(PY_dict[p], y)))


if __name__ == "__main__":
    main()