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

Fixed submission:
import collections
import math
n,k = map(int, raw_input().split(' '))
ais = map(int, raw_input().split(' '))
r = 0
m = 42
x = 0
for ii in range(m, -1, -1):
	cc = collections.Counter([(ai >> ii) & 1 for ai in ais])
	if (x + (1 << ii) <= k):
		if cc[0] > cc[1]: x += (1 << ii)
		
	  
for ai in ais:
	r += ai ^ x
print r

Buggy submission (verdict: Runtime Error):
import collections
import math
n,k = map(int, raw_input().split(' '))
ais = map(int, raw_input().split(' '))
r = 0
m = 42
x = 0
for ii in range(m, -1, -1):
	cc = collections.Counter([(ai >> ii) & 1 for ai in ais])
	if (1 << ii) <= k:
		if cc[1] > cc[0]:
			x = x
		elif cc[1] == cc[0]:
			a,b = 0,0
			for ai in ais:
				if (ai >> ii) & 1 == 0:
					a += ai		
				else:
					b += ai
			if a <= b:
				x |= (1 << i)
		else:
			x |= (1 << ii)
	  
for ai in ais:
	r += ai ^ x
print r
Problem p03145 (python)

Fixed submission:
a,b,c = map(int, raw_input().split(' '))
print (a*b) >> 1

Buggy submission (verdict: Runtime Error):
"""
8
4 23 75 0 23 96 50 100
"""

n = int(raw_input())
ais = map(int, raw_input().split(' '))

def f(ais):
	r = [0]
	for i in range(len(ais)):
		## looking for max
		if len(r) % 2:	
			if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0): 
				r.append(ais[i])
		else:
		## looking for min
			if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else 1000): 
				r.append(ais[i])

	t = 0
	for i in range(0,len(r),2):
		if i + 1 < len(r):
			u,v = r[i],r[i+1]
			t += v-u
	
	return t if len(ais) > 1 else ais[0]
print f(ais)
Problem p03147 (python)

Fixed submission:
"""
8
4 23 75 0 23 96 50 100
"""

n = int(raw_input())
ais = map(int, raw_input().split(' '))

def f(ais):
	r = [0]
	for i in range(len(ais)):
		## looking for max
		if len(r) % 2:	
			if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0): 
				r.append(ais[i])
		else:
		## looking for min
			if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else 1000): 
				r.append(ais[i])

	t = 0
	for i in range(0,len(r),2):
		if i + 1 < len(r):
			u,v = r[i],r[i+1]
			t += v-u
	
	return t if len(ais) > 1 else ais[0]
print f(ais)

Buggy submission (verdict: Runtime Error):
"""
8
4 23 75 0 23 96 50 100
"""

[0,75,0,96,50,100]

n = int(raw_input())
ais = map(int, raw_input().split(' ')) #set()
i = 0
while(i < len(ais) and ais[i] == 0): i+=1
ais = ais[i:]

r = [0]
for i in range(len(ais)):
	if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0): 
		r.append(ais[i])
	if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else +float('inf')): 
		if i:
			r.append(ais[i])

	
t = 0
for i in range(0,len(r),2):
	if i + 1 < len(r):
		u,v = r[i],r[i+1]
		t += v-u
print t if len(ais) > 1 else ais[0]

Buggy submission (verdict: Runtime Error):
"""
8
4 23 75 0 23 96 50 100
"""

[0,75,0,96,50,100]

n = int(raw_input())
ais = map(int, raw_input().split(' ')) #set()
i = 0
while(i < len(ais) and ais[i] == 0): i+=1
ais = ais[i:]

r = [0]
for i in range(len(ais)):
	if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0): 
		r.append(ais[i])
	if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else 0): 
		if i:
			r.append(ais[i])

	
t = 0
for i in range(0,len(r),2):
	if i + 1 < len(r):
		u,v = r[i],r[i+1]
		t += v-u
print t if len(ais) > 1 else ais[0]

Buggy submission (verdict: Runtime Error):
"""
8
4 23 75 0 23 96 50 100
"""

[0,75,0,96,50,100]


n = int(raw_input())
ais = map(int, raw_input().split(' ')) #set()


r = [0]
for i in range(len(ais)):
	if (ais[i-1] if i-1 >= 0 else 0) <= ais[i] > (ais[i+1] if i+1 < len(ais) else 0): r.append(ais[i])
	if (ais[i-1] if i-1 >= 0 else 0) >= ais[i] < (ais[i+1] if i+1 < len(ais) else 0): r.append(ais[i])

	
t = 0

for i in range(0,len(r),2):
	u,v = r[i],r[i+1]
	t += v-u
print t
Problem p03211 (python)

Fixed submission:

s= raw_input()
m = +float('inf')
for i in range(len(s)):
	if len(s[i:i + 3]) == 3: 
		m = min(abs(int(s[i:i + 3]) - 753), m)
print m

Buggy submission (verdict: Runtime Error):
s= raw_input()
m = +float('inf')
for i in range(len(s)):
	if len(s[i:i+3]) == 3:
		m = min(abs(s[i:i+3] - 753), m)
	if len(s[i:i+4]) ==4:
		
		m = min(abs(s[i:i+4] - 753), m)
print m

Buggy submission (verdict: Runtime Error):
s= raw_input()
m = +float('inf')
for i in range(len(s)):
	if len(s[i:i+3]) == 3:
		m = min(abs(s[i:i+3] - 753), m)
	if len(s[i:i+4]) ==4:
		
		m = min(abs(s[i:i+4] - 753), m)
print m
Problem p03238 (python)

Fixed submission:
n = int(raw_input())
if n == 1: print 'Hello World'
elif n == 2: print int(raw_input())+int(raw_input())

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
a = int(raw_input())
b = int(raw_input())
if n == 1:
	print 'Hello World'
elif n == 2:
	print a + b

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
a = int(raw_input())
b = int(raw_input())
if n == 1:
	print 'Hello World'
elif n == 2:
	print a + b
Problem p03241 (python)

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

def f(n,m):
	if n == 1:
		return m
	divisors = []
	for d in range(2, int(m ** 0.5)+1)[::-1]:
		if m % d == 0:
			divisors.append(d)
			if d != m/d: divisors.append(m/d)
	divisors.sort(key = lambda x:-x)
	for d in divisors:
		if m/d >= n:
			return d

	return 1

print f(n,m)

Buggy submission (verdict: Runtime Error):
n,m = map(int,raw_input().split())

def f(n,m):

	for d in range(2, m)[::-1]:
		if m % d == 0:
			if m / d >= n:
				return d		
				break

	return 1

print f(n,m)
Problem p03246 (python)

Fixed submission:
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
cco = collections.Counter([ais[i] for i in range(len(ais)) if i % 2])
cce = collections.Counter([ais[i] for i in range(len(ais)) if i % 2 == 0])
cce = [(cce[k],k) for k in cce]
cce.sort(key = lambda x:-x[0])

t = n/2
if cce:
	m = t + t- cce[0][0]
else:
	m = 2*t
for colori in cco:
	for v,colorj in cce:
		if colorj != colori:
			m = min(m,t - cco[colori] + t - v)
			break

print m

Buggy submission (verdict: Runtime Error):

n = int(raw_input())
h = {}
un = set()
for i,b in enumerate(map(int,raw_input().split())):

	for a in un:
		if a != b:
			h[(a,b)] = (h[(b,a)] if (b,a) in h else 1) + 1
	un.add(b)

print n - max(h.values())
Problem p03261 (python)

Fixed submission:
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
	return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input()))]) else 'No'

Buggy submission (verdict: Runtime Error):
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
	return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input())]) else 'No'

Buggy submission (verdict: Runtime Error):
def f(words):
	seen = set([words[0]])
	p = words[0]
	for w in words[1:]:
		if w in seen or p[-1] != w[0]: return False
		p = w
		seen.add(w)
		return True

print 'Yes' if f([raw_input() for _ in range(int(raw_input())]) else 'No'

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
def f(words):
seen = set([words[0]])
p = words[0]
for w in words[1:]:
	if w in seen or p[-1] != w[0]: return False
	p = w
	seen.add(w)
	return True

print 'Yes' if f(raw_input().split()) else 'No'
Problem p03263 (python)

Fixed submission:
import collections
h,w = map(int, raw_input().split())
mat = [map(int, raw_input().split(' ')) for _ in range(h)]
elems = [(i,j) for i in range(len(mat)) for j in range(len(mat[0]))]
elems.sort(key = lambda x: x[0] + x[1])
q = collections.deque(elems)
moves = []
while(q):
	i,j = q.popleft()
	if mat[i][j] % 2:
		if j + 1 < len(mat[0]):
			mat[i][j] -= 1
			mat[i][j+1] += 1
			moves.append([(i+1,j+1), (i+1, j + 2)])
			#q.append((i,j + 1))
		elif i + 1 < len(mat):
			mat[i][j] -=1
			mat[i+1][j] += 1
			moves.append([(i+1,j+1), (i+2, j+1)])
			#q.append((i + 1,j ))
print len(moves)
for u,v in moves: print u[0],u[1],v[0],v[1]

Buggy submission (verdict: Runtime Error):
import collections
mat = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
elems = [(i,j) for i in range(len(mat)) for j in range(len(mat[0]))]
elems.sort(key = lambda x: x[0] + x[1])
q = collections.deque(elems)
moves = []
while(q):
	i,j = q.popleft()
	if mat[i][j] % 2:
		if j + 1 < len(mat[0]):
			mat[i][j] -= 1
			mat[i][j+1] += 1
			moves.append([(i+1,j+1), (i+1, j + 2)])
			#q.append((i,j + 1))
		elif i + 1 < len(mat):
			mat[i][j] -=1
			mat[i+1][j] += 1
			moves.append([(i+1,j+1), (i+2, j+1)])
			#q.append((i + 1,j ))
print len(moves)
for u,v in moves: print u[0],u[1], v[0], v[1]

Buggy submission (verdict: Runtime Error):
import collections
mat = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
q = collections.deque([(0,0)])
moves = []
while(q):
	i,j = q.popleft()
	if mat[i][j] % 2:
		if j + 1 < len(mat[0]):
			mat[i][j+1] += 1
			moves.append([(i,j), (i, j + 1)])
			q.append((i,j + 1))
		elif i + 1 < len(mat):
			mat[i+1][j] += 1
			moves.append([(i,j), (i+1, j)])
			q.append((i + 1,j ))
print len(moves)
for u,v in moves: print u[0],u[1], v[0], v[1]

Buggy submission (verdict: Runtime Error):
import collections
mat = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
q = collections.deque([(0,0)])
moves = []
while(q):
	i,j = q.popleft()
	if mat[i][j] % 2:
		if j + 1 < len(mat[0]):
			moves.append([(i,j), (i, j + 1)])
			q.append((i,j + 1))
		elif i + 1 < len(mat):
			moves.append([(i,j), (i+1, j)])
			q.append((i + 1,j ))
print len(moves)
for u,v in moves: print u[0],u[1], v[0], v[1]

Buggy submission (verdict: Runtime Error):
import collections
mat = [map(int, raw_input().split(' ')) for _ in range(int(raw_input()))]
q = collections.deque([(0,0)])
moves = []
while(q):
	i,j = q.popleft()
	if mat[i][j] % 2:
		if j + 1 < len(mat[0]):
			moves.append([(i,j), (i, j + 1)])
			q.append((i,j + 1))
		elif i + 1 < len(mat):
			moves.append([(i,j), (i+1, j)])
			q.append((i + 1,j ))
for u,v in moves: print u[0],u[1], v[0], v[1]
Problem p03281 (python)

Fixed submission:
import collections
n = int(raw_input())
count = 0
cc= collections.Counter()
for i in range(1,n + 1):
	j = i
	while(j <= n):
		cc[j] += 1
		j +=i
	if i % 2 and cc[i] == 8 :
		count +=1
print count

Buggy submission (verdict: Runtime Error):
import collections
n = int(raw_input())
count = 0
cc= collections.Counter()
for i in range(1,n + 1):
	while(j <= n):
		cc[j] += 1
		j +=i
	if i % 2 and cc[i] == 8 :
		count +=1
print count

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
count = 0
cc= collections.Counter()
for i in range(1,n + 1):
	while(j <= n):
		cc[j] += 1
		j +=i
	if i % 2 and cc[i] == 8 :
		count +=1
print count

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
count = 0
cc= collections.Counter()
for i in range(1,n + 1):
	while(j <= n):
		cc[j] += 1
		j +=i
	if i % 2 and cc[i] == 8 :
		count +=1
print count
Problem p03289 (python)

Fixed submission:
"""
1. The initial character of S is an uppercase A.
2. There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
3. All letters except the A and C mentioned above are lowercase.
"""
import collections
def a(r): return r[0] == 'A'
def b(r): return collections.Counter(r[2:-1])['C'] == 1
def c(r): return all([l in set(['A', 'C']) or l.lower() ==l for l in r ])
def f(r):  return a(r) and b(r) and c(r)

print 'AC' if f(raw_input()) else 'WA'

Buggy submission (verdict: Runtime Error):
import collections
print 'AC' if ( r[0] == 'A' and  collections.Counter(r[2:-1])['C'] == 1 and  all([l in set(['A', 'C']) or l.lower() ==l for l in r ])) else 'WA'
Problem p03399 (python)

Fixed submission:
ais = [int(raw_input()) for jj in range(4)]
print min(ais[:2]) + min(ais[2:])

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, raw_input().split())
print min(a,b) + min(c,d)
Problem p03434 (python)

Fixed submission:
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = lambda x:-x)
print sum(s[0:n:2]) - sum(s[1:n:2])

Buggy submission (verdict: Runtime Error):
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = x:-x)
print sum(s[0:n:2]) - sum(s[1:n:2])

Buggy submission (verdict: Runtime Error):
n,s = int(raw_input()),map(int,raw_input().split())
s.sort(key = x:-x)
print sum(s[1:n:2]) - sum(s[2:n:2])
Problem p03448 (python)

Fixed submission:
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, a, b , c):
  	if x < 0:
  		return 0
  	if x == 0:
  		return 1
  	
  	if i == 3:
  		return 1 if x == 0 else 0
  	r = 0
  	m = {0:a,1:b,2:c}
  	v = {0:500,1:100,2:50}

  	for k in range(0, m[i] + 1):
  		r += dfs(x - k * v[i], i+1, a,b,c)
  	return r

print dfs(x,0,a,b,c)

Buggy submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, a, b , c):
  	if x < 0:
  		return 0
  	if x == 0:
  		return 1
  	
  	if i == 3:
  		return 1 if x == 0 else 0
  	r = 0
  	m = {0:a,1:b,2:c}
  	v = {0:500,1:100,2:50}

  	for k in range(1, m[i] + 1):
  		r += dfs(x - k * v[i], i+1, a,b,c)
  	return r

print f(x,0,a,b,c)
Problem p03449 (python)

Fixed submission:
n,mat = raw_input(),[ map(int,raw_input().split()) for i in range(2)]
def f(mat,i,j):
	if i<0 or j <0:
		return -float('inf')
	if i == 0 and j == 0:
		return mat[i][j] 
	return mat[i][j] + max(f(mat,i-1,j),f(mat,i,j-1))
print f(mat,1,len(mat[0])-1)

Buggy submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, m, v):
  	if x < 0: return 0
  	if x == 0 or i == 3: 
  		return 1 if x == 0 else 0   	
  	r = 0
  	for k in range(0, m[i] + 1): r += dfs(x - k * v[i], i + 1, m, v)
  	return r
m,v = {0:a,1:b,2:c}, {0:500,1:100,2:50}
print dfs(x,0,m,v)

Buggy submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, m, v):
  	if x < 0: return 0
  	if x == 0: return 1
  	if i == 2: return 1 if x % 50 else 0  	
  	r = 0
  	for k in range(0, m[i] + 1): r += dfs(x - k * v[i], i + 1, m, v)
  	return r
m,v = {0:a,1:b,2:c}, {0:500,1:100,2:50}
print dfs(x,0,m,v)

Buggy submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, m, v):
  	if x < 0: return 0
  	if x == 0: return 1
  	if i == 2: return 1 if x % 50 else 0  	
  	r = 0
  	for k in range(0, m[i] + 1):
  		r += dfs(x - k * v[i], i+1, m,v)
  	return r
m,v = {0:a,1:b,2:c}, {0:500,1:100,2:50}
print dfs(x,0,m,v)

Buggy submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

def dfs(x, i, m, v):
  	if x < 0: return 0
  	if x == 0: return 1
  	if i == 2: return 1 if x % 50 else 0  	
  	r = 0
  	for k in range(0, m[i] + 1):
  		r += dfs(x - k * v[i], i+1, a,b,c)
  	return r
m,v = {0:a,1:b,2:c}, {0:500,1:100,2:50}
print dfs(x,0,m,v)

Buggy submission (verdict: Runtime Error):

n = raw_input()
mat =[ map(int,raw_input()) for i in range(2)]
def f(mat,i,j):
	if i<0 or j <0:
		return -float('inf')
	return mat[i][j] + max(f(mat,i-1,j),f(mat,i,j-1))
print f(mat,1,len(mat[0])-1)
Problem p03455 (python)

Fixed submission:
a,b = map(lambda x:int(x) % 2, raw_input().split()) 
print 'Odd' if (a == b == 1) else 'Even'

Buggy submission (verdict: Runtime Error):
a,b = int(raw_input()) % 2,int(raw_input()) % 2
print 'Odd' if a == b else 'Even'
Problem p03457 (python)

Fixed submission:
prev,pt = (0,0),0
b = True
def f(a,b): return abs(b[0]- a[0]) + abs(b[1] - a[1])
for _ in range(int(raw_input())):
	t,x,y  = map(int, raw_input().split())
	if (t - pt) < f((x,y), prev) :
		b = False
		break 

	if ((t - pt) - f((x,y), prev)) % 2:
		b = False
		break
	prev,pt = (x,y),t

print 'Yes' if b else 'No'

Buggy submission (verdict: Runtime Error):
prev = (0,0)
pt = t
b = True

def f(a,b): return abs(b[0]- a[0]) + abs(b[1] - a[1])
for _ in range(int(raw_input())):
	t,x,y  = map(int, raw_input().split())
	if (t - pt) < f((x,y), prev):
		b = False
		break 
	prev,pt = (x,y),t

print 'Yes' if b else 'No'
Problem p03471 (python)

Fixed submission:
n, y = map(int,raw_input().split())
y/=1000


def g(y,n):
	for a in range(y/10 + 1):
		b,c = f(y - a * 10, n - a)
		if b != -1:
			return [a,b,c]
	return [-1,-1,-1]
def f(y,n):
	if y < 0 or n < 0:
		return [-1,-1]
	if y == 0:
		if n == 0:

			return [0,0]
		return [-1,-1]

	for b in range(y/5 + 1):
		if y - b * 5 == n - b and n - b >= 0:
			return [b,n-b]
	return [-1,-1]

print ' '.join(map(str, g(y,n)))

Buggy submission (verdict: Runtime Error):
n, y = map(int,raw_input().split())
y/=1000

h = {0:10, 1:5, 2:1}

mem = {}
ans = [-1,-1,-1]
def dfs(i, n, y, h,res,ans ):
	if (i,n,y) in mem:
		return mem[(i,n,y)]

	if y < 0:

		mem[(i,n,y)] = False
		return False
	if y == 0:
		if n == 0:
			mem[(i,n,y)] = True
			
			if ans[0] == -1: 
				for i in range(len(res)):
					ans[i] = res[i]
			return True
		mem[(i,n,y)] = False
		return False
	if i == 2:
		if n == y:
			res[2]+= y
			mem[(i,n,y)] = True
			

			if ans[0] == -1: 
				for i in range(len(res)):
					ans[i] = res[i]

			return True
		return False
	res[0] +=1
	if dfs(i, n - 1, y - h[i], h,res, ans):
		mem[(i,n,y)] = True

		if ans[0] == -1: 
			for i in range(len(res)):
				ans[i] = res[i]
		return True
	res[0] -= 1

	if dfs(i+1, n ,y, h,res, ans):
		mem[(i,n,y)] = True
		
		if not(ans): 
			ans = [e for  e in res]#res[::]
		return True
	mem[(i,n,y)] = False
	return False

res = [0,0,0]
if dfs(0, n, y, h, res, ans):
	print ' '.join(map(str,ans))
else:
	print ' '.join(map(str,[-1,-1,-1]))

Buggy submission (verdict: Runtime Error):
n, y = map(int,raw_input().split())
y/=1000

h = {0:10, 1:5, 2:1}

mem = {}
def dfs(i, n, y, h,res ):
	if (i,n,y) in mem:
		return mem[(i,n,y)]

	if y < 0:

		mem[(i,n,y)] = False
		return False
	if y == 0:
		if n == 0:
			mem[(i,n,y)] = True
			return True
		mem[(i,n,y)] = False
		return False
	if i == 2:
		if n == y:
			res[2]+= y
			mem[(i,n,y)] = True
			return True
		return False
	res[0] +=1
	if dfs(i, n - 1, y - h[i], h,res):
		mem[(i,n,y)] = True
		return True
	res[0] -= 1

	if dfs(i+1, n ,y, h,res):
		mem[(i,n,y)] = True
		return True
	mem[(i,n,y)] = False
	return False

res = [0,0,0]
if dfs(0, n, y, h, res):
	print ' '.join(map(str,res))
else:
	print ' '.join(map(str,[-1,-1,-1]))

Buggy submission (verdict: Runtime Error):
n, y = map(int,raw_input().split())
y/=1000

h = {0:10, 1:5, 2:1}

def dfs(i, n, y, h,res ):
	if y < 0:
		return False
	if y == 0:
		if n == 0:
			return True

		return False
	if i == 2:
		if n == y:
			res[2]+= y
			return True
		return False
	res[0] +=1
	if dfs(i, n - 1, y - h[i], h,res):
		return True
	res[0] -= 1

	if dfs(i+1, n ,y, h,res):
		return True
	return False

res = [0,0,0]
if dfs(0, n, y, h, res):
	print y, res[0] * 10 + res[1]*5 + res[2]
	print res
else:
	print [-1,-1,-1]
Problem p03472 (python)

Fixed submission:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]

	if cumul >= h:
		r = min(r, (i+1))
		break
	else:
		r = min(r, i+1 + math.ceil(abs(h - cumul) /  float(m)))
print int(r)

Buggy submission (verdict: Runtime Error):
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
mem = {}
def dfs(i, ais, h):
	if i == len(ais) or h <= 0:
		return 0 if h <= 0 else +float('inf')
	if (i,h) not in mem:
		mem[(i,h)] = min(dfs(i+1, ais, h - ais[i][1]) + 1,
		dfs(i, ais, h - ais[i][0]) + 1,
		dfs(i+1, ais, h),)
	return mem[(i,h)]
print dfs(0 , ais, h)
Problem p03494 (python)

Fixed submission:
n = int(raw_input())
ais = map(int, raw_input().split())
c = 0
while(all([(ai % 2 ==0) for ai in ais ])):
	ais = [ai/2 for ai in ais]	
	c +=1
print c

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
ais = map(int, raw_input().split())
c = 0
while(True):
  	if all([ai%2==0 for ai in ais ]):
	  	ais = [ai/2 for ai in ais]	
        c +=1
	else:
      	break
print c
Problem p03496 (python)

Fixed submission:

def f(n,ais):
	ma,mi = max(ais), min(ais)
	res = []
	if ma + mi > 0:
		j = [j for j in range(len(ais)) if ais[j] == ma][0]
		for i in range(len(ais)):
			if ais[i] != ma:
				ais[i] += ais[j]
				res.append([j+1,i+1])

		for i in range(1,len(ais)):
			if ais[i-1] > ais[i]:
				ais[i] += ais[i-1]
				res.append([i-1+1, i+1])
	else:
		j = [j for j in range(len(ais)) if ais[j] == mi][0]
		for i in range(len(ais)):
			if ais[i] != mi:
				ais[i] += ais[j]
				res.append([j+1, i+1])
		for i in range(len(ais)-1, 0, -1):
			if not(ais[i - 1] <= ais[i ]):
				ais[i-1] += ais[i]
				res.append([i+1, i-1+1])
	print len(res)
	for u,v in res:
		print u,v
f(int(raw_input()),map(int, raw_input().split()))

Buggy submission (verdict: Runtime Error):

def f(n,ais):
	ma,mi = max(ais), min(ais)
	res = []
	if ma + mi > 0:
		j = [j for j in range(len(ais)) if ais[j] == ma][0]
		for i in range(len(ais)):
			if ais[i] != ma:
				ais[i] += ais[j]
				res.append([j+1,i+1])

				a >b
		for i in range(1,len(ais)):
			if ais[i-1] > ais[i]:
				ais[i] += ais[i-1]
				res.append([i-1+1, i+1])
	else:
		j = [j for j in range(len(ais)) if ais[j] == mi][0]
		for i in range(len(ais)):
			if ais[i] != mi:
				ais[i] += ais[j]
				res.append([j+1, i+1])
		for i in range(len(ais)-1, 0, -1):
			if not(ais[i - 1] <= ais[i ]):
				ais[i-1] += ais[i]
				res.append([i+1, i-1+1])
	print len(res)
	for u,v in res:
		print u,v
f(int(raw_input()),map(int, raw_input().split()))
Problem p03544 (python)

Fixed submission:
import collections
n,q = int(raw_input()) + 1, collections.deque()
while(n):
	q.append(sum(list(q)) if len(q) == 2 else (2  - len(q)))
	if len(q) == 3: 
		q.popleft()

	n -=1
print q[-1]

Buggy submission (verdict: Runtime Error):
import collections
n,q = int(raw_input()) +1, collections.deque()
while(n):
	q.append(sum(list(q)) if len(q) < 2 else (len(q) +1))
	if len(q) == 3: q.popleft()
    n -=1
print q[-1]
Problem p03563 (python)

Fixed submission:
a,av =  int(raw_input()), int(raw_input())
print 2*av - a

Buggy submission (verdict: Runtime Error):
a , av =  map(int, raw_input().split())
print 2*av - a
Problem p03564 (python)

Fixed submission:
def f(current, n,k):
	if n == 0:
		return current
	return min(f(2*current, n- 1,k), f(+k + current, n- 1, k)) 
print f(1,int(raw_input()), int(raw_input()))

Buggy submission (verdict: Runtime Error):
def f(current, n,k):
	if n == 0:
		return current
    return min(f(2*current, n- 1,k), f(+k + current, n- 1, k)) 
print f(1,int(raw_input()), int(raw_input()))
Problem p03607 (python)

Fixed submission:
import collections
cc = collections.Counter()
for _ in range(int(raw_input())):
	v = int(raw_input())
	cc[v] += 1
	if cc[v] == 2:
		cc[v] = 0
s = 0
for k in cc:
	if cc[k] == 1:
		s +=1
print s

Buggy submission (verdict: Runtime Error):

for _ in range(int(raw_input())):
	v = int(raw_input())
	cc[v] += 1
	if cc[v] == 2:
		cc[v] = 0
s = 0
for k in cc:
	if cc[k] == 1:
		s +=1
print s
Problem p03611 (python)

Fixed submission:
import collections
n,cc = raw_input(),collections.Counter(map(int, raw_input().split()))
print max([cc[k] + cc[k+1] + cc[k-1] for k in cc] or [0])

Buggy submission (verdict: Runtime Error):
import collections
n,cc = raw_input(),collections.Counter(map(int, raw_input().split()))
print max([cc[k] + cc[k+1] + cc[k-1] for k in cc] or [0)

Buggy submission (verdict: Runtime Error):
n,cc = raw_input(),collections.Counter(map(int, raw_input().split()))
print max([cc[k] + cc[k+1] + cc[k-1] for k in cc] or [0)