Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    while True:
        n = int(input())
        if n == 0:
            exit()
        f = [s for input().split()]
        pm = 'd'
        cnt = 0
        for m in f:
            if m[1] == pm:
                cnt += 1
            pm = m[1]
        print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    while True:
        n = int(input())
        if n == 0:
            exit()
        f = [s for s in input().split()]
        pm = 'd'
        cnt = 0
        for m in f:
            if m[1] == pm:
                cnt += 1
            pm = m[1]
        print(cnt)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
max_v = A[1] - A[0]

l = 0
r = 1
while r + 1 < N:
    if A[l] > A[r]:
        l = r
    elif A[r] > A[r + 1]:
        max_v = max(max_v, A[r] - A[l])
        if A[l] > A[r + 1]:
            l = r + 1
            r = l
    r += 1
max_v = max(max_v, A[r] - A[l])
print(max_v)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
max_v = A[1] - A[0]

l = 0
r = 1
while r + 1 < N:
    if A[l] > A[r]:
        l = r
    elif A[r] > A[r + 1]:
        max_v = max(max_v, A[r] - A[l])
        if A[l] > A[r + 1]:
            l = r + 1
            r = l
    r += 1
if r<N:
    max_v = max(max_v, A[r] - A[l])
print(max_v)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

dq = collections.deque()
N, Q = map(int, input().split())
for i in range(N):
    name, time = input().split()
    dq.append((name, int(time)))
total_time = 0
while dq:
    name, time = dq.popleft()
    total_time += min(Q, time)
    if time <= Q:
        print(name, total_time)
    else:
        dq.append((name, time))

Fixed submission:
import collections

dq = collections.deque()
N, Q = map(int, input().split())
for i in range(N):
    name, time = input().split()
    dq.append((name, int(time)))
total_time = 0
while dq:
    name, time = dq.popleft()
    total_time += min(Q, time)
    if time <= Q:
        print(name, total_time)
    else:
        dq.append((name, time-Q))
Buggy python submission (verdict: Runtime Error):
V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    nodes[s].append(t)
    cost[s].append(d)

dist = [float('inf')] * V
dist[root] = 0

negative_cycle = False

for k in range(V):
    for i in range(V):
        for j in range(nodes[i]):
            if dist[nodes[i][j]] > dist[i] + cost[i][j]:
                dist[nodes[i][j]] = dist[i] + cost[i][j]
                if k==n-1:
                    dist[nodes[i][j]] = -float('inf')
                    negative_cycle = True
if negative_cycle:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        if dist[i] == float('inf'):
            print('INF')
        else:
            print(dist[i])

Fixed submission:
V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    nodes[s].append(t)
    cost[s].append(d)

dist = [float('inf')] * V
dist[root] = 0

negative_cycle = False

for k in range(V):
    for i in range(V):
        for j in range(len(nodes[i])):
            if dist[nodes[i][j]] > dist[i] + cost[i][j]:
                dist[nodes[i][j]] = dist[i] + cost[i][j]
                if k == V - 1:
                    dist[nodes[i][j]] = -float('inf')
                    negative_cycle = True
if negative_cycle:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        if dist[i] == float('inf'):
            print('INF')
        else:
            print(dist[i])
Buggy python submission (verdict: Time Limit Exceeded):
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    count = 0
    for i in range(2, n + 1):
        for j in range(2, i):
            if i % j == 0:
                break
        else:
            count += 1
    print count

Fixed submission:
N = 10 ** 6
sieve = map(lambda x:False, range(2, N + 1))
for i in range(2, N + 1):
    if sieve[i - 2]:
        continue
    for j in range(i * 2, N + 1, i):
        sieve[j - 2] = True
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    print sieve[:n - 1].count(False)

Buggy python submission (verdict: Time Limit Exceeded):
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    sieve = map(lambda x:False, range(2, n + 1))
    for i in range(2, n + 1):
        if sieve[i - 2]:
            continue
        for j in range(i * 2, n + 1, i):
            sieve[j - 2] = True
    print sieve.count(False)

Fixed submission:
N = 10 ** 6
sieve = map(lambda x:False, range(2, N + 1))
for i in range(2, N + 1):
    if sieve[i - 2]:
        continue
    for j in range(i * 2, N + 1, i):
        sieve[j - 2] = True
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    print sieve[:n - 1].count(False)
Buggy python submission (verdict: Runtime Error):
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except EOFError:
        break

Fixed submission:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except ValueError:
        break

Buggy python submission (verdict: Runtime Error):
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except EOFError:
        break

Fixed submission:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except ValueError:
        break

Buggy python submission (verdict: Runtime Error):
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
            if len(garage) == 0:
                break
        else:
            garage.append(came)

Fixed submission:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except ValueError:
        break

Buggy python submission (verdict: Runtime Error):
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except EOFError:
        break

Fixed submission:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except ValueError:
        break
Buggy python submission (verdict: Runtime Error):
while True:
    d = int(raw_input())
    print reduce(lambda x,y:x+y,map(lambda x:d*x*x,range(d, 600, d)))

Fixed submission:
while True:
    try:
        d = int(raw_input())
    except EOFError:
        break
    if d == 600:
        print 0
    else:
        rects = map(lambda x:d*x*x,range(d, 600, d))
        print reduce(lambda x,y:x+y,rects)

Buggy python submission (verdict: Runtime Error):
while True:
    try:
        d = int(raw_input())
    except EOFError:
        break
    print reduce(lambda x,y:x+y,map(lambda x:d*x*x,range(d, 600, d)))

Fixed submission:
while True:
    try:
        d = int(raw_input())
    except EOFError:
        break
    if d == 600:
        print 0
    else:
        rects = map(lambda x:d*x*x,range(d, 600, d))
        print reduce(lambda x,y:x+y,rects)

Buggy python submission (verdict: Runtime Error):
while True:
    try:
        d = int(raw_input())
    except EOFError:
        break
    rects = map(lambda x:d*x*x,range(d, 600, d))
    print reduce(lambda x,y:x+y,rects)

Fixed submission:
while True:
    try:
        d = int(raw_input())
    except EOFError:
        break
    if d == 600:
        print 0
    else:
        rects = map(lambda x:d*x*x,range(d, 600, d))
        print reduce(lambda x,y:x+y,rects)
Buggy python submission (verdict: Runtime Error):
import sys
l = []
c = list([0] * 100)
for i in sys.stdin.readlines():
    c[int(i)] += 1
m = max(c)
for i in xrange(c.count(m)):
    i = c.index(m)
    print i + 1
    c.pop(i)

Fixed submission:
l = []
c = list([0] * 100)
while True:
    try:
        c[int(raw_input()) - 1] += 1
    except:
        break
m = max(c)
for i in xrange(c.count(m)):
    j = c.index(m)
    print j + 1
    c[j] = 0

Buggy python submission (verdict: Runtime Error):
import sys
l = []
c = list([0] * 100)
for i in sys.stdin.readlines():
    c[int(i - 1)] += 1
m = max(c)
for i in xrange(c.count(m)):
    i = c.index(m)
    print i + 1
    c.pop(i)

Fixed submission:
l = []
c = list([0] * 100)
while True:
    try:
        c[int(raw_input()) - 1] += 1
    except:
        break
m = max(c)
for i in xrange(c.count(m)):
    j = c.index(m)
    print j + 1
    c[j] = 0
Buggy python submission (verdict: Runtime Error):
while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    r = xrange(10**(n-1),10**n)
    r = map(str,r)
    r = filter(lambda x:len(set(x)) == len(x),r)
    r = map(lambda x:map(int,x),r)
    r = filter(lambda x:reduce(lambda x,y:x+y,x) == s, r)
    print len(r)

Fixed submission:
def dfs(n, sum ,depth):
    if(depth == 0):
        return int(sum == s)
    else:
        count = 0
        for i in xrange(n+1,10):
            count += dfs(i, sum+i, depth-1)
        return count

while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    print dfs(-1,0,n)

Buggy python submission (verdict: Time Limit Exceeded):
def div(n,m):
    try:
        return n/m
    except ZeroDivisionError:
        return 0
def degit(n, m):
    r = []
    b = -1
    for i in xrange(m):
        s = div(n%(10**(i+1)),(10**i))
        if(b<s):
            b = s
            r.append(s)
    if(len(r) == m):
        return r
while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    ans = 0
    for i in xrange(10**n):
        r = degit(i,n)
        if(r==None):
            continue
        if(len(r)!=len(list(set(r)))):
            continue
        if(reduce(lambda x,y:x+y,r) == s):
            ans += 1
    print ans

Fixed submission:
def dfs(n, sum ,depth):
    if(depth == 0):
        return int(sum == s)
    else:
        count = 0
        for i in xrange(n+1,10):
            count += dfs(i, sum+i, depth-1)
        return count

while True:
    (n, s) = [int(i) for i in raw_input().split()]
    if((0,0) == (n,s)):
        break
    print dfs(-1,0,n)
Buggy python submission (verdict: Runtime Error):
while True:
    string = raw_input()
    strings = strings.split()
    a = int(strings[0])
    op = strings[1]
    b = int(strings[2])
    if op == '?':
        break
    elif op == '+':
        print a + b
    elif op == '-':
        print a - b
    elif op == '*':
        print a * b
    elif op == '/':
        print a / b

Fixed submission:
while True:
    string = raw_input()
    strings = string.split()
    a = int(strings[0])
    op = strings[1]
    b = int(strings[2])
    if op == '?':
        break
    elif op == '+':
        print a + b
    elif op == '-':
        print a - b
    elif op == '*':
        print a * b
    elif op == '/':
        print a / b
Buggy python submission (verdict: Runtime Error):
raw_input()
for i in raw_input().split().reverse():
    print i,

Fixed submission:
raw_input()
l = raw_input().split()
l.reverse()
for i in l:
    print i,
Buggy python submission (verdict: Runtime Error):
loop = int(raw_input())
have_card = []
for i in range(i):
    have_card.append(raw_input())
for i in range(4):
    if i == 0:
        g = 'S'
    elif i == 1:
        g = 'H'
    elif i == 2:
        g = 'C'
    elif i == 3:
        g = 'D'
    for j in range(1, 14):
        card = g + ' ' + str(j)
        if not card in have_card:
            print card

Fixed submission:
loop = int(raw_input())
have_card = []
for i in range(loop):
    have_card.append(raw_input())
for i in range(4):
    if i == 0:
        g = 'S'
    elif i == 1:
        g = 'H'
    elif i == 2:
        g = 'C'
    elif i == 3:
        g = 'D'
    for j in range(1, 14):
        card = g + ' ' + str(j)
        if not card in have_card:
            print card
Buggy python submission (verdict: Runtime Error):
string = ''
while True:
    string_l = raw_input()
    if string_l:
        string += string_l
    else:
        break
string = string.lower()
a = ord('a')
for i in range(a, a+26):
    print chr(i), ':', string.count(chr(i))

Fixed submission:
string = ''
while True:
    try:
        string += raw_input()
    except EOFError:
        break
string = string.lower()
a = ord('a')
for i in range(a, a+26):
    print chr(i), ':', string.count(chr(i))
Buggy python submission (verdict: Runtime Error):
W = raw_input().lower()
T = []
while True:
    TL = raw_input()
    if(TL == 'END_OF_TEXT'):
        break
    else:
        T += TL.split()
map(lower, T)
print T.count(W)

Fixed submission:
word = raw_input().lower()
text = []
while True:
    line = raw_input()
    if line == 'END_OF_TEXT':
        break
    else:
        text += line.lower().split()
print text.count(word)
Buggy python submission (verdict: Runtime Error):
import math
x1, y1, x2, y2 = [int(i) for i in raw_input().split()]
print math.sqrt(abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2)

Fixed submission:
import math
x1, y1, x2, y2 = [float(i) for i in raw_input().split()]
print math.sqrt(abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2)
Buggy python submission (verdict: Time Limit Exceeded):
raw_input()
S = map(int, raw_input().split())
raw_input()
T = map(int, raw_input().split())
count = 0
for i in T:
    if(i in S):
        count += 1
print count

Fixed submission:
raw_input()
S = set(map(int, raw_input().split()))
raw_input()
T = set(sorted(map(int, raw_input().split())))
print len(S) - len(S - T)

Buggy python submission (verdict: Time Limit Exceeded):
raw_input()
S = map(int, raw_input().split())
raw_input()
T = sorted(map(int, raw_input().split()))
count = 0
for i in T:
    if(i in S):
        count += 1
print count

Fixed submission:
raw_input()
S = set(map(int, raw_input().split()))
raw_input()
T = set(sorted(map(int, raw_input().split())))
print len(S) - len(S - T)
Buggy python submission (verdict: Runtime Error):
raw_input()
S = map(int, raw_input().split())
T = map(int, raw_input().split())
count = 0
for i in T:
    if(S in i):
        count += 1
print count

Fixed submission:
raw_input()
S = map(int, raw_input().split())
raw_input()
T = map(int, raw_input().split())
count = 0
for i in T:
    if(i in S):
        count += 1
print count
Buggy python submission (verdict: Runtime Error):
turn = int(raw_input())
taro, hanako = 0
for i in range(turn):
    t_card, h_card = [raw_input().split()]
    if t_card > h_card:
        taro += 3
    elif t_card < h_card:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print taro, hanako

Fixed submission:
turn = int(raw_input())
taro = hanako = 0
for i in range(turn):
    (t_card, h_card) = raw_input().split()
    if t_card > h_card:
        taro += 3
    elif t_card < h_card:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print taro, hanako

Buggy python submission (verdict: Runtime Error):
turn = int(raw_input())
taro = 0
hanako = 0
for i in range(turn):
    t_card, h_card = [raw_input().split()]
    if t_card > h_card:
        taro += 3
    elif t_card < h_card:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print taro, hanako

Fixed submission:
turn = int(raw_input())
taro = hanako = 0
for i in range(turn):
    (t_card, h_card) = raw_input().split()
    if t_card > h_card:
        taro += 3
    elif t_card < h_card:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print taro, hanako
Buggy python submission (verdict: Runtime Error):
mountain = []
removed = []
while True:
    command = raw_input()
    if command.split()[0] == 'push':
        mountain.append(command.split()[1])
    elif command.split()[0] == 'pop':
        removed.append(mountain[-1])
        mountain.pop(-1)
    elif command.split()[0] == 'quit':
        print ' '.join(removed)

Fixed submission:
mountain = []
removed = []
while True:
    command = raw_input()
    if command.split()[0] == 'push':
        mountain.append(command.split()[1])
    elif command.split()[0] == 'pop':
        removed.append(mountain[-1])
        mountain.pop(-1)
    elif command.split()[0] == 'quit':
        break
for block in removed:
    print block

Buggy python submission (verdict: Time Limit Exceeded):
mountain = []
removed = []
while True:
    try:
        command = raw_input()
    except EOFError:
        pass
    if command.split()[0] == 'push':
        mountain.append(command.split()[1])
    elif command.split()[0] == 'pop':
        removed.append(mountain[-1])
        mountain.pop(-1)
    elif command.split()[0] == 'quit':
        print ' '.join(removed)

Fixed submission:
mountain = []
removed = []
while True:
    command = raw_input()
    if command.split()[0] == 'push':
        mountain.append(command.split()[1])
    elif command.split()[0] == 'pop':
        removed.append(mountain[-1])
        mountain.pop(-1)
    elif command.split()[0] == 'quit':
        break
for block in removed:
    print block
Buggy python submission (verdict: Runtime Error):
mountain = [[]] * int(raw_input())
removed = []
while True:
    command = raw_input().split()
    if command[0] == 'push':
        mountain[int(command[1])].append(command[2])
    elif command[0] == 'pop':
        removed.append(mountain[int(command[1])][-1])
        mountain[int(command[1])].pop(-1)
    elif command[0] == move:
        mountain[int(command[2])].append(mountain[int(command[1])][-1])
        mountain[int(command[1])].pop(-1)
    elif command[0] == 'quit':
        break
for block in removed:
    print block

Fixed submission:
mountain = map(lambda x:[], range(int(raw_input())))
removed = []
while True:
    command = raw_input().split()
    if command[0] == 'push':
        mountain[int(command[1]) - 1].append(command[2])
    elif command[0] == 'pop':
        removed.append(mountain[int(command[1]) - 1][-1])
        mountain[int(command[1]) - 1].pop(-1)
    elif command[0] == 'move':
        mountain[int(command[2]) - 1].append(mountain[int(command[1]) - 1][-1])
        mountain[int(command[1]) - 1].pop(-1)
    elif command[0] == 'quit':
        break
for block in removed:
    print block

Buggy python submission (verdict: Runtime Error):
mountain = [[]] * int(raw_input())
removed = []
while True:
    command = raw_input().split()
    if command[0] == 'push':
        mountain[int(command[1])].append(command[2])
    elif command[0] == 'pop':
        removed.append(mountain[int(command[1])][-1])
        mountain[int(command[1])].pop(-1)
    elif command[0] == 'move':
        mountain[int(command[2])].append(mountain[int(command[1])][-1])
        mountain[int(command[1])].pop(-1)
    elif command[0] == 'quit':
        break
for block in removed:
    print block

Fixed submission:
mountain = map(lambda x:[], range(int(raw_input())))
removed = []
while True:
    command = raw_input().split()
    if command[0] == 'push':
        mountain[int(command[1]) - 1].append(command[2])
    elif command[0] == 'pop':
        removed.append(mountain[int(command[1]) - 1][-1])
        mountain[int(command[1]) - 1].pop(-1)
    elif command[0] == 'move':
        mountain[int(command[2]) - 1].append(mountain[int(command[1]) - 1][-1])
        mountain[int(command[1]) - 1].pop(-1)
    elif command[0] == 'quit':
        break
for block in removed:
    print block
Buggy python submission (verdict: Runtime Error):
while True:
 try:
  a=int(input())
  b=int(input())
  print len(str(a+b))
 except EOFError: break

Fixed submission:
while True:
    try:
        a,b = raw_input().split()
        print len(str(int(a)+int(b)))
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
x = int(input())
for a in range(x):
 y = map(int,raw_input(),split())
  sort(y[3])


if y[2]**2-y[1]**2 == y[0]**2:
  print "YES"
else:
  print "NO"

Fixed submission:
for i in range(input()):
    q = map(int,raw_input().split())
    q.sort()
    a = "YES" if q[0]**2 + q[1]**2 == q[2]**2 else "NO"
    print a
Buggy python submission (verdict: Runtime Error):
while True:
  try:
    q = map(int,raw_input().split(" "))
    y = (-1*q[0]*q[5] + q[2] * q[3]) / (-1*q[0] * q[4] + q[1] * q[3])
    x = (q[5]-q[4]* y)/ q[3]

    if x == -0 or  y == -0 : 
      x == 0   
      y == 0
    print "%.3f %.3f" % (x,y)
  except EOFError:
    break

Fixed submission:
while True:
    try:
        x = map(float, raw_input().split(" "))
        a = (x[2]*x[4]-x[1]*x[5])/(x[0]*x[4]-x[1]*x[3])
        b = (-x[3]*x[2]+x[0]*x[5])/(x[0]*x[4]-x[1]*x[3])
         
        if a == -0: a = 0
        if b == -0: b = 0
         
        print "%.3f %.3f" % (a, b)
     
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
str1 = raw_input() print "".join(reversed(str1))

Fixed submission:
str1 = raw_input() 
print "".join(reversed(str1))
Buggy python submission (verdict: Runtime Error):
ans = []
while True:
  try:
    a = input()
    if a != 0: ans.append(a)
    elif a == 0: 
      print ans[-1]
      del ans[-1]
  except EOFError: break

Fixed submission:
ans = []
while True:
  try:
    a = input()
    if a != 0: ans.append(a)
    elif a == 0: 
      print ans[-1]
      del ans[-1]
  except EOFError: break
  except SyntaxError: continue
Buggy python submission (verdict: Runtime Error):
import sys
while True:
  a=int(input())
  if a==0: break
  ans,name1,name2=[],[],[]
  hogehoge=0
  for i in range(a):
    hoge=map(int,raw_input().split())
    if hoge[0] in name2:
      ww = hoge[1]*hoge[2]
      r = name2.index(hoge[0])
      if len(ans[r]+ww) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else:
        ans[r]+=ww
    else:
      qq = hoge[1]*hoge[2]
      if len(str(qq)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else: 
        name2.append(hoge[0])
        ans.append(qq)
  if hogehoge == 0: print "NA"
  else: 
    for i in range(len(name1)):
      print name1[i]

Fixed submission:
import sys
while True:
  a=int(input())
  if a==0: break
  ans,name1,name2=[],[],[]
  hogehoge=0
  for i in range(a):
    hoge=map(int,raw_input().split())
    if hoge[0] in name2:
      ww = hoge[1]*hoge[2]
      r = name2.index(hoge[0])
      if len(str(ans[r]+ww)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else:
        ans[r]+=ww
    else:
      qq = hoge[1]*hoge[2]
      if len(str(qq)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else: 
        name2.append(hoge[0])
        ans.append(qq)
  if hogehoge == 0: print "NA"
  else: 
    for i in range(len(name1)):
      print name1[i]