Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
mport sys
def reviewRe():
    #print ' '.join(map(str,map(str,residence[i][j])))
    for area in range(4):
        for floor in range(3):
            sys.stdout.write(' ')
            print ' '.join(map(str,residence[area][floor][:]))
        print "####################"

def move_in():
    n=input()
    for i in range(n):
        b,f,r,v = map(int,raw_input().split())
        adding(b,f,r,v)

def adding(b,f,r,v):
    residence[b-1][f-1][r-1] = v


if __name__ == '__main__':
    residence = [[[0 for room in range(10)] for floor in range(3)] for area in range(4)]
    move_in()
    reviewRe()

Fixed submission:
import sys
def reviewRe():
    #print ' '.join(map(str,map(str,residence[i][j])))
    for area in range(4):
        for floor in range(3):
            sys.stdout.write(' ')
            print ' '.join(map(str,residence[area][floor][:]))
        if area <= 2:
            print "####################"

def move_in():
    n=input()
    for i in range(n):
        b,f,r,v = map(int,raw_input().split())
        adding(b,f,r,v)

def adding(b,f,r,v):
    residence[b-1][f-1][r-1] += v


if __name__ == '__main__':
    residence = [[[0 for room in range(10)] for floor in range(3)] for area in range(4)]
    move_in()
    reviewRe()
Buggy python submission (verdict: Runtime Error):
 import sys

def input_number():
    for i in range(n):
        adding=map(int,raw_input().split())
        A.append(adding)
    for i in range(m):
        adding=map(int,raw_input().split())
        B.append(adding)

if __name__ == '__main__':
    n,m,l=map(int,raw_input().split())
    A=[]
    B=[]
    ans=[[0 for i in range(n)]for j in range(l)]
    input_number()
    for i in range(n):
        for j in range(l):
            for k in range(m):
                ans[i][j] += A[i][k] * B[k][j]
    for i in range(n):
        for j in range(l):
            sys.stdout.write("%d" % ans[i][j])
            if j != l-1:
                sys.stdout.write(" ")
        sys.stdout.write("\n")

Fixed submission:
import sys

def input_number():
    for i in range(n):
        adding=map(int,raw_input().split())
        A.append(adding)
    for i in range(m):
        adding=map(int,raw_input().split())
        B.append(adding)

if __name__ == '__main__':
    n,m,l=map(int,raw_input().split())
    A=[]
    B=[]
    ans=[[0 for j in range(l)]for i in range(n)]
    input_number()
    for i in range(n):
        for j in range(l):
            for k in range(m):
                ans[i][j] += A[i][k] * B[k][j]
    for i in range(n):
        for j in range(l):
            sys.stdout.write("%d" % ans[i][j])
            if j != l-1:
                sys.stdout.write(" ")
        sys.stdout.write("\n")

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

def input_number():
    for i in range(n):
        adding=map(int,raw_input().split())
        A.append(adding)
    for i in range(m):
        adding=map(int,raw_input().split())
        B.append(adding)

if __name__ == '__main__':
    n,m,l=map(int,raw_input().split())
    A=[]
    B=[]
    ans=[[0 for i in range(n)]for j in range(l)]
    input_number()
    for i in range(n):
        for j in range(l):
            for k in range(m):
                ans[i][j] += A[i][k] * B[k][j]
    for i in range(n):
        for j in range(l):
            sys.stdout.write("%d" % ans[i][j])
            if j != l-1:
                sys.stdout.write(" ")
        sys.stdout.write("\n")

Fixed submission:
import sys

def input_number():
    for i in range(n):
        adding=map(int,raw_input().split())
        A.append(adding)
    for i in range(m):
        adding=map(int,raw_input().split())
        B.append(adding)

if __name__ == '__main__':
    n,m,l=map(int,raw_input().split())
    A=[]
    B=[]
    ans=[[0 for j in range(l)]for i in range(n)]
    input_number()
    for i in range(n):
        for j in range(l):
            for k in range(m):
                ans[i][j] += A[i][k] * B[k][j]
    for i in range(n):
        for j in range(l):
            sys.stdout.write("%d" % ans[i][j])
            if j != l-1:
                sys.stdout.write(" ")
        sys.stdout.write("\n")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    max_value = 0
    for start_i in range(N):
        for end_i in range(start_i + 1, N):
            sum_value = sum(A[start_i:end_i+1])
            if sum_value > max_value:
                max_value = sum_value
    print(max_value)

        

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


def max_seq(A):
    s = []
    s.append(A[0])
    for i in range(1, len(A)):
        v = max(A[i], A[i] + s[i-1])
        s.append(v)
    return max(s)

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math

N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


def max_seq(A):
    s = []
    s.append(A[0])
    for i in range(1, len(A)):
        v = max(A[i], A[i] + s[i-1])
        s.append(v)
    return max(s)

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


def max_seq(A):
    s = []
    s.append(A[0])
    for i in range(1, len(A)):
        v = max(A[i], A[i] + s[i-1])
        s.append(v)
    return max(s)

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

case = 1
for s in sys.stdin:
    W = int(s)
    if W == 0:
        break

    N = int(input())
    values = []
    weights = []
    for i in range(N):
        v, w = map(int, input().split(','))
        values.append(v)
        weights.append(w)

    max_value = 0
    max_value_weight = 0
    for use_flags in itertools.product([0, 1], repeat=len(weights)):

        sum_value = 0
        sum_weight = 0
        for i, use_flag in enumerate(use_flags):
            if use_flag == 1:
                sum_value += values[i]
                sum_weight += weights[i]
        if sum_weight <= W and sum_value > max_value:
            max_value = sum_value
            max_value_weight = sum_weight

    print('Case {}:'.format(case))
    case += 1
    print(max_value)
    print(max_value_weight)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

case = 1
for s in sys.stdin:

    # capacity
    C = int(s)
    if C == 0:
        break

    N = int(input())

    V = [0]
    W = [0]

    # max value table of (N+1) x (C+1)
    VT = [[0 for i in range(C+1)] for j in range(N+1)]
    WT = [[0 for i in range(C+1)] for j in range(N+1)]

    for i in range(N):
        v, w = map(int, input().split(','))
        V.append(v)
        W.append(w)

    for i in range(1, N+1):
        for j in range(1, C+1):
            if j >= W[i]:
                # can load
                value_on_load = VT[i-1][j - W[i]] + V[i]
                value_not_load = VT[i-1][j]

                weight_on_load = WT[i-1][j - W[i]] + W[i]
                weight_not_load = WT[i-1][j]

                if value_on_load > value_not_load:
                    VT[i][j] = value_on_load
                    WT[i][j] = weight_on_load
                elif value_on_load == value_not_load:
                    VT[i][j] = value_on_load
                    WT[i][j] = min(weight_on_load, weight_not_load)
                else:
                    VT[i][j] = value_not_load
                    WT[i][j] = weight_not_load
            else:
                VT[i][j] = VT[i - 1][j]
                WT[i][j] = WT[i - 1][j]

    print('Case {}:'.format(case))
    case += 1
    print(VT[N][C])
    print(WT[N][C])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

for s in sys.stdin:
    n = int(s)

    for i in range(n-1, 3, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 50000):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

for s in sys.stdin:
    n = int(s)

    for i in range(n-1, 0, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 100000, 1):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

for s in sys.stdin:
    n = int(s)

    for i in range(n-1, 3, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 100000, 1):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

for s in sys.stdin:
    n = int(s)

    for i in range(n-1, 0, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 100000, 1):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os

def is_prime(n):
    if n==2 or n==3: return True
    if n%2==0 or n<2: return False
    for i in range(3,int(n**0.5)+1,2):   # only odd numbers
        if n%i==0:
            return False
    return True

primes = [2]
i = 3
while True:
    if is_prime(i):
        primes.append(i)
        if len(primes) > 100000:
            break
    i += 2

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print(sum(subset))

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os

def is_prime_list():
    N = 105000
    lst = [True] * N
    lst[0] = False
    lst[1] = False
    for i in range(2, int(N ** 0.5) + 1):
        if lst[i] == True:
            for j in range(2, N):
                index = i * j
                if index < N:
                    lst[i * j] = False
    return [i for i in range(2, N) if lst[i]]


primes = is_prime_list()
for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print(sum(subset))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os

def is_prime(n):
    if n==2 or n==3: return True
    if n%2==0 or n<2: return False
    for i in range(3,int(n**0.5)+1,2):   # only odd numbers
        if n%i==0:
            return False
    return True

def make_primes():
    primes = [2]
    i = 3
    while True:
        if is_prime(i):
            primes.append(i)
            if len(primes) > 105000:
                break
        i += 2
    return primes

primes = make_primes()
for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print(sum(subset))

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os

def is_prime_list():
    N = 105000
    lst = [True] * N
    lst[0] = False
    lst[1] = False
    for i in range(2, int(N ** 0.5) + 1):
        if lst[i] == True:
            for j in range(2, N):
                index = i * j
                if index < N:
                    lst[i * j] = False
    return [i for i in range(2, N) if lst[i]]


primes = is_prime_list()
for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print(sum(subset))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    m = int(input())

    # adjacency matrix
    M = [[float('inf') for i in range(n)] for j in range(n)]

    for i in range(m):
        a, b, d = map(int, input().split(','))
        M[a][b] = d
        M[b][a] = d

    for i in range(m):
        M[i][i] = 0

    X = []
    Y = [i for i in range(n)]

    X.append(0)
    Y.remove(0)

    light_num = 0
    while len(X) != n:
        lst = []
        for x in X:
            for y in Y:
                dist = M[x][y]
                lst.append((dist, x, y))
        lst.sort()

        # selected node
        dist, x, y = lst[0]
        light_num += (dist // 100) - 1

        if x not in X:
            X.append(x)
            Y.remove(x)
        else:
            X.append(y)
            Y.remove(y)
    print(light_num)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    n = int(s) # node num
    if n == 0:
        break

    m = int(input()) # edge num

    # adjacency matrix
    M = [[float('inf') for i in range(n)] for j in range(n)]

    for i in range(m):
        a, b, d = map(int, input().split(','))
        M[a][b] = d
        M[b][a] = d

    for i in range(n):
        M[i][i] = 0

    X = [] # selected
    Y = [i for i in range(n)] # not selected

    X.append(0)
    Y.remove(0)

    light_num = 0
    while len(X) != n:
        lst = []
        for x in X:
            for y in Y:
                dist = M[x][y]
                lst.append((dist, x, y))
        lst.sort()

        # selected node
        dist, x, y = lst[0]
        light_num += (dist // 100) - 1

        if x not in X:
            X.append(x)
            Y.remove(x)
        else:
            X.append(y)
            Y.remove(y)
    print(light_num)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:

    n = int(s)
    if n == 0:
        break
    P = []

    for i in range(n):
        x, y = map(float, input().split(','))
        P.append(complex(x, y))

    def get_intersections(p0, p1):
        """
        :type p0: complex
        :type p1: complex
        :return:
        """
        dist = abs(p0 - p1)

        if dist > 2:
            return []
        elif dist == 2:
            return [(p0 + p1) / 2]
        else:
            m = (p0 + p1) / 2
            v = m - p0
            w = complex(v.imag, -v.real)
            n = w / abs(w)
            d = abs(v)
            l = math.sqrt(1 - d ** 2)

            inter0 = m + l * n
            inter1 = m - l * n
            return [inter0, inter1]


    intersections = []
    for i in range(n):
        for j in range(i+1, n):
            intersections += get_intersections(P[i], P[j])

    counts = []

    # each intersection, it is in how many circles?
    for intersection in intersections:
        cnt = 0
        for p in P:
            if abs(intersection - p) <= 1:
                cnt += 1
        counts.append(cnt)

    print(max(counts))

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:

    n = int(s)
    if n == 0:
        break
    P = []

    for i in range(n):
        x, y = map(float, input().split(','))
        P.append(complex(x, y))

    def get_intersections(p0, p1):
        """
        :type p0: complex
        :type p1: complex
        :return:
        """
        dist = abs(p0 - p1)

        if dist > 2:
            return []
        elif dist == 2:
            return [(p0 + p1) / 2]
        else:
            m = (p0 + p1) / 2
            v = m - p0
            w = complex(v.imag, -v.real)
            n = w / abs(w)
            d = abs(v)
            l = math.sqrt(1 - d ** 2)

            inter0 = m + l * n
            inter1 = m - l * n
            return [inter0, inter1]


    intersections = []
    for i in range(n):
        for j in range(i+1, n):
            intersections += get_intersections(P[i], P[j])

    counts = []

    # each intersection, it is in how many circles?
    for intersection in intersections:
        cnt = 0
        for p in P:
            if abs(intersection - p) <= 1.01:
                cnt += 1
        counts.append(cnt)

    if counts:
        print(max(counts))
    else:
        print(1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os

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

scores = [0 for i in range(n)]
for i in range(q):
    a, v = map(int, input().split())

    # add
    a -= 1
    scores[a] += v

    max_value = max(scores)
    max_index = scores.index(max_value)

    print(max_index + 1, max_value)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


n, q = map(int, input().split())
scores = [0] * n

max_value = 0
max_index = 0
for i in range(q):
    a, v = map(int, input().split())

    # zero index
    a -= 1
    scores[a] += v

    # need speed than naive implementation

    if max_index == a and v < 0:
        max_value = max(scores)
        max_index = scores.index(max_value)

    elif max_value < scores[a]:
        max_index = a
        max_value = scores[a]

    elif max_value == scores[a] and a < max_index:
        max_index = a

    print(max_index + 1, max_value)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math

m = int(input())
n = int(input())

# Manage people who entered earlier than me in a list
G = [[] for i in range(m)]

for i in range(n):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[y].append(x)

printed = [False] * m

while printed.count(False) > 1:
    # Delete node with degree 0
    for i, node in enumerate(G):
        if not printed[i] and len(node) == 0:
            print(i+1)
            printed[i] = True

            # Erase his existence
            for node in G:
                if i in node:
                    node.remove(i)

# cat
i = printed.index(False)
print(i+1)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math

m = int(input())
n = int(input())

# Manage people who entered earlier than me in a list
G = [[] for i in range(m)]

for i in range(n):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[y].append(x)

printed = [False] * m

while printed.count(False) > 1:

    # Delete node with degree 0
    for i, node in enumerate(G):
        if not printed[i] and len(node) == 0:
            print(i+1)
            printed[i] = True

            # Erase his existence
            for node in G:
                if i in node:
                    node.remove(i)

# cat
if False in printed:
    i = printed.index(False)
    print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_diff = lst[1] - lst[0]

for i in range(N):
    for j in range(i + 1, N):
        diff = lst[j] - lst[i]
        if diff > max_diff:
            max_diff = diff

print(max_diff)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_profit = lst[1] - lst[0]
min_value = min(lst[0], lst[1])

for i in range(2, N):
    price = lst[i]
    max_profit = max(max_profit, price - min_value)
    min_value = min(min_value, price)

print(max_profit)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
from collections import deque


N = int(input())
q = deque()

for i in range(N):
    lst = input().split()
    command = lst[0]
    if command == 'insert':
        v = int(lst[1])
        q.appendleft(v)
    elif command == 'delete':
        v = int(lst[1])
        q.remove(v)
    elif command == 'deleteFirst':
        q.popleft()
    elif command == 'deleteLast':
        q.pop()
print(*list(q))

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
from collections import deque


N = int(sys.stdin.readline())
q = deque()

lines = sys.stdin.readlines()
for s in lines:
    lst = s.split()
    command = lst[0]
    if command == 'insert':
        q.appendleft(lst[1])
    elif command == 'delete':
        try:
            q.remove(lst[1])
        except Exception:
            pass
    elif command == 'deleteFirst':
        q.popleft()
    elif command == 'deleteLast':
        q.pop()

print(*q)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import os


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

# query
q = int(input())
M = list(map(int, input().split()))

def solve(i, m):
    #print('i', i, 'm', m)

    # i????????\???????????????????????£???m??????????????¨???true
    # i = 0, ..., n-1
    if m == 0:
        return True
    elif i >= n:
        return False
    else:
        # Devide and Conquer

        # i??????????????°??????
        res0 = solve(i + 1, m)
        # i??????????????¶
        res1 = solve(i + 1, m - A[i])

        if res0 or res1:
            return True
        else:
            return False


# main
for m in M:
    result = solve(0, m)
    if result:
        print('yes')
    else:
        print('no')

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


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

# query
q = int(input())
M = list(map(int, input().split()))

# i x m matrix
memo = [[None for i in range(2000)] for j in range(n + 1)]

def solve(i, m):
    if memo[i][m] is not None:
        return memo[i][m]
    #print('i', i, 'm', m)

    # i????????\???????????????????????£???m??????????????¨???true
    # i = 0, ..., n-1
    if m == 0:
        return True
    elif i >= n:
        return False
    else:
        # Devide and Conquer

        # i??????????????°??????
        res0 = solve(i + 1, m)
        # i??????????????¶
        res1 = solve(i + 1, m - A[i])

        if res0 or res1:
            memo[i][m] = True
            return True
        else:
            memo[i][m] = False
            return False


# main
for m in M:
    result = solve(0, m)
    if result:
        print('yes')
    else:
        print('no')