Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 1, 0
stack = []
d[current] = time
while 0 in f:
    if not stack:
        stack.append(0)
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)

Fixed submission:
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 0, 0
stack = []
while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 1, 0
stack = []
d[current] = time
while 0 in f:
    if not stack:
        stack.append(0)
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)

Fixed submission:
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 0, 0
stack = []
while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    visited = [False] * n

    while not all(visited):
        dmin = inf
        for i, (d, v) in enumerate(zip(dist, visited)):
            if dmin > d and not v:
                dmin, u = d, i
        visited[u] = True
        for (v, c) in edge[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)

Fixed submission:
import heapq


def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    q = [(0, 0)]
    while q:
        u = heapq.heappop(q)[1]
        for (v, c) in edge[u]:
            alt = dist[u] + c
            if dist[v] > alt:
                dist[v] = alt
                heapq.heappush(q, (alt, v))
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    visited = [False] * n

    while not all(visited):
        dmin = inf
        for i, (d, v) in enumerate(zip(dist, visited)):
            if v:
                continue
            elif dmin > d:
                dmin, u = d, i
        visited[u] = True
        for (v, c) in edge[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)

Fixed submission:
import heapq


def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    q = [(0, 0)]
    while q:
        u = heapq.heappop(q)[1]
        for (v, c) in edge[u]:
            alt = dist[u] + c
            if dist[v] > alt:
                dist[v] = alt
                heapq.heappush(q, (alt, v))
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)
Buggy python submission (verdict: Runtime Error):
from collections import deque

dq = deque()
n = int(input())
for _ in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        dq.appendleft(cmd[1])
    elif cmd[0] == "delete":
        dq.remove(cmd[1])
    elif cmd[0] == "deleteFirst":
        dq.popleft()
    else:
        dq.pop()
print(*dq)

Fixed submission:
from collections import deque

dq = deque()
n = int(input())
for _ in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        dq.appendleft(cmd[1])
    elif cmd[0] == "delete":
        try:
            dq.remove(cmd[1])
        except ValueError:
            pass
    elif cmd[0] == "deleteFirst":
        dq.popleft()
    else:
        dq.pop()
print(*dq)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dictionary = []

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.append(arg)
    elif cmd == "find":
        if arg in dictionary:
            print("yes")
        else:
            print("no")

Fixed submission:
n = int(input())
dictionary = set()

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.add(arg)
    elif cmd == "find":
        if arg in dictionary:
            print("yes")
        else:
            print("no")

Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(dic, word, imin, imax):
    if imax < imin:
        return "no"
    imid = imin + (imax - imin) // 2
    if dic[imid] > word:
        return binary_search(dic, word, imin, imid - 1)
    elif dic[imid] < word:
        return binary_search(dic, word, imid + 1, imax)
    else:
        return "yes"


n = int(input())
dictionary = []

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.append(arg)
        dictionary.sort()
    elif cmd == "find":
        print(binary_search(dictionary, arg, 0, len(dictionary) - 1))

Fixed submission:
n = int(input())
dictionary = set()

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.add(arg)
    elif cmd == "find":
        if arg in dictionary:
            print("yes")
        else:
            print("no")
Buggy python submission (verdict: Time Limit Exceeded):
def exhaustive_search(arr, num):
    for bit in range(1 << len(arr)):
        total = 0
        for i in range(len(arr)):
            if 1 & (bit >> i) == 1:
                total += arr[i]
            if total == num:
                return "yes"
    return "no"

input()
A = [int(x) for x in input().split()]
input()
ms = [int(x) for x in input().split()]
for m in ms:
    print(exhaustive_search(A, m))

Fixed submission:
input()
A = [int(x) for x in input().split()]
input()
ms = [int(x) for x in input().split()]

enable_create = [False]*2000
for bit in range(1 << len(A)):
    n = 0
    for i in range(len(A)):
        if 1 & (bit >> i) == 1:
            n += A[i]
    enable_create[n] = True

for m in ms:
    print("yes" if enable_create[m] else "no")
Buggy python submission (verdict: Time Limit Exceeded):
def merge(A, left, mid, right):
    global cnt
    n1, n2 = mid - left, right - mid
    L, R = [], []
    for i in range(n1):
        L.append(A[left + i])
    for i in range(n2):
        R.append(A[mid + i])
    L.append(float('inf'))
    R.append(float('inf'))
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


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


cnt = 0
input()
A = list(map(int, input().split()))
merge_sort(A, 0, len(A))
print(*A)
print(cnt)

Fixed submission:
def merge(A, left, mid, right):
    global cnt
    inf = 1000000001
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


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


cnt = 0
input()
A = list(map(int, input().split()))
merge_sort(A, 0, len(A))
print(*A)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def merge(A, left, mid, right):
    global cnt
    inf = 1000000001
    n1, n2 = mid - left, right - mid
    L, R = [], []
    for i in range(n1):
        L.append(A[left + i])
    for i in range(n2):
        R.append(A[mid + i])
    L.append(inf)
    R.append(inf)
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


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


cnt = 0
input()
A = list(map(int, input().split()))
merge_sort(A, 0, len(A))
print(*A)
print(cnt)

Fixed submission:
def merge(A, left, mid, right):
    global cnt
    inf = 1000000001
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        cnt += 1


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


cnt = 0
input()
A = list(map(int, input().split()))
merge_sort(A, 0, len(A))
print(*A)
print(cnt)
Buggy python submission (verdict: Runtime Error):
def partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


def suitlist(cards):
    suits = [[]]*len(cards)
    for card in cards:
        suits[int(card[1])].append(card[0])
    return suits


def is_stable(before, after):
    suits_b = suitlist(before)
    suits_a = suitlist(after)
    for a, b in zip(suits_b, suits_a):
        if a != b:
            return False
    return True


n = int(input())
cards = []
origin = cards.copy()
for _ in range(n):
    cards.append(input().split())
origin = cards.copy()
quicksort(cards, 0, n - 1)
print("Stable" if is_stable(origin, cards) else "Not stable")
for card in cards:
    print(*card)

Fixed submission:
def partition(A, p, r):
    x = int(A[r][1])
    i = p-1
    for j in range(p, r):
        if int(A[j][1]) <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


def is_stable(cards):
    for i in range(1, len(cards)):
        if cards[i-1][1] == cards[i][1]:
            if cards[i-1][2] > cards[i][2]:
                return False
    return True


n = int(input())
cards = []
for i in range(n):
    cards.append(input().split() + [i])
quicksort(cards, 0, n - 1)
print("Stable" if is_stable(cards) else "Not stable")
for card in cards:
    print(card[0], card[1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def max_heapify(A, i):
    H = len(A) - 1
    l, r = i * 2 + 1, i * 2 + 2
    if l <= H and A[l] > A[i]:
            largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)


def build_max_heap(A):
    for i in range(len(A) // 2, -1, -1):
        max_heapify(A, i)


def insert(S, k):
    S.append(k)
    build_max_heap(S)


def extract(S):
    res = S.popleft()
    build_max_heap(S)
    return res

S = deque()
while True:
    cmd = input().split()
    if cmd[0] == "insert":
        insert(S, int(cmd[1]))
    elif cmd[0] == "extract":
        print(extract(S))
    else:
        break

Fixed submission:
import heapq


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

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


def max_heapify(A, i):
    H = len(A) - 1
    l, r = i * 2 + 1, i * 2 + 2
    if l <= H and A[l] > A[i]:
            largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)


def build_max_heap(A):
    for i in range(len(A) // 2, -1, -1):
        max_heapify(A, i)


def extract(S):
    build_max_heap(S)
    return S.popleft()

S = deque()
while True:
    cmd = input().split()
    if cmd[0] == "insert":
        S.append(int(cmd[1]))
    elif cmd[0] == "extract":
        print(extract(S))
    else:
        break

Fixed submission:
import heapq


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

Buggy python submission (verdict: Time Limit Exceeded):
import heapq


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

Fixed submission:
import heapq


hq = []
while True:
    cmd = input().split()
    if cmd[0] == "insert":
        heapq.heappush(hq, -int(cmd[1]))
    elif cmd[0] == "extract":
        print(-heapq.heappop(hq))
    else:
        break
Buggy python submission (verdict: Time Limit Exceeded):
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

    def getRight(self, t, f):
        top, front = self.nums.index(t), self.nums.index(f)
        for c in "NNNNEEE":
            self.move(c)
            if top == self.top:
                break
        while True:
            self.move("ESW")
            if front == self.front:
                return self.nums[self.right]

    def diffDice(self, dice):
        dice.getRight(self.nums[self.top], self.nums[self.front])
        if self.nums[self.top] == dice.nums[dice.top] and \
                self.nums[self.front] == dice.nums[dice.front] and \
                self.nums[self.right] == dice.nums[dice.right] and \
                self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    print ("Yes")
        else:
            print("No")

dice1 = Dice([int(n) for n in input().split()])
dice2 = Dice([int(n) for n in input().split()])
dice1.diffDice(dice2)

Fixed submission:
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def __eq__(self, dice):
        for x in "NNNNEEE":
            dice.move(x)
            for _ in range(4):
                dice.move("ESW")
                if self.nums[self.top] == dice.nums[dice.top] and \
                        self.nums[self.front] == dice.nums[dice.front] and \
                        self.nums[self.right] == dice.nums[dice.right] and \
                        self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                        self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                        self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    return True
        return False

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

dice1 = Dice([int(n) for n in input().split()])
dice2 = Dice([int(n) for n in input().split()])
if dice1 == dice2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
um = input().split()
num.sort()
print(num[0], num[1], num[2])

Fixed submission:
num = input().split()
num.sort()
print(num[0], num[1], num[2])
Buggy python submission (verdict: Runtime Error):
import math

r = int(input())
print((r * r * math.pi), (2 * r * math.pi))

Fixed submission:
import math

r = float(input())
print((r * r * math.pi), (2 * r * math.pi))
Buggy python submission (verdict: Runtime Error):
while True:
    m, f, v = [int(n) for n in input().split()]

    if m == f == v == -1:
        break
    sum = m + f
    if m == -1 or f == -1
        print("F")
    elif 80 <= sum:
        print("A")
    elif 65 <= sum < 80:
        print("B")
    elif 50 <= sum < 65:
        print("C")
    elif 30 <= sum < 50:
        if 50 <= v:
            print("C")
        else:
            print("D")
    else:
        print("F")

Fixed submission:
while True:
    m, f, v = [int(n) for n in input().split()]

    if m == f == v == -1:
        break
    sum = m + f
    if m == -1 or f == -1:
        print("F")
    elif 80 <= sum:
        print("A")
    elif 65 <= sum < 80:
        print("B")
    elif 50 <= sum < 65:
        print("C")
    elif 30 <= sum < 50:
        if 50 <= v:
            print("C")
        else:
            print("D")
    else:
        print("F")
Buggy python submission (verdict: Time Limit Exceeded):
class Quicksort:
    def quicksort(self, a, p, r):
        if p < r:
            q = self.partion(a, p, r)
            self.quicksort(a, p, q - 1)
            self.quicksort(a, q + 1, r)
        return(a)

    def partion(self, a, p, r): 
        x = a[r][1]
        i = p - 1
        for j in range(p, r):
            if a[j][1] <= x:
                i += 1
                a[i], a[j] = a[j], a[i]
        a[i + 1], a[r] = a[r], a[i + 1]
        return(i+1)

def bubbleSort(a, n):
    flag = 1
    while flag == 1:
        flag = 0
        for j in range(n-1, 0, -1):
            if a[j][1] < a[j - 1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
    return(a)

if __name__ == '__main__':
    n = int(input().rstrip())
    cards = []
    for i in range(n):
        tmp = input().rstrip().split(" ")
        tmp[1] = int(tmp[1])
        cards.append(tmp)
    a = cards[:]
    b = cards[:]
    
    x = Quicksort()
    a = x.quicksort(a, 0, n-1)
        
    b = bubbleSort(b, n)

    if a == b:
        print("Stable")
    else:
        print("Not stable")
    
    for i in a:
        i[1] = str(i[1])
        print(" ".join(i))

Fixed submission:
class Quicksort:
    def quicksort(self, a, p, r):
        if p < r:
            q = self.partion(a, p, r)
            self.quicksort(a, p, q - 1)
            self.quicksort(a, q + 1, r)
        return(a)

    def partion(self, a, p, r): 
        x = a[r][1]
        i = p - 1
        for j in range(p, r):
            if a[j][1] <= x:
                i += 1
                a[i], a[j] = a[j], a[i]
        a[i + 1], a[r] = a[r], a[i + 1]
        return(i+1)

def bubbleSort(a, n):
    flag = 1
    while flag == 1:
        flag = 0
        for j in range(n-1, 0, -1):
            if a[j][1] < a[j - 1][1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
    return(a)

if __name__ == '__main__':
    n = int(input().rstrip())
    cards = []
    for i in range(n):
        tmp = input().rstrip().split(" ")
        tmp[1] = int(tmp[1])
        cards.append(tmp)
    a = cards[:]
    b = cards[:]
    x = Quicksort()
    a = x.quicksort(a, 0, n-1)
    b = sorted(b, key=lambda i: i[1])
    
    if a == b:
        print("Stable")
    else:
        print("Not stable")
    
    for i in a:
        i[1] = str(i[1])
        print(" ".join(i))
Buggy python submission (verdict: Runtime Error):
import collections

while True:
    N, Q = map(int, input().split())
    if N == 0 and Q == 0:
        break
    D = []
    for _ in range(N):
        i = list(map(int, input().split()))
        del i[0]
        [D.append(ii) for ii in i]
    c = collections.Counter(D)
    cc = c.most_common()
    if cc[0][1] >= Q:
        print(cc[0][0])
    else:
        print(0)


Fixed submission:
import collections

while True:
    N, Q = map(int, input().split())
    if N == 0 and Q == 0:
        break
    D = []
    for _ in range(N):
        i = list(map(int, input().split()))
        del i[0]
        [D.append(ii) for ii in i]
    if not len(D) == 0:
        c = collections.Counter(D)
        cc = c.most_common()
        # print(cc)
        if cc[0][1] >= Q:
            ans = 1000000
            tmp = cc[0][1]
            for i in range(len(cc)):
                if cc[i][1] == tmp:
                    ans = min(cc[i][0], ans)
            print(ans)
        else:
            print(0)
    else:
        print(0)