peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import math

a, b, h, m = map(float, input().split(" "))
arg_a = 2 * math.pi * (h + m / 60) / 12
arg_b = 2 * math.pi * m / 60
arg = min(abs(arg_a - arg_b), 2 * math.pi - abs(arg_a - arg_b))
"""
print(str(arg_a / (math.pi * 2) * 360)
      + " "
      + str(arg_b / (math.pi * 2) * 360))
print(str(arg_a) + " " + str(arg_b))
print(arg / (math.pi * 2) * 360)
"""
length = math.sqrt((a*a + b*b) - (2*a*b * math.cos(arg)))
print(length)
# Judge status: Wrong Answer
s = str(input())
cnt = 0

print(s[0:13])

for i in range(len(s)-3):
    for j in range(len(s)-i+1):
        if j < 3:
            continue
        if (int(s[i:i+j]) % 2019 == 0):
            cnt += 1

print(cnt)
# Judge status: Accepted
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A =[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append((a,b))

now =0
A_sort =sorted(A,key=lambda x: x[1])
for  progress,deadline in A_sort:
    now +=progress
    if now <=deadline:
        ans ="Yes"
    else:
        ans ="No"
        break
print(ans)
# Judge status: Accepted
from fractions import gcd
n = int(input())
an = list(map(int, input().split()))

left = [an[0]]
right = [an[-1]]
for i in range(1, n-1):
    left.append(gcd(left[-1], an[i]))
    right.append(gcd(right[-1], an[-(i+1)]))

ans = max(right[-1], left[-1])
for i in range(n-2):
    ans = max(ans, gcd(left[i], right[-(i+2)]))

print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split());print("NYoe s"[(a<c<b or b<c<a)::2])
# Judge status: Wrong Answer
A, B, C, K= map(int, input().split())

if K%2==1: 
    ans = A - B
else:
    ans = B - A

if ans >= 10**8:
    ans = 'Unfair'
elif ans <= -1*10**8:
    ans = 'Unfair'

print(ans)
# Judge status: Accepted
import bisect

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

l.sort()
ans = 0

for b in range(n - 2):
    for c in range(b + 1,n - 1):
        left = bisect.bisect_left(l,l[c] + l[b])
        ans+=left - c - 1

print(ans)
# Judge status: Accepted
N,K=map(int,input().split())
S=input()

now=S[0]
a=-1
for s in S:
    a+=now==s
    now=s
a+=K*2
ans=min(N-1,a)
print(ans)
# Judge status: Accepted
S=input()
if (S[0]==S[1] and S[2]==S[3] and S[0]!=S[3]) or (S[0]==S[2] and S[1]==S[3] and S[0]!=S[3]) or (S[0]==S[3] and S[2]==S[1] and S[0]!=S[1]):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
W,H,X,Y=map(int,input().split())

ans2=0
if ((W%2==0)*W//2==X)*(X>0) and ((H%2==0)*H//2==Y)*(Y>0):
    ans2=1

ans1=W*H/2

print(ans1,ans2)
# Judge status: Accepted
n, k = map(int, input().split())
h = list(map(int, input().split()))

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

f_inf = float('inf')

for _ in range(k+2):
    h.append(f_inf)

dp = [f_inf]*(n+k)

dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        if i >= j:
            dp[i] = chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])
# Judge status: Accepted
from collections import deque
n,m = map(int, input().split())
V = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)
ans = [-1]*(n+1)
q = deque()
q.append(1)
while len(q):
    p = q.popleft()
    for c in V[p]:
        if c > 1 and ans[c] < 0:
            ans[c] = p
            q.append(c)
print('Yes')
for i in range(2,n+1): print(ans[i])
# Judge status: Wrong Answer
N = int(input())
K = format(N,'b')
L = len(K)
for i in range(L):
  if K[-(i+1)] == "1":
    print(2**(i))
# Judge status: Accepted
def answer(a: int, b: int) -> int:
    return sum(range(1, b - a + 1)) - b


def main():
    a, b = map(int, input().split())
    print(answer(a, b))


if __name__ == '__main__':
    main()
# Judge status: Accepted
A, B = input().split(' ')
A = int(A)
B = int(B)
if B == 1:
  print(0)
else:
  print(-(-(B-1) // (A-1)))
# Judge status: Accepted
import numpy as np

N = int(input())
time_array = np.array([int(input()) for _ in range(5)])
N_array = np.ones(5, dtype=np.int)*N

count_array = np.ceil(N_array / time_array)
answer = int(count_array.max() + 4)

print(answer)
# Judge status: Accepted
#ABC139B
a,b = map(int,input().split())
ans = 0 
outlet = 1
while b>outlet:
    outlet = outlet - 1
    outlet = outlet + a
    ans = ans + 1
print(ans)
# Judge status: Accepted
def main():
    x, k, d = map(int, input().split())
    if x < 0: x = -x

    if k * d <= x:
        print(x - k*d)
        return

    x %= d + d
    if k % 2 == 1:
        x -= d
    else:
        x = min(abs(x-d-d), x)

    print(abs(x))

main()
# Judge status: Accepted
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:]==t[:n-i]:
        print(n+i)
        break
else:print(2*n)
# Judge status: Accepted
import math
N = int(input())
r = 0
for i in range(2,int(math.sqrt(N))+1):
    if N % i == 0:
        r = max(r, i)

if r > 0:
    print(r+(N//r)-2)
else:
    print(N-1)
# Judge status: Accepted
n,a,b,c,d = map(int,input().split())
s = input()

ans = 'Yes'
if '##' in s[a-1:c]:
  ans = 'No'  
if '##' in s[b-1:d]:
  ans = 'No'
  
if c > d:
  if '...' not in s[b-2:d+1]:
    ans = 'No'

print(ans)
# Judge status: Wrong Answer
# 083 B
N,A,B = map(int, input().split())
t = 0
for i in range(N):
    s =0
    n = i+1
    while n > 0:
        s += n%10
        n = int(n/10)
    print(s)
    if (s >= A)and(s <= B):
        t += (i+1)
print(t)
# Judge status: Accepted
N,M = list(map(int,input().split()))
print(abs((N-2)*(M-2)))
# Judge status: Wrong Answer
f=lambda:map(int,input().split())
N,X=f()
*A,=f()

c=0
for i in range(N-1):
 print(A[i]+A[i+1]-X)
 c+=max(0,A[i]+A[i+1]-X)
 A[i+1]=min(A[i+1],X-A[i])
print(c)
# Judge status: Accepted
a,b,c=map(int,input().split())
print('Yes' if a<c<b or a>c>b else 'No')
# Judge status: Wrong Answer
S=list(input())
hug=0
for i in range(len(S)//2):
    if S[i]!=S[len(S)-i-1]:
        hug+=1
print(hug)
# Judge status: Wrong Answer
N=int(input())
if N%2==0:
	print(N/2)
else:
	print(N+1/2)
# Judge status: Accepted
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
a,b= LS()

jo = int(a + b)
flag = 0
for i in range(1,int(jo/2)+1):
    if i * i == jo:
        flag = 1
        break
    
if flag == 0:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
S = str(input())

S_len = len(S)
half_len = int(len(S)/2)

if S_len%2 != 0:
    print('No')
    exit()

for i in range(half_len):
    if S[2*i:2*i+2] != 'hi':
        print('No')
        exit()

print('Yes')
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)
# Judge status: Accepted
[A,B,C] = list(map(int,input().split()))
K = int(input())

cnt=0

while True:
    if A>=B:
        B=B*2
        cnt+=1
    else:
        break

while True:
    if B>=C:
        C=C*2
        cnt+=1
    else:
        break

if cnt<=K:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
#%%
n, k, s = map(int, input().split())
ans = []
tmp = 0
for i in range(n):
    if i < k :
        tmp = s
    else:
        if s == 1:
            tmp = 2
        else:
            tmp = 1
    ans.append(str(tmp))
print(' '.join(ans))
# Judge status: Wrong Answer
s = input()
s = s.replace('S', '')
print(len(s))
# Judge status: Accepted
n = int(input())
s1 = [int(input()) for i in range(n)]
total = sum(s1)
if total%10 != 0:
    print(total)
else:
    s1.sort()
    s2=[s for s in s1 if s%10!=0]
    if s2:
        print(total-s2[0])
    else:
        print(0)
# Judge status: Accepted
a,b,c,x,y = map(int,input().split())
l = 0
flg = x
if x > y:
    l += (x - y) * a
    flg = y
elif x < y:
    l += (y - x) * b
else:
    pass
l += flg * 2 * c
n = max(x,y) * 2 * c
m = x * a + y * b
print(min(l,n,m))
# Judge status: Accepted
# https://atcoder.jp/contests/abc101/tasks/arc099_a


import sys
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, K = read_ints()
if N == K:
    print(1)
    exit()
A = read_ints()

K -= 1
i = A.index(1)

# 怒りの全探索
ans = 0
for j in range(0, N - 1, K):
    ans += 1

print(ans)
# Judge status: Accepted
len = int(input())

dict = {}

for i in range(len):
    result = input()

    if result in dict:
        dict[result] += 1
    else:
        dict[result] = 1

keys = ['AC', 'WA', 'TLE', 'RE']
for k in keys:
    cnt = 0
    if k in dict:
        cnt = dict[k]
    print("{0} x {1}".format(k, cnt))
# Judge status: Accepted
S=input()
S=S.replace("/","")
if int(S)<=20190430:
    print("Heisei")
else:
    print("TBD")
# Judge status: Accepted
a, b, c = sorted(map(int, input().split()))
print(10*c+b+a)
# Judge status: Accepted
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

m = a[0]
for i in range(1,n):
    m = m^a[i]

sol = [str(m^a[i]) for i in range(n)]
print(' '.join(sol))
# Judge status: Wrong Answer
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=0
aa=[]
for i in range(n):
    for j in range(n):
        if j-a[j]-0.5<=i and j+a[j]+0.5>=i:
            b+=1
        elif j-a[j]-0.5>i:
            break
    aa.append(b)
    b=0
    # print(i,*a)
print(*aa)
# Judge status: Accepted
N , K =map(int,input().split())
H = []
for i in range(N):
    H.append(int(input()))
H =sorted(H)

ans = 1000000000
for j in range(N-K+1):
    ans=min(int(H[j+K-1])-int(H[j]),ans)
    

print(ans)
# Judge status: Accepted
n = int(input())
a,b = 2,1
for i in range(n):
    a,b=b,a+b
print(a)
# Judge status: Accepted
n = int(input())

print(111 * ((n-1) // 111 + 1))
# Judge status: Accepted
from math import gcd
from functools import reduce


def lcm(a, b):
    return (a * b) // gcd(a, b)


def main():
    n = int(input())
    t = {int(input()) for _ in range(n)}
    print(reduce(lcm, t))


if __name__ == '__main__':
    main()
# Judge status: Accepted
s,t = input().split()
a,b = map(int,input().split())
A = input()

if A == s:print(a-1,b)
else:print(a,b-1)
# Judge status: Wrong Answer
tmp = list(map(int, input().split()))

for i in range(2):
    if tmp[i] == 1:
        tmp[i] == 14

A, B = tmp

if A > B:
    print("Alice")
elif A == B:
    print("Draw")
else:
    print("Bob")
# Judge status: Accepted
from itertools import accumulate
from bisect import bisect_left,bisect_right

def main():
    n,m,k=map(int,input().split())
    a=[0]+list(accumulate(map(int,input().split())))
    b=[0]+list(accumulate(map(int,input().split())))

    result = 0
    for i in range(n+1):
        tmp = k - a[i]
        if tmp < 0:
            continue
        tmpNum = i + bisect_right(b, tmp) - 1
        if tmpNum > result:
            result = tmpNum

    print(result)       


if __name__ == "__main__":
    main()
# Judge status: Accepted
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(a,b,c,d,s):
  if '##' in s[a:c+1] or '##' in s[b:d+1]:
    return False
  if c < d:
    return True
  elif c > d:
    if "..." in s[b-1:d+2]:
      return True
    else:
      return False
  else:
    raise ValueError




def main():
  N,A,B,C,D = map(int,input().split())
  A -= 1
  B -= 1
  C -= 1
  D -= 1
  S = input()
  print("Yes" if solve(A,B,C,D,S) else "No")
  return

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counts = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (A*500 + B*100 + C*50)==X:
                counts += 1
                
print(counts)
# Judge status: Accepted
W, H, N = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)

max_x = max(a1) if a1 else 0
min_x = min(a2) if a2 else W
max_y = max(a3) if a3 else 0
min_y = min(a4) if a4 else H
ans = max(0, min_x - max_x) * max(0, min_y - max_y)
print(ans)
# Judge status: Accepted
A,B=map(int,input().split())

count=0

while count*A-count+1<B:
    count+=1

print(count)
# Judge status: Accepted
s = input()

A = s.find("A")
Z = s.rfind("Z")
print(Z-A+1)
# Judge status: Accepted
x,y = list(map(int,input().split()))
a = [x]
while a[-1] < y:
    a.append(a[-1]*2)
if a[-1] > y: a.pop(-1)
print(len(a))
# Judge status: Accepted
n = int(input())
a = []
b = []
for i in range(n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
a.sort()
b.sort()

if n%2==1:
    ans = b[n//2]-a[n//2]+1
else:
    x1 = a[n//2]+a[n//2-1]
    x2 = b[n//2]+b[n//2-1]
    ans = x2-x1+1
print(ans)
# Judge status: Wrong Answer
N = int(input())
L = list(map(int, input().split()))

L = sorted(L)
#print(L)

bucket=[0]*(2*10**3+1)
for val in L:
    bucket[val]+=1
#print(bucket)

for i in range(2*10**3):
    bucket[i+1] += bucket[i]
#print(bucket)


cnt=0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        cnt += bucket[L[i]+L[j]-1] - bucket[L[j]-1] -(1 if L[i] != L[j] else 2)
        #print(i,j,bucket[L[i]+L[j]-1], bucket[L[j]-1])
print(cnt)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ans = 1

if 0 in a:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        ans = -1
        break

print(ans)
# Judge status: Wrong Answer
import numpy as np
import math
n = input()
arr = np.array(list(map(int, input().split())))
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x
lcm_v = lcm(arr)
div_arr = lcm_v / arr
print(int(div_arr.sum()) % (10**9 + 7))
# Judge status: Accepted
#AtCoDeerくんとペンキ
def ABC_46_A():
    A,B,C = map(int, input().split())
    iroha = [0 for i in range(3)]
    iroha = []
    iroha.append(A)
    iroha.append(B)
    iroha.append(C)

    if iroha.count(A)==3:
        print(1)
    elif iroha.count(A)==2 or iroha.count(B)==2:
        print(2)
    else:
        print(3)

if __name__ == '__main__':

    ABC_46_A()
# Judge status: Wrong Answer
p,q,r = map(int, input().split())

print(max(p+q,q+r,r+p))
# Judge status: Accepted
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#
def main():
    n = II()
    s = IS()
    cnt_b = 0
    cnt_w = s.count('.')
    cnt = cnt_w
    for i in range(n):
        if s[i] == '#':
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

if N == 0:
	if A[0] == 1:
		print(1)
	else:
		print(-1)
	exit()

num = 1
M = [0] * (N+1)
for i in range(N+1):
	M[i] = num
	if A[i] > num:
		print(-1)
		exit()
	num = (num - A[i]) * 2
ans = sum(A)

inodes = 0
for i in range(N-1, -1, -1):
	inodes = min(M[i]-A[i], A[i+1]+inodes)
	ans += inodes
print(ans)
# Judge status: Accepted
n = int(input())
s = input()
t = s[:n//2]
if n%2 != 0:
    print('No')
elif s == t*2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
from collections import Counter
s=input()
t=input()
c1=list(Counter(s).values())
c2=list(Counter(t).values())
c1.sort()
c2.sort()
print('Yes' if c1==c2 else 'No')
# Judge status: Accepted
import re
print('AC' if re.match('^A[a-z]+C[a-z]+$', input()) else 'WA')
# Judge status: Wrong Answer
O = input()
E = input()
for o, e in zip(O, E):
    print(o,e, sep='', end='')
if abs(len(O) - len(E)) == 1:
    if abs(len(O) - len(E)) > 1:
        print(O[-1])
    elif abs(len(O) - len(E)) < 1:
        print(E[-1])
# Judge status: Accepted
n = int(input())
s = input()
#n = 45
#s = "tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"
ans = 0
alphabet = [chr(i) for i in range(97, 97+26)]
def count(i):
    num = 0
    a=list(set(list(s[:i])))
    b=list(set(list(s[i:])))
    for i in alphabet:
        if (i in a) & (i in b):
            num += 1
    return num
for j in range(1,len(s)-1):
    if ans < count(j): ans = count(j)
print(ans)
# Judge status: Wrong Answer
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        if csf[j][1] >= ans:
            ans = csf[j][0] + csf[j][1]
        else:
            ans += csf[j][0] + ans % csf[j][2]
    print(ans)
# Judge status: Accepted
# 参考　yy4さん
from heapq import heappush, heappop
import sys    
input = sys.stdin.readline    
n, m = map(int, input().split())
    
vmax = pow(10, 5)
jobs = {i:[] for i in range(1,vmax + 1)}
for _ in range(n):
    a, b = map(int, input().split())
    jobs[a].append(-b)
    

ans =0
hq = []
for i in range(1, m + 1):
    for j in jobs[i]:
        heappush(hq, j)
    if hq:
        v = heappop(hq)
        v *= -1
        ans += v
print(ans)
# Judge status: Accepted
x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
A.sort()
B.sort()
A=A[a-x:]
B=B[b-y:]
D=A+B+C
D.sort(reverse=True)
sum=0
for i in range(x+y):
    sum+=D[i]
print(sum)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

ans = 0

for i in range(N-1):
    if A[i+1] < A[i]:
        ans += A[i]-A[i+1]
        A[i+1] = A[i]

print(ans)
# Judge status: Wrong Answer
import numpy as np
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
#cnt = [0 for _ in range(n)]
win = [0 for _ in range(n)]
#p = np.array([k for _ in range(n)])
for ai in a:
  win[ai-1] += 1
print(win)

for w in win:
  if k-q+w<=0: print('No')
  else: print('Yes')
# Judge status: Wrong Answer
S=str(input())
T=str(input())
print('Yes' if S[0]==T[2] and S[1]==T[1] and S[2]==T[0] else 'No')
# Judge status: Wrong Answer
n = int(input())

print((n // 2) / n)
# Judge status: Accepted
k, a, b = map(int, input().split())

if b - a <= 2 or k-(a-1) <= 0:
    ans = 1 + k
else:
    k = k - (a-1)
    n = k // 2
    ans = (n-1) * (b-a) + b + (k-2*n)
print(ans)
# Judge status: Accepted
n,a,b =map(int, input().split())
s =input()
ca = 0
cb = 0
for i in s:
    if i=='a' and ca+cb<a+b:
        ca+=1
        print('Yes')
    elif i=='b' and ca+cb<a+b and cb<b:
        cb+=1
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
n = int(input())
s = list(map(int, input().split()))

if s == sorted(s):
  print('YES')
else:
  
  s1 = sorted(s)
  count = 0
  for i in range(n):
    if s1[i]!=s[i]: count+=1
      
  if count==2:
    print('YES')
  else:
    print('NO')
# Judge status: Wrong Answer
s = input()
ans = ""
for i in list(s):
	if i == "0" or i == "1":
		ans += i
	else:
		ans = ans[:-1]
print (ans)
# Judge status: Accepted
n, m = map(int, input().split())
H = list(map(int, input().split()))
ans = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1]<H[b-1]:
        ans[a-1] = 0
    elif H[b-1]<H[a-1]:
        ans[b-1] = 0
    else:
        ans[a-1], ans[b-1] = 0, 0
print(sum(ans))
# Judge status: Accepted
from collections import Counter
n = int(input())
s = input()
e = int(s.count('E'))
ans = e

a = 0
for i in range(n):
    if s[i] == 'W':
        a += 1
    b = e - ((i+1)-a)
    ans = min(ans, a+b)


print(ans)
# Judge status: Accepted
N = int(input())
S = input()
answer = 0
for i in range(1, N):
    # print(S[:i], S[i:])
    x = list(set(S[:i]))
    y = list(set(S[i:]))
    # print(x)
    # print(y)
    count = 0
    for j in range(len(x)):
        if x[j] in y:
            count += 1
    if answer <= count:
        answer = count

print(answer)
# Judge status: Wrong Answer
s = input()
print("2017/01/"+s[-2:])
# Judge status: Accepted
import sys
input = sys.stdin.readline

a = ['0'] + list(input())
n = len(a)-1
for i in range(n):
    a[i] = int(a[i])

res = 0
for i in range(n-1,-1,-1):
    if a[i] <= 4:
        res += a[i]
    elif a[i] == 5:
        if a[i-1] >= 5:
            res += 5
            a[i-1] += 1
        else:
            res += 5

    else:
        res += 10-a[i]
        a[i-1] += 1
print(res)
# Judge status: Accepted
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
h=lnii()+[10**10]

ans=0
t_ans=0
for i in range(n):
  if h[i]>=h[i+1]:
    t_ans+=1
  else:
    ans=max(ans,t_ans)
    t_ans=0

print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

ab = a - b
cab = c - ab

if cab >= 0:
    print(0)

if cab < 0:
    print(cab)
# Judge status: Accepted
N = int(input())

ans = 0
for i in range(1, N+1):
    if i%2 != 0:
        cnt = 0
        for j in range(1, i+1):
            if i%j == 0:
                cnt += 1
        if cnt == 8:
            ans += 1

print(ans)
# Judge status: Wrong Answer
import sys
n = int(sys.stdin.readline().rstrip())
li = list(map(int, sys.stdin.readline().split()))
li2 = []
for i in li:
  if not i % 2:
    li2.append(i)
if not len(li2):
  flag = True
else:
  flag = False
for i in li2:
  if not i % 3 and not i % 5:
    flag = False
    break
print('APPROVED' if flag else 'DENIED')
# Judge status: Wrong Answer
w, a, b = map(int, input().split())

if a + w < b:
	print(b - (a + w))
elif b + w < a:
	print(a - (b + w))
elif a < b < a + w :
	print(0)
# Judge status: Accepted
a,b,c,d = input()
print('Bad' if a==b or b==c or c==d else 'Good')
# Judge status: Accepted
A,B,C = list(map(int,input().split()))

if B >= A*C:
    print(C)
else:
    print(B//A)
# Judge status: Accepted
s = list(input())
s = sorted(s)
if s[0] == s[1] and s[1] != s[2] and s[2] == s[3]:
     print('Yes')
else:
     print('No')
# Judge status: Accepted
A,B=map(int,input().split())
ans=0
for i in range(2):
    if A>=B:
        ans=ans+A
        A=A-1
    else:
        ans=ans+B
        B=B-1
print(ans)
# Judge status: Wrong Answer
N = 20
x,y,z = [0,0,0]

for i in range(1,N+1):
    ans = 0
    if i < 6:
        print(0)
        continue
    for j in range(1,int(i**0.5)+1):
        for k in range(1,int(i**0.5)+1):
            for m in range(1,int(i**0.5)+1):
                if j**2 + k**2 + m**2 +j*k + j*m + m*k == i:
                    ans += 1
    print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * ((10 ** 6) + 1)

for elem in a:
    cnt[elem] += 1

unique = []

for i in range((10 ** 6) + 1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0] * ((10 ** 6) + 1)

a = list(set(a))

for elem in a:
    for m in range(elem * 2, (10 ** 6) + 1, elem):
        cnt[m] = 1

ans = 0
        
for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)
# Judge status: Accepted
input()
a = map(int, input().split())
for i in a :
    if i%2==0 and i%3 != 0 and i%5 != 0 :
        print("DENIED")
        break
else:
    print("APPROVED")
# Judge status: Accepted
x=int(input())
print(8-int((x-400)/200))
# Judge status: Accepted
coin = [int(input()) for _ in range(3)]
X = int(input())
A = []
for i in range(coin[0]+1):
  for j in range(coin[1]+1):
    for k in range(coin[2]+1):
      A.append(500*i+100*j+50*k)
ans = A.count(X)
print(ans)
# Judge status: Accepted
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,m = i2()
ls = []
for _ in range(n):
	a = intl()
	a = a[1:]
	ls.append(a)

for i in range(n-1):
	tmp = []
	for j in ls[i]:
		for k in ls[i+1]:
			if j == k:
				tmp.append(j)
	ls[i+1] = tmp

print( len(ls[-1]) )