Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

alist = list('abcdefghijklmnopqrstuvwxyz')
r = {}
for al in alist:
    r[al] = 0

line = sys.stdin.read().lower

for i in range(len(line)):
    if line[i] in r.keys():
        r[line[i]] += 1

for k,v in r.items():
    print("{} : {}".format(k, v))


Fixed submission:
import sys

alist = list('abcdefghijklmnopqrstuvwxyz')
r = {}
for al in alist:
    r[al] = 0

line = sys.stdin.read().lower()

for i in range(len(line)):
    if line[i] in r.keys():
        r[line[i]] += 1

for k,v in r.items():
    print("{} : {}".format(k, v))
Buggy python submission (verdict: Runtime Error):
import sys
w = input()
print(sys.stdin.read().lower().split().cout(w))


Fixed submission:
w = input().lower()
r = []
s = input()
while (s != "END_OF_TEXT"):
    r += s.lower().split()
    s = input()
print(len([x for x in r if x == w]))

Buggy python submission (verdict: Runtime Error):
import sys
W=input()
print(sys.stdin.read().lower().split().count(W)


Fixed submission:
w = input().lower()
r = []
s = input()
while (s != "END_OF_TEXT"):
    r += s.lower().split()
    s = input()
print(len([x for x in r if x == w]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
M = N
result = []
i = 2
while True:
    if N % i == 0:
        N = N / i
        result.append(i)
        if N == 1:
            break
    else:
        i += 1
print(str(M) + ": " + " ".join(map(str, result)))



Fixed submission:
N = int(input())
M = N
result = []
i = 2
while i * i <= N:
    while N % i == 0:
        N //= i
        result.append(i)
    i += 1
if N > 1:
    result.append(N)
print(str(M) + ": " + " ".join(map(str, result)))
Buggy python submission (verdict: Time Limit Exceeded):
m, n = map(int, input().split())
print(m**n % 1000000007)


Fixed submission:
m, n = map(int, input().split())
print(pow(m, n, 1000000007))

Buggy python submission (verdict: Time Limit Exceeded):
m, n = map(int, input().split())
mod = 1000000007
print(((m % mod) ** (n % mod)) % mod)



Fixed submission:
m, n = map(int, input().split())
print(pow(m, n, 1000000007))
Buggy python submission (verdict: Runtime Error):
x = int(input())**2
y = int(input())**2
print("{0:d} {1:d}".format(x,y))


Fixed submission:
x,y = map(int, input().split())
print("{0:d} {1:d}".format(x*y, (x+y)*2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

print(" ".join(map(str, A)))
for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = key
    print(" ".join(map(str, A)))



Fixed submission:
N = int(input())
A = list(map(int, input().split()))

print(" ".join(map(str, A)))
for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = key
    print(" ".join(map(str, A)))
Buggy python submission (verdict: Runtime Error):
in = input().split()
A = int(in[0])
B = int(in[1])

if A < B:
  v = B
  B = A
  A = v

R = A % B
while R !=0:
  R = A % B
  A = B
  B = R
return A


Fixed submission:
s = input().split()
A = int(s[0])
B = int(s[1])

if A < B:
  v = B
  B = A
  A = v

R = A % B
while R !=0:
  A = B
  B = R
  R = A % B
print(B)
Buggy python submission (verdict: Runtime Error):
isprime :: Int -> Bool
isprime 1 = False
isprime 2 = True
isprime n = not $ or (map ((0==).(mod n)) [2..ceil])
    where ceil = ceiling (sqrt (fromIntegral n))

getNLines :: Int -> IO [String]
getNLines n = do
    ans <- sequence $ take n (repeat getLine)
    return ans

main = do
    n <- getLine >>= return . read
    numbers <- getNLines n
    let integers = map read numbers
    print $ foldl (\acc x -> if isprime x then acc+1 else acc) 0 integers 




Fixed submission:
#coding: UTF-8
def isPrime(n):
  if n == 1:
    return False
  import math
  m = math.floor(math.sqrt(n))
  for i in range(2,m+1):
    if n % i == 0:
      return False
  return True

n = int(input())
count = 0
for j in range(n):
  m = int(input())
  if isPrime(m):
    count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
# coding: UTF-8
from collections import deque

dll = deque()

n = int(input())
for _ in range(n):
  raw = input().split()
  command = raw[0]
  if command == 'delete': 
    value = raw[1]
    dll.remove(value)
  elif command == 'insert':
    value = raw[1]
    dll.appendleft(value)
  elif command == 'deleteFirst':
    dll.popleft()
  else:
    dll.pop()

print(" ".join(dll))


Fixed submission:
# coding: UTF-8
from collections import deque

dll = deque()

n = int(input())
for _ in range(n):
  raw = input().split()
  command = raw[0]
  if command == 'delete': 
    value = raw[1]
    try:
      dll.remove(value)
    except ValueError as err:
      continue
  elif command == 'insert':
    value = raw[1]
    dll.appendleft(value)
  elif command == 'deleteFirst':
    try:
      dll.popleft()
    except IndexError as err:
      continue
  elif command == 'deleteLast':
    try:
      dll.pop()
    except IndexError as err:
      continue

print(" ".join(dll))
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
value = [0]
weight = [0]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(N+10) for _ in range(W+10)]
#dp[k][w]はk番目までの荷物を使ってw以内に抑えた時の最大値
#dp[0][_] = dp[_][w] = 0と定義する（荷物は1番目、2番目、・・・、N番目と定義する）

for w in range(1,W+2):
    for k in range(1,N+1):
        if weight[k] > w:
            dp[k][w] = dp[k-1][w]
        else:
            dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]])
print(dp[N][W])



Fixed submission:
N,W = map(int,input().split())
value = [0]
weight = [0]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(W+3) for _ in range(N+3)]
for w in range(1,W+1):
    for k in range(1,N+1):
        if weight[k] > w:
            dp[k][w] = dp[k-1][w]
        else:
            #print(dp[k-1][w])
            dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]])
print(dp[N][W])

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
value = [0]
weight = [0]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(N+10) for _ in range(W+10)]

for w in range(1,W+2):
    for k in range(1,N+1):
        if weight[k] > w:
            dp[k][w] = dp[k-1][w]
        else:
            dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]])
print(dp[N][W])



Fixed submission:
N,W = map(int,input().split())
value = [0]
weight = [0]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(W+3) for _ in range(N+3)]
for w in range(1,W+1):
    for k in range(1,N+1):
        if weight[k] > w:
            dp[k][w] = dp[k-1][w]
        else:
            #print(dp[k-1][w])
            dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]])
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
while (True):
    b = list(map(int, input().split(" ")))
    print(b)
    if(b == ['']): break
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)



Fixed submission:
# 何行あるかわからない入力をまとめて処理する
import sys
line = sys.stdin.readlines()
#print(line)
for i in line:
    # map関数は配列の型を一括変換するのに便利
    b = list(map(int, i.split(" ")))
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)

Buggy python submission (verdict: Runtime Error):
#a = []
while (True):
    b = list(map(int, input().split(" ")))
    #print(b)
    if(b == ['']): break
    #a.append(b)
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)


Fixed submission:
# 何行あるかわからない入力をまとめて処理する
import sys
line = sys.stdin.readlines()
#print(line)
for i in line:
    # map関数は配列の型を一括変換するのに便利
    b = list(map(int, i.split(" ")))
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
for i in range(int(input())):
    x = int(input())
    flg = False # なんらかの数で割り切れるかどうか
    if x == 1:
        continue
    if x == 2:
        cnt += 1
        continue
    for k in range(2, x):
        if not(x % k):
            flg = True
            break
    if not flg:
        cnt += 1
print(cnt)


Fixed submission:
import math
cnt = 0
for i in range(int(input())):
    x = int(input())
    flg = False # なんらかの数で割り切れるかどうか
    if x == 1:
        continue
    if x == 2:
        cnt += 1
        continue
    for k in range(2, math.floor(math.sqrt(x))+1):
        if not(x % k):
            flg = True
            break
    if not flg:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
R = []
for i in range(N):
    R.append(int(input()))

mprof = R[1] - R[0]
for i in range(1, len(R)):
    for k in range(i):
        if mprof < (R[i] - R[k]):
            mprof = (R[i] - R[k])

print(mprof)

Fixed submission:
N = int(input())
R = []
for i in range(N):
    R.append(int(input()))

maxv = R[1] - R[0]
minv = R[0]
for i in range(1, len(R)):
        maxv = max(maxv, (R[i] - minv))
        minv = min(minv, R[i])

print(maxv)
Buggy python submission (verdict: Runtime Error):
# Quick Sort #
# 安定かどうかの判定の計算量を減らすことができなかったので，悪いことをした...
def partition(A, p, r):
    x = A[r][1]
    i = p-1
    for k in range(p, r):
        if A[k][1] <= x:
            i += 1
            A[i], A[k] = A[k], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

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

def bubble_sort(c, n):
    x = c[:]
    for i in range(n):
        for k in range(n-1, i, -1):
            if x[k][1] < x[k-1][1]:
                x[k], x[k-1] = x[k-1], x[k]
    return x

def is_stable(_in, out):
    n = len(_in)
    for i in range(n):
        for k in range(i+1, n):
            for a in range(n):
                for b in range(a+1, n):
                    if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:
                        return False
    return True

n = int(input())
a = []
for i in range(n):
    mrk, num = input().split()
    num = int(num)
    a.append((mrk, num))
b = a[:]
quick_sort(b, 0, n-1)
if n > 10000:
    print("Not stable")
else:
# BubbleSortは常に安定
    c = bubble_sort(a[:], n)
    if b == c:
        print("Stable")
    else:
        print("Not stable")
for i in b:
    print(*i)


Fixed submission:
def bubble_sort(c, n):
    x = c[:]
    for i in range(n):
        for k in range(n-1, i, -1):
            if x[k][1] < x[k-1][1]:
                x[k], x[k-1] = x[k-1], x[k]
    return x

def selection_sort(c, n):
    x = c[:]
    for i in range(n):
        mink = i
        for k in range(i, n):
            if x[k][1] < x[mink][1]:
                mink = k
        x[i], x[mink] = x[mink], x[i]
    return x

n = int(input())
c = []
for i in list(input().split()):
    c.append((i[0], int(i[1]))) # tupleで渡す

b = bubble_sort(c, n)
print(" ".join(map(str, [i[0]+str(i[1]) for i in b])))
# bubble_sortは常に安定なソート
stable = True
print("Stable")

s = selection_sort(c, n)
print(" ".join(map(str, [i[0]+str(i[1]) for i in s])))
if b != s:
    stable = False
if stable:
    print("Stable")
else:
    print("Not stable")
Buggy python submission (verdict: Runtime Error):
import math

cnt = 0
m = 0
g = []

def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
    global cnt
    for i in range(g, n):
        v = a[i]
        k = i - g
        while k >= 0 and a[k] > v:
            a[k+g] = a[k]
            k -= g
            cnt += 1
        a[k+g] = v

def shell_sort(a, n):
    global m, g
    g = []
    h = 1
    while h <= n:
        g.append(h)
        h = h * 3 + 1
    g.reverse()
    m = len(g)
    for i in g:
        insertion_sort(a, n, i)

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
shell_sort(a, n)
print(m)
print(" ".join(map(str, g)))
print(cnt)
for i in a:
    print(i)


Fixed submission:
cnt = 0
m = 0
g = []

def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
    global cnt
    for i in range(g, n):
        v = a[i]
        k = i - g
        while k >= 0 and a[k] > v:
            a[k+g] = a[k]
            k -= g
            cnt += 1
        a[k+g] = v

def shell_sort(a, n):
    global m, g
    h = 1
    while h <= n:
        g.append(h)
        h = h * 3 + 1
    g.reverse()
    m = len(g)
    for i in range(m):
        insertion_sort(a, n, g[i])

n = int(input())
a = [int(input()) for i in range(n)]
shell_sort(a, n)
print(m)
print(*g)
print(cnt)
for i in a:
    print(i)

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

cnt = 0
m = 0
g = []

def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
    global cnt
    for i in range(g, n):
        v = a[i]
        k = i - g
        while k >= 0 and a[k] > v:
            a[k+g] = a[k]
            k -= g
            cnt += 1
        a[k+g] = v

def shell_sort(a, n):
    global m, g
    g = []
    h = 1
    while h <= n:
        g.append(h)
        h = h * 3 + 1
    g.reverse()
    m = len(g)
    for i in g:
        insertion_sort(a, n, i)

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
shell_sort(a, n)
print(m)
print(" ".join(map(str, g)))
print(cnt)
for i in a:
    print(i)


Fixed submission:
cnt = 0
m = 0
g = []

def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
    global cnt
    for i in range(g, n):
        v = a[i]
        k = i - g
        while k >= 0 and a[k] > v:
            a[k+g] = a[k]
            k -= g
            cnt += 1
        a[k+g] = v

def shell_sort(a, n):
    global m, g
    h = 1
    while h <= n:
        g.append(h)
        h = h * 3 + 1
    g.reverse()
    m = len(g)
    for i in range(m):
        insertion_sort(a, n, g[i])

n = int(input())
a = [int(input()) for i in range(n)]
shell_sort(a, n)
print(m)
print(*g)
print(cnt)
for i in a:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
input()
s = list(map(int, input().split()))
input()
t = list(map(int, input().split()))

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


Fixed submission:
def binary_search(ary, key, imin, imax):
    if imax < imin:
        return False
    else:
        imid = imin + (imax - imin) // 2
        if ary[imid] > key:
            return binary_search(ary, key, imin, imid - 1)
        elif ary[imid] < key:
            return binary_search(ary, key, imid + 1, imax)
        else:
            return True

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

cnt = 0
for i in t:
    if binary_search(s, i, 0, n-1):
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
class Dictionary:
    def __init__(self):
        self.dic = []
    def insert(self, key):
        if not self.find(key):
            self.dic.append(key)
    def find(self, key):
        return key in self.dic

dic = Dictionary()
n = int(input())
for i in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        dic.insert(cmd[1])
    elif cmd[0] == "find":
        if dic.find(cmd[1]):
            print("yes")
        else:
            print("no")
    else:
        print("wrong command")


Fixed submission:
dic = set()
n = int(input())
for i in range(n):
    cmd, val = input().split()
    if cmd == "insert":
        dic.add(val)
    elif cmd == "find":
        print("yes" if val in dic else "no")
    else:
        print("wrong command")

Buggy python submission (verdict: Time Limit Exceeded):
class Dictionary:
    def __init__(self):
        self.dic = []
    def insert(self, key):
        self.dic.append(key)
    def find(self, key):
        return key in self.dic

dic = Dictionary()
n = int(input())
for i in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        dic.insert(cmd[1])
    elif cmd[0] == "find":
        if dic.find(cmd[1]):
            print("yes")
        else:
            print("no")
    else:
        print("wrong command")


Fixed submission:
dic = set()
n = int(input())
for i in range(n):
    cmd, val = input().split()
    if cmd == "insert":
        dic.add(val)
    elif cmd == "find":
        print("yes" if val in dic else "no")
    else:
        print("wrong command")
Buggy python submission (verdict: Time Limit Exceeded):
def cnt_car(w, p):
    car = 1
    wi = 0
    for i in w:
        if (wi + i) <= p:
            wi += i
        else:
            car += 1
            wi = i
    return car

n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
p = max(w)
while True:
    if cnt_car(w, p) <= k:
        print(p)
        break
    else:
        p += 1


Fixed submission:
def cnt_car(w, p):
    car = 1
    wi = 0
    for i in w:
        if (wi + i) <= p:
            wi += i
        else:
            car += 1
            wi = i
    return car

n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
p = max(max(w), sum(w) // k)
while True:
    if cnt_car(w, p) <= k:
        print(p)
        break
    else:
        #print("failed: ", p, cnt_car(w, p))
        if cnt_car(w, p + 100) > k:
            p += 100
        else:
            p += 1

Buggy python submission (verdict: Time Limit Exceeded):
def cnt_car(w, p):
    car = 1
    wi = 0
    for i in w:
        if (wi + i) <= p:
            wi += i
        else:
            car += 1
            wi = i
    return car

n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
p = max(max(w), sum(w) // k)
while True:
    if cnt_car(w, p) <= k:
        print(p)
        break
    else:
        p += 1


Fixed submission:
def cnt_car(w, p):
    car = 1
    wi = 0
    for i in w:
        if (wi + i) <= p:
            wi += i
        else:
            car += 1
            wi = i
    return car

n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
p = max(max(w), sum(w) // k)
while True:
    if cnt_car(w, p) <= k:
        print(p)
        break
    else:
        #print("failed: ", p, cnt_car(w, p))
        if cnt_car(w, p + 100) > k:
            p += 100
        else:
            p += 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for k in range(i+1, n):
        if a[i] > a[k]:
            cnt += 1
print(cnt)


Fixed submission:
# Merge Sortを元に分割統治で反転数を求める
cnt = 0
def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [A[i] for i in range(left, mid)]
    R = [A[i] for i in range(mid, right)]
    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:
# R[j]について，Lに含まれマージ後にR[j]よりも後に移動するような要素の数
            cnt += n1 - i
            A[k] = R[j]
            j += 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)

input()
a = list(map(int, input().split()))
merge_sort(a, 0, len(a))
print(cnt)
Buggy python submission (verdict: Runtime Error):
def counting_sort(A, k):
    C = [0 for i in range(k)]
# C[i]にiの出現数を記録する
    for l in A:
        C[l] += 1
# C[i]にi以下の数の出現数を記録する
    for i in range(1, k):
        C[i] = C[i] + C[i-1]

    B = [None for i in range(len(A))]
    for l in A[::-1]:
        B[C[l]-1] = l
        C[l] -= 1

    return B

input()
a = list(map(int, input().split()))
b = counting_sort(a, 10)
print(*b)


Fixed submission:
def counting_sort(A, k):
    C = [0 for i in range(k)]
# C[i]にiの出現数を記録する
    for l in A:
        C[l] += 1
# C[i]にi以下の数の出現数を記録する
    for i in range(1, k):
        C[i] = C[i] + C[i-1]

    B = [None for i in range(len(A))]
    for l in A[::-1]:
        B[C[l]-1] = l
        C[l] -= 1

    return B

input()
a = list(map(int, input().split()))
b = counting_sort(a, 10000)
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
class Tree:
    nodes = []
    def __init__(self, root = None):
        self.root = root
    def insert(self, label, children = []):
        self.nodes.append(Node(label, children))
    def search_label(self, label):
        for i in self.nodes:
            if i.label == label:
                return i
    def find_parent(self):
        for i in self.nodes:
            if i.children != []:
                for k in i.children:
                    self.search_label(k).parent = i.label
    def distribute_type(self):
        for i in self.nodes:
            if i.parent != -1:
                if i.children == []:
                    i.type_ = "leaf"
                else:
                    i.type_ = "internal node"
    def distribute_depth(self, node):
        if node.children == []:
            return
        for i in node.children:
            x = self.search_label(i)
            x.depth += node.depth + 1
            self.distribute_depth(x)

class Node:
# type_は0:root, 1:internal node, 2:leaf
    def __init__(self, label, children = []):
        self.label = label
        self.type_ = "root"
        self.depth = 0
        self.parent = -1
        self.children = children


tree = Tree()
n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    label = a[0]
    if a[1] > 0:
        children = a[2:]
        tree.insert(label, children)
    else:
        tree.insert(label)
tree.find_parent()
tree.distribute_type()
tree.nodes.sort(key = lambda x: x.label)
for i in tree.nodes:
    if i.type_ == "root":
        tree.distribute_depth(i)
for i in tree.nodes:
    print("node {0:}: parent = {1:}, depth = {2:}, {3:}, {4:}".format(i.label, i.parent, i.depth, i.type_, i.children))


Fixed submission:
class Tree:
    nodes = []
    def __init__(self, root = None):
        None
    def insert(self, label, children = []):
        if children != []:
            for i in children:
                self.nodes[label].children.append(self.nodes[i])
                self.nodes[i].parent = self.nodes[label]
                self.nodes[i].type_ = "internal node"
    def depth(self, node):
        if node.children == []:
            node.type_ = "leaf"
        else:
            for i in node.children:
                i.depth = node.depth + 1
                self.depth(i)

class Node:
    def __init__(self, label, children = []):
        self.label = label
        self.type_ = "root"
        self.depth = 0
        self.parent = -1
        self.children = [] # self.children = childrenにするとハマる

tree = Tree()
n = int(input())
for i in range(n):
    tree.nodes.append(Node(i))
for i in range(n):
    children = []
    label, num, *children = map(int, input().split())
    tree.insert(label, children)
for i in tree.nodes:
    if i.parent == -1:
        tree.depth(i)
        None
if n == 1:
    tree.nodes[0].type_ = "root"
for i in tree.nodes:
    print("node {0:}: parent = {1:}, depth = {2:}, {3:}, ".\
            format(i.label, i.parent if i.parent == -1 else i.parent.label,\
            i.depth, i.type_), end = "")
    print([i.label for i in i.children])