Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
from collections import Counter
import itertools


n, x, y = map(int,input().split())
edges = [[] for _ in range(n)]

def dijkstra(s, edges):
    d = [float('inf')] * n
    d[s] = 0
    heap = [(0, s)]
    while heap:
        c, node = heappop(heap)
        for cost, v in edges[node]:
            if c + cost < d[v]:
                d[v] = c + cost
                heappush(heap, (d[v], v))
    return d

for i in range(n-1):
    u, v = i, i+1
    edges[u].append([1,v])
    edges[v].append([1,u])
edges[x-1].append([1, y-1])
edges[y-1].append([1, x-1])

ans = []

for s in range(n):
    ans.append(dijkstra(s, edges))

f_ans = []
for i in range(n):
    f_ans.append(ans[i][i+1:])
f_ans = list(itertools.chain.from_iterable(f_ans))
f_ans = Counter(f_ans)

for i in range(1, n):
    print(f_ans[i])

Fixed submission:
n, x, y = map(int,input().split())
ls = [0] * n
for u in range(1, n):
    for v in range(u, n+1):
        u2x = abs(u-x)
        v2y = abs(v-y)

        d = min(v-u, u2x + 1 + v2y)
        ls[d] += 1

for k in range(1, n):
    print(ls[k])

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
from collections import Counter
import itertools


n, x, y = map(int,input().split())
edges = [[] for _ in range(n)]

def dijkstra(s, edges):
    d = [float('inf')] * n
    d[s] = 0
    heap = [(0, s)]
    while heap:
        c, node = heappop(heap)
        for cost, v in edges[node]:
            if c + cost < d[v]:
                d[v] = c + cost
                heappush(heap, (d[v], v))
    return d

for i in range(n-1):
    u, v = i, i+1
    edges[u].append([1,v])
    edges[v].append([1,u])
edges[x-1].append([1, y-1])
edges[y-1].append([1, x-1])

ans = []

for s in range(n):
    ans.append(dijkstra(s, edges))

f_ans = []
for i in range(n):
    f_ans.append(ans[i][i+1:])
f_ans = Counter(list(itertools.chain.from_iterable(f_ans)))

for i in range(1, n):
    print(f_ans[i])

Fixed submission:
n, x, y = map(int,input().split())
ls = [0] * n
for u in range(1, n):
    for v in range(u, n+1):
        u2x = abs(u-x)
        v2y = abs(v-y)

        d = min(v-u, u2x + 1 + v2y)
        ls[d] += 1

for k in range(1, n):
    print(ls[k])
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
SC = {}
num = ["0"]*n
for _ in range(m):
    s, c = map(int,input().split())
    num[s-1] = str(c)
    if s in SC and SC[s] != c:
        print(-1)
        exit()
    if c == 0 and s == n:
        print(0)
        exit()
    SC[s] = c

if num[0] == "0"and num[1] == "0":
    print(-1)
    exit()

print("".join(num))


Fixed submission:
n, m = map(int,input().split())
SC = [list(map(int, input().split())) for _ in range(m)]

def check(num):
    num = str(num)
    if len(num) != n:
        return False

    for s, c in SC:
        if num[s-1] != str(c):
            return False
    return True


for i in range(1000):
    if check(i):
        print(i)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int,input().split())
mod = 10**9+7
total = pow(2, n, mod) - 1
def c(n, r):
    p, q = 1, 1
    for i in range(r):
        p *= (n-i)%mod
        q *= (i+1)%mod
    return p * pow(q, mod-2, mod)%mod

print((total - c(n, a) - c(n, b))%mod)

Fixed submission:
import math
def f_pow(x,n):
    if n == 0:
        return 1
    half = f_pow(x, n//2)
    if n % 2:
        return x * half * half % mod
    else:
        return half * half % mod

def c(n, r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * f_pow(q, mod-2)%mod

n,a,b = map(int,input().split())
mod = 10**9+7

s = f_pow(2, n) - 1
print((s - c(n,a) - c(n,b))%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
P = list(map(int,input().split()))

def E(x):
    ans = 0
    for i in range(1,x+1):
        ans += (1/x)*i
    return ans
ans = 0
for i in range(len(P)):
    P[i] = round(E(P[i]),2)

max_v = tmp = sum(P[:k])
l = 0
r = k
for i in range(1,len(P)-k+1):
    tmp = tmp-P[i-1]+P[r]
    max_v = max(max_v, tmp)
    r += 1
print(max_v)

Fixed submission:
n,k = map(int,input().split())
P = list(map(int,input().split()))



def E(x):
    # ans = 0
    tmp = (x*(x+1))/2 if x % 2 == 0 else x+(((x-1)*(x))/2)
    return tmp/x
ans = 0
for i in range(len(P)):
    P[i] = round(E(P[i]),1)
max_v = tmp = sum(P[:k])
l = 0
r = k
for i in range(1,len(P)-k+1):
    tmp = tmp-P[i-1]+P[r]
    max_v = max(max_v, tmp)
    r += 1
print(max_v)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
h,w=map(int,input().split())
meiro=[input() for _ in range(h)]
n=w*h
e=[[0]*n for _ in range(n)]
d=[(1,0),(0,1),(-1,0),(0,-1)]
for i in range(h):
  for j in range(w):
    if meiro[i][j]==".":
      for x,y in d:
        ni,nj=i+x,j+y
        if 0<=ni<h and 0<=nj<w and meiro[ni][nj]==".":
          e[w*i+j][w*ni+nj]=1

ans=floyd_warshall(e)
INF=float("inf")
print(int(max(max(a if a != INF else 0 for a in a) for a in ans)))

Fixed submission:
h,w = map(int,input().split())
meiro = [list(input()) for i in range(h)]
max_d = 0
from collections import deque

def bfs(sx,sy):
    que = deque([(sx,sy,0)])
    d = [[0]*w for i in range(h)]
    d[sx][sy] = 1
    max_len=0
    while que:
        x,y,tmp_len = que.popleft()
        for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
            tmp = tmp_len
            nx,ny = x+dx,y+dy
            if 0 <= nx < h and 0 <= ny < w and d[nx][ny] == 0 and meiro[nx][ny] =='.':
                d[nx][ny] = 1
                max_len = max(max_len, tmp+1)
                que.append((nx,ny,tmp+1))
    return max_len

for s_i in range(h):
    for s_j in range(w):
        if meiro[s_i][s_j] == "#":
            continue
        max_d = max(bfs(s_i,s_j), max_d)
print(max_d)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
meiro = [list(input()) for i in range(h)]
max_d = 0
from collections import deque



def bfs(sx,sy,t_i,t_j):
    que = deque([(sx,sy)])
    INF= float('inf')
    d = [[INF]*w for i in range(h)]
    d[sx][sy] = 0
    while que:
        x,y =que.popleft()
        for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
            nx,ny = x+dx,y+dy
            if 0 <= nx < h and 0 <= ny < w and d[nx][ny] == INF and meiro[nx][ny] =='.':
                d[nx][ny] = d[x][y] +1
                que.append((nx,ny))
    return d[t_i][t_j] if d[t_i][t_j] != float('inf') else 0

for s_i in range(h):
    for s_j in range(w):
        for t_i in range(h):
            for t_j in range(w):
                if not (s_i == t_i and s_j == t_j):
                    # visited = [[0 for i in range(w)] for i in range(h)]
                    max_d = max(bfs(s_i,s_j,t_i,t_j), max_d)
print(max_d)

Fixed submission:
h,w = map(int,input().split())
meiro = [list(input()) for i in range(h)]
max_d = 0
from collections import deque

def bfs(sx,sy):
    que = deque([(sx,sy,0)])
    d = [[0]*w for i in range(h)]
    d[sx][sy] = 1
    max_len=0
    while que:
        x,y,tmp_len = que.popleft()
        for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
            tmp = tmp_len
            nx,ny = x+dx,y+dy
            if 0 <= nx < h and 0 <= ny < w and d[nx][ny] == 0 and meiro[nx][ny] =='.':
                d[nx][ny] = 1
                max_len = max(max_len, tmp+1)
                que.append((nx,ny,tmp+1))
    return max_len

for s_i in range(h):
    for s_j in range(w):
        if meiro[s_i][s_j] == "#":
            continue
        max_d = max(bfs(s_i,s_j), max_d)
print(max_d)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
A = sorted(list(map(int, input().split())),reverse=True)

def cnt(x):
    c = 0
    for j in reversed(range(len(A))):
        i = 0
        while i <n and A[j]+A[i]>=x:
            c += 1
            i += 1
    return c

def happiness(x):
    c = 0
    for j in reversed(range(len(A))):
        i = 0
        while i <n and A[j]+A[i]>=x:
            c += A[j]+A[i]
            i += 1
    return c

def binary_search(l, r):
    mid = (l+r)//2
    c = cnt(mid)
    if c < m:
        return binary_search(l, mid)   
    else:
        if l == mid:
            return(l, c-m)
        return binary_search(mid, r)

x, dm = binary_search(0, A[0]*2+1)
print(happiness(x)-dm*x)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int,input().split())), reverse=True)

# jとの組み合わせがx以上になるiの個数
def combinations(x):
  s = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      i += 1
    s += i
  return s
 
#↑のような組み合わせの合計幸福度
def koufukudo(x):
  s = 0
  si = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      si += A[i]
      i += 1
    s += si + A[j]*i  
  return s
 
#
def bsearch(l, u):
  m = (l+u)//2
  c = combinations(m)
#   print(f"m{m}, c{c},c-M{c-M}")
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)
 
x, dm = bsearch(0, A[0]*2+1)
print(koufukudo(x)-dm*x)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
A = sorted(list(map(int, input().split())),reverse=True)

def cnt(x):
    c = 0
    for j in range(len(A)):
        i = 0
        while i <n and A[j]+A[i]>=x:
            c += 1
            i += 1
    return c

def happiness(x):
    c = 0
    for j in range(len(A)):
        i = 0
        while i <n and A[j]+A[i]>=x:
            c += A[j]+A[i]
            i += 1
    return c

def binary_search(l, r):
    mid = (l+r)//2
    c = cnt(mid)
    if c < m:
        return binary_search(l, mid)   
    else:
        if l == mid:
            return(l, c-m)
        return binary_search(mid, r)

x, dm = binary_search(0, A[0]*2+1)
print(happiness(x)-dm*x)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int,input().split())), reverse=True)

# jとの組み合わせがx以上になるiの個数
def combinations(x):
  s = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      i += 1
    s += i
  return s
 
#↑のような組み合わせの合計幸福度
def koufukudo(x):
  s = 0
  si = 0
  i = 0
  for j in reversed(range(N)):
    while i<N and A[i]+A[j]>=x:
      si += A[i]
      i += 1
    s += si + A[j]*i  
  return s
 
#
def bsearch(l, u):
  m = (l+u)//2
  c = combinations(m)
#   print(f"m{m}, c{c},c-M{c-M}")
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)
 
x, dm = bsearch(0, A[0]*2+1)
print(koufukudo(x)-dm*x)
Buggy python submission (verdict: Runtime Error):
n=int(input())
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[j][0]-xy[i][0]
		q = xy[j][1]-xy[i][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Fixed submission:
n=int(input())
if n==1:
	print(1)
	exit()
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[j][0]-xy[i][0]
		q = xy[j][1]-xy[i][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
xy = sorted([list(map(int,input().split())) for i in range(n)])
A = Counter([xy[i+1][0]-xy[i][0] for i in range(0,len(xy)-1)]).keys()
B = Counter([xy[i+1][1]-xy[i][1] for i in range(0,len(xy)-1)]).keys()
A = [i for i in range(-1*max(A),max(A)+1)] if max(A)>=0 else  [i for i in range(max(A),-1*max(A)+1)]
B = [i for i in range(-1*max(B),max(B)+1)] if max(B)>=0 else  [i for i in range(max(B),-1*max(B)+1)]
final_ans=10**9
for a in A:
	if a==0:
		continue
	for b in B:
		if b==0:
			continue
		ans=0
		tmp0,tmp1 = xy[0]
		for i in range(1,len(xy)):
			ans += 0 if tmp0 == xy[i][0]-a  and tmp1 == xy[i][1]-b else 1
			tmp0=xy[i][0]
			tmp1=xy[i][1]
		tmp = ans
		ans=0
		for i in range(len(xy)-1,-1,-1):
			ans += 0 if tmp0 == xy[i][0]-a and tmp1 == xy[i][1]-b else 1
			tmp0=xy[i][0]
			tmp1=xy[i][1]
		tmp_ans = min(ans,tmp)
		final_ans = min(final_ans,tmp_ans)

print(final_ans if final_ans!=0 else final_ans+1)



Fixed submission:
n=int(input())
if n==1:
	print(1)
	exit()
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[j][0]-xy[i][0]
		q = xy[j][1]-xy[i][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
xy = [list(map(int,input().split())) for i in range(n)]
a = Counter([xy[i+1][0]-xy[i][0] for i in range(0,len(xy)-1)]).most_common()[0][0]
b = Counter([xy[i+1][1]-xy[i][1] for i in range(0,len(xy)-1)]).most_common()[0][0]

ans=0
tmp0,tmp1 = xy[0]
for i in range(1,len(xy)):
	ans += 0 if tmp0 == xy[i][0]-a  and tmp1 == xy[i][1]-b else 1
	tmp0=xy[i][0]
	tmp1=xy[i][1]
tmp = ans
ans=0
for i in range(len(xy)-1,-1,-1):
	ans += 0 if tmp0 == xy[i][0]-a and tmp1 == xy[i][1]-b else 1
	tmp0=xy[i][0]
	tmp1=xy[i][1]

print(min(ans,tmp)+1)

Fixed submission:
n=int(input())
if n==1:
	print(1)
	exit()
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[j][0]-xy[i][0]
		q = xy[j][1]-xy[i][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ls=set(list(map(int,input().split()))[1:])
unique=ls.copy()
for i in range(n-1):
  A=list(map(int,input().split()))
  for j in ls:
    if j not in A[1:]:
      unique.remove(j)
print(len(unique))

Fixed submission:
n,m=map(int,input().split())
ls=[0]*m
for i in range(n):
  A=list(map(int,input().split()))[1:]
  for j in A:
    ls[j-1]+=1
print(sum(list(map(lambda x:x//n,ls))))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
X=sorted(list(map(int,input().split())))
init=[]
mario=n
tmp=0
i=1

if m<n:
  n=m

while i<len(X):
  init.append([X[i]-X[i-1],i])
  i+=1
init.sort(reverse=True,key=lambda x:x[0])
ans=0

for i in range(n-1):
  X.insert(init[i][1]+i,"あ")
i=0
start=0
while i<len(X):
  if i+1<len(X):
    if X[i+1]=="あ":
      ans+=X[i]-X[start]
      start=i+2
      i+=1
  else:
    ans+=X[i]-X[start]
  i+=1
print(ans)


Fixed submission:
n,m=map(int,input().split())
X=sorted(list(map(int,input().split())))
init=[]
tmp=0
i=1

if m<n:
  n=m

while i<len(X):
  init.append([X[i]-X[i-1],i])
  i+=1
init.sort(reverse=True,key=lambda x:x[0])
init=list(map(lambda x:x[1],init))
ans=0
init=sorted(init[:n-1])
if len(init)==0:
  print(X[-1]-X[0])
  exit()
tmp=0
for i in init:
  ans+=(X[i-1]-X[tmp])
  tmp=i
try:
  if i!=len(X)-1:
    ans+=X[-1]-X[i]
except IndexError:
  print(0)
  exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
string="keyence"
flag1=0
flag2=0
flag3=0
v=0

for i in range(len(s)):
  if s[i]==string[v]:
    v+=1
    if flag1==1:
      flag2=1
  else:
    flag1=1
    if flag1==1 and flag2==1:
      print("NO")
      exit()

if flag1==0 and flag2==0:
  print('YES')
elif flag2==0:
  print('NO')
else:
  print('YES')


Fixed submission:
s = input()
n = len(s)

for i in range(n):
    for j in range(i, n):
        tmp = s[:i]+s[j:]
        if tmp == "keyence":
            print("YES")
            quit()

print("NO")
Buggy python submission (verdict: Runtime Error):
s=list(input())
count=0

indexes = [i for i, x in enumerate(s) if x == "B"]
if len(s)%2==1:
  ideal=[i for i in range(len(s)//2+1,len(s))]
else:
  ideal=[i for i in range(len(s)//2,len(s))]

for i in range(len(s)//2):
  count+= ideal[i]-indexes[i]
print(count)

Fixed submission:
s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
s=list(input())
count=0
while True:
  flag=1
  i=bisect_left(s,"B")
  while i+1 <len(s):
    if s[i]=="B" and s[i+1]=="W":
      s[i]="W"
      s[i+1]="B"
      count+=1
      i+=1
      flag=0
    else:
      i+=1
      continue
  if flag==1:
    print(count)
    exit()

Fixed submission:
s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
count=0
i=0
while True:
  flag=1
  for i in range(len(s)):
    if i+1<len(s):
      if s[i]=="B" and s[i+1]=="W":
        s[i]="W"
        s[i+1]="B"
        count+=1
        i+=1
        flag=0
  if flag==1:
    break

print(count)

Fixed submission:
s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
X=[0,1,2,3,3]
a=0
print
if n==1:
  print(0)
if n >1:
  if x %2 ==0:
    tmp=int(x/2**(n-1))
    if tmp>=len(X):
      print((X[tmp-1]+1)*(2**(n-1))-1)
    else:
      print(X[tmp]*(2**(n-1))-1)
  else:
    tmp=int(x/2**(n-1))
    print(X[tmp]*(2**(n-1))+1)

Fixed submission:
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)

def f(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<= 1 + a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])


print(f(n,x))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import Counter
import itertools

def prime_factors(n):
  i = 2
  factors = []
  while i * i <= n:
    if n % i==0:
      n //= i
      factors.append(i)
    else:
      i += 1
  if n > 1:
    factors.append(n)
  return factors

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return sorted(divisors)

n=int(input())
num=math.factorial(n)
yakusu=make_divisors(num)

cnt=0
for i in yakusu:
  factors=list(map(lambda x:x+1,Counter(prime_factors(i)).values()))
  tmp=1
  for j in factors:
    tmp*=j
  if tmp==75:
    cnt+=1
print(cnt)


Fixed submission:
n=int(input())
e=[0]*(n+1)

#素因数分解をしている
for i in range(2,n+1):
  cur=i
  for j in range(2,i+1):
    while cur % j == 0:
      e[j] += 1
      cur //=j

def num(m):
  return len(list(filter(lambda x: x>=m-1,e)))

print(num(75)+ num(25)*(num(3)-1)+ num(15)*(num(5)-1)+ num(5)*(num(5)-1)*(num(3)-2)//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
temp = list(map(int,input().split()))
tmp = 10**9
index= 1

for i in temp:
  if abs(a- (t - tmp)) > abs(a- (t - i * 0.006)):
    tmp = t - i * 0.006
    index = temp.index(i)+1


print(index)

Fixed submission:
x,y = map(int,input().split())
print(x+int(y/2))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
years = [[]for i in range(n)]
yearss = []

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


for i in range(n):
  years[i].sort()

for i in range(m):
  print("{0:06d}".format(yearss[i][0]),"{0:06d}".format(int(years[yearss[i][0]-1].index(yearss[i][1]))+1),sep="")


Fixed submission:
import bisect

n,m = map(int,input().split())
years = [[]for i in range(n)]
yearss = []

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


for i in range(n):
  years[i].sort()

for i in range(m):
  print("{0:06d}".format(yearss[i][0]),"{0:06d}".format(bisect.bisect_right(years[yearss[i][0]-1],yearss[i][1])),sep="")
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
if len(set(V))==1:
  print(n//2)
else:
  v1=Counter(V[::2])
  v2=Counter(V[1::2])
  ans=0
  if v1.most_common()[0][0]==v2.most_common()[0][0]:
    if v1.most_common()[0][1]>v2.most_common()[0][1]:
      v1_s=v1.most_common()[0][1]
      v2_s=v2.most_common()[1][1]
    else:
      v1_s=v1.most_common()[1][1]
      v2_s=v2.most_common()[0][1]
  if len(v1)!=1:
    ans+=len(list(v1.elements()))-v1_s
  if len(v2)!=1:
    ans+=len(list(v2.elements()))-v2_s
  print(ans)

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
if len(a) ==1:
  a.append([0,0])
if len(b) == 1:
  b.append([0,0])
if a[0][0] == b[0][0]:
  if a[1][1]>b[1][1]:
    print(n-a[1][1] - b[0][1])
  else:
    print(n-a[0][1]-b[1][1])
else:
  print(n-a[0][1]-b[0][1])
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
if s[0]=="1":
  print(s[1])
else:
  print(s[0])

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

for i in range(k):
  if s[i]!="1":
    break
print(s[i])

Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
if s[0]=="1":
  try:
    if s[k-1]=="1":
      print('1')
    else:
      print(s[s.rfind("1")+1])
  except IndexError:
    print(s[s.rfind("1")+1])
else:
  print(s[0])


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

for i in range(k):
  if s[i]!="1":
    break
print(s[i])

Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
if s[0]=="1":
  print(s[1])
else:
  print(s[0])


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

for i in range(k):
  if s[i]!="1":
    break
print(s[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n ==0:
  print(0)
s=''
while n !=0:
  if n%2==1:
    s="1"+
    n-=1
  else:
    s='0'+s
  n-=n//2
print(s)


Fixed submission:
n = int(input())
if n ==0:
  print(0)
s=''
while n !=0:
  if n%2==1:
    s="1"+s
    n-=1
  else:
    s='0'+s
  n=-n//2
print(s)
Buggy python submission (verdict: Runtime Error):
d,g = map(int,input().split())
ps=[]
cs=[]
counts = []
count = 0
visited = [0 for i in range(d)]
sums=0


for i in range(d):
  p,c = map(int,input().split())
  ps.append(p)
  cs.append(c)

def dfs(i,count,visited,sums):
  if visited[i] != ps[i]:
    local_visited=visited[:]
    count += 1
    sums += (i+1)*100
    local_visited[i] += 1
    if local_visited[i] == ps[i]:
      sums += cs[i]
    if sums >= g:
      counts.append(count)
      return
    for i in range(d):
      dfs(i,count,local_visited,sums)


for i in range(d):
  dfs(i,count,visited,sums)


print(min(counts))



Fixed submission:
import itertools
from collections import Counter
D, G = map(int, input().split())
P = [list(map(int, input().split())) for i in range(D)]
min_num = 10**8

judge_list = list(itertools.product([0, 1, 2], repeat=D)) #0:中途半端に解く 1:一問も解かない 2: 全部解く


for judge in judge_list:
    score = 0
    num = 0
    d = Counter() #インスタンスを生成
    d.update(judge)
    if (d[0] <= 1):
        for i in range(1, len(judge) + 1):
            if score >= G:
                break

            if judge[-i] == 1:
                pass

            if judge[-i] == 2:
                score += P[-i][0] * (D - i + 1) * 100 + P[-i][1]
                num += P[-i][0]

            if (judge[-i] == 0):
                for j in range(P[-i][0]):
                    if score >= G:
                        break
                    score += 100 * (D - i + 1)
                    num += 1

        if score >= G:
            min_num = min(num, min_num)

print(min_num)