Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
 
n, k = map(int,input().split())
a = list(map(int,input().split()))
 
c = Counter(a)
l = len(c)
cnt = 0
if k < l:
    i = -1
    for _ in range(l-k):
        cnt += c.most_common()[i][1]
        i -= 1
print(cnt)

Fixed submission:
from collections import Counter
import heapq
n, k = map(int,input().split())
a = list(map(int,input().split()))
c = Counter(a)
heapc = list(c.values())
heapq.heapify(heapc)
l = len(c)
cnt = 0
if k < l:
    for _ in range(l-k):
        cnt += heapq.heappop(heapc)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
input = sys.stdin.readline

n, k = map(int,input().split())
a = list(map(int,input().split()))

c = Counter(a)
l = len(c)
cnt = 0
if k < l:
    i = -1
    for _ in range(l-k):
        cnt += c.most_common()[i][1]
        i -= 1
print(cnt)

Fixed submission:
from collections import Counter
import heapq
n, k = map(int,input().split())
a = list(map(int,input().split()))
c = Counter(a)
heapc = list(c.values())
heapq.heapify(heapc)
l = len(c)
cnt = 0
if k < l:
    for _ in range(l-k):
        cnt += heapq.heappop(heapc)
print(cnt)

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

n, k = map(int,input().split())
a = list(map(int,input().split()))

c = Counter(a)
l = len(c)
cnt = 0
if k < l:
    i = -1
    for _ in range(l-k):
        cnt += c.most_common()[i][1]
        i -= 1
print(cnt)

Fixed submission:
from collections import Counter
import heapq
n, k = map(int,input().split())
a = list(map(int,input().split()))
c = Counter(a)
heapc = list(c.values())
heapq.heapify(heapc)
l = len(c)
cnt = 0
if k < l:
    for _ in range(l-k):
        cnt += heapq.heappop(heapc)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

length = 0
for i in range(n) :
    for j in range(n):
        route = 10000000000
        for k in range(n):
            if k == i or k == j : continue
            route = min(route, a[i][k] + a[k][j] ) #< a[i][j]
            if route < a[i][j]:
                print(-1)
                exit() 
        if route > a[i][j] :
            length +=  a[i][j]
print(int(length/2))

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

length = 0
for i in range(n) :
    for j in range(n):
        route = 10000000000
        for k in range(n):
            if k == i or k == j : continue
            route = min(route, a[i][k] + a[k][j] ) #< a[i][j]
            if route < a[i][j]:
                print(-1)
                exit() 
        if route > a[i][j] :
            length +=  a[i][j]
print(int(length/2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

def fanc(n, a):
    if n == 1: 
        print(1)
        return 0
    cnt = 0
    while len(a) > 0:
        same_cnt = 1
        j = 1
        while a[0] == a[j]:
            same_cnt += 1
            if j == len(a) - 1:
                break
            j += 1
        if same_cnt  % 2 == 1:
            cnt += 1
        del a[0:same_cnt]
    print(cnt)
    return 0

fanc(n, a)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

def fanc(n, a):
    if n == 1: 
        print(1)
        return 0
    cnt = 0
    while len(a) > 1:
        same_cnt = 0
        j = 1
        while a[0] == a[j]:
            same_cnt += 1
            if j == len(a) - 1:
                break
            j += 1
        if same_cnt  % 2 == 0:
            cnt += 1
        del a[0:same_cnt+1]
    if len(a) == 1: cnt += 1
    print(cnt)
    return 0

fanc(n, a)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

if len(a) == 1: cnt = 1
else: cnt = 0
while len(a) > 0:
    same_cnt = 1
    j = 1
    while a[0] == a[j]:
        same_cnt += 1
        if j == len(a) - 1:
            break
        j += 1
    if same_cnt  % 2 == 1:
        cnt += 1
    del a[0:same_cnt]
print(cnt)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

def fanc(n, a):
    if n == 1: 
        print(1)
        return 0
    cnt = 0
    while len(a) > 1:
        same_cnt = 0
        j = 1
        while a[0] == a[j]:
            same_cnt += 1
            if j == len(a) - 1:
                break
            j += 1
        if same_cnt  % 2 == 0:
            cnt += 1
        del a[0:same_cnt+1]
    if len(a) == 1: cnt += 1
    print(cnt)
    return 0

fanc(n, a)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

cnt = 0
while len(a) > 0:
    same_cnt = 1
    j = 1
    while a[0] == a[j]:
        same_cnt += 1
        if j == len(a) - 1:
            break
        j += 1
    if same_cnt  % 2 == 1:
        cnt += 1
    del a[0:same_cnt]
print(cnt)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

def fanc(n, a):
    if n == 1: 
        print(1)
        return 0
    cnt = 0
    while len(a) > 1:
        same_cnt = 0
        j = 1
        while a[0] == a[j]:
            same_cnt += 1
            if j == len(a) - 1:
                break
            j += 1
        if same_cnt  % 2 == 0:
            cnt += 1
        del a[0:same_cnt+1]
    if len(a) == 1: cnt += 1
    print(cnt)
    return 0

fanc(n, a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

i = 0
cnt = 0
while not i == 1:
    i = a[i] - 1
    cnt += 1
    if i >= n or cnt > 100000:
        exit("-1")
print(cnt)

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

i = 0
cnt = 0
while not i == 1:
    i = a[i] - 1
    cnt += 1
    if i >= n or cnt > 100000:
        print(-1)
        exit()
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
rslt = 1
while n > 0:
    rslt *= n
    n -= 1
print(rslt%(10**9+7))

Fixed submission:
import math
n = int(input())
print( math.factorial(n)%(10**9+7) )

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
rslt = 1
while n > 1:
    rslt *= n
    n -= 1
print(rslt%(10**9+7))

Fixed submission:
import math
n = int(input())
print( math.factorial(n)%(10**9+7) )
Buggy python submission (verdict: Runtime Error):
abc = input()
abc_int = int(abc)
prolist = []
chk = int(abc_int**0.5)+2
for c1 in range(chk):
	if abc_int % c1 == 0:
		prolist.append(c1+abc_int//c1-2)
print(min(prolist))

Fixed submission:
j=input()
i = j.split(' ')
k = []
for c in i:
    k.append(int(c))
if k[0]<10 and k[1]<10:
	print(k[0]*k[1])
else:
	print(-1)

Buggy python submission (verdict: Runtime Error):
i = int(input().split(' '))
if i[0]<10 and i[1]<10:
	print(i[0]*i[1])
else:
	print(-1)

Fixed submission:
j=input()
i = j.split(' ')
k = []
for c in i:
    k.append(int(c))
if k[0]<10 and k[1]<10:
	print(k[0]*k[1])
else:
	print(-1)
Buggy python submission (verdict: Runtime Error):
abc = input()
abc_int = int(abc)
prolist = []
chk = int(abc_int**0.5)
print(chk)
for c1 in range(chk):
    for c2 in range(chk):
        if (c1+1)*(c2+1) == abc_int:
            prolist.append(c1+c2)
print(min(prolist))

Fixed submission:
abc = input()
abc_int = int(abc)
prolist = []
chk = int(abc_int**0.5)+2
for c1 in range(chk):
	if abc_int % (c1+1) == 0:
		prolist.append(c1+1+abc_int//(c1+1)-2)
print(min(prolist))
Buggy python submission (verdict: Runtime Error):
n,m,d = map(int,raw_input().split())

print (((n-d)*2)*(m-1)*n)/float(n**m)

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

print (((n-d)*2)/float(n**2))*(m-1) if d != 0 else ((((n-d)*2)/float(n**2))*(m-1))/2
Buggy python submission (verdict: Runtime Error):
n = int(input())

arr = map(int,raw_input().split())

for i in range(n):
	arr[i] -= (i+1)

mi = min(arr)
ma = max(arr)


ans = float("inf")
for i in range(mi,ma+1):
	count = 0
	for j in range(n):
		count += abs(arr[j]-i)

	ans = min(ans,count)

print ans

Fixed submission:
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

arrb = []

for i in range(n):
	arrb.append(arr[i]-i)

med = np.median(arrb)

ans = 0
for i in range(n):
	ans += abs(arrb[i]-med)

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = float('-inf')

def check(k,o,f,p,i):
	global ans,m,n
	if i < n and p < m:
		check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

	if i < n:
		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans

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

arr = []

for i in range(n):
	arr.append(map(int,raw_input().split()))

v = [[1,1,1],[1,1,-1],[1,-1,-1],[1,-1,1],[-1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1]]

ans = 0

for i in range(8):
	tmp = []
	for j in range(n):
		tmp.append(arr[j][0] * v[i][0] + arr[j][1] * v[i][1] + arr[j][2] * v[i][2])

	tmp.sort()
	ans = max(ans,sum(tmp[n-m:]))

print ans

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = float('-inf')

def check(k,o,f,p,i):
	global ans,m,n
	if i < n:

		if p < m:
			check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans

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

arr = []

for i in range(n):
	arr.append(map(int,raw_input().split()))

v = [[1,1,1],[1,1,-1],[1,-1,-1],[1,-1,1],[-1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1]]

ans = 0

for i in range(8):
	tmp = []
	for j in range(n):
		tmp.append(arr[j][0] * v[i][0] + arr[j][1] * v[i][1] + arr[j][2] * v[i][2])

	tmp.sort()
	ans = max(ans,sum(tmp[n-m:]))

print ans

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

arr = []
for i in range(n):
	arr.append(map(int,raw_input().split()))


ans = -10000000
print arr
def check(k,o,f,p,i):
	global ans,m,n
	if i < n:

		if p < m:
			check(k+arr[i][0],o+arr[i][1],f+arr[i][2],p+1,i+1)

		check(k,o,f,p,i+1)

	if p == m:
		ans = max(ans,abs(k)+abs(o)+abs(f))


check(0,0,0,0,0)

print ans

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

arr = []

for i in range(n):
	arr.append(map(int,raw_input().split()))

v = [[1,1,1],[1,1,-1],[1,-1,-1],[1,-1,1],[-1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1]]

ans = 0

for i in range(8):
	tmp = []
	for j in range(n):
		tmp.append(arr[j][0] * v[i][0] + arr[j][1] * v[i][1] + arr[j][2] * v[i][2])

	tmp.sort()
	ans = max(ans,sum(tmp[n-m:]))

print ans
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print max(a+b,a-b,a*b)

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

print max(a+b,a-b,a*b)
Buggy python submission (verdict: Runtime Error):
s = raw_input()

print 700 + s.count(o)*100

Fixed submission:
s = raw_input()
 
print 700 + s.count('o')*100
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())

arr = []
for i in range(n):
	arr.append(raw_input())

count = 0

for combs in list(itertools.combinations(range(n),3)):
	rest = 'MARCH'
	c = 0
	for i in combs:
		if arr[i][0] in rest:
			rest = rest.replace(arr[i][0],'')
			c += 1
		else :
			break

	if c == 3:
		count += 1

print count


Fixed submission:
import itertools
n = int(raw_input())

d = {'M':0,'A':0,'R':0,'C':0,'H':0}

for i in range(n):
	s = raw_input()
	if d.has_key(s[0]):
		d[s[0]] += 1

count = 0

for comb in list(itertools.combinations(d.keys(),3)):
	count += d[comb[0]]* d[comb[1]]*d[comb[2]]

print count

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

arr = []
for i in range(n):
	arr.append(raw_input())

count = 0

def dfs(rest_str,person_count,i):
	global count
	if person_count == 3:
		count += 1

	elif i < n:
		if arr[i][0] in rest_str :
			dfs(rest_str.replace(arr[i][0],''),person_count+1,i+1)

		dfs(rest_str,person_count,i+1)

dfs('MARCH',0,0)
print count


Fixed submission:
import itertools
n = int(raw_input())

d = {'M':0,'A':0,'R':0,'C':0,'H':0}

for i in range(n):
	s = raw_input()
	if d.has_key(s[0]):
		d[s[0]] += 1

count = 0

for comb in list(itertools.combinations(d.keys(),3)):
	count += d[comb[0]]* d[comb[1]]*d[comb[2]]

print count
Buggy python submission (verdict: Runtime Error):
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]


for i in range(n):
	l,r = inputs[i]

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans

Fixed submission:
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]

Buggy python submission (verdict: Runtime Error):
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(n):
	l,r = map(int,raw_input().split())

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans

Fixed submission:
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]
Buggy python submission (verdict: Runtime Error):
h,w = map(int,raw_input().split())
d = [map(int,raw_input().split()) for i in range(10)]

	for k in range(10):
		for i in range(10):
			for j in range(10):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
arr = [map(int,raw_input().split()) for i in range(h)]

print sum(sum(d[a][1] if a>=0 else 0 for a in aa) for aa in arr)

Fixed submission:
h,w = map(int,raw_input().split())
d = [map(int,raw_input().split()) for i in range(10)]
for t in xrange(10):
	for i in range(10):
		for j in range(10):
			for k in range(10):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
arr = [map(int,raw_input().split()) for i in range(h)]

print sum(sum(d[a][1] if a>=0 else 0 for a in aa) for aa in arr)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
	if b == 0 :
		return a
	else :
		return gcd(b,a%b)
 
def lcm(a,b):
	return a*b/gcd(a,b)
 
n = int(input())
arr = []
for i in range(n):
 
	arr.append(int(input()))
 
 
def mlcm():
 	if n = 1:
 		return arr[0]
 		
	ans = lcm(arr[0],arr[1])
 
	i = 2
	while i<n:
		ans = lcm(ans,arr[i])
		i+=1
 
	return ans
 
print mlcm()

Fixed submission:
def gcd(a,b):
	if b == 0 :
		return a
	else :
		return gcd(b,a%b)
 
def lcm(a,b):
	return a*b/gcd(a,b)
 
n = int(input())
arr = []
for i in range(n):
 
	arr.append(int(input()))
 
 
def mlcm():
 	if n == 1:
 		return arr[0]

	ans = lcm(arr[0],arr[1])
 
	i = 2
	while i<n:
		ans = lcm(ans,arr[i])
		i+=1
 
	return ans
 
print mlcm()

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
	if b == 0 :
		return a
	else :
		return gcd(b,a%b)

def lcm(a,b):
	return a*b/gcd(a,b)

n = int(input())
arr = []
for i in range(n):

	arr.append(int(input()))


def mlcm():

	ans = lcm(arr[0],arr[1])

	i = 2
	while i<n:
		ans = lcm(ans,arr[i])
		i+=1

	return ans

print mlcm()


Fixed submission:
def gcd(a,b):
	if b == 0 :
		return a
	else :
		return gcd(b,a%b)
 
def lcm(a,b):
	return a*b/gcd(a,b)
 
n = int(input())
arr = []
for i in range(n):
 
	arr.append(int(input()))
 
 
def mlcm():
 	if n == 1:
 		return arr[0]

	ans = lcm(arr[0],arr[1])
 
	i = 2
	while i<n:
		ans = lcm(ans,arr[i])
		i+=1
 
	return ans
 
print mlcm()
Buggy python submission (verdict: Runtime Error):
n = int(input())

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]


Fixed submission:
import sys

sys.setrecursionlimit(10**5+100)
n = int(input())

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]

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

edges = [[] for i in range(n)]
distance = [-1 for i in range(n)]

for i in range(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append([t,c])
	edges[t].append([f,c])

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for i in range(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]


Fixed submission:
import sys

sys.setrecursionlimit(10**5+100)
n = int(input())

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]

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

edges = [[] for i in range(n)]
distance = [-1 for i in range(n)]

for i in range(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append([t,c])
	edges[t].append([f,c])

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			print to,cost
			dfs(to,c+cost)

dfs(k,0)

for i in range(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]


Fixed submission:
import sys

sys.setrecursionlimit(10**5+100)
n = int(input())

edges = [[] for _ in xrange(n)]
distance = [-1 for _ in xrange(n)]

for _ in xrange(n-1):
	f,t,c = map(int,raw_input().split())

	f -= 1
	t -= 1

	edges[f].append((t,c))
	edges[t].append((f,c))

q,k = map(int,raw_input().split())
k -= 1

def dfs(v,c):
	if distance[v] == -1:
		distance[v] = c
		for to,cost in edges[v]:
			dfs(to,c+cost)

dfs(k,0)

for _ in xrange(q):
	x,y = map(int,raw_input().split())
	x -= 1
	y -= 1
	print distance[x] + distance[y]
Buggy python submission (verdict: Runtime Error):
inf = float("inf")
dist1 = [inf for i in range(n)]

dist1[0] = 0
stk = []
for i in edge[0]:
    stk.append([i,1])

while stk:
    t,c = stk.pop()
    if dist1[t] == inf :
        dist1[t] = c
        for i in edge[t]:
            stk.append([i,c+1])

dist2 = [inf for i in range(n)]
dist2[n-1] = 0
for i in edge[n-1]:
    stk.append([i,1])
while stk:
    t,c = stk.pop()
    if dist2[t] == inf :
        dist2[t] = c
        for i in edge[t]:
            stk.append([i,c+1])

fennec = 0
snuke = 0

for i in range(n):
    if dist1[i] <= dist2[i]:
        fennec += 1
    else :
        snuke += 1
print fennec
print snuke

if fennec > snuke:
    print "Fennec"
else:
    print "Snuke"

Fixed submission:
n = int(input())

edge = [[] for i in range(n)]

for i in range(n-1):
    f,t = map(int,raw_input().split())
    f -= 1
    t -= 1

    edge[f].append(t)
    edge[t].append(f)

inf = float("inf")
dist1 = [inf for i in range(n)]

dist1[0] = 0
stk = []
for i in edge[0]:
    stk.append([i,1])

while stk:
    t,c = stk.pop()
    if dist1[t] == inf :
        dist1[t] = c
        for i in edge[t]:
            stk.append([i,c+1])

dist2 = [inf for i in range(n)]
dist2[n-1] = 0
for i in edge[n-1]:
    stk.append([i,1])
while stk:
    t,c = stk.pop()
    if dist2[t] == inf :
        dist2[t] = c
        for i in edge[t]:
            stk.append([i,c+1])

fennec = 0
snuke = 0

for i in range(n):
    if dist1[i] <= dist2[i]:
        fennec += 1
    else :
        snuke += 1


if fennec > snuke:
    print "Fennec"
else:
    print "Snuke"
Buggy python submission (verdict: Time Limit Exceeded):
import math
mod = 10**9+7
n,m = map(int,raw_input().split())

if abs(n-m) > 1:
	print 0
	quit()

if max(n,m) > min(n,m):
	print math.factorial(max(n,m)) % mod * math.factorial(min(n,m)) % mod

else :
	print (((math.factorial(n))%mod)**2 * 2)%mod

Fixed submission:

mod = 10**9+7
n,m = map(int,raw_input().split())
def factorial(x):
	retval = 1
	for i in range(2,x+1):
		retval = (retval * i)% mod
	return retval

if abs(n-m) > 1:
	print 0
	quit()

if max(n,m) > min(n,m):
	print (factorial(max(n,m)) * factorial(min(n,m))) % mod

else :
	print ((factorial(n)**2)%mod * 2)%mod

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m = map(int,raw_input().split())

if abs(n-m) > 1:
	print 0
	quit()

if max(n,m) > min(n,m):
	print math.factorial(max(n,m)) * math.factorial(min(n,m)) % (10**9 + 7)

else :
	print (math.factorial(n)**2 * 2)%(10**9 + 7)

Fixed submission:

mod = 10**9+7
n,m = map(int,raw_input().split())
def factorial(x):
	retval = 1
	for i in range(2,x+1):
		retval = (retval * i)% mod
	return retval

if abs(n-m) > 1:
	print 0
	quit()

if max(n,m) > min(n,m):
	print (factorial(max(n,m)) * factorial(min(n,m))) % mod

else :
	print ((factorial(n)**2)%mod * 2)%mod
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,raw_input().split())

print (a + b(n - 1) ) - (a(n-1) + b) + 1

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

ans =  (a + b*(n - 1) ) - (a*(n-1) + b) + 1 
print ans if ans > 0 else 0
Buggy python submission (verdict: Time Limit Exceeded):
import Queue
t = int(input())

queue = Queue.Queue()
queue.put([0,0])
while True :
	x = queue.get()
	if x[0] == t:
		print x[1]
		break

	else :
		queue.put([ x[0]+x[1]+1 , x[1]+1 ])
		queue.put([ x[0] , x[1]+1])
		if x[0] - (x[1]+1) > 0 :
			queue.put([x[0]-(x[1]+1),x[1]+1])



Fixed submission:
n = int(input())

ans = 0
i = 1
while n > ans :
	ans += i
	i += 1

print i-1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = map(int,raw_input().split())
arr.sort()
cnt = 0

for i in range(1,n):
	if sum(arr[:i])*2 < arr[i]:
		cnt = i

print n-cnt


Fixed submission:
import numpy as np
n = int(input())

arr = map(int,raw_input().split())
arr.sort()
cs = np.cumsum(arr)

ans = 1

i = n-2
while i > -1 and cs[i] * 2 >= arr[i+1]:
	ans += 1
	i -= 1

print ans