Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [-1] * num
    d[0] = 0
    q = Queue()javascript:void(0)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)

    for i, v in enumerate(d):
        print(i+1, v)


main()

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)

    for i, v in enumerate(d):
        print(i+1, v)


main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint


def main():
    num = int(stdin.readline())

    M = []
    for _ in xrange(num):
        M.append([int(s) for s in stdin.readline().split()])

    g = set(xrange(1, num+1))
    index = g.pop()
    h = {index}
    weight = 0

    while g:_
        minimum = maxint
        for j in h:
            mj = M[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]
        h.add(index)
        g.remove(index)
        weight += minimum

    print(weight)


main()

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint


def main():
    num = int(stdin.readline())

    M = []
    for _ in xrange(num):
        M.append([int(s) for s in stdin.readline().split()])

    g = set(xrange(1, num+1))
    index = g.pop()
    h = {index}
    weight = 0

    while g:
        minimum = maxint
        for j in h:
            mj = M[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]
        h.add(index)
        g.remove(index)
        weight += minimum

    print(weight)


main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
cnt = 0
for _ in range(int(stdin.readline())):
    n = int(stdin.readline())
    for i in xrange(2, n):
        if n % i == 0:
            break
    else:
        cnt += 1
print(cnt)

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from math import sqrt
n = int(stdin.readline())
cnt = 0
for _ in range(n):
    v = int(stdin.readline())
    if v == 2:
        cnt += 1
    elif v % 2 == 1:
        for i in xrange(3, int(sqrt(v))+1, 2):
            if v % i == 0:
                break
        else:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
cnt = n = int(stdin.readline())
for _ in range(n):
    v = int(stdin.readline())
    if v == 2:
        continue
    elif v % 2 == 0:
        cnt -= 1
    else:
        for i in xrange(3, v//2, 2):
            if v % i == 0:
                cnt -= 1
                break
print(cnt)

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from math import sqrt
n = int(stdin.readline())
cnt = 0
for _ in range(n):
    v = int(stdin.readline())
    if v == 2:
        cnt += 1
    elif v % 2 == 1:
        for i in xrange(3, int(sqrt(v))+1, 2):
            if v % i == 0:
                break
        else:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def bubble(cards):
    for i in range(len(cards)):
        for j in range(len(cards)-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]


def selection(cards):
    for i in range(len(cards)):
        mini = i
        for j in range(i, len(cards)):
            if cards[j][1] < cards[mini][1]:
                mini = j
        cards[i], cards[mini] = cards[mini], cards[i]


def stable_test(orders, crads):
    for order in orders:
        n = -1
        for c in order:
            p = n
            n = cards.index(c)
            if p > n:
                return False
    return True


stdin.readline()
data1 = stdin.readline().split()
data2 = data1[:]
orders = [[c for c in data1 if s.endswith(str(i))] for i in range(1, 10)]
orders = [o for o in orders if len(s) > 1]

bubble(data1)
print(*data1)
print('Stable' if stable_test(orders, data1) else 'Not stable')

selection(data2)
print(*data2)
print('Stable' if stable_test(orders, data2) else 'Not stable')

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def bubble(cards):
    for i in range(len(cards)):
        for j in range(len(cards)-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]


def selection(cards):
    for i in range(len(cards)):
        mini = i
        for j in range(i, len(cards)):
            if cards[j][1] < cards[mini][1]:
                mini = j
        cards[i], cards[mini] = cards[mini], cards[i]


def stable_test(orders, cards):
    for order in orders:
        n = -1
        for c in order:
            p = n
            n = cards.index(c)
            if p > n:
                return False
    return True


stdin.readline()
data1 = stdin.readline().split()
data2 = data1[:]
orders = [[c for c in data1 if c.endswith(str(i))] for i in range(1, 10)]
orders = [o for o in orders if len(c) > 1]

bubble(data1)
print(*data1)
print('Stable' if stable_test(orders, data1) else 'Not stable')

selection(data2)
print(*data2)
print('Stable' if stable_test(orders, data2) else 'Not stable')
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def solve(a, al, m, i):
    if m == 0:
        return True
    if m > 0 and i < al:
        if solve(a, al, m-a[i], i+1) or solve(a, al, m, i+1):
            return True
    return False


stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]

for m in ms:
    if solve(a, len(a), m, 0):
        print('yes')
    else:
        print('no')

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations


def enum_sum_numbers(sets, s_range, r):
    for cmb in combinations(sets, r):
        yield sum(cmb)
    if r <= s_range:
        for s in enum_sum_numbers(sets, s_range, r+1):
            yield s


stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}

for m in ms:
    print('yes' if m in sets else 'no')

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def solve(a, al, m, i):
    if not m:
        return True
    if m > 0 and i < al:
        if solve(a, al, m-a[i], i+1) or solve(a, al, m, i+1):
            return True
    return False


stdin.readline()
a = [int(s) for s in stdin.readline().split()]
a.sort(reverse=True)
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]

for m in ms:
    if solve(a, len(a), m, 0):
        print('yes')
    else:
        print('no')

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations


def enum_sum_numbers(sets, s_range, r):
    for cmb in combinations(sets, r):
        yield sum(cmb)
    if r <= s_range:
        for s in enum_sum_numbers(sets, s_range, r+1):
            yield s


stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}

for m in ms:
    print('yes' if m in sets else 'no')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def calc_depth(tree, i):
    for j in tree[i][2:]:
        tree[j][0] += 1
        calc_depth(tree, j)


n = int(stdin.readline())
tree = [0] * n
#assert 1 <= n <= 100000
for _ in range(n):
    node = [int(s) for s in stdin.readline().split()]
    tree[node[0]] = [0] + node[1:]

for i in range(n):
    calc_depth(tree, i)

fmt = 'node {}: parent = {}, depth = {}, {}, {}'.format
for i, node in enumerate(tree):
    pa = -1
    for j, n in enumerate(tree):
        if i in n[2:]:
            pa = j
            break
    if pa == -1:
        kind = 'root'
    elif not node[1]:
        kind = 'leaf'
    else:
        kind = 'internal node'
    print(fmt(i, pa, node[0], kind, node[2:]))

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin

FORMAT = ('node {0.id}: parent = {0.parent}, depth = {0.depth},'
          ' {0.kind}, {0.childs}').format


class Node(object):
    def __init__(self, node):
        self.depth = 0
        self.parent = -1
        self.id = node[0]
        self.degree = node[1]
        self.kind = 'internal node' if node[1] else 'leaf'
        self.childs = node[2:]

    def __str__(self):
        return FORMAT(self)


def calc_depth(tree, i):
    for j in tree[i].childs:
        tree[j].depth += 1
        calc_depth(tree, j)


n = int(stdin.readline())
tree = [-1] * n
#assert 1 <= n <= 100000
for _ in range(n):
    node = Node([int(s) for s in stdin.readline().split()])
    i = node.id
    node.parent = tree[i]
    for j in node.childs:
        if isinstance(tree[j], int):
            tree[j] = i
        else:
            tree[j].parent = i
    tree[i] = node

for i in range(n):
    calc_depth(tree, i)

for i, node in enumerate(tree):
    if node.parent == -1:
        node.kind = 'root'
    print(node)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self):
        self.id = None
        self.parent = -1
        self.childs = None


def preorder_walk(data, index, out):
    node = data[index]
    out.append(node.id)
    for cidx in node.childs:
        if cidx >= 0:
            preorder_walk(data, cidx, out)


def inorder_walk(data, index, out):
    node = data[index]
    for cidx in node.childs:
        if cidx >= 0:
            inorder_walk(data, cidx, out)
            if node.id not in out:
                out.append(node.id)
    if node.id not in out:
        out.append(node.id)


def postorder_wark(data, index, out):
    node = data[index]
    for cidx in node.childs:
        if cidx >= 0:
            postorder_wark(data, cidx, out)
    out.append(node.id)


n = int(stdin.readline())
#assert 1 <= n <= 25
data = [Node() for _ in range(n)]
for _ in range(n):
    idx, left, right = (int(s) for s in stdin.readline().split())
    data[idx].id = idx
    data[idx].childs = [left, right]
    for c in data[idx].childs:
        data[c].parent = idx

start = None
for node in data:
    if node.parent == -1:
        start = node.id
        break

for name, func in (('Preorder\n', preorder_walk),
                   ('Inorder\n', inorder_walk),
                   ('Postorder\n', postorder_wark)):
    out = []
    func(data, start, out)
    print(name, *out)

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self):
        self.id = None
        self.parent = -1
        self.childs = None


def preorder_walk(data, index, out):
    node = data[index]
    out.append(node.id)
    for cidx in node.childs:
        if cidx >= 0:
            preorder_walk(data, cidx, out)


def inorder_walk(data, index, out):
    cid = data[index].childs[0]
    if cid >= 0:
        inorder_walk(data, cid, out)
    out.append(data[index].id)
    cid = data[index].childs[1]
    if cid >= 0:
        inorder_walk(data, cid, out)


def postorder_wark(data, index, out):
    node = data[index]
    for cidx in node.childs:
        if cidx >= 0:
            postorder_wark(data, cidx, out)
    out.append(node.id)


n = int(stdin.readline())
#assert 1 <= n <= 25
data = [Node() for _ in range(n)]
for _ in range(n):
    idx, left, right = (int(s) for s in stdin.readline().split())
    data[idx].id = idx
    data[idx].childs = [left, right]
    for c in data[idx].childs:
        if c >= 0:
            data[c].parent = idx

start = None
for node in data:
    if node.parent == -1:
        start = node.id
        break

for name, func in (('Preorder\n', preorder_walk),
                   ('Inorder\n', inorder_walk),
                   ('Postorder\n', postorder_wark)):
    out = []
    func(data, start, out)
    print(name, *out)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def tree_find(node, key):
    if not node:
        return False
    if node.key == key:
        return True
    return tree_find(node.left, key) or tree_find(node.right, key)


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    elif cmd.startswith('f'):
        key = int(cmd[5:])
        r = tree_find(top, key)
        print('yes' if r else 'no')
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def tree_find(node, key):
    if not node:
        return False
    if node.key == key:
        return True
    if key < node.key:
        return tree_find(node.left, key)
    return tree_find(node.right, key)


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    elif cmd.startswith('f'):
        key = int(cmd[5:])
        r = tree_find(top, key)
        print('yes' if r else 'no')
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    n, q = (int(s) for s in stdin.readline().split())
    s = [{i} for i in range(n)]

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            for si in s:
                if x in si and y in si:
                    print(1)
                    break
            else:
                print(0)
        else:
            for si in s:
                if x in si:
                    a = si
                elif y in si:
                    b = si
            s.append(a | b)
            s.remove(a)
            s.remove(b)


main()

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    n, q = (int(s) for s in stdin.readline().split())
    s = [{i} for i in range(n)]

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x in s[x] and y in s[x]:
                print(1)
            else:
                print(0)
        else:
            a = s[x]
            b = s[y]
            if a is not b:
                a |= b
                for i in a:
                    s[i] = a


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    n, q = (int(s) for s in stdin.readline().split())
    s = [{i} for i in range(n)]

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            for si in s:
                if x in si and y in si:
                    print(1)
                    break
            else:
                print(0)
        else:
            for si in s:
                if x in si:
                    a = si
                if y in si:
                    b = si
            if a != b:
                s.append(a | b)
                s.remove(a)
                s.remove(b)


main()

Fixed submission:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    n, q = (int(s) for s in stdin.readline().split())
    s = [{i} for i in range(n)]

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x in s[x] and y in s[x]:
                print(1)
            else:
                print(0)
        else:
            a = s[x]
            b = s[y]
            if a is not b:
                a |= b
                for i in a:
                    s[i] = a


main()
Buggy python submission (verdict: Runtime Error):
print('{0[0]} {0[1]} {0[2]:.5f}'.format(
      (lambda a, b: (a // b, a % d, a / b))(
       *map(int, input().split())))

Fixed submission:
from __future__ import division, print_function
from sys import stdin
a, b = (int(s) for s in stdin.readline().split())
print(a // b, a % b, '{:.6f}'.format(a / b))

Buggy python submission (verdict: Runtime Error):
print('{0[0]} {0[1]} {0[2]:.6f}'.format(
      (lambda a, b: (a // b, a % d, a / b))(
       *map(int, input().split())))

Fixed submission:
from __future__ import division, print_function
from sys import stdin
a, b = (int(s) for s in stdin.readline().split())
print(a // b, a % b, '{:.6f}'.format(a / b))

Buggy python submission (verdict: Runtime Error):
print('{0[0]} {0[1]} {0[2]}'.format(
      (lambda a, b: (a // b, a % d, a / b))(
       *map(int, input().split())))

Fixed submission:
from __future__ import division, print_function
from sys import stdin
a, b = (int(s) for s in stdin.readline().split())
print(a // b, a % b, '{:.6f}'.format(a / b))

Buggy python submission (verdict: Runtime Error):
print('{0[0]} {0[1]} {0[2]}'.format(
      (lambda a, b: (a // b, a % b, a / b))(
       *map(int, input().split())))

Fixed submission:
from __future__ import division, print_function
from sys import stdin
a, b = (int(s) for s in stdin.readline().split())
print(a // b, a % b, '{:.6f}'.format(a / b))
Buggy python submission (verdict: Runtime Error):
(lambda *_: None)(*map(print,
                       map(eval,
                           map(lambda s: s.replace('/', '//'),
                               iter(input, '0 ? 0')))))

Fixed submission:
from __future__ import division, print_function
from sys import stdin, exit
from operator import add, sub, mul, floordiv
d = {'+': add, '-': sub, '*': mul, '/': floordiv, '?': lambda a,b: exit(0)}
while True:
    a, op, b = stdin.readline().split()
    print(d[op](int(a), int(b)))

Buggy python submission (verdict: Runtime Error):
(lambda *_: None)(*map(print,
                       map(eval,
                           map(lambda s: s.replace('/', '//'),
                               iter(input, '0 ? 0')))))

Fixed submission:
from __future__ import division, print_function
from sys import stdin, exit
from operator import add, sub, mul, floordiv
d = {'+': add, '-': sub, '*': mul, '/': floordiv, '?': lambda a,b: exit(0)}
while True:
    a, op, b = stdin.readline().split()
    print(d[op](int(a), int(b)))

Buggy python submission (verdict: Runtime Error):
from itertools import takewhile
(lambda *_: None)(*map(print,
                       map(eval,
                           map(lambda s: s.replace('/', '//'),
                               takewhile(lambda s: '?' not in s,
                                         iter(input))))))

Fixed submission:
from __future__ import division, print_function
from sys import stdin, exit
from operator import add, sub, mul, floordiv
d = {'+': add, '-': sub, '*': mul, '/': floordiv, '?': lambda a,b: exit(0)}
while True:
    a, op, b = stdin.readline().split()
    print(d[op](int(a), int(b)))

Buggy python submission (verdict: Runtime Error):
from itertools import takewhile
(lambda *_: None)(*map(print,
                       map(eval,
                           map(lambda s: s.replace('/', '//'),
                               takewhile(lambda s: '?' not in s,
                                         iter(input, '')))))

Fixed submission:
from __future__ import division, print_function
from sys import stdin, exit
from operator import add, sub, mul, floordiv
d = {'+': add, '-': sub, '*': mul, '/': floordiv, '?': lambda a,b: exit(0)}
while True:
    a, op, b = stdin.readline().split()
    print(d[op](int(a), int(b)))
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>
int main(void) {
	char in[201], tmp[201];
	int m, n, i, j;

	while (1) {
		scanf("%200s ", in);
		if (in[0] == '-')
			break;

		scanf("%d ", &m);
		while (m--) {
			scanf("%d ", &n);
			for (i = 0; in[i+n] != '\0'; i++) {
				tmp[i] = in[i+n];
			}
			for (j = 0; j < n; j++) {
				tmp[i+j] = in[j];
			}
			tmp[i+j] = '\0';
			for (i = 0; tmp[i] != '\0'; i++) {
				in[i] = tmp[i];
			}
		}
		puts(in);
	}
	return 0;
}

Fixed submission:
from __future__ import division, print_function
from sys import stdin
while True:
    cards = stdin.readline().rstrip()
    if cards.startswith('-'):
        break
    for _ in range(int(stdin.readline())):
        n = int(stdin.readline())
        cards = cards[n:] + cards[:n]
    print(cards)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n=int(input())

for line in stdin:
    x=list(map(int,line.split()))
    x.sort()
    y=map(lambda t:t^2,x)
    if y[0]+y[1]==y[2]: print("YES")
    else: print("NO")

Fixed submission:
import sys

for line in sys.stdin: print(len(str(sum(map(int,line.split())))))