Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(10**7) #再帰関数の呼び出し制限

N = int(input())

def ch(x, y):
    cnt = 0
    while x**cnt <= y:
        cnt += 1
    return cnt

coin = [1]
for i in range(1, ch(6, N)):
    coin.append(6**i)

for i in range(1, ch(9, N)):
    coin.append(9**i)

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    
    res = n
    
    for c in coin:
        res = min(res, rec(n-c)+1)
    
    memo[n] = res
    return memo[n]

memo = [-1]*(10**5+10)
rec(N)
print(memo[N])

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    
    res = n
    i = 1
    while 6**i <= n:
        res = min(res, rec(n - 6**i) + 1)
        i += 1
    
    i = 1
    while 9**i <= n:
        res = min(res, rec(n - 9**i) + 1)
        i += 1
    
    memo[n] = res
    return res

n = int(input())
memo = [-1]*(n+10)
print(rec(n))
import numpy as np
N=int(input())
P=np.array(list(map(int, input().split())))



mini=1
count=1
index_min=P.argmin()
while P[0]>mini:
  if P==P.sort()[::-1]:
    count+=P.shape[0]
    break
  P=P[:index_min]
  mini=min(P)
  index_min=P.argmin()
  count+=1
"""
count=1
for i in range(1,N):
  if min(P[:i+1])==P[i]:
    count+=1
"""
print(count)



### FIXED CODE ###

n=int(input())
p=list(map(int, input().split()))
ans=1
l=[p[0]]
buf=p[0]
for i in range(1,n):
    l.append(p[i])
    if p[i]<=buf:
        ans+=1
        buf=p[i]
print(ans)
import math
def solve():
    n, m, q = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(q)]

    ans = 0
    for i in range(2**(n-2)):
        cur = []
        for j in range(n-2):
            if (i>>j)&1:
                cur.append(i+1)
        A = [1] + cur + [n, m]
        print(A)
        tot = 0
        for k in range(q):
            a, b, c, d = l[k]
            if b+1 <= n and A[b] - A[a] == c:
                print(A[0], A[a])
                tot += d
        ans = max(ans, tot)
    
    return ans


print(solve())


### FIXED CODE ###

from itertools import combinations_with_replacement
def solve():
    n, m, q = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(q)]

    com = [int(x) for x in range(1, m+1)]
    ans = 0
    for i in combinations_with_replacement(com, n-1):
        cur = list(i)
        A = [1] + cur
        tot = 0
        for k in range(q):
            a, b, c, d = l[k]
            if A[b-1] - A[a-1] == c:
                tot += d
        ans = max(ans, tot)
    
    return ans


print(solve())
[N,M,Q] = list(map(int,input().split()))

abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))

from itertools import permutations, combinations,combinations_with_replacement,product
AA=range(1,M+1)
CM = list(combinations(AA,N))


wa =0
A=[0]*N
dammy=[]
for i in range(len(CM)):
        A = sorted(CM[i])
        for j in range(Q):
            #print(abcd[2][j])
            if (A[abcd[j][1]-1] - A[abcd[j][0]-1]) == abcd[j][2]:
                wa+=abcd[j][3]
        dammy.append(wa)
        wa =0

print(max(dammy))

### FIXED CODE ###

[N,M,Q] = list(map(int,input().split()))

abcd = []
for i in range(Q):
    abcd.append(list(map(int,input().split())))

from itertools import permutations, combinations,combinations_with_replacement,product
AA=range(1,M+1)
CM = list(combinations_with_replacement(AA,N))
#print(CM)
wa = 0
A = [0]*N
dammy=[]
for i in range(len(CM)):
    A = CM[i]
    for j in range(Q):
        #print(abcd[2][j])
        if (A[abcd[j][1]-1] - A[abcd[j][0]-1]) == abcd[j][2]:
            wa+=abcd[j][3]
    dammy.append(wa)
    wa =0

print(max(dammy))
N = int(input())
a = list(map(int,input().split()))
one = 0
four = 0
two = 0
     
for j in range(N):
     
  if a[j]%2 == 1:
	one += 1
  elif a[j]%4 == 0:
	four += 1
  else :
	two +=1
     
      
if one <= four:
	print('Yes')
else :
	if two == 0:
          if four >= (one+1):
	    print('Yes')
        else:
	  print('No')

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
one = 0
four = 0
two = 0

for j in range(N):

  if a[j]%2 == 1:
    one += 1
  elif a[j]%4 == 0:
    four += 1
  else :
    two +=1

print("Yes" if four >= one or (four == one - 1 and two == 0) else "No")
S = int(input())

if (S[0] == S[1] or S[1] == S[2] or S[2] == S[3]):
    print('Bad')
else:
    print('Good')

### FIXED CODE ###

S = str(input())

if (S[0] == S[1] or S[1] == S[2] or S[2] == S[3]):
    print('Bad')
else:
    print('Good')
n = map(int,input().split())
print(n*n*n/27)

### FIXED CODE ###

n = int(input())
print((n/3)**3)
a, b, k = map(int, input().split())
da = []
db = []
dc = []
for i in range(1,a+1):
    if a%i == 0:
    	da.append(i)

for j in range(1, b+1):
    if b%j == 0:
    	db.append(j)

for k in range da:
    if k in db:
    	dc.append(k)

### FIXED CODE ###

a, b, k = map(int, input().split())
da = []
db = []
dc = []
for i in range(1,a+1):
    if a%i == 0:
    	da.append(i)

for j in range(1, b+1):
    if b%j == 0:
    	db.append(j)

for l in da:
    if l in db:
    	dc.append(l)

dc.sort(reverse = True)
print(dc[k-1])
n, m = map(int, input().split())
ab = [ list(map(int, input().split())) for _ in range(m) ]

graph = [ [False] * 8 for _ in range(8) ]
visited = [False] * n

def dfs(a, N, visited):
    finish = True
    for i in range(N):
        if not visited[i]:
            finish = False
    if finish:
        return 1
    ans = 0
    for i in range(N):
        if not graph[a][i] or visited[i]:
            continue
        visited[i] = True
        ans += dfs(i,N,visited)
        visited[i] = False

for i in range(m):
    graph[ab[i][0]-1][ab[i][1]-1], graph[ab[i][1]-1][ab[i][0]-1] = True, True

visited[0] = True
print(dfs(0,n,visited))

### FIXED CODE ###

n, m = map(int, input().split())
ab = [ list(map(int, input().split())) for _ in range(m) ]

graph = [ [False] * 8 for _ in range(8) ]
visited = [False] * n

def dfs(a, N, visited):
    finish = True
    for i in range(N):
        if not visited[i]:
            finish = False
    if finish:
        return 1
    ans = 0
    for i in range(N):
        if not graph[a][i] or visited[i]:
            continue
        visited[i] = True
        ans += dfs(i,N,visited)
        visited[i] = False
    return ans

for i in range(m):
    graph[ab[i][0]-1][ab[i][1]-1], graph[ab[i][1]-1][ab[i][0]-1] = True, True

visited[0] = True
print(dfs(0,n,visited))
n = int(input())
a = [int(input()) for i in range(n)]
dist = []
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dist.append(abs(a[i]-a[j]))
print(max(dist))

### FIXED CODE ###

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

print(max(a)-min(a))
dp = [0] * (n+1)
dp[0] = 1

for i in range( 1, n+1):
    if i in a:
        dp[i]= 0
    else:
        dp[i]= (dp[i-1] + dp[i-2]) % 1000000007

print(dp[n])

### FIXED CODE ###

n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
a = set(a)
dp = [0] * (n+1)
dp[0] = 1

for i in range( 1, n+1):
    if i in a:
        dp[i]= 0
    else:
        dp[i]= (dp[i-1] + dp[i-2])

print(dp[n] % 1000000007)
import math


def insertionsort(A, n, g):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v
    return cnt


def shellsort(A, n):
    G = []         ##??§????°???¨?????????????????°???(gap??????????????????)???????????????
    gap = 1
    while gap <= math.ceil(n / 3):
        G.append(gap)
        gap = gap * 3 + 1
    G = G[::-1]
    m = len(G)
    print(m)
    print(*G)
    cnt = 0
    for i in range(m):
        insertionsort(A, n, G[i])
    print(cnt)


n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellsort(A, n)
print("?\n".join(map(str, A)))  ##a?????¨??????????´????str()????????§??????list??????????????????

### FIXED CODE ###

import math


def insertionsort(A, n, g):
    cnt = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v
    return cnt


def shellsort(A, n):
    G = []         
    gap = 1
    while gap <= math.ceil(n / 3):
        G.append(gap)
        gap = gap * 3 + 1
    G = G[::-1]
    m = len(G)
    print(m)
    print(*G)
    cnt = 0
    for i in range(m):
        cnt += insertionsort(A, n, G[i])
    print(cnt)


n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellsort(A, n)
for i in range(n):
    print(A[i])
a,b=input(),split()
print('HD'[a!=b])

### FIXED CODE ###

a,b=input().split()
print('HD'[a!=b])
import itertools

white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.combinations_with_replacement(white_num_list, len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
 
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    if 0 in white_num_list:
        white_num_list.remove(0)
    placeholder = str(min(white_num_list))
    return int(placeholder * (len(str(N)) + 1))
  
print(price(N, num_list, white_num_list))

### FIXED CODE ###

a, b, c = map(int,input().split(" "))

count_5 = 0
count_7 = 0

#aについて
if a == 5:
	count_5 += 1
elif a == 7:
	count_7 += 1

#bについて
if b == 5:
	count_5 += 1
elif b == 7:
	count_7 += 1

#cについて
if c == 5:
	count_5 += 1
elif c == 7:
	count_7 += 1

if count_5 == 2 and count_7 == 1:
  print("YES")
else:
  print("NO")
import collections

n = int(input())

f = [1] * (n + 1)
for i in range(2, n + 1):
    if f[i] != 1: continue
    m = i
    while m <= n:
        tmp = m
        cnt = 0
        while tmp % i == 0:
            tmp = tmp // i
            cnt += 1
            loop += 1
        f[m] *= cnt + 1
        m += i

ans = 0
for i in range(1, n + 1):
    ans += i * f[i]
print(ans)

### FIXED CODE ###

import collections

n = int(input())

f = [1] * (n + 1)
for i in range(2, n + 1):
    if f[i] != 1: continue
    m = i
    while m <= n:
        tmp = m
        cnt = 0
        while tmp % i == 0:
            tmp = tmp // i
            cnt += 1
        f[m] *= cnt + 1
        m += i

ans = 0
for i in range(1, n + 1):
    ans += i * f[i]
print(ans)
import sys
input = sys.stdin.readline
A, B, C = [int(x) for x in input().split()]
AmodB = A % B
if C % AmodB == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

import sys
input = sys.stdin.readline
A, B, C = [int(x) for x in input().split()]
AmodB = A % B
if AmodB == 0:
    if C == 0:
        print("YES")
        sys.exit()
    else:
        print("NO")
        sys.exit()

mod = [AmodB]
i = AmodB
while True:
    if C in mod:
        print("YES")
        sys.exit()
    i += AmodB
    i %= B
    if i in mod:
        print("NO")
        sys.exit()
    else:
        mod.append(i)
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a / 2
        a /= 2
        
    else:
        if b % 2 == 1:
            b -= 1
        a += b / 2
        b /= 2
print(f"{a} {b}")

### FIXED CODE ###

a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a //= 2
        
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b //= 2
print(a, b)
s = raw_input()
a,b = s.split('/')
a,b = int(a),int(b)

def mul(a,b):
    if a <= 9 and a >=1 and (1 <= b <= 9):
        return a * b
    else:
        return -1

print mul(a,b)

### FIXED CODE ###

def main(a, b):
    if a>9:
        return -1
    if b>9:
        return -1
        
    return a*b

inp = input().split();
a = int(inp[0])
b = int(inp[1])
print(main(a,b))
N, X, M = map(int, input().split())
table = [0]*M

pre = X%M
table[pre] = 1
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        fir = table[A]
        sec = cnt
        break
    
ans = 0
for i in range(fir + (N-fir)%(sec-fir)):
    ans += seq[i]
mul = (N-fir)//(sec-fir)
for i in range(fir, sec):
    ans += seq[i]*mul

print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
table = [0]*(M+1)

pre = X
table[pre] = 0
seq = [pre]
cnt = 0
while True:
    cnt += 1
    A = pre**2%M
    if not table[A]:
        seq.append(A)
        table[A] = cnt
        pre = A
    else:
        f = table[A]
        s = cnt
        break
    
ans = 0
for i in range(f + (N-f)%(s-f)):
    ans += seq[i]
m = (N-f)//(s-f)
for i in range(f, s):
    ans += seq[i]*m

print(ans)
k = int(input())
x = 7 % k
for i in range(1, k+1):
    if x == 0:
        print(i)
    x = (x*10+7)%k
print(-1)


### FIXED CODE ###

x,k,d = map(int, input().split())
x = abs(x)
kd = k*d

if kd<=x:
    print(x-kd)
else:
    count = x // d
    k_dash = k - count
    x -= count * d
    if k_dash % 2 == 0:
        print(x)
    else:
        print(d-x)
import math
import fraction
from functools import reduce


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
a = [int(i) for i in input().split()]

ans1 = 0

lcm = lcm_list(a)

for num in a:
    ans1 += (lcm - 1) % num

print(ans1)


### FIXED CODE ###

import fractions
from functools import reduce
 
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
 
 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
 
n = int(input())
a = [int(i) for i in input().split()]
 
ans1 = 0
 
lcm = lcm_list(a)
 
for num in a:
    ans1 += (lcm - 1) % num
 
print(ans1)
a = int(input())
b = int(input())
c=int(a*b)
if c%2==1:
  print("Odd")
else:
  print("Even")

### FIXED CODE ###

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

print("Even" if a*b%2==0 else "Odd")
import sys
sys.setrecursionlimit(100000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))
N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  a=list(s1)
  b=list(s2)
  a.sort()
  b.sort()
  if a==b:
    return True
  else:
    return False
  
cnt=0
for i in range(len(sn)-1):
  m=1
  for ii in range(i+1,len(sn)):
    if sn[ii] and check(sn[i],sn[ii]):
      cnt+=m
      m+=1
      sn[ii]=None

print(cnt)

### FIXED CODE ###

N=int(input())
dict={}
for _ in range(N):
  s=''.join(sorted(input()))
  dict[s]=dict.setdefault(s,0)+1
  
cnt=0
for c in dict.values():
  cnt+=(1+c-1)*(c-1)//2
  
print(cnt)
x = input()
n = []
for i in range(x):
    n[i] = input()

def cal(n):
    count = 0
    for i in range(len(n)):
        if n[i] % 2 == 0 and n[i] % 3 == 0 and n[i] % 5 == 0:
            count += 1
    if count == len(n):
        print("APPROVED")
    else:
        print("DENIED")

cal(n)


### FIXED CODE ###


x = int(input())

n = []
# for i in range(x):
#     n[i] = int(input())
n = [int(e) for e in input().split()]

def cal(n):
    count = 0
    for i in range(len(n)):
        if n[i] % 2 == 0:
           if n[i] % 3 == 0 or n[i] % 5 == 0:
                count += 1
        else:
            count += 1
    if count == len(n):
        print("APPROVED")
    else:
        print("DENIED")

cal(n)
from math import gcd
from fractions import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)

### FIXED CODE ###

from fractions import gcd
from functools import reduce

n, x = map(int, input().split())
town = map(int, input().split())

dist = map(lambda y: abs(x - y), town)
res = reduce(gcd, dist)
print(res)
def factorial(x):
  if x == 1: return 1
  else: return x*factorial(x-1)
 
n = int(input())
n_bikkuri = factorial(n)
 
total = 1
 
for i in range(2, n_bikkuri+1):
  n_b = n_bikkuri
  while(not n_b % i):
    total += 1
    n_b /= i
  
print(total % int(1e9+7))

### FIXED CODE ###

mod = 1000000000 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
dat = [0] * 2000 # 約数として求められたある数の合計

# N! の各要素の素因数分解をする
res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod

print(res)
a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) + max(a) * (2 ** (K - 1)))

### FIXED CODE ###

a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) - max(a) + max(a) * (2 ** k))
n = int(input())
a = [0] + list(map(int, input().split()))

for i in range(1, n + 1):
    print(f"node {i}: key = {a[i]}," + (f" parent key = {a[int(i / 2)]}," if i != 1: else "") + (f"{ left key = {a[2 * i]}, " if i * 2 <= n: else = "") + (f" right key = {a[2 * i + 1]}," if 2 * i + 1 <= n: else = ""))
    


### FIXED CODE ###

n = int(input())
a = [0] + list(map(int, input().split()))
def pi(i):
    global a, n
    s = f"node {i}: key = {a[i]}, "
    if i != 1:
        s += f"parent key = {a[int(i / 2)]}, "
    if i * 2 <= n:
        s += f"left key = {a[2 * i]}, "
        if i * 2 + 1 <= n:
            s += f"right key = {a[2 * i + 1]}, "
    print(s)

for i in range(1, n + 1):
    pi(i)
import math
from functools import reduce

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

input()
l = list(map(int, input().split()))
m = reduce(lcm, l, 1) - 1

ans = 0
for i in range(len(l)):
	ans += m % l[i]

print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
print(sum(l) - n)
n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)
for i in range(n):
    if b[a[i]] == 0:
        b[a[i]] += 1
    else:
        d = a[i]

l = 0
r = 0
c = 0
for i in range(n+1):
    if a[i] != d and c == 0:
        l += 1
    elif a[i] != d and c == 2:
        r += 1
    if a[i] == d:
        c += 1


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7
N = 100001
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


print(n)
for i in range(2, n+2):
    print(cmb(n+1, i, mod)-max(0, r-i+2)-max(0, l-i+2))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)
for i in range(n+1):
    if b[a[i]] == 0:
        b[a[i]] += 1
    else:
        d = a[i]

l = 0
r = 0
c = 0
for i in range(n+1):
    if a[i] != d and c == 0:
        l += 1
    elif a[i] != d and c == 2:
        r += 1
    elif a[i] == d:
        c += 1


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7
N = 100011
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(1, n+2):
    print((cmb(n+1, i, mod)-cmb(r+l, i-1, mod))%mod)
a,b = map(int,raw_input().split())
sum=1
if((a<0 and b>0) or a==0 or b==0):
    print("Zero")
else:
    for i in range(a,b+1):
        sum*=i
    if(sum>0):
        print("Positive")
    else:
        print("Negative")


### FIXED CODE ###

a,b = map(int,raw_input().split())

if((a<0 and b>0) or a==0 or b==0):
    print("Zero")
elif(a>0):
    print("Positive")
else:
    if((((a-b)*-1)+1)%2==1):
        print("Negative")
    else:
        print("Positive")
# -*- coding: utf-8 -*-

def parse_input():

    # 出力
    nm = input().split(" ")
    n = int(nm[0])
    m = int(nm[1])

    rows = []
    for i in range(0, n):
        rows.append([int(e) for e in input().split(" ")])

    return (n, m, rows)

def solve(n, m, rows):

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return str(len(result))

def main():

    print(solve(parse_input()))

if __name__ == '__main__':

    main()


### FIXED CODE ###

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

def solve(n, m, *lines):

    
    rows = []
    for line in lines:
        rows.append([int(e) for e in line.split(" ")])

    # print(n)
    # print(m)
    # print(rows)

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return str(len(result))

def main():
    # 出力
    params = []
    nm = input().split(" ")
    n = int(nm[0])
    m = int(nm[1])
    params.append(n)
    params.append(m)

    for i in range(0, n):
        params.append(input())   
    print(solve(*params))

if __name__ == '__main__':

    main()
color = input()
num = int(input())
if num >= 3200:
    print(s)
else:
    print('red')


### FIXED CODE ###

num = int(input())
color = input()
if num >= 3200:
    print(color)
else:
    print('red')
s=str(input())
a=len(s)
b=len(s[1:len[s]])
print(s[0]+'a'+s[-1])


### FIXED CODE ###

s=input()
l=len(s)
print(s[0]+str(l-2)+s[-1])
n = int(input())
d,x = map(int, input().split())
a = [input() for i in range(n)]
co = 0
for i in range(1, d + 1):
  for j in a:
    for k in range(d + 1):
      if i ==  k * j + 1:
        co =+ 1
co += x
print(co)

### FIXED CODE ###

n = int(input())
d,x = map(int, input().split())
a = [int(input()) for i in range(n)]
co = 0
for i in range(1, d + 1):
  for j in a:
    for k in range(d + 1):
      if i ==  k * j + 1:
        co += 1
co += x
print(co)
s=input()
ans=[0]*4
checK='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if (ans[0]%2+ans[2]%2)%2==0 and (ans[1]%2+ans[3]%2)%2==0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s=input()
ans=[0]*4
check='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if ans[0]!=0 and ans[2]!=0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
elif ans[0]!=0 and ans[2]!=0 and ans[1]==0 and ans[3]==0:
  print('Yes')
elif ans[0]==0 and ans[2]==0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
else:
  print('No')