Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_4_C
n = int(input())
dic = []
for i in range(n):
    cmd, word = input().split()
    if cmd == "find":
        if word in dic:
            print("yes")
        else:
            print("no")
    else:
        dic.append(word)

Fixed submission:
#coding:utf-8
#1_4_C
n = int(input())
dic = set()
for i in range(n):
    cmd, word = input().split()
    if cmd == "find":
        if word in dic:
            print("yes")
        else:
            print("no")
    else:
        dic.add(word)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_5_A
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False

    res = solve(i+1, m) or solve(i+1, m-numbers[i])
    return res

n = int(input())
numbers = list(map(int, input().split()))
q = int(input())

for i in range(q):
    if solve(0, int(input())):
        print("yes")
    else:
        print("no")

Fixed submission:
#coding:utf-8
#1_5_A
from itertools import combinations

n = int(input())
A = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))

numbers = set()
for i in range(1, n+1):
    for com in combinations(A, i):
        numbers.add(sum(com))

for m in ms:
    if m in numbers:
        print("yes")
    else:
        print("no")

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_5_A
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False

    res = solve(i+1, m) or solve(i+1, m-A[i])
    return res

n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

for i in range(q):
    if solve(0, m[i]):
        print("yes")
    else:
        print("no")

Fixed submission:
#coding:utf-8
#1_5_A
from itertools import combinations

n = int(input())
A = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))

numbers = set()
for i in range(1, n+1):
    for com in combinations(A, i):
        numbers.add(sum(com))

for m in ms:
    if m in numbers:
        print("yes")
    else:
        print("no")
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_5_B
def merge_sort(array):
    if len(array) > 1:
        L, countL = merge_sort(array[0:len(array)//2])
        R, countR = merge_sort(array[len(array)//2:])
        return merge(L, R, countL+countR)

    if len(array) == 1:
        return [array, 0]

def merge(L, R, count=0):
    L.append(10**9+1)
    R.append(10**9+1)
    response = []
    i = 0
    j = 0
    for k in range(len(L)-1 + len(R)-1):
        if L[i] <= R[j]:
            response.append(L[i])
            i += 1
            count += 1
        else:
            response.append(R[j])
            j += 1
            count += 1
    return [response, count]

n = int(input())
S = list(map(int, input().split()))
print(' '.join(map(str, merge_sort(S)[0])))
print(merge_sort(S)[1])

Fixed submission:
#coding:utf-8
#1_5_B
def merge(array, left, mid, right):
    global cnt
    L = array[left:mid]  + [sentinel]
    R = array[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
    cnt += right - left

def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right)


n = int(input())
S = list(map(int, input().split()))
cnt = 0
sentinel = 10 ** 9 + 1
merge_sort(S, 0, len(S))
print(*S)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
import itertools

n = int(input())
numbers = list(map(int, input().split()))
count = 0

for item in itertools.combinations(numbers, 2):
    if item[0] > item[1]:
        count += 1

print(count)

Fixed submission:
#coding:utf-8
#1_5_D

def merge(array, left, mid, right):
    global cnt
    L = array[left:mid]  + [SENTINEL]
    R = array[mid:right] + [SENTINEL]
    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
            cnt += len(L) - 1 - i

def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right)

n = int(input())
numbers = list(map(int, input().split()))
cnt = 0
SENTINEL = 10 ** 9 + 1
merge_sort(numbers, 0, len(numbers))
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_9_C
l = list()
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        l.append(int(cmd[1]))
    else:
        print(max(l))
        l.remove(max(l))

Fixed submission:
#coding:utf-8
#1_9_C
import heapq

h = []
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        heapq.heappush(h, -int(cmd[1]))
    else:
        print(-heapq.heappop(h))

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_9_C
s = set()
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        l.add(int(cmd[1]))
    else:
        print(max(s))
        l.remove(max(s))

Fixed submission:
#coding:utf-8
#1_9_C
import heapq

h = []
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        heapq.heappush(h, -int(cmd[1]))
    else:
        print(-heapq.heappop(h))

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_9_C
import queue

q = queue.PriorityQueue()
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        q.put(-int(cmd[1]))
    else:
        print(-q.get())

Fixed submission:
#coding:utf-8
#1_9_C
import heapq

h = []
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        heapq.heappush(h, -int(cmd[1]))
    else:
        print(-heapq.heappop(h))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_10_A 2015.4.10
import math

position = list(map(int,input().split()))
distance = math.sqrt((position[2] - position[0]) ** 2 + (position[3] - position[1]) ** 2)
print('{:.5f}'.format(distance))

Fixed submission:
#coding:utf-8
#1_10_A 2015.4.10
import math

x1,y1,x2,y2 = map(float,input().split())
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print('{:.5f}'.format(distance))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_10_B 2015.4.14

import math

a,b,C = map(int,input().split())
C = math.radian(C)
h = b * math.sin(C)
S = a * h / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h))

Fixed submission:
#coding:utf-8
#1_10_B 2015.4.14

import math

a,b,C = map(int,input().split())
C = math.radians(C)
h = b * math.sin(C)
S = a * h / 2
L = a + b + math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h))
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
#1_11_C 2015.4.20
class Dice:
    def __init__(self,ary):
        self.top , self.south , self.east , self.west , self.north ,self.bottom = ary

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def twist(self):
        self.north , self.west , self.south , self.east = self.east , self.north , self.west , self.south

dice1 = Dice(input().split())
dice2 = Dice(input().split())

while dice1.top != dice2.top or dice1.south != dice2.south:
    if dice1.top == dice2.top:
        while dice1.south != dice2.south:
            dice1.twist()
    elif dice1.south == dice2.south:
        while dice1.top != dice2.top:
            dice1.roll_e()
    else:
        dice1.roll_n()

if dice1.top == dice2.top and dice1.north == dice2.north and dice1.south == dice2.south and dice1.east == dice2.east and dice1.west == dice2.west and dice1.bottom == dice2.bottom:
    print('Yes')
else:
    print('No')

Fixed submission:
#coding:utf-8
#1_11_C

class Dice:
    def __init__(self, ary):
        self.top, self.south, self.east, self.west, self.north, self.bottom = ary

    def roll_n(self):
        self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom

    def roll_e(self):
        self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom

    def twist(self):
        self.north, self.east, self.south, self.west = self.west, self.north, self.east, self.south

    def isEqual(self, dice):
        if self.top == dice.top and self.south == dice.south and self.east == dice.east and self.west == dice.west and self.north == dice.north and self.bottom == dice.bottom:
            return True
        else:
            return False

dice1 = Dice(map(int,input().split()))
dice2 = Dice(map(int,input().split()))

flag = False

for i in range(6):
    if i % 2 == 0:
        dice1.roll_n()
    else:
        dice1.roll_e()

    for j in range(4):
        if dice1.isEqual(dice2):
            flag = True
            break
        else:
            dice1.twist()

    if flag:
        break

if flag:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_4_B 2015.3.24
import math
r = int(input())
area = r ** 2 * math.pi
circumference = 2 * r * math.pi
print('{0:.6f} {1:.6f}'.format(area,circumference))

Fixed submission:
#coding:utf-8
#1_4_B 2015.3.24
import math
r = float(input())
area = r ** 2 * math.pi
circumference = 2 * r * math.pi
print('{0:.6f} {1:.6f}'.format(area,circumference))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
#1_9_A 2015.4.10
w = input().lower()
c = 0
while True:
    t = input()
    if 'END_OF_TEXT' in t:
        break
    c += t.lower().split()lower().count(w)
print(c)

Fixed submission:
#coding:utf-8
#1_9_A 2015.4.12
w = input().lower()
c = 0
while True:
    t = input()
    if 'END_OF_TEXT' in t:
        break
    c += t.lower().split().count(w)
print(c)
Buggy python submission (verdict: Runtime Error):
def dfs(field, i, j, w, h):
    field[i][j] = "0"
    
    OFFSETS = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
    for di, dj in OFFSETS:
        if i+di < 0 or i+di >= h:
            continue
        if j+dj < 0 or j+dj >= w:
            continue
        if field[i+di][j+dj] == "1":
            dfs(field, i+di, j+dj, w, h)


def main():
    while True:
        w, h = [int(s) for s in input().strip().split()]

        if w == 0 and h == 0:
            break

        num_island = 0
    
        field = []
        for _ in range(h):
            field.append(input().strip().split())
       
        #print(field) 
        for i in range(h):
            for j in range(w):
                if field[i][j] == "1":
                    num_island += 1
                    dfs(field, i, j, w, h)
        
        print(num_island)


if __name__ == "__main__":
    main()



Fixed submission:
def bfs(field, start_i, start_j, w, h):
    OFFSETS = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

    queue = [(start_i,start_j)]

    while len(queue) > 0:
        i, j = queue.pop()
        field[i][j] = "0"

        for di, dj in OFFSETS:
            if i+di < 0 or i+di >= h:
                continue
            if j+dj < 0 or j+dj >= w:
                continue
            if field[i+di][j+dj] == "1":
                queue.append((i+di, j+dj))


def main():
    while True:
        w, h = [int(s) for s in input().strip().split()]

        if w == 0 and h == 0:
            break

        num_island = 0
    
        field = []
        for _ in range(h):
            field.append(input().strip().split())
       
        #print(field) 
        for i in range(h):
            for j in range(w):
                if field[i][j] == "1":
                    num_island += 1
                    bfs(field, i, j, w, h)
        
        print(num_island)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import itertools

def calc(n):
    for op in itertools.product(operators, repeat=3):
        for form in forms:
            formula = form.format(op[0], op[1], op[2], n[0], n[1], n[2], n[3])
            if eval(formula) == 10:
                print(formula)
                return True
    return False

operators = ("+", "-", "*")

forms = (
  "(({3}{0}{4}){1}{5}){2}{6}",
  "({3}{0}{4}){1}({5}{2}{6})",
  "({3}{0}({4}{1}{5})){2}{6}",
  "{3}{0}(({4}{1}{5}){2}{6})",
  "{3}{0}({4}{1}({5}{2}{6}))",
)

while (True):
    nums = tuple(map(int, raw_input().split()))
    if nums == (0,0,0,0):
        break
    for n in itertools.permutations(nums):
        if calc(n):
            break
    else:
        print(0)

Fixed submission:
import itertools

def calc(n):
    for op in itertools.product(operators, repeat=3):
        for form in forms:
            formula = form.format(op[0], op[1], op[2], n[0], n[1], n[2], n[3])
            if eval(formula) == 10:
                print(formula)
                return True
    return False

operators = ("+", "-", "*")

forms = (
  "(({3}{0}{4}){1}{5}){2}{6}",
  "({3}{0}{4}){1}({5}{2}{6})",
  "({3}{0}({4}{1}{5})){2}{6}",
  "{3}{0}(({4}{1}{5}){2}{6})",
  "{3}{0}({4}{1}({5}{2}{6}))",
)

while (True):
    nums = tuple(map(int, input().split()))
    if nums == (0,0,0,0):
        break
    for n in itertools.permutations(nums):
        if calc(n):
            break
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
import itertools

def calc(n):
    for op in itertools.product(operators, repeat=3):
        for form in forms:
            formula = form.format(op[0], op[1], op[2], n[0], n[1], n[2], n[3])
            if eval(formula) == 10:
                print(formula)
                return True
    return False

operators = ("+", "-", "*")

forms = (
  "(({3}{0}{4}){1}{5}){2}{6}",
  "({3}{0}{4}){1}({5}{2}{6})",
  "({3}{0}({4}{1}{5})){2}{6}",
  "{3}{0}(({4}{1}{5}){2}{6})",
  "{3}{0}({4}{1}({5}{2}{6}))",
)

while (True):
    nums = tuple(map(int, raw_input().split()))
    if nums == (0,0,0,0):
        break
    for n in itertools.permutations(nums):
        if calc(n):
            break
    else:
        print(0)

Fixed submission:
import itertools

def calc(n):
    for op in itertools.product(operators, repeat=3):
        for form in forms:
            formula = form.format(op[0], op[1], op[2], n[0], n[1], n[2], n[3])
            if eval(formula) == 10:
                print(formula)
                return True
    return False

operators = ("+", "-", "*")

forms = (
  "(({3}{0}{4}){1}{5}){2}{6}",
  "({3}{0}{4}){1}({5}{2}{6})",
  "({3}{0}({4}{1}{5})){2}{6}",
  "{3}{0}(({4}{1}{5}){2}{6})",
  "{3}{0}({4}{1}({5}{2}{6}))",
)

while (True):
    nums = tuple(map(int, input().split()))
    if nums == (0,0,0,0):
        break
    for n in itertools.permutations(nums):
        if calc(n):
            break
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
while True:
        a, b = map(int, input().split())
        print(len(str(a+b)))

Fixed submission:
while True:
    try:
        a, b = map(int, input().split())
        print(len(str(a+b)))
    except:
        break
Buggy python submission (verdict: Runtime Error):
import sys

[print(len(str(y[0] + y[1]))) for y in [[int(z) for z in x.split()] for x in sys.stdin]]

Fixed submission:
[print(y) for y in sorted([int(input()) for x in range(10)], reverse=True)[:3]]

Buggy python submission (verdict: Runtime Error):
import sys

[print(len(str(y[0] + y[1]))) for y in [[int(z) for z in x.split()] for x in sys.stdin]]

Fixed submission:
[print(y) for y in sorted([int(input()) for x in range(10)], reverse=True)[:3]]
Buggy python submission (verdict: Runtime Error):
import math
print(int(math.log10(int(input()) + 1)))

Fixed submission:
import sys
 
[print(len(str(y[0] + y[1]))) for y in [[int(z) for z in x.split()] for x in sys.stdin]]
Buggy python submission (verdict: Runtime Error):
mport math

while True:
    n = int(input().strip())
    if n == 0:
        break
    else:
        line = input().strip().split()
        scores = list(map(float, line))
        sum = 0.0
        ss = 0.0
        for score in scores:
            sum += score
            ss += score ** 2
        sd = math.sqrt((n * ss - sum ** 2) / n ** 2)
        print("%.5f" % sd)

Fixed submission:
import math

while True:
    n = int(input().strip())
    if n == 0:
        break
    else:
        line = input().strip().split()
        scores = list(map(float, line))
        sum = 0.0
        ss = 0.0
        for score in scores:
            sum += score
            ss += score ** 2
        sd = math.sqrt((n * ss - sum ** 2) / n ** 2)
        print("%.5f" % sd)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
s = input().strip().split(" ")
q = int(input().strip())
t = input().strip().split(" ")

count = 0
for i in t:
    if i in s:
        count += 1
print(count)

Fixed submission:
n = int(input().strip())
s = list(map(int, input().strip().split(" ")))
q = int(input().strip())
t = list(map(int, input().strip().split(" ")))

s.sort()
t.sort()

count = 0
index = 0
for number in t:
    while (number > s[index] and index < n - 1):
        index += 1
    if number == s[index]:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, raw_input().split())
if a < b && b < c :
    print "Yes"
else
    print "No"

Fixed submission:
a,b,c = map(int, raw_input().split())
if a < b < c :
    print "Yes"
else :
    print "No"
Buggy python submission (verdict: Runtime Error):
for i in range(1,10):
    for j in range(1,10):
        print str(i) + 'x' + str(j) + '=' + str(i*j)

Fixed submission:
for i in range(1,10):
    for j in range(1,10):
        print str(i) + 'x' + str(j) + '=' + str(i*j)
Buggy python submission (verdict: Runtime Error):
mtlist=[]

while True:
    mtlist.append(input())
    mt
print(list.sort())

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
mtlist=[]

while True:
    mtlist.append(input())
print(list.sort())

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
import sys
heights = sort([ int(h) for h in sys.stdin],reverce)
for h in heights:
    print(h)

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
import sys
heights = sorted([ int(h) for h in sys.stdin],reverce)
for h in heights:
    print(h)

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
import sys
heights = sorted([ int(h) for h in sys.stdin],reverce)
for h in heights:
    print(h)

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
import sys
heights = sort([ int(h) for h in sys.stdin],reverce)
heights[0]
heights[1]
heights[2]

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )

Buggy python submission (verdict: Runtime Error):
import sys
heights = sorted([ int(h) for h in sys.stdin],reverce)
heights[0]
heights[1]
heights[2]

Fixed submission:
import sys
heights = sorted([ int(h) for h in sys.stdin ], reverse=True)
print( heights[0] )
print( heights[1] )
print( heights[2] )
Buggy python submission (verdict: Runtime Error):
import sys
for line in sys.stdin;
    items_sorted = sorted( line.split() , reverse=True )
    print( "{} {}".format( items_sorted[0],items_sorted[1]) )

Fixed submission:
from sys import stdin

for line in range(3000 + 5):
    x , y = map( int, stdin.readline().split() )

    if not ( x + y):
       break

    if x > y:
       x , y = y , x

    print(x, y)
Buggy python submission (verdict: Runtime Error):
f = open('newfile.txt')
all = []
sums = f.read()
f.close()

lines = sums.split('\n')
for i in range(len(lines)):
	all.append(lines[i].split(' '))

for i in range(len(all)):
	keta = str(int(all[i][0]) + int(all[i][1]))
	print(len(list(keta)))

Fixed submission:
import sys
L = sys.stdin.readlines()
for line in L:
	N = line[:-1].split(' ')
	sums = int(N[0]) + int(N[1])
	print(len(str(sums)))

Buggy python submission (verdict: Runtime Error):
while True:
	try:
		N = map(int, input().split(' '))
		sums = N[0] + N[1]
		keta = list(str(sums))
		print(len(kata))
	except EOFError:
		break

Fixed submission:
import sys
L = sys.stdin.readlines()
for line in L:
	N = line[:-1].split(' ')
	sums = int(N[0]) + int(N[1])
	print(len(str(sums)))

Buggy python submission (verdict: Runtime Error):
try:
	lines = []
	while True:
		lines.append(map(int, input().split(' ')))
except EOFError:
	for i in range(len(lines)):
		sums = lines[i][0] + lines[i][1]
		print(len(str(sums)))

Fixed submission:
import sys
L = sys.stdin.readlines()
for line in L:
	N = line[:-1].split(' ')
	sums = int(N[0]) + int(N[1])
	print(len(str(sums)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = int(input())

def fact(s):
	if s == 0 : return 1
	return n * fact(s - 1)

print(fact(s))

Fixed submission:
print(int(input())**3)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

def SquareArea(a, b):
	return str(a * b)

def SideLength(a, b):
	return str((a + b)*2)

print(SquareArea(a, b)???+ " " + SideLength(a, b))

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

def SquareArea(a, b):
	return a * b

def SideLength(a, b):
	return (a + b)*2

print('{} {}'.format(SquareArea(a, b),SideLength(a, b)))
Buggy python submission (verdict: Runtime Error):
a = []
while True:
    n = input()
    if n == 0:
        break
    a.append(n)

for i in range(a):
    print("case " + str(i) + ": " + str(a[i]))

Fixed submission:
a = []
while True:
	n = input()
	if n == "0":
		break
	a.append(n)

for i in range(len(a)):
	print("Case " + str(i + 1) + ": " + a[i])