Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mine_map = [list(input().split()) for x in range(H)]
for i in range(H):
  for j in range(W):
    count = 0
    if mine_map[i][j] == ".":
      for k in range(-1,2):
        for l in range(-1,2):
          if i+k >= 0 and i+k < H and j+l >= 0 and j+l < W:
            if mine_map[i+k][j+l] == "#":
              count += 1
      mine_map[i][j] = count
    print(mine_map[i][j],end="")
  print()

Fixed submission:
H,W = map(int,input().split())
mine_map = [list(input()) for x in range(H)]
for i in range(H):
  for j in range(W):
    count = 0
    if mine_map[i][j] == ".":
      for k in range(-1,2):
        for l in range(-1,2):
          if i+k >= 0 and i+k < H and j+l >= 0 and j+l < W:
            if mine_map[i+k][j+l] == "#":
              count += 1
      mine_map[i][j] = count
    print(mine_map[i][j],end="")
  print()

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mine_map = [list(input().split()) for x in range(H)]
for i in range(H):
  for j in range(W):
    count = 0
    if mine_map[i][j] == ".":
      for k in range(-1,2):
        for l in range(-1,2):
          if i+k >= 0 and i+k < H and j+l >= 0 and j+l < W:
            if mine_map[i+k][j+l] == "#":
              count += 1
      mine_map[i][j] = count
    print(mine_map[i][j],end="")
  print("")

Fixed submission:
H,W = map(int,input().split())
mine_map = [list(input()) for x in range(H)]
for i in range(H):
  for j in range(W):
    count = 0
    if mine_map[i][j] == ".":
      for k in range(-1,2):
        for l in range(-1,2):
          if i+k >= 0 and i+k < H and j+l >= 0 and j+l < W:
            if mine_map[i+k][j+l] == "#":
              count += 1
      mine_map[i][j] = count
    print(mine_map[i][j],end="")
  print()
Buggy python submission (verdict: Runtime Error):
def dfs(num):
  global visited
  for next_num in num:
    if visited[next_num]:
      continue
    if has_edge[num][next_num]:
      visited[next_num]=1
      dfs(next_num)
      
N,M = map(int,input().split())
ab = []
edge = [[] for x in range(N+1)]
has_edge = [[0 for x in range(N+1)] for x in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  ab.append([a,b])
  edge[a].append(b)
  edge[b].append(a)
  has_edge[a][b] = 1
  has_edge[b][a] = 1
  
count = 0
for a,b in ab:
  visited = [0 for x in range(N+1)]
  visited[1] = 1
  has_edge[a][b] = 0
  has_edge[b][a] = 0
  dfs(1)
  if sum(visited) != N:
    count += 1
  has_edge[a][b] = 1
  has_edge[b][a] = 1
print(count)

Fixed submission:
def dfs(num):
  global visited
  for next_num in edge[num]:
    if visited[next_num]:
      continue
    if has_edge[num][next_num]:
      visited[next_num]=1
      dfs(next_num)
      
N,M = map(int,input().split())
ab = []
edge = [[] for x in range(N+1)]
has_edge = [[0 for x in range(N+1)] for x in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  ab.append([a,b])
  edge[a].append(b)
  edge[b].append(a)
  has_edge[a][b] = 1
  has_edge[b][a] = 1
  
count = 0
for a,b in ab:
  visited = [0 for x in range(N+1)]
  visited[1] = 1
  has_edge[a][b] = 0
  has_edge[b][a] = 0
  dfs(1)
  if sum(visited) != N:
    count += 1
  has_edge[a][b] = 1
  has_edge[b][a] = 1
print(count)
Buggy python submission (verdict: Runtime Error):
n=input()
a=list(input())
result = 0
for num in a:
    result += 1/int(num)
    
print(1/result)




Fixed submission:
n=input()
a=str(input())
li = list(a.split(" "))
result = 0
for num in li:
    result += 1/int(num)
    
print(1/result)

Buggy python submission (verdict: Runtime Error):
n=input()
a=list(input())
result = 0
for num in a:
    result += 1/num
    
print(1/result)



Fixed submission:
n=input()
a=str(input())
li = list(a.split(" "))
result = 0
for num in li:
    result += 1/int(num)
    
print(1/result)
Buggy python submission (verdict: Runtime Error):
stay = int(input())
plan_change_day =int(input())
high_price=int(input())
low_price=int(input())
 
def main():
	if stay - plan_change_day > 0:
		cost = high_price * plan_change_day + low_price * (stay - plan_change_day)
        print(int(cost))
    else:
        cost = high_price * plan_change_day 
  	    print(int(cost))
  	    
main()


Fixed submission:
stay = int(input())
plan_change_day =int(input())
high_price=int(input())
low_price=int(input())
 
def main():
    if stay - plan_change_day > 0:
        cost = high_price * plan_change_day + low_price * (stay - plan_change_day)
        print(int(cost))
    else:
        cost = high_price * stay
        print(int(cost))
  	    
main()

Buggy python submission (verdict: Runtime Error):
stay = int(input())
plan_change_day =int(input())
high_price=input()
low_price=input()

def main():
  cost = high_price * plan_change_day + low_price * (stay - plan_change_day)
  print(cost)
  
 main()

Fixed submission:
stay = int(input())
plan_change_day =int(input())
high_price=int(input())
low_price=int(input())
 
def main():
    if stay - plan_change_day > 0:
        cost = high_price * plan_change_day + low_price * (stay - plan_change_day)
        print(int(cost))
    else:
        cost = high_price * stay
        print(int(cost))
  	    
main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
kati = 0

v.sort()
kati = (v[0] + v[1]) / 2

if n == 2:
  print(kati)
else:
  for i in range(2,n):
    kati = (kati + v[i]) / 2
  print(kati)


Fixed submission:
a = int(input())
s = input()

if a >= 3200:
  print(s)
else:
  print('red')

Buggy python submission (verdict: Runtime Error):
a=input()
s=input()

if a>=3200:
    print(s)

else:
    print('red')

Fixed submission:
a=int(input())
s=input()

if a>=3200:
    print(s)

else:
    print('red')

Buggy python submission (verdict: Runtime Error):
a=input()
s=input()

if a>=3200:
    print(s)

if a<3200:
    print('red')

Fixed submission:
a=int(input())
s=input()

if a>=3200:
    print(s)

else:
    print('red')

Buggy python submission (verdict: Runtime Error):
a=int(input())
s=input()

if a>=3200:
    print(s)
else if a<3200:
    print("red")

Fixed submission:
a=int(input())
s=input()

if a>=3200:
    print(s)
elif a<3200:
    print("red")

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

i, q = [int(x) for x in input().split(' ')]

root = Node(1)
for idx in range(i-1):
    a, b = [int(x) for x in input().split(' ')]
    root.add_child(a, b)

for _ in range(q):
    p, x = [int(x) for x in input().split(' ')]
    root.set_count(p, x)

root.add_count()

counts = sorted(root.get_counts(), key=itemgetter(0))
print(' '.join([str(x[1]) for x in counts]))


class Node:
    def __init__(self, id):
        self.id = id
        self.count = 0
        self.children = []

    def add_child(self, parent_id, child_id):
        if parent_id < self.id:
            return

        if parent_id == self.id:
            # 追加
            self.children.append(Node(child_id))
            return

        for child in self.children:
            child.add_child(parent_id, child_id)
        return

    def set_count(self, target_id, num, is_count=False):
        # if target_id == self.id:
        #     is_count = True

        # if is_count:
        #     self.count += num

        # for child in self.children:
        #     child.add_count(target_id, num, is_count)
        if target_id < self.id:
            return
        if target_id == self.id:
            self.count += num
            return
        for child in self.children:
            child.set_count(target_id, num, is_count)
        return

    def add_count(self, num=0):
        self.count += num
        for child in self.children:
            child.add_count(self.count)
        return

    def get_counts(self):
        res = [(self.id, self.count)]
        # print(self.id, self.count)
        for child in self.children:
            res += child.get_counts()
        return res


Fixed submission:
a = int(input())
s = input()
 
if a < 3200:
  s = 'red'
print(s)
Buggy python submission (verdict: Runtime Error):
s=input()
a=0
for i in range(3):
  if i%2==0 and s[i]=="0":
  	a=1
  if i%2==1 and s[i]=="1":
  	a+=1  
print(min(a,len(s)-a))

Fixed submission:
s=input()
a=0
for i in range(len(s)):
  if i%2==0 and s[i]=="0":
  	a+=1
  if i%2==1 and s[i]=="1":
  	a+=1  
print(min(a,(len(s)-a)))

Buggy python submission (verdict: Runtime Error):
s=input()
a=0
for i in range(len(s)):
  if i%2==0:
    if s[i]==0:
      a+=1
  if i%2==1:
    if s[i]==1:
      a+=1
print(min(a,len(s)-a)

Fixed submission:
s=input()
a=0
for i in range(len(s)):
  if i%2==0 and s[i]=="0":
  	a+=1
  if i%2==1 and s[i]=="1":
  	a+=1  
print(min(a,(len(s)-a)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a=0
for i in range(N):
  b=input().split()
  if b[1]=="JPY":
    a+=b[0]
  else:
    a+=b[0]*380000
print(a)
  

Fixed submission:
N = int(input())
a=0
for i in range(N):
  b=input().split()
  if b[1]=="JPY":
    a+=float(b[0])
  else:
    a+=float(b[0])*380000
print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for i in range(n)]
print(int(sum(a)-max(a)/2))

Fixed submission:
a=int(input())
if 22<=a<=25:
	print("Christmas"+" Eve"*(25-a))
Buggy python submission (verdict: Runtime Error):

print("YES" if int(input() in [7,5,3] else "NO")

Fixed submission:
print("YES" if int(input()) in [7,5,3] else "NO")
Buggy python submission (verdict: Runtime Error):
n,i=map(int,input().split())
print(n-p+1)

Fixed submission:
n,i=map(int,input().split())
print(n-i+1)
Buggy python submission (verdict: Runtime Error):
a = [list(map(int, input().split())) for i in range(3)]
print(a[0][0]+a[1][1]+a[2][2])

Fixed submission:
a = [input() for i in range(3)]
print(a[0][0]+a[1][1]+a[2][2])
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
c=0
for i in range(a,b+1):
  d=str(i)
  if d[0]=d[-1] and d[-2]=d[1]:
    c+=1
print(c)
  
  
  

Fixed submission:
a,b=map(int, input().split())
c=0
for i in range(a,b+1):
  d=str(i)
  if d[0]==d[-1] and d[-2]==d[1]:
    c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
b=0
for i in range(n):
  b+=a[i]*(-1)**i
print(b)

Fixed submission:
a=int(input())
b=int(input())
if a%500<=b:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())
a=0
for i in range(A+1):
  for j in range(B+1):
    if 0<=X-500*i-100*j<=50*C:
      a+=1
print(a)

Fixed submission:
X,A,B=[int(input()) for i in range(3)]
print((X-A)%B)
Buggy python submission (verdict: Runtime Error):
print(48-int(input())

Fixed submission:
print(48-int(input()))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
l=a+b
r=c+d
printT("Left" if l>r else "Balanced" if l==r else "Right")

Fixed submission:
a,b,c,d = map(int, input().split())
l=a+b
r=c+d
print("Left" if l>r else "Balanced" if l==r else "Right")
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
b=[0,0,0]
for i in range(N):
  while a[i]%2==0:
    a[i]=int(a[i]/2)
    b[i]+=1
print(min(b))

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
for i in range(N):
  while a[i]%2==0:
    a[i]=int(a[i]/2)
    b[i]+=1
print(min(b))
Buggy python submission (verdict: Runtime Error):
x,y= map(int, input().split())
print("=" if x==y else ">" if x>y else "<")

Fixed submission:
x,y= input().split()
print("=" if x==y else ">" if x>y else "<")
Buggy python submission (verdict: Runtime Error):
l=[input() for i in range()]
print("YES" if l[0][0]==l[1][2] and l[0][1]==l[1][1] and l[0][2]==l[1][0] else "NO")

Fixed submission:
l=[input() for i in range(2)]
print("YES" if l[0][0]==l[1][2] and l[0][1]==l[1][1] and l[0][2]==l[1][0] else "NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
print(N**2-a)

Fixed submission:
N = int(input())
A = int(input())
print(N**2-A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(6):
  if 2**(i+1)<=N:
    a=2**(i+1)
print(a)

Fixed submission:
N = int(input())
a=1
for i in range(6):
  if 2**(i+1)<=N:
    a=2**(i+1)
print(a)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
pint("Possible" if N*K*(N+K)%3==0 else "Impossible")

Fixed submission:
N, K = map(int, input().split())
print("Possible" if N*K*(N+K)%3==0 else "Impossible")
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
print(a[0].upper+b[0].upper+c[0].upper)

Fixed submission:
a,b,c=input().split()
print(a[0].upper()+b[0].upper()+c[0].upper())
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int, input().split())
print("YES" if b-a=c-b else "NO")

Fixed submission:
a,b,c=map(int, input().split())
print("YES" if b-a==c-b else "NO")
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")

Fixed submission:
a,b,c=sorted(map(int,input().split()))
print("YES" if a==b==5 and c==7 else "NO")

Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
list=sorted([input() for i in range(n)])
print(*list,sep="")

Fixed submission:
a,b,c=sorted(map(int,input().split()))
print("YES" if a==b==5 and c==7 else "NO")

Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
list=sorted([input() for i in range(n)])
print(*list,sep="")

Fixed submission:
a,b,c=sorted(map(int,input().split()))
print("YES" if a==b==5 and c==7 else "NO")
Buggy python submission (verdict: Runtime Error):
n = int(input()
arr = [[int(i) for i in list(input().split())] for j in range(n)]
for i in range(1,n):
	arr[i][0] += max(arr[i-1][1], arr[i-1][2])
	arr[i][2] += max(arr[i-1][1], arr[i-1][0])
	arr[i][1] += max(arr[i-1][0], arr[i-1][2])
print(max(arr[n-1]))

Fixed submission:
n = int(input())
arr = [[int(i) for i in list(input().split())] for j in range(n)]
for i in range(1,n):
	arr[i][0] += max(arr[i-1][1], arr[i-1][2])
	arr[i][2] += max(arr[i-1][1], arr[i-1][0])
	arr[i][1] += max(arr[i-1][0], arr[i-1][2])
print(max(arr[n-1]))
Buggy python submission (verdict: Runtime Error):
A = list()
B = [0] * 200000

for i in range(N):
  i = int(input())
  A.append(i)
  
C = sorted(A,reverse=True)

for k in range(N):
  if max(A) != A[k]:
    print(C[0])
  else:
    B[k] = A[k]
    A[k] = 0
    print(max(A))
    A[k] = B[k]

Fixed submission:
N = int(input())
A = list()

for i in range(N):
  i = int(input())
  A.append(i)
  
ma = max(A)
sa = sorted(A)

for k in range(N):
  if ma != A[k]:
    print(ma)
  else:
    print(sa[-2])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list()
B = [0] * 200000

for i in range(N):
  i = int(input())
  A.append(i)

for k in range(N):
  if max(A) != A[k]:
    print(max(A))
  else:
    B[k] = A[k]
    A[k] = 0
    print(max(A))
    A[k] = B[k]

Fixed submission:
N = int(input())
A = list()

for i in range(N):
  i = int(input())
  A.append(i)
  
ma = max(A)
sa = sorted(A)

for k in range(N):
  if ma != A[k]:
    print(ma)
  else:
    print(sa[-2])

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list()
B = [0] * 50

for i in range(N):
  i = int(input())
  A.append(i)

for k in range(N):
  if max(A) != A[k]:
    print(max(A))
  else:
    B[k] = A[k]
    A[k] = 0
    print(max(A))
    A[k] = B[k]

Fixed submission:
N = int(input())
A = list()

for i in range(N):
  i = int(input())
  A.append(i)
  
ma = max(A)
sa = sorted(A)

for k in range(N):
  if ma != A[k]:
    print(ma)
  else:
    print(sa[-2])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def calc(vlist):
    sum = vlist[0]
    for i in range(len(vlist) - 1):
        sum = ((sum + vlist[i+1]) / 2)        

    return sum

try:
    n = int(input())
    
    v = [int(x) for x in input().split(' ')]
    
    pattern = itertools.permutations(v)
    
    results = []
    for plist in pattern:
      results.append(calc(plist))
      
    print(max(results))
    
except ValueError:
    print("数値を入力してください")

Fixed submission:
def calc(vlist):
    sum = vlist[0]
    for i in range(len(vlist) - 1):
        sum = ((sum + vlist[i+1]) / 2)

    return sum
   
try:
    n = int(input())

    v = [int(x) for x in input().split(' ')]
    v.sort()
    
    print(calc(v))
    
except ValueError:
    print("数値を入力してください")
Buggy python submission (verdict: Runtime Error):
import sys
import math

def main():
    input = sys.stdin.readline
    
    L = [int(input()) for i in range(5)]
    
    #最後の注文を決める
    last_orders = [10 - (i % 10) for i in L if i % 10 != 0]
    last_order = max(last_orders)
    
    #一の位を切り上げ
    all_order = sum([math.ceil(i / 10) * 10 for i in L])
    
    print(all_order - last_order)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys
import math

def main():
    input = sys.stdin.readline
    
    L = [int(input()) for i in range(5)]
    
    #最後の注文を決める
    last_orders = [10 - (i % 10) for i in L if i % 10 != 0]
    last_order = 0 if not last_orders else max(last_orders)
    
    #一の位を切り上げ
    all_order = sum([math.ceil(i / 10) * 10 for i in L])
    
    print(all_order - last_order)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    
    for i in range(Q):
        start, end = list(map(int, input().split()))
        s = S[start-1:end]
        
        cnt = 0
        while True:
            #print(s)
            
            f = s.find('AC')
            if f == -1:
                break
            else:
                cnt = cnt + 1
                s = s[:f] + s[f + 2:]
        
        print(cnt)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    t = [0] * (N + 1)
    
    for i in range(N):
        t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
    
    for i in range(Q):
        start, end = map(int, input().split())
        print(t[end - 1] - t[start - 1])
    
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    
    for i in range(Q):
        start, end = list(map(int, input().split()))
        print(S[start-1:end].count('AC'))
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    t = [0] * (N + 1)
    
    for i in range(N):
        t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
    
    for i in range(Q):
        start, end = map(int, input().split())
        print(t[end - 1] - t[start - 1])
    
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    tr = [list(map(int, input().split())) for i in range(Q)]
    
    [print(S[l[0]-1:l[1]].count('AC')) for l in tr ]
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    S = input()
    t = [0] * (N + 1)
    
    for i in range(N):
        t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
    
    for i in range(Q):
        start, end = map(int, input().split())
        print(t[end - 1] - t[start - 1])
    
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

if len(ary) > 1 :
    ary.sort()
    sa = []
    for i in range(0, m - 1):
        sa.append(ary[i + 1] - ary[i])
        
    for i in range(0, n -1):
        sa.remove(max(sa))
        
    print(sum(sa))
else :
    print(0)

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

if n < m :
    ary.sort()
    sa = []
    
    for i in range(0, m - 1):
        sa.append(ary[i + 1] - ary[i])
    
    #print(sa)
    
    sa.sort()
    
    for i in range(0, n - 1):
        sa.pop(-1)
    
    print(sum(sa))
else :
    print(0)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

ary.sort()

ary2 = copy.copy(ary)
ary2.pop(0)
ary2.append(0)

sa = []

for i in range(0, m - 1):
    sa.append(ary2[i] - ary[i])

#print(sa)

for i in range(0, n -1):
    sa.remove(max(sa))

#print(sa)

print(sum(sa))

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

if n < m :
    ary.sort()
    sa = []
    
    for i in range(0, m - 1):
        sa.append(ary[i + 1] - ary[i])
    
    #print(sa)
    
    sa.sort()
    
    for i in range(0, n - 1):
        sa.pop(-1)
    
    print(sum(sa))
else :
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

n = int(input())

cnt = 0
pre = ['753', '735', '573', '537', '375', '357']

for i in range(n):

    l = [s for s in str(i+1)]
    
    #print(set(l))
    uni = ''.join(set(l))
    
    for p in pre:
        if uni == p : 
            cnt+=1
            #print(uni)
            break
            
print(cnt)

Fixed submission:
n = int(input())
cnt = 0

def out(s):
    
    i_s = int(s)
    if i_s <= n:
        #7, 5, 3が1以上出現する
        if all([True if str(i_s).count(s) > 0 else False for s in '753']):
            global cnt
            #print(i_s)
            cnt +=1 
            #7, 5, 3を引っ付ける
            
        [out(str(i_s) + s) for s in '753']

out('0')
print(cnt)
Buggy python submission (verdict: Runtime Error):

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

l = [0 for i in range(n)]

for i in range(m):
    p, y = map(int, input().split())
    l[ p - 1 ] += 1

def out(l, cnt):
    
    if any([True for i in l if i > 0]): 
        [print('{ken:06}{shi:06}'.format(ken=i+1, shi=l[i])) for i in range(len(l)) if l[i] > 0]
        return out([i - 1 for i in l], cnt+1)
    else:
        return

out(l, 1)



Fixed submission:
n, m = map(int, input().split())

l = []
ans = [0] * m

for i in range(m):
    l.append([int(j) for j in input().split()])
    l[i].append(i)

#[県, 市, 元の順番]
l2 = sorted(l, key=lambda x:(x[0],x[1]))
cnt = 1

for i in range(m):
    
    l2[i][1] = cnt
    
    if i < m -1 and l2[i][0] == l2[i + 1][0]:
        cnt += 1
    else:
        cnt = 1

    ans[l2[i][2]] = '{:06}{:06}'.format(l2[i][0],l2[i][1])

for s in ans:
    print(s)

Buggy python submission (verdict: Runtime Error):

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

l = [0 for i in range(n)]

for i in range(m):
    p, y = map(int, input().split())
    #print('p:{} y:{} i:{}'.format(p, y, i))
    l[ p - 1 ] += 1

shi = 1
def out(l, cnt):
    
    if any([True for i in l if i > 0]):
        global shi
        
        for i in range(len(l)):
            if l[i] > 0:
                print('{ken:06}{shi:06}'.format(ken=i+1, shi=shi)) 
                
        shi+=1
        return out([i - 1 for i in l], cnt+1)
    else:
        return

out(l, 1)



Fixed submission:
n, m = map(int, input().split())

l = []
ans = [0] * m

for i in range(m):
    l.append([int(j) for j in input().split()])
    l[i].append(i)

#[県, 市, 元の順番]
l2 = sorted(l, key=lambda x:(x[0],x[1]))
cnt = 1

for i in range(m):
    
    l2[i][1] = cnt
    
    if i < m -1 and l2[i][0] == l2[i + 1][0]:
        cnt += 1
    else:
        cnt = 1

    ans[l2[i][2]] = '{:06}{:06}'.format(l2[i][0],l2[i][1])

for s in ans:
    print(s)