peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.reverse()
for i in range(n-1):
    a[i]-=a[i+1]-a[n-1]
a.append(k-max(a))
ans = max(a)
print(ans)
# Judge status: Accepted
n,a,b = map(int,input().split())
sl = list(input())

naka = 0
soto = 0

for s in sl:
    if s == "c":
        print("No")
    if s == "a":
        if naka + soto < a + b:
            print("Yes")
            naka += 1
        else:
            print("No")
    if s == "b":
        if naka + soto < a + b and soto < b:
            print("Yes")
            soto += 1
        else:
            print("No")
# Judge status: Accepted
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**10
for i in range(n - k + 1):
  ans = min(ans, max(0, -x[i]) + max(0, 2 * x[i + k - 1]),
            max(0, -2 * x[i]) + max(0, x[i + k - 1]))
print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:-1].copy()
    for x in a:
        if x < n:
            break
    else:
        print(*a)
        exit(0)
print(*a)
# Judge status: Accepted
s = input()
ans=0
j=1
for i in range(len(s)):
    if s[i]=="A":
        while s[-j] != "Z":
            j += 1
        ans = len(s)-j-i+1
        break
    else:
        continue

print(ans)
# Judge status: Accepted
s = input()
ans = 0
n = len(s)
for i in range(n//2):
    if s[i] != s[n-1-i]:
        ans+=1
print(ans)
# Judge status: Accepted
S = input()
N = len(S)

A = S[:int((N-1)/2)]
B = S[int((N+3)/2)-1:]
# print(S,A,B)
# def palindrome(string): return 
#     string.find(string[::-1])
def palindrome(string): return 1 if string==string[::-1] else 0

# print(palindrome(S),palindrome(A),palindrome(B))
if palindrome(S) and palindrome(A) and palindrome(B):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
s = 0
for i in range(10**5):
    if i**2 > n:
        break
print((i-1)**2)
# Judge status: Accepted
import queue

q = queue.Queue()

k = int(input())

for i in range(1,10):
    q.put(i)
    
while(k > 0):
    x = q.get()
    if x % 10 != 0:
        q.put(x*10 + (x%10 - 1))
    q.put(x*10 + x%10)
    if x % 10 != 9:
        q.put(x*10 + (x%10 + 1))
    k -= 1
    
print(x)
# Judge status: Wrong Answer
k,s = map(int,input().split())
ans = 0
for i in range(k):
	for j in range(k):
		if 0 <= s - i - j <= k: ans += 1
		#elif s - i - j > k: break
print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
P = list(map(int, input().split()))
print(sum(sorted(P)[:K]))
# Judge status: Accepted
import sys
input=sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))

l = [0] * 9
mn = 0
for i in A:
    t = min(i // 400, 8)
    l[t] += 1
for i in range(8):
    if l[i] != 0:
        mn += 1
if mn == 0:
    mn = 1
    mx = l[8]
else:
    mx = mn + l[8]

print(mn, mx)
# Judge status: Accepted
n, m = map(int, input().split())
PAIRS = [(a, 1) for a in map(int, input().split())]

for _ in range(m):
    b, c = map(int, input().split())
    PAIRS.append((c, b))
PAIRS.sort(reverse = True)

answer, count = 0, 0
for pair in PAIRS:
    answer += pair[0] * pair[1]
    count += pair[1]
    if count > n:
        answer -= pair[0] * (count - n)
        break

print(answer)
# Judge status: Accepted
s = input()
print("Heisei" if s <= "2019/04/30" else "TBD")
# Judge status: Accepted
n = int(input())
a = [0] + list(map(int, input().split()))
ans = []
for i in range(n, 0, -1):
    j = 2 * i
    while j <= n:
        a[i] ^= a[j]
        j += i
    if a[i] == 1:
        ans.append(i)
print(len(ans))
if ans:
    print(' '.join(list(map(str, ans))))
# Judge status: Accepted
str_l = list(map(str, input().split()))
print(''.join(list(reversed(str_l))))
# Judge status: Accepted
if __name__ == '__main__':
	N = int(input())
	X = [int(x) for x in input().split()]

	ans = 10000000

	for i in range(1,101):
		s = 0
		for x in X:
			s += (x-i)**2

		if ans > s:
			ans = s

	print(ans)
# Judge status: Wrong Answer
import itertools

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

A = [[ int(n) for n in input().split()] for _ in range(Q) ]
n = [i for i in range(1,M+1)]
numbers = list(itertools.combinations_with_replacement(n, N))
ans = [0 for _ in range(len(numbers))]

q = Q
while  q> 0:
    q -= 1
    a, b, c, d = A[q][0], A[q][1], A[q][2], A[q][3]
    print(a,b,c,d)

    for i in range(len(numbers)):
        if numbers[i][b-1] - numbers[i][a-1] == c:
            ans[i] += d


print(max(ans))
# Judge status: Accepted
import math 
N = int(input())
rootN = math.ceil(math.sqrt(N))
yakusuu = []
for i in range(1,rootN+1):
    if N % i == 0:
        yakusuu.append(i)

hitoketaFLG = 0
for j in yakusuu:
    if len(str(int(N / j))) == 1:
        hitoketaFLG = 1
print('Yes' if hitoketaFLG == 1 else 'No')
# Judge status: Accepted
a, b, c, d = map(int, input().split())
aa = [0 for i in range(101)]
bb = [0 for i in range(101)]
ans = 0
for i in range(a, b):
    aa[i] = 1
for i in range(c, d):
    bb[i] = 1
for i in range(101):
    if aa[i] == 1 and bb[i] == 1:
        ans += 1
print(ans)
# Judge status: Accepted
# -*- coding: utf-8 -*-

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if abs(a - e) > k:
    print(':(')
else:
    print('Yay!')
# Judge status: Accepted
S = input()
N = len(str(S))
P = 2019
list_a = [0] * P
list_a[0] += 1
counter = 0
temp = 0
power = 1
for i in range(N):
    temp += pow(10, i, P) * int(S[N - i - 1])
    temp %= P
    counter += list_a[temp]
    list_a[temp] += 1
print(counter)
# Judge status: Wrong Answer
def resolve():
    A, B, C, K = list(map(int, input().split()))
    MX = 10 ** 18
    if K == 0:
        print(A-B)
        return


    AK = (K-1) * A + K * (B+C)
    BK = (K-1) * B + K * (C+A)
    CK = (K-1) * C + K * (A+B)
    if (abs(AK-BK)>=MX):
        print('Unfair')
        return
    print(AK - BK)

    return

resolve()
# Judge status: Accepted
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        if i%2 == 0 and a[i]%2 == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
import math


def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()
# Judge status: Wrong Answer
n = int(input())
h_L = list(map(int,input().split()))

#dp = [float("inf")] * (10**4 + 1)
dp = [10**8] * n

dp[0] = 0
dp[1] = abs(h_L[0]-h_L[1])

for i in range(2,n):
    #dp[i]
    # 1
    tmp1 = dp[i-1] + abs(h_L[i-1] - h_L[i])
    dp[i] = min(dp[i],tmp1)
    # 2
    tmp2 = dp[i-2] + abs(h_L[i-2] - h_L[i])
    dp[i] = min(dp[i],tmp2)
#print(dp)
print(dp[len(h_L)-1])
# Judge status: Wrong Answer
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み
K=int(input())

bansu=10
n=9

while bansu <= K:
	n += 1
	n_str = str(n)
	l=len(n_str)
	lun_flag = True
	for i in range(l-1):
		if abs(int(n_str[i]) - int(n_str[i+1])) >     1:
			lun_flag = False
	
	#print(n,bansu,lun_flag)
	
	if lun_flag == True:
		bansu += 1
	
print(n)
		
	

input = _input
# Judge status: Accepted
X = int(input())

while True:
    isDivisible = False
    divider = 2
    while not isDivisible or divider < X:
        isDivisible = (X % divider == 0)

        if isDivisible:
            break
        else:
            divider += 1

    if divider == X:
        break
    else:
        X += 1

print(X)
# Judge status: Wrong Answer
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    l = r = ans = 0
    if N % 2 == 0:
        l = sum(A[:len(A)//2])
        r = sum(A[len(A)//2:])
        ans = abs(l - r)

    else:
        l = sum(A[:len(A)//2])
        r = sum(A[len(A)//2+1:])
        m = A[len(A)//2]
        ans = m + min(l, r) - max(l, r)

    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = 1e12
    
for i in range(N-K+1):
    a = abs(x[i])+abs(x[i]-x[i+K-1])
    b = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans,min(a,b))

print(ans)
# Judge status: Accepted
import numpy as np
import sys
buf = sys.stdin.buffer
N = int(buf.readline())
L = list(input())

tE = L.count("E")
tW = N-tE
ce,cw = 0,0
ans = 3*(10**5)
for i in range(N):
    if L[i] == "E":
        ce +=1
    elif L[i] == "W":
        cw +=1
    if L[i] == "E":
        ans = min(ans,cw+(tE-ce))
    elif L[i] == "W":
      
        ans = min(ans,cw-1+(tE-ce))
print(ans)
# Judge status: Accepted
n = int(input())
a = [9,900,90000]
order = len(str(n))
if order == 1:
    print(n)
elif order == 2:
    print(9)
elif order == 3:
    print(n-100+1 + 9)
elif order == 4:
    print(909)
elif order == 5:
    print(n-10000+1 + 909)
else:
    print(90909)
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())

def abc131_c(a,b,c,d):
    count = 0
    for i in range(a,b-1):
        if i % c == 0 or i % d == 0:
            continue
        count += 1
    return count
  
print(abc131_c(A,B,C,D))
# Judge status: Wrong Answer
l=int(input())
ans=0
for a in range(1,l+1):
  b=(l-a)/2
  c=(l-a)/2
  ans=max(ans,a*b*c)
print(ans)
# Judge status: Accepted
N, Y = map(int, input().split())

ans = [-1, -1, -1]
for i in range(Y//1000+1):
    for j in range(Y//5000+1):
        k = (Y - 10000*i - 5000*j)//1000
        if k < 0:
            break
        if i + j + k == N:
            ans = i, j, k
# print(10000*ans[0] + 5000*ans[1] + 1000*ans[2])
print(*ans)
# Judge status: Accepted
S = input()

import sys

for i in range(0,len(S)):
    for j in range(i,len(S)):
        if S[:i] + S[j:] == 'keyence':
            print('YES')
            sys.exit()
        
print('NO')
# Judge status: Accepted
a, b, n = map(int, input().split())

tmp = min(b-1, n)
print(int(a*tmp/b)-a*int(tmp/b))
# Judge status: Accepted
N, A, B, C, D, E = [int(input()) for _ in range(6)]

s = min(A, B, C, D, E)

print((N // s + (N % s != 0) - 1) + 5)
# Judge status: Accepted
import sys
import bisect

def main():
    input = sys.stdin.buffer.readline
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    B = list(map(int, input().split()))
    B.sort()
    C = list(map(int, input().split()))
    C.sort()
    ans = 0
    for i in B:
        a = bisect.bisect_left(A, i)
        c = bisect.bisect_right(C, i)
        ans += a*(N-c)
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

aa = sorted(a)
flag=True
for i in range(n-1):
    if aa[i]==aa[i+1]:
        flag=False
if flag:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N = int(input())
X = list(map(int,input().split()))
tmp = 0
mi =100000000000
for i in range(1,101):
  for k in range(N):
    tmp += (X[k] - i)**2
  if tmp < mi:
    mi = tmp
  tmp = 0
print(mi)
# Judge status: Wrong Answer
import numpy as np
import math 

def resolve():
    n = input()
    m = math.ceil(np.log2(int(n)))

    ans = 0
    for i in range(m + 1):
        ans += np.power(2, i)

    print(ans)
resolve()
# Judge status: Accepted
n = int(input())
ans = 'No'
for i in range(n//4 + 1):
    for j in range(n//7 + 1):
        if 4*i + 7*j == n:
            ans = 'Yes'

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

l = [0,0]
if S <= 10 ** 9:
    a = [S, 0, 0, 1]
else:
    u = S // 10 ** 9
    if S % 10 ** 9 != 0:
        u += 1
    d = u * (10 ** 9) - S
    a = [u, d, 1, 10 ** 9]
l.extend(a)
print(" ".join(map(str, l)))
# Judge status: Wrong Answer
A,B=map(int,input().split())
print(A*B if 1<=A<=9 and 1<=B<=9 else "–1")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
tmp = 0
tate = 0
yoko = 0
cnt = 0
for i in A:
    if tmp == i and cnt == 0:
        tate = i
        cnt += 1
        tmp = 0
        continue
    if tmp == i and cnt == 1:
        yoko = i
        cnt += 1
        break
    tmp = i

print(tate*yoko)
# Judge status: Accepted
import math

[N,X] = list(map(int,input().split()))
x = list(map(int,input().split()))

#x = sorted(x, reverse=True)

out=x[0] - X
for i in range(N):
    out = math.gcd(abs(x[i]-X), out)

print(out)
# Judge status: Wrong Answer
#E - Logs
import math
# 入力
N,K = map(int,input().split())
A   = list(map(int,input().split()))
Amax = int(max(A))
high = Amax
Cancut = Amax
low  = 0
while ( abs(high - low) > 0.1 ) :
    Cut = 0
    X = (high + low) / 2.0
    for i in range(N):
        Cut = Cut + math.ceil(A[i]/X) - 1
    if Cut <= K:
        high = X
        Cancut = X
    else:
        low  = X
# 出力
print(math.ceil(Cancut))
# Judge status: Wrong Answer
n, k = map(int, input().split())
plist = list(map(int, input().split()))

plist.sort()
ans = sum(plist, k)

print(ans)
# Judge status: Wrong Answer
s = "101"
print(s.count("1"))
# Judge status: Wrong Answer
s=input()
t=input()

swich=[]
stay=[]
for x,y in zip(s,t):
    if x!=y:
        swich.append([x,y])
    else:
        stay.append(x)
#print(swich,stay,sep=('\n'))
for i in swich:
    if i[0] in stay or i[1] in stay:
        print('No')
        exit()
    for j in swich:
        if i[0]==j[0] and i[1]!=j[1]:
            print('No')
            exit()


print('Yes')
# Judge status: Accepted
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l=[l1,l2,l3]
c=l[0][0]
for i in range(3):
    for j in range(3):
        l[i][j] -=c
if (l[1][1]==l[0][1]+l[1][0]) and (l[2][1]==l[0][1]+l[2][0]) and (l[1][2]==l[0][2]+l[1][0])and (l[2][2]==l[2][0]+l[0][2]):
    print('Yes')
else:
    print("No")
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[18]:


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


# In[19]:


if a*b <= 0:
    print("Zero")
elif a > 0 and b > 0:
    print("Positive")
else:
    if (b-a)%2 == 1:
        print("Positive")
    else:
        print("Negative")


# In[ ]:
# Judge status: Accepted
# A - Day of Takahashi
a, b = map(int ,input().split())
ans = 0

for i in range(1, 13):
	if i < a:
		ans += 1
	elif i == a and i <= b:
		ans += 1

print(ans)
# Judge status: Accepted
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if a == n:
        continue
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    h, n = map(int, input().split())
    A = list(map(int, input().split()))

    print("Yes" if h <= sum(A) else "No")


if __name__ == '__main__':
    resolve()
# Judge status: Accepted
h1,m1,h2,m2,k=map(int,input().split())
if h1==h2:
    print(m2-m1-k)
else:
    print((60-m1)+(h2-h1-1)*60-k+m2)
# Judge status: Accepted
A, B, C, X = [int(input()) for i in range(4)]

ans = 0
for i in range(0, A+1):
    for j in range(0, B+1):
        for k in range(0, C+1):
            if (i*500 + j*100 + k*50)==X:
                ans+=1

print(ans)
# Judge status: Accepted
s = input()
if s=="SUN": print(7)
if s=="MON": print(6)
if s=="TUE": print(5)
if s=="WED": print(4)
if s=="THU": print(3)
if s=="FRI": print(2)
if s=="SAT": print(1)
# Judge status: Wrong Answer
A,B=input().split()

A=int(A)
B=int(B.replace('.',''))

C=int(A*B/100)

print(C)
# Judge status: Accepted
x = int(input())
print('YES' if x == 3 or x == 5 or x == 7 else 'NO')
# Judge status: Accepted
import math

def main():
    N, K = map(int, input().split())
    input()
    print(math.ceil((N-K)/(K-1) + 1.0))

main()
# Judge status: Wrong Answer
N = int(input())
s = input()
t = input()

ans = 2 * N

for tail, head in zip(reversed(s), t):
    if s == t:
        print(N)
        break
    if tail == head:
        ans -= 1
    else:
        print(ans)
        break
# Judge status: Accepted
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()
# Judge status: Accepted
N = int(input())
w = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']


def dfs(s, i):
    # s:文字列 i:最大のアルファベットのindex
    if len(s) == N:
        print(s)
    else:
        for k in range(i+2):
            if k == i+1:
                dfs(s+w[k], i+1)
            else:
                dfs(s+w[k], i)


x = dfs('a', 0)
# Judge status: Wrong Answer
n = int(input())
s = map(int,input().split())
cnt = 0
t = sorted(s)

for i in range(n):
    a = t[i]
    for j in range(i, n):
        b = t[j]
        for k in range(j, n):
            c = a + b
            if t[k] != c and a != b and b != t[k] and a != t[k]:
                cnt += 1
print(cnt)
# Judge status: Wrong Answer
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
ls=[a,b,c]
ls.sort()
print(ls[0]*ls[1]/2)
# Judge status: Wrong Answer
n = int(input())
a_nums = list(map(int, input().split()))

if 0 in a_nums:
  print(0)

ans = 1
for num in a_nums:
  ans *= num

if ans > 10 **18:
  print(-1)
else:
  print(ans)
# Judge status: Wrong Answer
A, B, C, X = [int(input()) for i in range(4)]

ans = 0
for i in range(0, A):
    for j in range(0, B):
        for k in range(0, C):
            if (i*500 + j*100 + k*50)==X:
                ans+=1

print(ans)
# Judge status: Wrong Answer
s=input()
if s.count('N')==s.count('S')==0 or (s.count('N')!=0 and s.count('S')!=0):
  if s.count('E')==s.count('W')==0 or (s.count('E')!=0 and s.count('W')!=0):
    print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
s_long = input()
s_shor = input()

ans = len(s_shor)

strr_1 = s_shor
strr_2 = s_shor

if (strr_1 in s_long):
    print(0)
    exit()

else:
    for i in range(1, len(s_shor)):
        strr_1 = s_shor[: - i]
        strr_2 = s_shor[i:]
    
        if (strr_1 in s_long or strr_2 in s_long):
            ans = min(ans, i)
    
    

print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
ans = n * m

if n > 1 or m > 1:
    if n >= 2 and m >= 2:
        ans -= 4
    else:
        ans -= 2

if n > 1:
    ans -= max((m - 2) * 2, 0)

if m > 1:
    ans -= max((n - 2) * 2, 0)

print(ans)
# Judge status: Wrong Answer

for i in range(10):
    a=i+1
    print(a+a^2+a^3)
# Judge status: Accepted
def main():
    import math
    a, b, c = map(int, input().split())
    # a = math.sqrt(a)
    # b = math.sqrt(b)
    # c = math.sqrt(c)
    # n = math.sqrt(a*b)

    if 4 * a*b < (c-a-b)**2 and c-a-b > 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
Lo = 0
L2 = 0
L4 = 0
for i in range(N):
    if A[i]%2==1:
        Lo+=1
    elif A[i]%4==0:
        L4+=1
    else:
        L2+=1
if Lo<=L4:
    print("Yes")
else:
    if Lo==L4+1 and L2==0:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

from itertools import product
for i,j in product(range(n-m+1), repeat=2):
    t = []
    for k in range(m):
        t.append(a[i+k][j:j+m])

    if t == b:
        print("Yes")
        break

else:
    print("No")
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))

import collections
c=collections.Counter(A)
lst=c.most_common()[::-1]
val_lst=[el[1] for el in lst]
#print(val_lst)
print(sum(val_lst[:(len(lst)-K)]))
# Judge status: Wrong Answer
N,K = map(int,input().split())
A = list(map(int,input().split()))
tmp = [0]*N
tmp_2 = [0]*N
Cnt=0
result = 0
for i in range(N):
  tmp[A[i]-1]+= 1
  tmp_2[A[i]-1] = 1

m = sum(tmp_2)-K
tmp = sorted(tmp)
for i in range(N):
	if tmp[i]!=0:
		result += tmp[i]
		Cnt +=1
	if Cnt == m:
		break
    
print(result)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
satisfaction = 0
for i in range(N):
    satisfaction += B[A[i] - 1]
    if (i != 0) and (A[i - 1] + 1 == A[i]):
        satisfaction += C[A[i - 1] - 1]
print(satisfaction)
# Judge status: Accepted
def f11():
    N, M=map(int, input().split())
    item=[0 for i in range(M)]
    for i in range(N):
        A = [int(j) for j in input().split()]
        for j in range(A[0]):
            item[A[j+1]-1] += 1
    print(sum([1 if item[i]==N else 0 for i in range(M)]))

def main():
    f11()

main()
# Judge status: Accepted
import bisect
n, q = map(int, input().split())
S = list(input())
X = []
for i in range(n-1):
    if S[i] == 'A' and S[i+1] == 'C':
        X.append(i)
for j in range(q):
    l, r = map(int, input().split())
    a = bisect.bisect_left(X, l-1)
    b = bisect.bisect_left(X, r-1)
    print(b-a)
# Judge status: Accepted
N=int(input())
x=(10**N-2*(9**N)+8**N)%(10**9+7)
print(x)
# Judge status: Accepted
a=["Rainy","Cloudy","Sunny"]
s=input()
for i in range(3):
    if a[i]==s:
        print(a[i-1])
# Judge status: Accepted
#!/usr/bin/python3
# -*- coding: utf-8 -*-
s, w = map(int, input().split())

if s > w:
    print("safe")
else:
    print("unsafe")
# Judge status: Accepted
n=int(input())
for i in range(100//4):
    for j in range(100//7+1):
        if 4*i+7*j==n:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    s = input()

    cnt = 0
    score = 0
    for i in range(1, n):
        if s[i - 1] != s[i]:
            cnt += 1
        else:
            score += 1

    res = min(n - 1, score + min(k, cnt) * 2)
    print(res)


if __name__ == '__main__':
    resolve()
# Judge status: Accepted
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
lis = inpl()
counts = [0]*(N+10)
for i in lis:
    counts[i] += 1

S = 0
for i in lis:
    S += counts[i] - 1

S //= 2

for i in lis:
    print(S - counts[i] + 1)
# Judge status: Accepted
n,m,k = map(int,input().split())
for a in range(n+1):
  for b in range(m+1):
    if k == a*m+b*n-2*a*b:
      print('Yes')
      exit()
print('No')
# Judge status: Wrong Answer
n=int(input())
print(int((n*(n+1))/2))
# Judge status: Wrong Answer
N = input()

if N <= str(999):
    print('ABC')

elif N <= str(1998):
    print('ABD')
# Judge status: Accepted
n = int(input())
s = input()
if n %2 != 0:
  print("No")
else:
  if s[:(n//2)] == s[(n//2):]:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted
n = int(input())

now = [0,0,0]
for i in range(n):
    s = list(map(int,input().split()))
    time = s[0] - now[0]
    dis = abs(s[1] - now[1]) + abs(s[2] - now[2])
    if time < dis or (time-dis)%2 == 1:
        print("No")
        exit()
    now = s

print("Yes")
# Judge status: Accepted
n,m,x,y=map(int,input().split())
x=sorted(list(map(int,input().split()))+[x])
y=sorted(list(map(int,input().split()))+[y])
if x[-1]<y[0]:
    print('No War')
else:
    print('War')
# Judge status: Accepted
import sys
n=int(input())
k=2
l=list(map(int,input().split()))
ans=[0,abs(l[1]-l[0])]
for i in range(2,n):
    m=sys.maxsize
    c=1
    while c<min(k+1,i+1):
        
        m=min(abs(l[i]-l[i-c])+ans[-c],m)
        c+=1
    ans.append(m)
# print(ans)
print(ans[-1])
# Judge status: Wrong Answer
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2*l.count(0)])