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

Fixed submission:
import collections 
s = input()

n = len(s)
m = [0]
mod = 0
ten = 1
for i in s[::-1]:
  mod += (int(i)*ten)%2019
  mod %= 2019
  m.append(mod)
  ten *= 10
  ten %= 2019

count = collections.Counter(m)
print(sum([c*(c-1)//2 for c in count.values()]))

Buggy submission (verdict: Runtime Error):
s = input()[::-1]

counts = [0]*2019 # 剰余の余りの回数を保存
counts[0] = 1 # 0%2019を累積和として含めることを想定

num, d = 0,1　# numは余りの累積和、dはcharの桁数
'''
charに一桁ずつ取り出す。そのmod2019を考え、累積和をとる。
しかし、それぞれの数字には10の累乗がかかっているので、それについては別途dを用意してmod2019をとる
つまり、numは1桁目のmod2019、2桁目のmod2019に1桁目のmod2019を加える
'''
for char in s:
  num += int(char) * d
  num %= 2019
  d *= 10
  d %= 2019
  counts[num] += 1

ans = 0
for c in counts:
  ans += c*(c-1)//2
  
print(ans)
Problem p02747 (python)

Fixed submission:
s = input()

n = s.count("hi")
print("Yes" if n*2 == len(s) else "No")

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

n = s.count("hi")
print("Yes" if n*2 == len(n) else "No")
Problem p02761 (python)

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

t = [-1]*n
for _ in range(m):
  s,c = map(int, input().split())
  s -= 1
  if t[s] != -1 and t[s] != c:
    print(-1)
    exit()
  t[s] = c
  
if n != 1:
  if t[0] == 0:
    print(-1)
    exit()
    
  if t[0] == -1:
    t[0] = 1
    
  for i in range(1, n):
    if t[i] == -1:
      t[i] = 0
else:
  if t[0] == -1:
    t[0] = 0
    
print(''.join(map(str, t)))

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

p = [0]*n
q = [False]*n
for i in range(m):
  s,c = map(int, input().split())
  if s == 1 and c == 0 and n != 1:
    #continue
  if s > n:
    print(-1)
    sys.exit()
    
  if q[s-1] == False:
    p[s-1] = c
    q[s-1] = True
  elif p[s-1] > c:
    p[s-1] = c

t = ''
for i in p:
  t += str(i)
  
t = int(t)
if len(str(t)) == n:
  print(t)
else:
  print(-1)
Problem p02791 (python)

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

result = 0
m = P[0]
for i in range(N):
    if P[i] <= m:
        result += 1
        m = P[i]
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(n):
  if i == 0:
    count+=1
  elif p[i - 1] => p[i]:
    count+=1
print(count)
Problem p02844 (python)

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

# 3桁の番号を作るにあたり、文字列から抽出して作るのではなく、000〜999までの組み合わせが存在するかを確認する。
ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1) # aの取得位置の次から検索を行う
    for k in range(10):
      c = s.find(str(k), b+1) # bの取得位置の次から検索を行う
      if a == -1 or b == -1 or c == -1: continue
      else: ans += 1
print(ans)

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

# 3桁の番号を作るにあたり、文字列から抽出して作るのではなく、000〜999までの組み合わせが存在するかを確認する。
ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1) # aの取得位置の次から検索を行う
    for k in range(10):
      c = s.find(str(k), b+1)　# bの取得位置の次から検索を行う
      if a == -1 or b == -1 or c == -1: continue
      else: ans += 1
print(ans)
Problem p02861 (python)

Fixed submission:
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
  x1,y1 = map(int, input().split())
  x[i] = x1
  y[i] = y1

a = 0
b = 0
for i in range(n):
  t = list(range(n))
  t.remove(i)
  for j in t:
    a += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
    b += 1
    
print(a*(n-1)/b)

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
  for j in range(n):
    if i == j: continue
    ans += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
    t += 1
print(ans/n)
Problem p02924 (python)

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())

nums = list(range(1,n+1))
print(sum(nums)-n)

Buggy submission (verdict: Runtime Error):
n = int(input())

nums = list(range(1,n+1))
print(sum(nums[:-1]))
Problem p02999 (python)

Fixed submission:
x,a = map(int, input().split())

if a <= x: print(10)
else: print(0)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

s = 0
d = 0
for i in range(n):
  d += l[i]
  s += 1
  if d >= x:
    break
print(s)
Problem p03000 (python)

Fixed submission:
n,x = map(int, input().split())
l = list(map(int, input().split()))

s = 1
d = 0
for i in l:
  d += i
  if d <= x:
    s += 1
print(s)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

ans = 1
t = 0
for i in range(x):
  t += l[i]
  if t <= x:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

ans = 1
t = 0
for i in range(x):
  t += l[i]
  if t <= x:
    ans += 1
  else:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

s = 0
d = 0
for i in range(n):
  d += l[i]
  s += 1
  if t > x:
    break
print(s)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

s = 0
t = 0
for i in range(n+1):
  t += l[i]
  s += 1
  if t >= x:
    break
print(s)

Buggy submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

s = 0
t = 0
for i in range(n+1):
  t += l[i]
  s += 1
  if t > x:
    break
print(s)
Problem p03001 (python)

Fixed submission:
w,h,x,y = map(int, input().split())

t = w * h / 2

if x == w/2 and y == h/2:
  print(t, 1)
else:
  print(t, 0)

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int, input().split())

if w%x == 0 and h%y == 0:
  print(w*h/2, 1)
else:
  print(w*h/2, 0)
Problem p03574 (python)

Fixed submission:
h,w = map(int, input().split())
s = [list(input()) for _ in range(h)]

ans = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      ans[i][j] = "#"
      for i2 in range(i-1, i+2):
        if i2 < 0 or h-1 < i2: continue
        for j2 in range(j-1, j+2):
          if (j2 < 0 or w-1 < j2): continue
          elif ans[i2][j2] == "#": continue
          ans[i2][j2] += 1
for i in ans:
  print("".join(map(str,i)))

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
s = [list(input()) for _ in range(h)]

ans = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "#": ans[i][j] = "#"
      for i2 in range(i-1, i+2):
        if i2 < 0 or h-1 < i2: continue
        for j2 in range(j-1, j+2):
          if (j2 < 0 or w-1 < j2): continue
          elif ans[i2][j2] == "#": continue
          ans[i2][j2] += 1
for i in ans:
  print("".join(map(str,i)))
Problem p03611 (python)

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

nums = [0]*(max(a)+1)
for i in a: nums[i] += 1

if len(nums) <= 2:
  print(sum(nums))
  exit()
  
ans = 0
for i in range(1,max(a)):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

nums = [0]*(max(a)+1)
for i in a: nums[i] += 1

if n == 1:
  print(1)
  exit()
elif n == 2:
  if abs(a[0]-a[1]) <= 2: print(2)
  else: print(1)
  exit()
    
ans = 0
for i in range(1,n-1):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)
Problem p03625 (python)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

count = Counter(a)
t = 4
s = []
for i in sorted(count.items(), key=lambda x: x[0], reverse=True):
  if i[1] >= 4 and t == 4:
    print(i[0]**2)
    exit()
  if i[1] >= 2 and t != 0:
    t -= 2
    s.append(i[0])
  elif t == 0: break
    
if len(s) != 0: print(s[0]*s[1])
else: print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

count = Counter(a)
ans = [0]*2
t = 0
for i in sorted(count.items(), reverse=True):
  if i[1] >= 4:
    if t == 0:
      ans[0],ans[1] = i[0],i[0]
      t = 2
    elif t == 1:
      ans[t] = i[0]
      t += 1
  if i[1] >= 2:
    ans[t] = i[0]
    t += 1
  if t == 2: break
print(ans[0]*ans[1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

count = Counter(a)
t = 4
s = []
for i in sorted(count.items(), key=lambda x: x[0], reverse=True):
  if i[1] >= 4 and t == 4:
    print(i**2)
    exit()
  if i[1] >= 2 and t != 0:
    t -= 2
    s.append(i[0])
  elif t == 0: break
    
if len(s) != 0: print(s[0]*s[1])
else: print(0)
Problem p03695 (python)

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

flag = [False]*8
t = 0
for i in a:
  if i < 400: flag[0] = True
  elif i < 800: flag[1] = True
  elif i < 1200: flag[2] = True
  elif i < 1600: flag[3] = True
  elif i < 2000: flag[4] = True
  elif i < 2400: flag[5] = True
  elif i < 2800: flag[6] = True
  elif i < 3200: flag[7] = True
  elif 3200 <= i: t += 1
    
minNum = 0
p = flag.count(True)
if p > 0: minNum = p
elif p == 0 and t > 0:
  minNum = 1
  
maxNum = p + t

print(minNum,maxNum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

flag = [False]*8
t = 0
for i in a:
  if i < 400: flag[0] = True
  elif i < 800: flag[1] = True
  elif i < 1200: flag[2] = True
  elif i < 1600: flag[3] = True
  elif i < 2000: flag[4] = True
  elif i < 2400: flag[5] = True
  elif i < 2800: flag[6] = True
  elif i < 3200: flag[7] = True
  elif 3200 <= i: t += 1
    
minNum = 0
p = flag.count(True)
if p > 0: minNum = p
elif p == 0 and t > 0:
  minNum = 1
  
maxNum = 0
if minNum < 8:
  maxNum = min(8, minNum + t)
else: maxNum = minNUm

print(minNum,maxNum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

flag = [False]*8
t = 0
for i in a:
  if i < 400: flag[0] = True
  elif i < 800: flag[1] = True
  elif i < 1200: flag[2] = True
  elif i < 1600: flag[3] = True
  elif i < 2000: flag[4] = True
  elif i < 2400: flag[5] = True
  elif i < 2800: flag[6] = True
  elif i < 3200: flag[7] = True
  elif 3200 <= i: t += 1
    
minNum = 0
p = flag.count(True)
if p > 0: minNum = p
elif p == 0 and t > 0:
  minNum = 1
  t -= 1
  
maxNum = 0
if minNum < 8:
  maxNum = min(8, minNum + t)
else: maxNum = minNUm

print(minNum,maxNum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

flag = [False]*8
t = 0
for i in a:
  if i < 400: flag[0] = True
  elif i < 800: flag[1] = True
  elif i < 1200: flag[2] = True
  elif i < 1600: flag[3] = True
  elif i < 2000: flag[4] = True
  elif i < 2400: flag[5] = True
  elif i < 2800: flag[6] = True
  elif i < 3200: flag[7] = True
  elif 3200 <= i: t += 1
    
minNum = flag.count(True)
maxNum = 0
if minNum < 8:
  maxNum = min(8, minNum + t)
else: maxNum = minNUm

print(minNum,maxNum)
Problem p03699 (python)

Fixed submission:
n = int(input())
s = [int(input()) for _ in range(n)]

sumNum = sum(s)
if sumNum % 10 != 0:
  print(sumNum)
  exit()

t = 0
for i in s:
  if (sumNum - i)%10 != 0:
    t = max(t, sumNum-i)
print(t)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [int(input()) for _ in range(n)]

sumNum = sum(s)
if sumNum % 10 != 0:
  print(sumNum)
  exit()

t = 0
for i in s:
  if (sumNum - i)%10 != 0:
    t = max(t, sum-i)
print(t)
Problem p03846 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))

if n%2 == 0: # 人数が偶数の場合に不整合があるか確認
  for i in range(0,n,2):
    if a[i] != i+1 or a[i+1] != i+1:
      print(0)
      exit()
else: # 人数が奇数の場合に不整合があるか確認
  if a[0] != 0: # 差分が0存在していることを確認
    print(0)
    exit()
  else:
    for i in range(1,n,2):
      if a[i] != i + 1 or a[i+1] != i + 1:
        print(0)
        exit()
        
ans = 1        
for i in range(n//2):
  ans = ans*2%(10**9+7)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))

if n%2 == 0:
  for i in range(0,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()
else:
  if a[0] != 0 or a[1] == 0:
    print(0)
    exit()
  for i in range(1,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()

mod = 10**9+7
if n%2 == 0: print(2**(n//2)%mod)
else: print(2**((n-1)//2)%mod)
Problem p02536 (python)

Fixed submission:

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

def g(u,parent):
    if parent[u]!= u:
        parent[u] = g(parent[u], parent)
    return parent[u]
parent = {u:u for u in range(1, n+1)}
for _ in range(m):
    u,v = map(int, raw_input().split())
    pu,pv = g(u,parent), g(v,parent)
    if pu!= pv:
        parent[pu] = pv

ans = 0
for u in parent:
    if g(u,parent) == u:
        ans+=1
print ans -1

Buggy submission (verdict: Runtime Error):

n,m = map(int, raw_input())

def g(u,parent):
    if parent[u]!= u:
        parent[u] = g(parent[u], parent)
    return parent[u]
parent = {u:u for u in range(1, n+1)}
for _ in range(m):
    u,v = map(int, raw_input().split())
    pu,pv = g(u,parent), g(v,parent)
    if pu!= pv:
        parent[pu] = pv

ans = 0
for u in parent:
    if g(u,parent) == u:
        ans+=1
print ans -1
Problem p02582 (python)

Fixed submission:
s = raw_input()
count = 0
a = 0
for j in range(len(s)):
	if s[j] == 'R':
		count +=1
	else:
		count = 0
	a = max(count, a)
print a

Buggy submission (verdict: Runtime Error):

s = raw_input()
count = 0
a = 0
for j in range(len(s))
	if s[j] == 'R':
		count +=1
	else:
		count = 0
	a = max(count, a)
print
Problem p02584 (python)

Fixed submission:
x,k,d = map(int, raw_input().split())
def f(x,k,d):
	if k == 0:
		return abs(x)

	if abs(x) <= d:
		if k % 2 == 0:
			if k <= 2:
				return abs(x)
			else:
				return min(abs(x),abs(x-2*d), abs(x+2*d) )#f(x+d,k-1,d), f(x-d,k-1,d))	
		else:
			return min(abs(x+d), abs(x-d))
	else:
		if x > d:
			if x/d <= k:
				return f(x - (x/d) * d, k - x/d, d)
			elif x / d > k:
				#get as close to zero as u can
				return f(x - k*d, 0, d)
		elif x < -d:
			return f(-x, k, d)

print f(x,k,d)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, raw_input().split())
def f(x,k,d):
	if k == 0:
		return abs(x)

	if abs(x) <= d:
		if k % 2 == 0:
			if k == 0:
				return x
			else:
				return min(f(x+d,k-1,d), f(x-d,k-1,d))	
		else:
			return min(abs(x+d), abs(x-d))
	else:
		if x > d:
			if x/d <= k:
				return f(x - (x/d) * d, k - x/d, d)
			elif x / d > k:
				#get as close to zero as u can
				return f(x - k*d, 0, d)
		elif x < -d:
			return f(-x, k, d)

print f(x,k,d)
Problem p02613 (python)

Fixed submission:
import collections
n = int(raw_input())
cc = collections.Counter([raw_input() for _ in range(n)])

for u in ['AC', 'WA', 'TLE', 'RE']:
	print '{} x {}'.format(u, cc[u])

Buggy submission (verdict: Runtime Error):
import collections
n = raw_input()
cc = collections.Counter([raw_input() for _ in range(n)])

for u in ['AC', 'WA', 'TLE', 'RE']:
	print '{}x{}'.format(u, cc[u])
Problem p02628 (python)

Fixed submission:
n,k = map(int ,raw_input().split(' '))
prices = map(int, raw_input().split(' '))
prices.sort()
print sum(prices[:k])

Buggy submission (verdict: Runtime Error):
n,k = map(int ,raw_input().split(' '))
prices = map(int, raw_input().split(' ')
print sum(prices[:k])
Problem p02640 (python)

Fixed submission:
x,y = map(int, raw_input().split(' '))


"""
a + b = x
2a + 4b = y

a = x-b
2x- 2b + 4b = y

a = x-b
2b = y  - 2x
"""
def f(x,y):
  	
	if (y - 2*x) < 0: return False
	b = (y - 2*x)/2
	a = x - b

	b = (y - 2*x)/2
	a = x - b
	
	if a < 0: return False


	return a+b == x and 2*a + 4*b ==y
  
print 'Yes' if f(x,y) else 'No'

Buggy submission (verdict: Runtime Error):
x,y = map(int, raw_input().split(' '))


"""
a + b = x
2a + 4b = y

a = x-b
2x- 2b + 4b = y

a = x-b
2b = y  - 2x
"""
def f(x,y):
  
	if (y - 2*x) < 0 or (y - 2*x) %2 != 0:
      return False
  	b = y - 2*x
    a = x - b
    if a < 0:
      return False
    return True
  
print 'Yes' if f(x,y) else 'No'
Problem p02646 (python)

Fixed submission:
a,v = map(int, raw_input().split(' '))
b,w = map(int, raw_input().split(' '))
t = int(raw_input())

print 'YES' if (v*t >= w*t + abs(a-b)) else 'NO'

Buggy submission (verdict: Runtime Error):


a,v = map(int, raw_input().split(' '))
b,w = map(int, raw_input().split(' '))
t = int(raw_input())

print 'YES' ig v*t >= w*t + abs(a-b) else 'NO'

Buggy submission (verdict: Runtime Error):
1 2
3 1
3

a,v = map(int, raw_input().split(' '))
b,w = map(int, raw_input().split(' '))
t = int(raw_input())

print 'YES' ig v*t >= w*t + abs(a-b) else 'NO'
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
print int(raw_input()) * int(raw_input())
Problem p02658 (python)

Fixed submission:
cumul = 1
n = int(raw_input())
ais = map(int, raw_input().split(' '))
i = 0
ais.sort(key = lambda x:-x)
if ais[-1] == 0:
	cumul = 0
while(i < len(ais) and cumul <= 10 ** 18):
  cumul *= ais[i]
  i +=1
  if cumul == 0:
  	break

print cumul if cumul <= 10 ** 18 else -1

Buggy submission (verdict: Runtime Error):
cumul = 1
n = int(raw_input())
ais = map(int, raw_input().split(' '))
while(i < len(ais) and cumul < 10 ** 18):
  cumul *= ais[i]
  i+=1
print cumul if cumul < 10 ** 18 else -1
Problem p02660 (python)

Fixed submission:
def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	p = True
	for d in range(2, int(on ** 0.5) + 2):
		if n % d == 0:
			p = False
			e = 0
			while(n%d == 0): 
				e +=1
				n/=d
			res+= f(e)
	if n > 1: res += 1
	return res

print answer(int(raw_input()))

Buggy submission (verdict: Runtime Error):

def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	for d in range(2, int(on ** 0.5) + 1)
		if n % d == 0:
			e = 0
			while(n%d == 0): e +=1
			res+= f(e)
		
	return res if n == 1 else 1

print answer(int(raw_input()))

Buggy submission (verdict: Runtime Error):

def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	for d in range(2, int(on ** 0.5) + 1)
		if n % d == 0:
			e = 0
			while(n%d == 0): e +=1
			res+= f(e)
		d +=1
	return res if n == 1 else 1

Buggy submission (verdict: Runtime Error):

def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	for d in range(2, int(n ** 0.5) + 1)
		if n % d == 0:
			e = 0
			while(n%d == 0): e +=1
			res+= f(e)
		
	return res if n == 1 else 1

print answer(int(raw_input()))

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
 
def f(c):

	cumul = 0
	step = 1
	cc = 0
	while(cumul < c):
		cc +=1
		cumul += step
		step += 1
	if cumul > c: count -=1
	return cc
	
d = 2
count = 0

while(n != 1 and d*d <= n):
	if n%d==0:
		c = 0
		while(n%d == 0): 
			c += 1
			n /= d
		count += f(c)
	d+=1
print count
Problem p02681 (python)

Fixed submission:
u = raw_input()
v = raw_input()
print 'Yes' if u == v[:-1] else 'No'

Buggy submission (verdict: Runtime Error):
def f(s,t): return t[:-1] == s and len(t) == len(s) + 1
s,t = raw_input().split()
print 'Yes' if f(s,t) else 'No'

Buggy submission (verdict: Runtime Error):

u,v = raw_input().split(' ')
print 'Yes' if u == v[:-1] else 'No'
Problem p02686 (python)

Fixed submission:
n = int(raw_input())
def gb(s):
	bal = 0
	m = 0
	for l in s: 
		bal += 1 if l == '(' else -1
		m = min(m, bal)
	return (bal,m)


adds, dels = [], []
for _ in range(n):
	e = gb(raw_input())
	if e[0] >= 0:
		adds.append(e)
	else:
		dels.append(e)
adds.sort(key = lambda x: (-x[1], -x[0]))
dels.sort(key = lambda x: (x[1] - x[0], -x[0]))
def f(adds, dels):
	s = 0
	for aa,bb in adds:

		if s + aa < 0:
			return False
		if s + bb < 0:
			return False
		s += aa
		

	for aa,bb in dels:

		if s + aa < 0:
			return False
		if s + bb < 0:
			return False
		s += aa
	return s == 0

print 'Yes' if f(adds, dels) else 'No'

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
def gb(s):
	bal,m = 0
	for l in s: 
		bal += 1 if l == '(' else -1
		m = min(m, bal)
	return (bal,m)


rs = [gb(raw_input()) for _ in range(n)]
rs.sort(key = lambda x: (0,-x[1], x[0]) if x[0]>=0 else (1,x[1] - x[0], -x[0]))

def f(rs):
	s = 0
	for aa,bb in rs:
		if s + bb < 0: return False
		s += aa
	return s == 0

print 'Yes' if f(rs) else 'No'
Problem p02687 (python)

Fixed submission:
print 'ARC' if raw_input() == 'ABC' else 'ABC'

Buggy submission (verdict: Runtime Error):
print {'ABC':'ARC', 'ARC', 'ABC'}[raw_input()]
Problem p02691 (python)

Fixed submission:
import collections
n = int(raw_input())
hs = map(int, raw_input().split(' '))
def f(nums):
	cc,count = collections.Counter(), 0

	#j - i = aj + ai  =>  ai + i = j - aj
	for i in range(len(nums)-1, -1, -1):
		count += cc[nums[i] + i]
		cc[i - nums[i]]+=1
	return count
		


print f(hs)

Buggy submission (verdict: Runtime Error):
import collections
cc = collections.Counter()
count = 0
n = raw_input()
for i,e in enumerate(map(int, raw_input().split())):
	count += cc[e - i]
    cc[e-  i] +=1
    
print count
Problem p02706 (python)

Fixed submission:
n,m = map(int,raw_input().split(' '))
a = n - sum(map(int,raw_input().split(' ')) or [0])
print a if a >= 0 else -1

Buggy submission (verdict: Runtime Error):
import collections

n,m = map(int,raw_input().split(' '))
print n - sum([map(int,raw_input().split(' '))] or [0])