Problem: In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.  City i is established in year Y_i and belongs to Prefecture P_i.  You can assume that there are no multiple cities that are established in the same year.  It is decided to allocate a 12-digit ID number to each city.  If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.  Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.  Find the ID numbers for all the cities.  Note that there can be a prefecture with no cities.

Submission attempts (in order):
n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j+=1
    print(int(u))
  else:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j-=j-1
    print(int(u))
    
  


n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1

for k in range(m):
  print(str(lst[k][0])+str(lst[k][1]))
  
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([i,p,y])
lst.sort(key=lambda x:(x[1],x[2]))
j=1
Lst=[]
for i in range(m):
  if lst[i][1]==lst[min(m-1,i+1)][1]:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    Lst.append([lst[i][0],u])
  else:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    Lst.append([lst[i][0],u])
Lst.sort(lambda x:x[0])
for k in range(m):
  print(Lst[k][1])
  


n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:x[0])
lst.sort(key=lambda x:x[1])
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if i<m-1:
    if lst[i][0]==lst[i+1][0]:
      s=str(lst[i][0])
      t=str(j)
      s.zfill(6)
      t.zfill(6)
      u=s+t
      j+=1
      print(int(u))
    else:
      s=str(lst[i][0])
      t=str(j)
      s.zfill(6)
      t.zfill(6)
      u=s+t
      j-=j-1
      print(int(u))
    
  


n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    ''.join(list(s).insert(0,'0'))
for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))
  
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1

for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))
  
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))
  
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s.insert(0,'0')
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))
  





n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
for i in range(m):
  j=1
  while lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    s.zfill(6)
    t.zfill(6)
    u=s+t
    j+=1
    print(int(u))
    
  

n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([i,p,y])
lst.sort(lambda x:(x[1],x[2]))
j=1
Lst=[]
for i in range(m):
  if lst[i][1]==lst[min(m-1,i+1)][1]:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    Lst.append([lst[i][0],u])
  else:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    Lst.append([lst[i][0],u])
Lst.sort(lambda x:x[0])
for k in range(m):
  print(Lst[k][1])
  


n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([p,y])
lst.sort(lambda x:(x[0],x[1]))
j=1
for i in range(m):
  if lst[i][0]==lst[min(m-1,i+1)][0]:
    s=str(lst[i][0])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    print(int(u))
  else:
    s=str(lst[i][0])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    print(int(u))
    
  


n,m=map(int,input().split())
lst=[]
for i in range(m):
  p,y=map(int,input().split())
  lst.append([i,p,y])
lst.sort(key=lambda x:(x[1],x[2]))
j=1
Lst=[]
for i in range(m):
  if lst[i][1]==lst[min(m-1,i+1)][1]:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j+=1
    Lst.append([lst[i][0],u])
  else:
    s=str(lst[i][1])
    t=str(j)
    u=s.zfill(6)+t.zfill(6)
    j-=j-1
    Lst.append([lst[i][0],u])
Lst.sort(key=lambda x:x[0])
for k in range(m):
  print(Lst[k][1])
  


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted