Harryxun/stf_run huggingface dataset:
from collections import deque

def search(h, w, pre_h, pre_w):
    can = []
    if h > 0:
        can.append((h-1, w))
    if h < H-1:
        can.append((h+1, w))
    if w > 0:
        can.append((h, w-1))
    if w < W-1:
        can.append((h, w+1))
    res = []
    for h, w in can:
        if S[h][w]=='.' and (h, w) != (pre_h, pre_w):
            res.append((h, w))
    return res

def bfs(h, w):
    d = [[float('inf') for _ in range(W)] for _ in range(H)]
    d[h][w] = 0
    pre_h, pre_w = h, w
    adj_list = search(h, w, pre_h, pre_w)
    open_list = deque([])
    closed_list = []
    closed_list = set(closed_list)
    for adj in adj_list:
        open_list.append((adj[0], adj[1], pre_h, pre_w))
    cnt = 0
    while True:
        cnt+=1
        if H==20 and W==20:
            if cnt > 2200:
                break
        if len(open_list) == 0:
            break
        h, w, pre_h, pre_w = open_list.popleft()
        closed_list.add((h, w, pre_h, pre_w))
        d[h][w] = min(d[h][w], d[pre_h][pre_w] + 1)
        adj_list = search(h, w, pre_h, pre_w)
        for adj in adj_list:
            if (adj[0], adj[1], h, w) in closed_list:
                continue
            open_list.append((adj[0], adj[1], h, w))

    res = 0
    for h in range(H):
        for w in range(W):
            if not d[h][w] == float('inf'):
                res = max(res, d[h][w])
    return res

def bounday():
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                return False
    return True

H, W = map(int, input().split())
S = []
for i in range(H): 
    S.append(list(input()))

if __name__ == "__main__":

    if bounday():
        print(H+W-2)
        exit(0)

    ans = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            maxd = bfs(h, w)
            ans = max(maxd, ans)
    print(ans)

### FIXED CODE ###

c = input()
print(chr(ord(c) + 1))
from math import gcd

print(gcd(120, 24))

### FIXED CODE ###

N = int(input())

def isOk(k):
    n = N
    while n % k == 0:
        n //= k
    return n % k == 1

if N <= 10**6:
    ans = 0
    for i in range(2, N + 1):
        if isOk(i):
            ans += 1
    print(ans)
    exit()

ans = 0
V = set()
for i in range(2, int(N**0.5) + 10):
    if isOk(i):
        ans += 1
        V.add(i)

# 約数の全列挙
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort(reverse=True)  # ソート
    return divisors

divN = divisors(N - 1)

ans += len([d for d in divN if not d in V])
print(ans)
def sumTree(index, children, prev, pointTree=[]):
    sumPoint = point[index] + prev
    pointTree.append(sumPoint)

    for key in children:
        sumTree(key, tree[key], sumPoint, pointTree)    
    return pointTree

if __name__ == "__main__":
    tree = {}
    N, Q = map(int, input().split(' '))
    for i in [input() for i in range(N-1)]:
        A, B = map(int, i.split(' '))
        if A in tree:
            tree[A].append(B)
        else:
            tree[A] = [B]

        if B not in tree:
            tree[B] = []

    point = [0] * (N + 1)
    for i in [input() for i in range(Q)]:
        A, B = map(int, i.split(' '))
        point[A] = point[A] + B

    firstKey = list(tree.keys())[0]
    pointTree = sumTree(firstKey, tree[firstKey], 0)
    print(' '.join(map(str, pointTree)))

### FIXED CODE ###

from collections import deque
 
if __name__ == "__main__":
    N, q = map(int, input().split())
    links = [[] for _ in range(N)]
    
    for i in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    
    ans = [0] * N
    for i in range(q):
        p, x = map(int, input().split())
        ans[p - 1] += x

    deq = deque([0])
    visited = [False] * N
    while deq:
        parent = deq.popleft()
        link = links[parent]
        for v in link:
            if not visited[v]:
                ans[v] += ans[parent]
                deq.append(v)
        visited[parent] = True
    
    print(*ans)
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)

for d in D:
    memo[d] += 1

for t in T:
    memo[t] -= 1

memo.sort()

print("YES" if memo[0] >= 0 else "NO")

### FIXED CODE ###

from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)

for d in D:
    memo[d] += 1

for t in T:
    memo[t] -= 1

memo = list(memo.values())
memo.sort()

print("YES" if memo[0] >= 0 else "NO")
a=int(input())
c=len(a)
b=a[:(c-1)//2]
d=a[(c+3)//2:]
if a==a[::-1] and b==b[::-1] and d==d[::-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=input()
c=len(a)
b=a[:(c-1)//2]
d=a[(c+3)//2-1:]
if a==a[::-1] and b==b[::-1] and d==d[::-1]:
  print("Yes")
else:
  print("No")
n=int(input())
kei=0
for i in range(n):
    l,r=map(int,input().split())
kei += sum(r)-sum(l)
kei += n
print(kei)

### FIXED CODE ###

N=int(input())
ans=0
for i in range(N):
	l,r=map(int,input().split())
	ans+=r-l+1
print(ans)
from collections import defaultdict
from itertools import product
 
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
 
i = 0
while i < len(S):
  if '1' in S[i]:
    i += 1
  else:
    del S[i]
H = len(S)
 
C = [[int(s[i]) for s in S] for i in range(W)]#列を一括りにする

total = sum(sum(c) for c in C)#すべての値の合計を算出
 
answer = H * W
for X in product([False, True], repeat=H-1):#Hは行数
  #あるXについて一回目のfor文が回る
  ans = sum(X)#Trueの数を換算
  if ans > answer:
    continue
  M = [[0]]
  for i, x in enumerate(X):
    if x:#Trueなら実行
      M.append([])#Trueの数の配列が作成される
    M[-1].append(i+1)#一番最後にその番目をappendする
  D = [0] * len(M)#初期値を設定
  for c in C:
    for k, m in enumerate(M):
      D[k] += sum(c[i] for i in m)#k番目の要素に足していく
      #Dにどんどん代入することによってどの列まで足すことができるか算出することができる
    if any(d > K for d in D):#一つでもKを超えていたら
      ans += 1
      if ans > answer:
        break
      D = [sum(c[i] for i in m) for m in M]#Dの更新(1番最初のDに戻る)
      if any(d > K for d in D):#一つでもKを超えていたら
        ans = answer + 1#ansの更新
        break
  answer = min(answer, ans)

print(answer)

### FIXED CODE ###

from collections import defaultdict
from itertools import product
 
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
 
i = 0
while i < len(S):
  if '1' in S[i]:
    i += 1
  else:
    del S[i]
H = len(S)
 
C = [[int(s[i]) for s in S] for i in range(W)]
 
total = sum(sum(c) for c in C)
 
if total <= K:
  answer = 0
else:
  answer = H * W
  for X in product([False, True], repeat=H-1):
    ans = sum(X)
    if ans > answer:
      continue
    M = [[0]]
    for i, x in enumerate(X):
      if x:
        M.append([])
      M[-1].append(i+1)
    D = [0] * len(M)
    for c in C:
      for k, m in enumerate(M):
        D[k] += sum(c[i] for i in m)
      if any(d > K for d in D):
        ans += 1
        if ans > answer:
          break
        D = [sum(c[i] for i in m) for m in M]
        if any(d > K for d in D):
          ans = answer + 1
          break
    answer = min(answer, ans)
   
print(answer)
A, op, B = map(int, input().split())
if op == '+':
  print(A + B)
else:
  print(A - B)

### FIXED CODE ###

A, op, B = input().split()
A = int(A)
B = int(B)
if op == '+':
  print(A + B)
else:
  print(A - B)
N = int(input())
C=list(input())
L=0
R=0
X=0
for i in range(N):
  L=i
  if L==N-1-R:
    break
  if C[i]=='W':
    for ii in range(N-L-R):
      R+=ii 
      if C[N-1-R]=='R':
        C[L]='R'
        C[N-1-R]='W'
        X+=1
        R+=1
        if L==N-1-R:
          break
        break
print(X)


### FIXED CODE ###

X=int(input())
if X>=30:
  print('Yes')
else:
  print('No')
N,K,L = map(int, input().split())

#print(N,K,L,D,T)

list_D = [set([i]) for i in range(N)]
list_T = [set([i]) for i in range(N)]
root_D = [i for i in range(N)]
root_T = [i for i in range(N)]

#print(list_D)

for _ in range(K):
    d = map(int, input().split())
    d0 = d[0] - 1
    d1 = d[1] - 1
    r0 = root_D[d0]
    r1 = root_D[d1]
    list_D[r0] = list_D[r0] | list_D[r1]
    root_D[r1] = r0
    root_D[d1] = r0
    #print(list_D, root_D)

for for _ in range(L):
    t = map(int, input().split())
    t0 = t[0] - 1
    t1 = t[1] - 1
    r0 = root_T[t0]
    r1 = root_T[t1]
    list_T[r0] = list_T[r0] | list_T[r1]
    root_T[r1] = r0
    root_T[t1] = r0
    #print(list_T, root_T)

#和集合
res = [0] * N
for i in range(N):
    rd = root_D[i]
    rt = root_T[i]
    d = list_D[rd]
    t = list_T[rt]
    res[i] = len(d & t)
#print(*(res[i] for i in range(N)))
print(" ".join([str(i) for i in res]))

### FIXED CODE ###

import sys
 
sys.setrecursionlimit(10000)

N,K,L = map(int, input().split())

#print(N,K,L,D,T)

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

def execOne(num, uf):
    for _ in range(num):
        d0, d1 = map(int, input().split())
        d0 = d0 - 1
        d1 = d1 - 1
        uf.union(d0, d1)

uf_D = UnionFind(N)
uf_T = UnionFind(N)

execOne(K, uf_D)
execOne(L, uf_T)


pairs = []
for i in range(N):
    pairs.append((uf_D.find(i), uf_T.find(i)))

pairs_count = {}
for p in pairs:
    if not p in pairs_count:
        pairs_count[p] = 1
    else:
        pairs_count[p] += 1

res = [0] * N
for i in range(N):
    res[i] = pairs_count[pairs[i]]
#print(*(res[i] for i in range(N)))
print(" ".join([str(i) for i in res]))
import sys
args = sys.argv

arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(arr[int(args[1]) - 1])

### FIXED CODE ###

arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(arr[int(input()) - 1])
#coding: UTF-8
A, B, C, D = map(int, input().split())
a1 = A*B
a2 = C*D
if a1 >= a2:
    print(a1)
else:
    print(a2)

### FIXED CODE ###

#coding: UTF-8
A, B, C, D = map(int, input().split())
a1 = A*B
a2 = C*D
if a1 >= a2:
    print(a1)
else:
    print(a2)
def main():
    import math
    n, m = map(int, input().split())
    if n - m <= -2 or n - m >= 2:
        print(0)
        exit()

    else:
        if n < m:
            n, m = m, n
        else:
            if n != m:
                ans = math.factorial(n) % (10*9 + 7) * math.factorial(m) % (10**9 + 7)
            else:
                ans = math.factorial(n) * 2 % (10**9 + 7) * math.factorial(m) % (10**9 + 7)

    print(ans)


    

 
    
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    import math
    n, m = map(int, input().split())
    if n - m <= -2 or n - m >= 2:
        print(0)
        exit()

    else:
        if n != m:
            ans = math.factorial(n) % (10**9 + 7) * math.factorial(m) % (10**9 + 7)
        else:
            ans = math.factorial(n) * 2 % (10**9 + 7) * math.factorial(m) % (10**9 + 7)

    print(ans)


    

 
    
    
if __name__ == "__main__":
    main()
n = int(input())
i = int(input())

print(n-1+1)

### FIXED CODE ###

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

print(n-i+1)
K,N=map(int,input().split())
A=[list(map(int,input().split()))]
print(max(A)-min(A))

### FIXED CODE ###

K,N=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
C=[]
for i in range(N-1):
    C.append(B[i+1]-B[i])
C.append(B[0]+K-B[N-1])
print(K-max(C))
K, S = map(int,input().split())
listK = [i for i in range(K+1)]
ans = 0
for i in range(K+1):
    for j in range(K+1):
        id = bisect.bisect_left(listK,S-i-j)
        if id < len(listK) and listK[id] == S-i-j:
                ans += 1
print(ans)

### FIXED CODE ###

K, S = map(int,input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        z = S-x-y
        if 0 <= z and z <= K:
            ans += 1
print(ans)
a,b,c=map(int,input().split())
n=0
for i in range(a,b+1)
	if c%i==0:
		n +=1
	else:
		n=n
print(n)


### FIXED CODE ###

a,b,c=map(int,input().split())
n=0
while a<=b:
	if c%a==0:
		n+=1
		a+=1
	else:
		a+=1
print(n)
import numpy as np
def XOR(X):
	X=np.array(X)
	out=0
	i=0
	while(max(X)>0):
		out+=(np.sum(X%2)%2)*(2**i)
		X=X//2
		i+=1

	return out



A,B=input().split(" ")
A=int(A)
B=int(B)


X=[for i in range(A,B+1)]
print(XOR(X))



### FIXED CODE ###

A,B=input().split(" ")
A=int(A)
B=int(B)



if(A%2==1):
	A_=A+1
else:
	A_=A
if(B%2==0):
	B_=B-1
else:
	B_=B

out=((B_-A_+1)//2)%2
#import numpy as np
if(A%2==1):
	out^=A
if(B%2==0):
	out^=B
print(out)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop,heappush

n,m = map(int,readline().split())
ab = list(map(int,read().split()))

if(m%2==1):
    print(-1)
    exit()

it = iter(ab)
links = [[] for _ in range(n+1)]
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

depth = [-1] * (n+1)
parent = [0] * (n+1)
child = [set() for _ in range(n+1)]
hq_dep = []

stack = [1]
depth[1] = 0
heappush(hq_dep, (0,1))
now_dep = 1
while(stack):
    stack2 = []
    while(stack):
        i = stack.pop()
        for j in links[i]:
            if(depth[j] == -1):
                depth[j] = now_dep
                parent[j] = i
                heappush(hq_dep,(now_dep*-1,j))
                stack2.append(j)
            else:
                child[j].add(i)
    now_dep += 1
    stack = stack2[::]

# print(parent)
# print(child)
# print(d)
# print(hq_dep)

ans = []
for _ in range(m//2):
    while(True):
        i_dep,i= hq_dep[0]
        if(not child[i]):
            heappop(hq_dep)
        else:
            break

    if(len(child[i]) >= 2):
        j = child[i].pop()
        k = child[i].pop()
        child[j].remove(i)
        child[k].remove(i)

    else:
        j = child[i].pop()
        k = parent[i]
        parent[i] = 0
        if(i in child[j]):
            child[j].remove(i)


    ans.append((i,j))
    ans.append((i,k))



print('\n'.join(map(lambda x: ' '.join(map(str,x)), ans)))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop,heappush
from collections import defaultdict

n,m = map(int,readline().split())
ab = list(map(int,read().split()))

if(m%2==1):
    print(-1)
    exit()

it = iter(ab)
links = [[] for _ in range(n+1)]
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

depth = [-1] * (n+1)
parent = [0] * (n+1)
child = [set() for _ in range(n+1)]
hq_dep = []

stack = [1]
depth[1] = 0
# heappush(hq_dep, (0,1))
now_dep = 1
while(stack):
    stack2 = []
    while(stack):
        i = stack.pop()
        for j in links[i]:
            if(depth[j] == -1):
                depth[j] = now_dep
                parent[j] = i
                heappush(hq_dep,(now_dep*-1,j))
                stack2.append(j)
            else:
                child[j].add(i)
    now_dep += 1
    stack = stack2[::]

# 0:未定　1:done
ans = []
d = defaultdict(int)
outs = [0] * (n+1)
while(hq_dep):
    i_dep,i = heappop(hq_dep)
    for j in child[i]:
        if(d[min(i,j)*10**6 + max(i,j)] == 0):
            d[min(i,j)*10**6 + max(i,j)] = 1
            outs[j] += 1
            ans.append([j,i])
    j = parent[i]
    if(outs[i]%2==1):
        d[min(i,j)*10**6 + max(i,j)] = 1
        outs[i] += 1
        ans.append([i,j])
    else:
        d[min(i,j)*10**6 + max(i,j)] = 1
        outs[j] += 1
        ans.append([j,i])

print('\n'.join(map(lambda x: ' '.join(map(str,x)), ans)))
a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = (2/3)* a - (1/3)* b
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


### FIXED CODE ###

a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = int((2 * a -  b)/3)
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)
# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in len(directions):
        d.roll(directions[i])

    print(d.get_top())

### FIXED CODE ###

# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in range(len(directions)):
        d.roll(directions[i])

    print(d.get_top())
N = int(raw_input())
A = map(int, raw_input().split())
 
#N = 200000
#A = [200000]*N
 
count = [0]*(N+2)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1
 
sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)
 
#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)

### FIXED CODE ###

N = int(raw_input())
A = map(int, raw_input().split())

#N = 200000
#A = [200000]*N

count = [0]*(N+2)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1

sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)

#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)
a,s,d=input()
 
print(a,s,d)

### FIXED CODE ###

x= input()
print(x[:3])
n,m = map(int, input().split())
a = [[0]*m for i in range(n)]
def rev(k):
    if k==1:
        return 0
    else:
        return 1
for i in range(n):
    for j in range(m):
        a[i][j] = rev(a[i][j])
        if j > 0:
            a[i][j-1] = rev(a[i][j-1])
        if j < m-1:
            a[i][j+1] = rev(a[i][j+1])
        if i > 0:
            a[i-1][j] = rev(a[i-1][j])
            if j > 0:
                a[i-1][j-1] = rev(a[i-1][j-1])
            if j < m-1:
                a[i-1][j+1] = rev(a[i-1][j+1])
        if i < n-1:
            a[i+1][j] = rev(a[i+1][j])
            if j > 0:
                a[i+1][j-1] = rev(a[i+1][j-1])
            if j < m-1:
                a[i+1][j+1] = rev(a[i+1][j+1])

ans = 0
for i in range(n):
    for j in range(m):
        ans += a[i][j]
print(ans)


### FIXED CODE ###

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

ans = 0
if n == 1:
    if m == 1:
        ans = 1
    elif m == 2:
        ans = 0
    else:
        ans = m - 2

if n == 2:
    ans = 0

if n > 2:
    if m == 1:
        ans = n-2
    elif m == 2:
        ans = 0
    else:
        ans = (n-2)*(m-2)
    



print(ans)
n,m=map(int,input().split())
s=set(range(1,m+1))
for i in range(n):
    k,*a=map(int,input().split())
    s&=set(a)
print(les(s))


### FIXED CODE ###

n,m=map(int,input().split())
s=set(range(1,m+1))
for i in range(n):
    k,*a=list(map(int,input().split()))
    s&=set(a)
print(len(s))
N=int(input())
X=list(map(int,input().split()))
D=[]
for i in range(min(X),max(X)):
    sum=0
    for j in range(len(X)):
        sum += abs(X[j]-i)**2
    D.append(sum)
print(min(D))


### FIXED CODE ###

N=int(input())
X=list(map(int,input().split()))
D=[]
for i in range(1,101):
    sum=0
    for j in range(len(X)):
        sum += abs(X[j]-i)**2
    D.append(sum)
print(min(D))
def abc106_c():
    s = input()
    k = int(input())

    if s[:k] == "1"*k:
        return 1
    else:
        return (s.replace("1", ""))[0]


print(abc106_c())

### FIXED CODE ###

def abc106_c():
    s = input()
    k = int(input())

    if s[:k].replace("1", "") == "":
        return 1
    else:
        return (s.replace("1", ""))[0]


print(abc106_c())
n,m = map(int, input().split())
if n == 1:
    print(input().split()[0])
else:
    kdict = {i:0 for i in range(1,m+1)}
    for _ in range(n):
        for i in map(int, set(input().split()[1:])):
            kdict[i] += 1
    print(len([i for i in kdict.values()() if i == n]))


### FIXED CODE ###

n,m = map(int, input().split())
if n == 1:
    print(input().split()[0])
else:
    kdict = {i:0 for i in range(1,m+1)}
    for _ in range(n):
        for i in map(int, set(input().split()[1:])):
            kdict[i] += 1
    print(len([i for i in kdict.values() if i == n]))
road = int(input())
while road > 0:
    answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
    for _ in range(road):
        c1, c2, w = (int(n) for n in input().split(" "))
        answer[c1][c2] = w
        answer[c2][c1] = w
    city = max(connect.keys()) + 1
    for i in range(city):
        for j in range(city):
            for k in range(city):
                answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
    sum_ans = [-1 , float("inf")]
    for i in range(city):
        if sum(answer[i][:city]) < sum_ans[1]:
            sum_ans = [i, sum(answer[i][:city])]
    print(*sum_ans)
    road = int(input())

### FIXED CODE ###

road = int(input())
while road > 0:
    answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
    city = 0
    for _ in range(road):
        c1, c2, w = (int(n) for n in input().split(" "))
        answer[c1][c2] = w
        answer[c2][c1] = w
        city = max(city, c1, c2)
    city += 1
    for i in range(city):
        for j in range(city):
            for k in range(city):
                answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
    sum_ans = [-1 , float("inf")]
    for i in range(city):
        if sum(answer[i][:city]) < sum_ans[1]:
            sum_ans = [i, sum(answer[i][:city])]
    print(*sum_ans)
    road = int(input())