Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03032 (python)

Fixed submission:
def solve2():
    N, K = [int(_) for _ in raw_input().split()]
    V = [int(_) for _ in raw_input().split()]
    MAX_GET = min(N, K)
    ans = 0
    for i in range(MAX_GET + 1):
        for j in range(MAX_GET + 1 - i):
            get = V[:i] + V[(N - j):]
            if len(get) == 0:
                continue
            get.sort(reverse = True)
            for k in range(K - i - j):
                if len(get) > 0 and get[-1] < 0:
                    get.pop()
                else:
                    break
            ans = max(ans, sum(get))
    print ans

if __name__ == '__main__':
    solve2()

Buggy submission (verdict: Runtime Error):
from copy import deepcopy

def IntToMani(N, K):
    ret = []
    start = N
    while start / 4 > 0:
        ret.append(start % 4)
        start /= 4
    ret.append(start % 4)
    while len(ret) < K:
        ret.insert(0, 0)
    return ret

def addToKeep(_keep, _ele):
    low_ind = 0
    up_ind = len(_keep) - 1
    found = None
    while (up_ind - low_ind) > 1:
        mid = (up_ind + low_ind) / 2
        if _keep[mid] < _ele:
            low_ind = mid
        elif _keep[mid] > _ele:
            up_ind = mid
        elif _keep[mid] == _ele:
            found = mid
            break
    if found is not None:
        cnt = found
    else:
        cnt = up_ind
    _keep.insert(cnt, _ele)

def solve():
    N, K = [int(_) for _ in raw_input().split()]
    V = [int(_) for _ in raw_input().split()]
    MAX_CASE = 1<<(2*K)
    ans = 0
    for i in range(MAX_CASE):
        tmpV = deepcopy(V)
        mani = IntToMani(i,K)
        keep = []
        sum_keep = 0
        # tmp_ret = []
        for _man in mani:
            if _man == 0:
                if len(tmpV) == 0:
                    break
                else:
                    ele = tmpV.pop(0)
                    addToKeep(keep, ele)
                    sum_keep += ele
            elif _man == 1:
                if len(tmpV) == 0:
                    break
                else:
                    ele = tmpV.pop()
                    addToKeep(keep, ele)
                    sum_keep += ele
            else:
                if len(keep) == 0:
                    break
                else:
                    ele = keep.pop(0)
                    sum_keep -= ele
                    if _man == 2:
                        tmpV.insert(0, ele)
                    elif _man == 3:
                        tmpV.append(ele)
            # addToKeep(tmp_ret, sum_keep)
            ans = max(ans, sum_keep)
        # ans = max(ans, tmp_ret[-1])
    print ans

if __name__ == '__main__':
    solve()
Problem p03039 (python)

Fixed submission:
MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = (M*N* ((M*(N+1)*(N-1))%MAX + (N*(M+1)*(M-1)) % MAX)) % MAX
    disSum *= mod_inv(6, MAX) % MAX
    ret = disSum * combination(M*N-2, K-2) % MAX
    print ret

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from scipy.misc import comb

def man_comb(_N, _K):
    if _K > (_N/2):
        return comb(_N, _N - _K, exact=True)
    else:
        return comb(_N, _K, exact=True)

MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = M*N* (M*(N+1)*(N-1) + N*(M+1)*(M-1)) // 6
    ret = disSum * combination(M*N-2, K-2) % MAX
    print ret

def cum_sum(N):
    return N * (N+1) // 2

def solve2():
    N, M, K = [int(_) for _ in raw_input().split()]
    sumx = 0
    for xi in range(1, N+1):
        sumx = (sumx + cum_sum(N) - (N + 1 - xi) * xi)
    sumx = (sumx * M * M) // 2 %MAX
    sumy = 0
    for yi in range(1, M+1):
        sumy = (sumy + cum_sum(M) - (M + 1 - yi) * yi)
    sumy = (sumy * N * N) // 2 %MAX
    ret = (sumx + sumy) * combination(M*N-2, K-2) % MAX
    print ret

if __name__ == '__main__':
    solve2()

Buggy submission (verdict: Runtime Error):
def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up *= (_N - i)
        low *= (i + 1)
    ret = up /low
    if ret >= MAX:
        ret %= MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = M*N* (M*(N+1)*(N-1) + N*(M+1)*(M-1)) / 6
    if disSum >= MAX:
        disSum %= MAX
    ret = disSum * combination(M*N-2, K-2)
    if ret >= MAX:
        ret %= MAX
    print ret

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb

MAX = 10**9 + 7

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = M*N* (M*(N+1)*(N-1) + N*(M+1)*(M-1)) / 6
    if disSum >= MAX:
        disSum %= MAX
    ret = disSum * comb(M*N-2, K-2, exact=True)
    if ret >= MAX:
        ret %= MAX
    print ret

if __name__ == '__main__':
    solve()
Problem p03047 (python)

Fixed submission:
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    ret = N - K + 1
    print str(ret)

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
MAX = 10**9 + 7

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    xor_acu = [0] * (N + 1)
    for i in range(1, N + 1):
        xor_acu[i] = xor_acu[i - 1] ^ arr[i - 1]
    if xor_acu[N] != 0: # search for 0, X, 0, X ..., 0, X type
        X = xor_acu[N]
        dp0 = [1] * (N + 1)
        dpX = [0] * (N + 1)
        for i in range(1,N+1):
            dp0[i] = dp0[i-1] + dpX[i-1] if xor_acu[i] == 0 else dp0[i - 1]
            dpX[i] = dp0[i-1] + dpX[i-1] if xor_acu[i] == X else dpX[i - 1]
        ret = dp0[N - 1]
    else: # search for 0, X, 0, X ..., X, 0 type
        # X == 0 case
        tmp = 1
        Not0Set = set()
        for i in range(1, N):
            if xor_acu[i] == 0:
                tmp *= 2
            else:
                Not0Set.add(xor_acu[i])
        ret = tmp
        if ret > MAX:
            ret = ret % MAX
        # X != 0 case
        for X in list(Not0Set):
            RLE = [] # Run Length Encoding
            _tmp = xor_acu[0]
            cnt = 1
            all_cnt = 1
            for i in range (1, N+1):
                if xor_acu[i] == 0 or xor_acu[i] == X:
                    if xor_acu[i] == _tmp:
                        cnt += 1
                    else:
                        RLE.append((_tmp, cnt))
                        _tmp = xor_acu[i]
                        cnt = 1
                    all_cnt += 1
            RLE.append((_tmp, cnt))
            lRLE = all_cnt
            Not0dp0 = [1] * lRLE
            Not0dpX = [0] * lRLE
            ind = 1
            for i in range(len(RLE)):
                start = 1 if i == 0 else 0
                if RLE[i][0] == 0:
                    for j in range(start, RLE[i][1]):
                        Not0dp0[ind] = Not0dp0[ind - 1] + Not0dpX[ind - 1]
                        Not0dpX[ind] = Not0dpX[ind - 1]
                        ind += 1
                else:
                    for j in range(start, RLE[i][1]):
                        Not0dp0[ind] = Not0dp0[ind - 1]
                        Not0dpX[ind] = Not0dp0[ind - 1] + Not0dpX[ind - 1]
                        ind += 1
            ret += Not0dpX[ind - 2]
            if ret > MAX:
                ret = ret % MAX
    print str(ret)

if __name__ == '__main__':
    solve()
Problem p02618 (python)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
for i in range(D):
  T = S[i]
  T.sort()
  a = S[i].index(T[-1])
  print(a)

Buggy submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
A = [0 for i in range(26)]
ans = 0
for i in range(D):
  t = int(input())
  A[t-1] = i+1
  c = 0
  for j in range(26):
    c += C[j] * (i+1-A[j])
  ans += S[i][t-1]-c
  print(ans)
Problem p02641 (python)

Fixed submission:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    m = min(P[N-1]-X, X-P[0])
    for i in range(1,m+2):
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
        break
      elif X+i != P[b]:
        ans = X+i
        break
      else:
        a -= 1
        b += 1
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 0
    a = x
    b = x
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)
      
        
    
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 0
    a = x
    b = x
    while ans == 0:
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 0
    a = x
    b = x
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
  else:
    ans = X
print(ans)
Problem p02658 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

if ans == 0:
  print(0)
elif ans < 0:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = 1
b = 1
c = 1
p = 10**18
    
for i in range(N):
  elif A[i] == 0:
    c = 0
    break
  else:
    ans *= A[i]
    if p < ans:
      b = -1
      ans = 0
if c == 0:
  print(c)
elif b == -1:
  print(b)
else:
  print(ans)
Problem p03695 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(8)]
a = 0
for i in range(N):
  if A[i] < 400:
    B[0] = 1
  elif A[i] < 800:
    B[1] = 1
  elif A[i] < 1200:
    B[2] = 1
  elif A[i] < 1600:
    B[3] = 1
  elif A[i] < 2000:
    B[4] = 1
  elif A[i] < 2400:
    B[5] = 1
  elif A[i] < 2800:
    B[6] = 1
  elif A[i] < 3200:
    B[7] = 1
  else:
    a += 1
b = sum(B)
m = b
M = b + a
if b == 0:
  m = 1
print(m, M, sep=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
A = [0 for i in range(8)]
b = 0
ans1 = 0
for i in range(N):
  if a[i] < 400:
    if A[0] == 0:
      A[0] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 800:
    if A[1] == 0:
      A[1] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 1200:
    if A[2] == 0:
      A[2] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 1600:
    if A[3] == 0:
      A[3] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2000:
    if A[4] == 0:
      A[4] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2400:
    if A[5] == 0:
      A[5] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 2800:
    if A[6] == 0:
      A[6] = 1
      ans1 += 1
    else:
      continue
  elif a[i] < 3200:
    if A[7] == 0:
      A[7] = 1
      ans += 1
    else:
      continue
  else:
    b += 1
ans2 = ans1 + b
if ans1 < 1:
  ans1 = 1
  ans2 = b
if ans2 > 8:
  ans2 = 8
print(ans1, ans2, sep=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
A = [0 for i in range(8)]
b = 0
ans1 = 0
for i in range(N):
  if a[i] < 400:
    if A[0] == 0:
      A[0] = 1
      ans1 += 1
  elif a[i] < 800:
    if A[1] == 0:
      A[1] = 1
      ans1 += 1
  elif a[i] < 1200:
    if A[2] == 0:
      A[2] = 1
      ans1 += 1
  elif a[i] < 1600:
    if A[3] == 0:
      A[3] = 1
      ans1 += 1
  elif a[i] < 2000:
    if A[4] == 0:
      A[4] = 1
      ans1 += 1
  elif a[i] < 2400:
    if A[5] == 0:
      A[5] = 1
      ans1 += 1
  elif a[i] < 2800:
    if A[6] == 0:
      A[6] = 1
      ans1 += 1
  elif a[i] < 3200:
    if A[7] == 0:
      A[7] = 1
      ans += 1
  elif a[i] >= 3200:
    b += 1
ans2 = ans1 + b
if ans1 < 1:
  ans1 = 1
  ans2 = b
if ans2 > 8:
  ans2 = 8
print(ans1, ans2, sep=' ')
Problem p02684 (python)

Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(K):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
		continue
	
	
	a = K - y
	b = a % (k-y)
	for _ in range(b):
		i = A[i]
	
	p(x,y,k)
	p("M[1:]", M[1:])
	
	break

ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(1, K+1):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
	
	else:
		
		break

else:
	ans = i
	print(ans)
	exit(0)


p(x,y,k)
p("M[1:]", M[1:])

k = k - y

j = k % (k-y)

for a in range(j):
	x,y = M[i]
	M[i][0] = A[i]
	M[i][1] = k
	i = A[i]

print(i)

Buggy submission (verdict: Runtime Error):
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(1, K+1):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
	
	else:
		
		break

else:
	ans = i
	print(ans)
	exit(0)


p(x,y,k)
p("M[1:]", M[1:])

k = k - y

j = k % (k-y)

i = 
for a in range(j):
	x,y = M[i]
	M[i][0] = A[i]
	M[i][1] = k
	i = A[i]

print(i)
Problem p03006 (python)

Fixed submission:
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N = int(input())						# 5

if N==1:
	print(1)
	exit()

P=[]
for i in range(N):
	x, y = map(int, input().split())
	P.append((x,y))

#print(P)


from itertools import permutations
from itertools import combinations
L = list(combinations(P, 2))
#print( L )
#print( len(L) )

A=[]

for l in L:
	a=l[1][0]-l[0][0]
	b=l[1][1]-l[0][1]
	if a<0:
		a,b=-a,-b
	if a==0 and b<0:
		b=-b
	A.append((a,b))

#print(A)


# 各朝食メニューの回数を調べる
from collections import defaultdict

d = defaultdict(int)
for b in A:
	d[b] += 1

#print("dict(d)", dict(d))
# => {'pan': 2, 'kome': 4, 'cereal': 1}

# Value降順
B=[]
for k, v in sorted(d.items(), key=lambda x: -x[1]):
	#print(str(k) + ": " + str(v))
	break

#print("k,v", k,v)

print(N-v)

Buggy submission (verdict: Runtime Error):
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N = int(input())						# 5

P=[]
for i in range(N):
	x, y = map(int, input().split())
	P.append((x,y))

#print(P)


from itertools import permutations
from itertools import combinations
L = list(combinations(P, 2))
#print( L )
#print( len(L) )

A=[]

for l in L:
	a=l[1][0]-l[0][0]
	b=l[1][1]-l[0][1]
	A.append((a,b))

#print(A)


# 各朝食メニューの回数を調べる
from collections import defaultdict

d = defaultdict(int)
for b in A:
	d[b] += 1

#print(dict(d))
# => {'pan': 2, 'kome': 4, 'cereal': 1}

# Value降順
B=[]
for k, v in sorted(d.items(), key=lambda x: -x[1]):
	#print(str(k) + ": " + str(v))
	break

#print(k,v)

p=k[0]
q=k[1]

ans=0


def dellist(L, a, p,q):
	b = (a[0]-p, a[1]-q)
	c = (a[0]+p, a[1]+q)
	
	#print("__dellist, a,b,c", a,b,c)
	
	while b in L:
		L.remove(b)
		dellist(L, b, p,q)

	while c in L:
		L.remove(c)
		dellist(L, c, p,q)
	
	while a in L:
		L.remove(a)
	


while len(A)>0:
	a = A[0]
	ans+=1
	#print(ans, a, A)
	dellist(A, a, p, q)
	


print(ans)
Problem p03415 (python)

Fixed submission:
a = input()
b = input()
c = input()

print( a[0] + b[1] + c[2] )

Buggy submission (verdict: Runtime Error):
ant
obe
rec
Problem p03471 (python)

Fixed submission:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

N,Y=map(int, input().split())
p(N,Y)

NAmax=min(N,Y//10000)
NBmax=min(N,Y//5000)
NCmax=min(N,Y//1000)
p(NAmax, NBmax, NCmax)

NA=NAmax
for a in range(NA,-1,-1):
  NB=min(NBmax,N-a)

  for b in range(NB,-1,-1):
    c = N-a-b
    y = (a*10000)+(b*5000)+(c*1000)
    if y==Y:
      print(a,b,c,sep=" ")
      exit()
      
i=-1
print(i,i,i, sep=" ")

Buggy submission (verdict: Runtime Error):
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

N,Y=map(int, input().split())

p(N)
p(Y)

Amax=min(N,Y//10000)
Bmax=min(N,Y//5000)
Cmax=min(N,Y//1000)

p(Amax)
p(Bmax)
p(Cmax)

for a in range(Amax,-1,-1):
  B=min(Bmax,N-a)
  p("B="+str(B))
  for b in range(B,-1,-1):
    C=min(Cmax,N-a-b)
    p("a="+str(a)+", B="+str(B)+", C="+str(C))
    for c in range(C,-1,-1):
      n = a+b+c
      y = (a*10000)+(b*5000)+(c*1000)
      if n==N and y==Y:
        print(a,b,c,sep=" ")
        exit(1)

i=-1
print(i,i,i, sep=" ")

Buggy submission (verdict: Runtime Error):
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

N,Y=map(int, input().split())

p(N)
p(Y)

Amax=min(N,Y//10000)
Bmax=min(N,Y//5000)
Cmax=min(N,Y//1000)

p(Amax)
p(Bmax)
p(Cmax)

for a in range(Amax,-1,-1):
  B=min(Bmax,N-a)
  p("B="+str(B))
  for b in range(B,-1,-1):
    C=min(Cmax,N-a-b)
    p("a="+str(a)+", B="+str(B)+", C="+str(C))
    for c in range(C,-1,-1):
      n = a+b+c
      y = (a*10000)+(b*5000)+(c*1000)
      if n==N and y==Y:
        print(a,b,c,sep=" ")
        exit(1)

i=-1
print(i,i,i, sep="")

Buggy submission (verdict: Runtime Error):
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

N,Y=map(int, input().split())

p(N)
p(Y)

Amax=min(N,Y//10000)
Bmax=min(N,Y//5000)
Cmax=min(N,Y//1000)

p(Amax)
p(Bmax)
p(Cmax)

for a in range(Amax,-1,-1):
  B=min(Bmax,N-a)
  p("B="+str(B))
  for b in range(B,-1,-1):
    C=min(Cmax,N-a-b)
    p("a="+str(a)+", B="+str(B)+", C="+str(C))
    for c in range(C,-1,-1):
      n = a+b+c
      y = (a*10000)+(b*5000)+(c*1000)
      if n==N and y==Y:
        print(a,b,c,sep=" ")
        exit(1)

print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

N,Y=map(int, input().split())

p(N)
p(Y)

Amax=min(N,Y//10000)
Bmax=min(N,Y//5000)
Cmax=min(N,Y//1000)

p(Amax)
p(Bmax)
p(Cmax)

for a in range(Amax+1):
  B=min(Bmax,N-a)
  p("B="+str(B))
  for b in range(B+1):
    C=min(Cmax,N-a-b)
	#p("C="+str(C))
    for c in range(C+1):
      n = a+b+c
      y = (a*10000)+(b*5000)+(c*1000)
      if n==N and y==Y:
        print(a,b,c,sep=" ")
        exit(1)

print("-1 -1 -1")
Problem p03487 (python)

Fixed submission:
N = int(input())						# 5
a = list( map(int, input().split()) )


from collections import defaultdict
d = defaultdict(int)


for i in a:
	d[i] += 1

#print(d)

ans = 0
for i in d.keys():
	x = d[i]
#	print(i, x)
	if x == i: continue
	if x < i: ans += x
	if x > i: ans += (x - i)

#print(d)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())						# 5
b = list( map(int, input().split()) )
a = []

#print("N", N)
#print("b", b)

big = 0
#でかいのを除外する
for i in b:
	if i <= 10000:
		a.append(i)
	else:
		big += 1

if len(a) == 0:
	print(big)
	exit(0)

l=[0]*( max(a) +1)


for i in b:
	l[i] += 1

#print("l", l)

ans=big

for i in range( len(l) ):
	if l[i] == 0: continue
	if l[i] == i: continue
	
	x=1000000000 + 1
	y=1000000000 + 1
	if l[i] > i: x = l[i] - i
	if l[i] < i: y = l[i]
	
	ans += min(x, y)
	

print(ans)
Problem p03494 (python)

Fixed submission:
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

n = int(input())
a = [int(i) for i in input().split()]

ans=1000000000

for i in a:
  p(i)
  count=0
  while i%2==0:
    count+=1
    if count>ans:
      break
    i /= 2
    p("i="+str(i))
  
  ans = min(ans, count)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]

ans=1000000000

for i in a:
  'print(i)
  count=0
  while i%2==0:
    count+=1
  
  ans = min(ans, count)

print(ans)
Problem p03557 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

A.sort()
B.sort()
C.sort()

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	if b<N-1:
		bc[b] += bc[b+1]
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
#	ans += sum(bc[N-i:N])
	if i>0:
		ans += bc[N-i]

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

A.sort()
B.sort()
C.sort()

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	if b<N-1:
		bc[b] += bc[b+1]
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
#	ans += sum(bc[N-i:N])
	ans += bc[N-i]

print(ans)