Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

s = input()
n = len(s)
if int(s) < 2019:
    print(0)
else:
    ruiseki = [0]*(len(s)+1)
    a = 0
    for i in range(len(s)):
        t = int(s[i])
        ruiseki[i+1] = a+t
        a = ruiseki[i+1]

    count = 0
    for i in range(n-3):
        for j in range(i+4, n+1):
            b = ruiseki[j]-ruiseki[i]
            if b % 3 == 0:
                c = int(s[i:j])
                if c % 2019 == 0:
                    count += 1
                    # print(s[i:j])

    # print(ruiseki)
    # print(n)
    print(count)


### FIXED CODE ###

s = input()
ans = 0
# 2019までの余りの分布
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = 0
for i in range(len(s)-1, -1, -1):
    # 後ろから見てく
    sum_i_to_n += int(s[i]) * pow(10, len(s)-i-1, mod)
    sum_i_to_n %= mod
    if sum_i_to_n % mod == 0:
        # 2019で割り切れたら
        ans += 1
    # 1817181712114と81712114はあまりが同じ。
    # 二つの差の1817100000000は2019の倍数よって18171も2019の倍数
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1

print(ans)
### BUGGY CODE ###

from math import gcd
import sys
sys.setrecursionlimit(1000000)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = gcd(A[0],A[1])
    set_A = set(A)
    for i in range(2,N):
        tmp = gcd(tmp, A[i])

    if tmp != 1:
        print('not coprime')
        exit()
    max_A = max(A)
    ans = [0] * (max_A + 1)
    ans = [set() for _ in range(max_A + 1)]
    flag = True
    for i in range(2,int(max_A ** 0.5) +1):
        tmp = 1
        b = 0
        c = set()
        while b <= max_A:
            b = i * tmp
            if {b} & set_A:
                c.add(b)
            if len(c) >= 2:
                flag = False
                break
            if b > max_A:
                break
            ans[b].add(i)
            tmp += 1
    if flag:
        print('pairwise coprime')
    else:
        print('setwise coprime')
    






if __name__ == "__main__":
    main()

### FIXED CODE ###

from math import gcd
import sys
sys.setrecursionlimit(1000000)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = gcd(A[0],A[1])
    set_A = set(A)
    for i in range(2,N):
        tmp = gcd(tmp, A[i])

    if tmp != 1:
        print('not coprime')
        exit()
    max_A = max(A)
    ans = [False] * (max_A + 1)
    flag = True
    def divisor(n):
        ass = []
        for i in range(1,int(n**0.5)+1):
            if n%i == 0:
                ass.append(i)
                if ans[i]:
                    return False
                if i != 1:
                    ans[i] = True
                if i**2 == n:
                    continue
                if ans[n//i]:
                    return False
                ans[n//i] = True
                ass.append(n//i)
        if n != 1:
            ans[n] = True
        return True #sortされていない
    for a in A:
        if not divisor(a):
            flag = False
            break

    if flag:
        print('pairwise coprime')
    else:
        print('setwise coprime')
    






if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
 
cost = [0]
 
for i in range(1,N):
    c = cost[i-1]+abs(h[i]-h[i-1])
    for j in range(2,min(i,K)+1):
        c = min(c,cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(c)
 
print(cost[N-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(N)

for i in range(1,N):
    now = h[i]
    dp[i] = min([abs(now-h[j])+dp[j] for j in range(max(i-K,0),i)])

print(dp[N-1])
### BUGGY CODE ###

def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


N = int(input())
a = map(int, input().split())

N_MAX = 1 << N.bit_length()

v = [0 for _ in range(2 * N_MAX - 1)]
# Segment Tree

for idx, aa in enumerate(a):
    idx += N_MAX - 1  # Segment Treeの葉ノードのIndexに変換
    v[idx] = aa
    while idx > 0:
        idx = (idx - 1) // 2  # 親ノードのIndexに変換
        v[idx] = gcd(v[idx * 2 + 1], v[idx * 2 + 2])  # ノードの値は、2つの子ノードの値の最大公約数

# print(v)

def query(a, b, k=0, l=0, r=N_MAX):
    # [a,b)の最大公約数
    # print(a, b, k, l, r)
    if r <= a or b <= l: return 0  # 交差しない
    if a <= l and r <= b: return v[k]  # 含まれる
    gcd_l = query(a, b, 2 * k + 1, l, (l + r) // 2)
    gcd_r = query(a, b, 2 * k + 2, (l + r) // 2, r)
    return gcd(gcd_l, gcd_r)


g = 0
for i in range(N):
    g = max(g, gcd(query(0, i), query(i + 1, N)))
print(g)


### FIXED CODE ###

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N = int(input())
a = list(map(int, input().split()))
a.sort()

g_left = []
g_right = []

t = a[0]
for i in range(N):
    t = gcd(t, a[i])
    g_left.append(t)

t = a[-1]
for i in range(N - 1, -1, -1):
    t = gcd(t, a[i])
    g_right.append(t)

g_right.reverse()

g = 1
for i in range(1, N - 1):
    g = max(g, gcd(g_left[i - 1], g_right[i + 1]))
g = max(g, g_left[N - 2])
g = max(g, g_right[1])

print(g)
### BUGGY CODE ###

N = int(input())
# num_list = list(input().split())
num_list = list(map(int, input().split()))

import collections
answer_list = []

for i in range(N):
    poped_num = num_list[i]
    num_list.pop(i)
    c = collections.Counter(num_list)
    num_list.insert(i, poped_num)

    comb = 0
    
    for value in c.values():
        comb += value*(value-1)/2

    answer_list.append(comb)

for i in answer_list:
    print(int(i))

### FIXED CODE ###

N = int(input())
num_list = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)
for i in num_list:
  d[i] += 1
 
total = 0
for i in set(num_list):
  x = d[i]
  total += x*(x-1)/2
 
for i in num_list:
  x = d[i]
  print(int(total-((x*(x-1)/2))+((x-1)*(x-2)/2)))
### BUGGY CODE ###

#解説解答
#23:17
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
a = []
for _ in range(h):
  a.append(input())
inf = 10**10
dijk = [[[inf for _ in range(w)] for _ in range(h)] for _ in range(4)]
import heapq
now = [[0,0,x1,y1]]
# 0up 1down 2right 3left
while now:
  pt,dr,x,y = heapq.heappop(now)
  if x == x2 and y == y2:
    print((pt-1)//k+1)
    break
  if dijk[dr][x][y] != inf:
    continue
  dijk[dr][x][y] = pt
  
  if dr == 0 and x != 0:
    if a[x-1][y] == '.':
      heapq.heappush(now,[pt+1,dr,x-1,y])
  if dr == 0:
    for dr2 in range(4):
      if dr2 != dr:
        heapq.heappush(now,[(pt-1)//k*k+k,dr2,x,y])
        
  if dr == 1 and x != h-1:
    if a[x+1][y] == '.':
      heapq.heappush(now,[pt+1,dr,x+1,y])
  if dr == 1:
    for dr2 in range(4):
      if dr2 != dr:
        heapq.heappush(now,[(pt-1)//k*k+k,dr2,x,y])
        
  if dr == 2 and y != 0:
    if a[x][y-1] == '.':
      heapq.heappush(now,[pt+1,dr,x,y-1])
  if dr == 2:
    for dr2 in range(4):
      if dr2 != dr:
        heapq.heappush(now,[(pt-1)//k*k+k,dr2,x,y])
  
  if dr == 3 and y != w-1:
    if a[x][y+1] == '.':
      heapq.heappush(now,[pt+1,dr,x,y+1])
  if dr == 3:
    for dr2 in range(4):
      if dr2 != dr:
        heapq.heappush(now,[(pt-1)//k*k+k,dr2,x,y])
  
  #print(now)
else:
  print(-1)
'''
for x in dijk:
  print('##')
  for y in x:
    print(y)
'''

### FIXED CODE ###

#16:41
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(lambda x:int(x)-1, input().split())
raw = []
for _ in range(h):
  raw.append(input())
inf = 10**6
seen = [[inf for _ in range(w)] for _ in range(h)]
seen[x1][y1] = 0
from heapq import heappush as push
from heapq import heappop as pop
now = [[0,x1,y1]]

while now:
  s,x,y = pop(now)
  if x == x2 and y == y2:
    print(s)
    exit()
  for i in range(1,k+1):
    if x-i == -1 or raw[x-i][y] == '@' or seen[x-i][y] < s+1:
      break
    if seen[x-i][y] != s+1:
      seen[x-i][y] = s+1
      push(now,[s+1,x-i,y])
  for i in range(1,k+1):
    if y-i == -1 or raw[x][y-i] == '@' or seen[x][y-i] < s+1:
      break
    if seen[x][y-i] != s+1:
      seen[x][y-i] = s+1
      push(now,[s+1,x,y-i])
  for i in range(1,k+1):
    if x+i == h or raw[x+i][y] == '@' or seen[x+i][y] < s+1:
      break
    if seen[x+i][y] != s+1:
      seen[x+i][y] = s+1
      push(now,[s+1,x+i,y])
  for i in range(1,k+1):
    if y+i == w or raw[x][y+i] == '@' or seen[x][y+i] < s+1:
      break
    if seen[x][y+i] != s+1:
      seen[x][y+i] = s+1
      push(now,[s+1,x,y+i])
print(-1)
### BUGGY CODE ###

k = int(input())

def gcd(a, b, c):
    mini = a
    if a > b:
        mini = b
    if b > c:
        mini = c
    for i in range(mini + 1, 1, -1):
        if (a % i == 0) & (b % i == 0) & (c % i == 0):
            return i
    return 1

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            a = gcd(i, j, l)
            s += int(a)

print(s)

### FIXED CODE ###

k = int(input())

def gcd(a, b, c):
    mini = a
    if a > b:
        mini = b
    if b > c:
        mini = c
    if (a % mini == 0) & (b % mini == 0) & (c % mini == 0):
        return mini
    if mini % 2 == 0:
        h = mini / 2
        if (a % h == 0) & (b % h == 0) & (c % h == 0):
            return h
    for i in range((mini + 1)//3 + 1, 1, -1):
        if (a % i == 0) & (b % i == 0) & (c % i == 0):
            return i
    return 1

s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            if i <= j <= l:
                if i < j < l:
                    a = gcd(i, j, l) * 6
                    s += int(a)
                elif ((i == j) & (j != l)) | ((i != j) & (j == l)):
                    a = gcd(i, j, l) * 3
                    s += int(a)
                else:
                    a = gcd(i, j, l) 
                    s += int(a)
            else:
                continue

print(s)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
print(dp[-1]*(2**n) % mod)

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
S,T
"""

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
    p %= mod
p *= 2
p %= mod
print(dp[-1]*p % mod)
### BUGGY CODE ###

N, K, Q, *A = map(int, open(0).read().split())
print("\n".join(("Yes" if Q < K + A.count(a)
                 else "No" for a in range(1, N + 1))))


### FIXED CODE ###

from sys import stdin
from collections import Counter

lines = stdin.readlines()

N, K, Q = map(int, lines[0].split())
ans = [0] * N
A = Counter((int(i) - 1 for i in lines[1:]))
for k in A.keys():
    ans[k] += A[k]
print("\n".join(("Yes" if Q < K + a
                 else "No" for a in ans)))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ans*=a[i]
if ans>(10)**(18):
    print('-1')
else:
    print(ans)

### FIXED CODE ###

import sys
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    if a[i]==0:
        print(0)
        sys.exit()
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**(18):
        print('-1')
        sys.exit()
print(ans)
### BUGGY CODE ###

N = int(input())

tmp = 0
while N != 0:
    tmp += N % 10
    tmp %= 9
    N //= 10

if tmp == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = list(map(int, input()))

N = sum(N)

if N % 9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys


def main():
    s = input()
    t = input()
    for i in range(len(s)):
        if s[i] != t[i]:
            s = s.translate(str.maketrans({s[i]: t[i], t[i]: s[i]}))
    if s == t:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import Counter


def main():
    s = input()
    t = input()
    s_count = [0]*26
    t_count = [0]*26
    for i in range(ord("a"), ord("z")+1):
        s_count[i-97] = s.count(chr(i))
        t_count[i-97] = t.count(chr(i))
    s_count.sort()
    t_count.sort()
    if s_count == t_count:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = [False,False ] + [True for _ in range(10**5-1)]

def check_prime(x):
    for i in range(x*2,10**5+1,x):
        n[i] = False

check_prime(2)
for i in range(3,10**5+1,2):
    check_prime(i)

for _ in range(int(input())):
    l,r = map(int,input().split())
    ans = 0
    for i in range(l,r+1):
        if i % 2 == 1 and n[i] and n[(i+1)//2]:
           ans += 1
    print (ans)


### FIXED CODE ###

import math
n = [0,0,1] + [1 for _ in range(10**5-2)]

def check_prime(x):
    for i in range(x*2,10**5+1,x):
        n[i] = 0

check_prime(2)
for i in range(3,int(math.sqrt(10**5))+1,2):
    check_prime(i)

c = [0 for _ in range(10**5+1)]
for i in range(1,10**5+1):
    c[i] = c[i-1] + (n[i] * n[(i+1)//2])

for _ in range(int(input())):
    l,r = map(int,input().split())
    ans = c[r] - c[l-1]
    print (ans)
### BUGGY CODE ###

n, l = map(int, input().split())
a = list(map(int, input().split()))

ans = []
seen = [0] * (n - 1)
while True:
    changed = False
    for i in range(n - 1):
        if not seen[i] and a[i] + a[i + 1] >= l:
            seen[i] = 1
            ans.append(i + 1)
            a[i] = l
            a[i + 1] = l
            changed = True
    if not changed:
        break

if len(ans) == n - 1:
    print("Possible")
    print(*ans[::-1], sep="\n")
else:
    print("Impossible")   



### FIXED CODE ###

import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))

knot = []
for i in range(N - 1):
    heapq.heappush(knot, (-A[i]-A[i+1], i))

ans = []
seen = [False]*N
while knot:
    L, i = heapq.heappop(knot)
    L = -L

    if seen[i]:
        continue
    if L < K:
        break

    seen[i] = True
    ans.append(i + 1)

    if i + 1 < N - 1:
        heapq.heappush(knot, (-L - A[i + 1], i + 1))
    if i - 1 >= 0:
        heapq.heappush(knot, (-L - A[i - 1], i - 1))

if len(ans) != N - 1:
    print("Impossible")
else:
    print("Possible")
    print(*ans[::-1], sep="\n")
### BUGGY CODE ###

from collections import Counter

N = int(input())
S = input()

sum = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue

        RGB = ['R','G','B']
        RGB.remove(S[j])
        RGB.remove(S[i])
        c = Counter(S[(j+1):])
        sum += c[RGB[0]]

        # S[k]
        k = 2 * j - i
        if k < len(S):
            if S[k] == RGB[0]:
                sum -= 1
print(sum)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
h, w, m = map(int, input().split())

h_list = [0]*h
w_list = [0]*w

h_w_list = [[0 for j in range(w)] for i in range(h)]
# h_w_list = []

for zzz in range(m):
  # print("---")
  bom_h, bom_w = map(int, input().split())
  # print(bom_h, bom_w)
  h_list[bom_h-1] += 1
  w_list[bom_w-1] += 1

  h_w_list[bom_h-1][bom_w-1] = 1
  # h_w_list.append((bom_h, bom_w))

mh = max(h_list)
mw = max(w_list)
h_max_indexs = [i for i, v in enumerate(h_list) if v == mh]
w_max_indexs = [i for i, v in enumerate(w_list) if v == mw]

double_chance = False
# print("---")
for h_index in h_max_indexs:
  if double_chance:
    break
  for w_index in w_max_indexs:
    if double_chance:
      break
    chance = h_w_list[h_index][w_index] != 1

    # print(h_index, w_index, chance)
    if chance:
      double_chance = True


if double_chance:
  result = h_list[h_index] + w_list[w_index]
else:
  result = h_list[h_index] + w_list[w_index] -1

print(result)


### FIXED CODE ###

H,W,M = map(int,input().split())
listh = [0] * H
listw = [0] * W
s = set()
for i in range(M):
    hm,wm = map(int,input().split())
    listh[hm-1] += 1
    listw[wm-1] += 1
    s.add((hm-1,wm-1))
mh = max(listh)
mw = max(listw)
maxh = [i for i,v in enumerate(listh) if v == mh]
maxw = [i for i,v in enumerate(listw) if v == mw]

import sys
for i in maxh:
    for j in maxw:
        if (i,j) not in s:
            print(mh + mw)
            sys.exit()
print(mh + mw - 1)
### BUGGY CODE ###

#

import sys
from copy import deepcopy
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    satsum=0
    for day in range(1,D+1):
        lastt=deepcopy(last)
        maxt=0
        maxsat=0
        for t in range(1,27):
            sat=0
            for j in range(day,D+1):
                    last[j][t]=day
            sat+=S[day-1][t-1]
            for j in range(1,27):
                sat-=C[j-1]*(day-last[day][j])
            if t==1:
                maxt=t
                maxsat=sat
            elif maxsat<sat:
                maxt=t
                maxsat=sat
            last=deepcopy(lastt)
            
        satsum+=maxsat
        for j in range(day,D+1):
            last[j][maxt]=day
        satsum+=maxsat
        print(maxt)
    
if __name__=="__main__":
    main()


### FIXED CODE ###

#

import sys
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    for day in range(1,D+1):
        maxt=0
        maxx=0
        sat=0
        for t in range(1,27):
            for j in range(day,D+1):
                    last[j][t]=day
            sat+=S[day-1][t-1]
            for j in range(1,27):
                sat-=C[j-1]*(day-last[day][j])
            if maxx<sat:
                maxt=t
                maxx=sat
        print(maxt)
    
if __name__=="__main__":
    main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
def mincost(n,h,i,dp,k):
    if i==(n-1):
        return 0
    elif i==(n-2):
        return abs(h[n-1]-h[i])
    mncost=sys.maxsize
    mn=min(i+k+1,n)
    for j in range(i+1,mn):
        if dp[j]==-1:
            cost=mincost(n,h,j,dp,k)
            dp[j]=cost
        else:
            cost=dp[j]
        mncost=min(mncost,cost+abs(h[j]-h[i]))
    return mncost

n,k=map(int,input().split())
h=[int(x) for x in input().split()]
dp=[-1 for i in range(n)]
print(mincost(n,h,0,dp,k))

### FIXED CODE ###

from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def mincost(n,h,k):
  dp=[-1 for i in range(n)]
  dp[n-1]=0
  dp[n-2]=abs(h[n-2]-h[n-1])
  for i in range(n-3,-1,-1):
    mn=min(i+k+1,n)
    mnm=sys.maxsize
    for j in range(i+1,mn):
      mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
    dp[i]=mnm    
  return dp[0]
 
def main():
  n,k=map(int,input().split())
  h=[int(x) for x in input().split()]
  print(mincost(n,h,k)) 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
maxfigure = sorted(A)[-1]
B = 0
for i in A:
    if A.count(i)%2 == 1:
        B += 1
print(B)

### FIXED CODE ###

N = int(input())
list = set()
for i in range(N):
    i = int(input())
    if i not in list:
        list.add(i)
    elif i in list:
        list.remove(i)
print(len(list))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = list(input())
R = []
G = []
B = []
for i in range(N):
    if S[i] =="R":
        R.append(i)
    if S[i] =="G":
        G.append(i)
    if S[i] =="B":
        B.append(i)
cnt = 0
for r in R:
    for g in G:
        for b in B:
            L = [r,g,b]
            if (r+g+b)/3 not in L:
                cnt +=1
print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = list(input())
R = []
G = []
B = set()
for i in range(N):
    if S[i] =="R":
        R.append(i)
    if S[i] =="G":
        G.append(i)
    if S[i] =="B":
        B.add(i)
M =len(B)
cnt = 0
for r in R:
    for g in G:
        a = (r+g)/2
        b = 2*g-r
        c = 2*r-g
        if a in B:
            cnt-=1
        if b in B:
            cnt-=1
        if c in B:
            cnt-=1
        cnt += M
        
print(cnt)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
tree = {n:{} for n in range(N)}
children = set()

for n in range(N):
    inp = [int(m) for m in input().split()]
    tree[n]["leaf"] = inp[2:]
    children.update(inp[2:])

parent = set([n for n in range(N)]).difference(children).pop()
tree[parent]["depth"] = 0
tree[parent]["parent"] = -1

siblings = tree[parent]["leaf"]
for c in siblings:
    tree[c]["depth"] = 1
    tree[c]["parent"] = parent

depth = 2
while len(children):
    children = children.difference(siblings)
    next_gen = []
    for s in siblings:
        next_gen.extend(tree[s]["leaf"])
        for c in tree[s]["leaf"]:
            tree[c]["depth"] = depth
            tree[c]["parent"] = s
    siblings = next_gen
    depth += 1

    
for n in range(N):
    if tree[n]["depth"] == 0:
        tree[n]["type"] = "root"
    elif tree[n]["leaf"] == []:
        tree[n]["type"] = "leaf"
    else:
        tree[n]["type"] = "internal node"
        
    print("node {}: parent = {}, depth = {}, {}, {}" \
              .format(n, tree[n]["parent"], tree[n]["depth"], tree[n]["type"], tree[n]["leaf"]))

### FIXED CODE ###

# -*- coding: utf-8 -*-
#import sys
#sys.setrecursionlimit(1145141919)


N = int(input())
tree = {n:{"parent":-1, "left": -1, "right": -1} for n in range(N)} # left-child right-sibing
parent = set([n for n in range(N)])
for n in range(N):
    inp = [int(n) for n in input().split()]
    tree[inp[0]]["children"] = inp[2:]

    tree[inp[0]]["left"] = inp[2] if len(inp) > 2 else -1
    
    for ip in inp[2:]:
        tree[ip]["parent"] = inp[0]
    
    for i, ip in enumerate(inp[2:-1]):
        tree[inp[2+i]]["right"] = inp[3+i]
    parent = parent.difference(inp[2:])    

def set_depth(n, depth):
    print(depth)
    tree[n]["depth"] = depth
    if tree[n]["left"] != -1:
        set_depth(tree[n]["left"], depth+1)
    if tree[n]["right"] != -1:
        set_depth(tree[n]["right"], depth)

def get_depth(n):
    d = 0
    while tree[n]["parent"] != -1:
        d += 1
        n = tree[n]["parent"]
    return d

#set_depth(parent.pop(), 0)
        
for n in range(N):
    tree[n]["depth"] = get_depth(n)
    if tree[n]["parent"] == -1:
        tree[n]["type"] = "root"
    elif tree[n]["children"] != []:
        tree[n]["type"] = "internal node"
    else:
        tree[n]["type"] = "leaf"
        
    print("node {}: parent = {}, depth = {}, {}, {}"\
          .format(n, tree[n]["parent"], tree[n]["depth"], tree[n]["type"], tree[n]["children"]))