peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7

bins_zero=[0]*61
bins_one=[0]*61
for a_i in a:
    a_i_bin=list(str(bin(a_i))[2:].zfill(61))
    for i in range(len(a_i_bin)):
        if a_i_bin[i]=='0':
            bins_zero[i]+=1
        else:
            bins_one[i]+=1

ans=0
for i in range(61):
    ans+=(bins_one[i]*bins_zero[i]*(2**(60-i)))
print(ans%mod)
# Judge status: Accepted
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = list(str(i))
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[j][0]-1] == str(sc[j][1]))
        if (f):
            ans = i
            break

print(ans)
# Judge status: Wrong Answer
import math
N = int(input())

if N < 2 or N % 2 == 1:
  print(0)
  exit()
  
res = 0

de = 10
while 1:
  quot = math.floor(N / de)
  if quot == 0:
    break
  res += quot
  de *= 5
print(res)
# Judge status: Wrong Answer
S = int(input())
memo = {1:0,2:0,3:1,4:1,5:1}

def Redi(n):
    if n in memo:
        return memo[n]
    else:
        ans = 1
        for i in range(3,n-2):
            ans += Redi(n-i)
        memo[n] = ans
        return memo[n]

print(Redi(S))
# Judge status: Wrong Answer
# A - Colorful Subsequence
import numpy as np

N,S = int(input()),input()
count = np.zeros(26)

for i in range(N):
    count[ord(S[i])-ord('a')] += 1

ans = 1
for i in range(26):
    ans *= (count[i]+1)

print((ans-1)%(10**9+7))
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
x=A-B
print(C-x)
# Judge status: Accepted
a,b,c=map(int, input().split())
print(int(a*b/2))
# Judge status: Wrong Answer
n, k = map(int, input().split())
l = []
for i in range(n):
    a, b = map(int, input().split())
    l += [a] * b
print(l[k-1])
# Judge status: Wrong Answer
A=list(map(int, input().split()))
A.sort()
print(sum(A)+A[0]*9)
# Judge status: Accepted
k,s=map(int,input().split())
ret=0
k+=1
for i in range(k):
  for j in range(k):
    d=s-i-j
    if k>d>=0:
      ret+=1
print(ret)
# Judge status: Accepted
from collections import Counter
n=int(input())
a=Counter(input().split())
ans=0
for i,j in a.items():
    i=int(i)
    if i>j:
        ans+=j
    elif i<j:
        ans+=j-i
print(ans)
# Judge status: Wrong Answer
from scipy.sparse.csgraph import dijkstra

def main():
    N, M = map(int, input().split())

    l = [[0] * N for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        l[a-1][b-1] = 1
        l[b-1][a-1] = 1

    res = dijkstra(l)
    if 2 in res[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == "__main__":
    main()
# Judge status: Accepted
h = list(map(int, input().split()))
h1 = h[0]
m1 = h[1]
h2 = h[2]
m2 = h[3]
k = h[4]

lh = h2 - h1
if lh < 0:
    lh = lh + 24
lm = m2 - m1

if lh == 0 and lm < 0:
    lm = lm + 24*60

l = lh * 60 + lm - k
    

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

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

for i in range(n):
  x,y = a[i]
  
  count = 0
  l = abs(x-c[0][0]) + abs(y-c[0][1])
  for j in range(m):
    
    p,q = c[j]
    
    if l > abs(x-p) + abs(y-q):
      l = abs(x-p)+abs(y-q)
      count = j
      
  print(count+1)
# Judge status: Accepted
X = input()

result = len(X)
n_S = 0
for c in X:
    if c == 'S':
        n_S += 1
    elif c == 'T':
        if n_S > 0:
           n_S -= 1 
           result -= 2
    else:
        raise ValueError
print(result)
# Judge status: Wrong Answer
(str_len,cng_cnt) = input().split(" ")
str_input = list(input())


print(str_len)
print(cng_cnt)
cng_cnt= int(cng_cnt)
#print(asd)
tmp1=""
cnt=0
cnt2=0
for st in str_input:
    if(tmp1 == st ):
      cnt = cnt+1
    else:
      cnt2= cnt2 + 1
      
    tmp1=st

if (cng_cnt < cnt2 ):
	c_up = cng_cnt * 2 
else:
	c_up= (cnt2 * 2) + (cng_cnt - cnt2)
ans =cnt + c_up

print(ans)
# Judge status: Accepted
from heapq import heappush, heappop

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

day = [[] for _ in range(10 ** 5)]
for a, b in ab:
    day[a - 1].append(b)

work, ans = [], 0
for i in range(m):
    for j in day[i]:
        heappush(work, -j)
    if len(work) > 0:
        ans -= heappop(work)
print(ans)
# Judge status: Wrong Answer
K = int(input())
ans = []
i = 1

while len(ans) < K :
  l = len(str(i)) - 1
  que = 'yes'
  for k in range(l):
    a = str(i)
    if abs( int(a[k])- int(a[k+1]) ) >= 2:
      que = 'no'
      break

  if que == 'yes':
    ans = ans + [i]


  i +=1

print(i)
# Judge status: Accepted
N = int(input())
ans = 0
for i in range(1, N+1, 2):
    count = 0
    for j in range(1, int(i ** 0.5) + 1):
        if i % j == 0:
            count += 2
    if int(i ** 0.5) ** 2 == i:
        count -= 1
    if count == 8:
        ans += 1
print(ans)
# Judge status: Accepted
import heapq
N,M = map(int,input().split())
AB = [[] for i in range(M+1)]
for i in range(N):
    a,b = list(map(int,input().split()))
    if a <= M:
        AB[a].append(-b)
work = 0
AB2 = []
heapq.heapify(AB2)
for i in range(1,M+1):
    for j in AB[i]:
        heapq.heappush(AB2,j)
    if not AB2:
        continue
    b = heapq.heappop(AB2)
    work += -b
print(work)
# Judge status: Accepted
def main():
    n, m = map(int, input().split())
    kas = [list(map(int, input().split())) for _ in range(n)]
    question_dict = {i: 0 for i in range(1, m+1)}
    ans = 0

    for ka in kas:
        a = ka[1:]
        for i in a:
            question_dict[i] += 1

    for food, num in question_dict.items():
        if num == n:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
a,b = map(int,input().split())
k = (a+b)/2

if k.is_integer():
    print(int(k))
else:
    print('IMPOSSIBLE')
# Judge status: Wrong Answer
s = list(map(int, input().split()))
N = s[0]
K = s[1]
S = s[2]
t =[]
a = K//701
b = K%701
c = (N - K)//701
d = (N - K)%701
for i in range(a):
    t = t + [S]*701
for i in range(b):
    t = t + [S]
for j in range(c):
    t = t + [S + 1]*701
for j in range(d):
    t = t + [S + 1]
print(*t)
# Judge status: Accepted
import sys
input = sys.stdin.readline

n = int(input())

cnt = 0
for _ in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    
    if cnt == 3:
        break

if cnt == 3:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a, b, c= map(int, input().split())
if a==b and b==c:
  print(1)
elif a==b:
  print(2)
elif b==c:
  print(2)
else:
  print(3)
# Judge status: Wrong Answer
from sys import stdin

def main():
    n = int(input())
    ary = [list(map(int, stdin.readline().split())) for _ in range(n)]
    dp = [[]] * n

    def max_act(abc,yesterday=None):
        if yesterday:
            del abc[yesterday]
        v = max(abc)
        i = abc.index(v)
        return [i,v]

    dp[0] = max_act(ary[0])

    for i in range(1,n):
        dp[i] = max_act(ary[i],dp[i-1][0])
    print(sum([i[1] for i in dp]))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
if n % 1000 == 0:
    print(0)
    exit()
print((n//1000+1) * 1000 - n)
# Judge status: Wrong Answer
N,K,*P=map(int,open(0).read().split())
print(sum(sorted(P[:K])))
# Judge status: Accepted
a, b = map(int, input().split())
n = a * b
if n % 2 == 0:
    print('Even')
else:
    print('Odd')
# Judge status: Accepted
n=int(input())
import heapq
q=[]

for i in range(n):
    x,l=map(int,input().split())
    heapq.heappush(q,(x+l,l))

largest=-float('inf')
c=0
while q:
    a,l=heapq.heappop(q)
    if largest<=a-2*l:
        largest=a
        c+=1
print(c)
# Judge status: Wrong Answer
p = input() .split()
s = set()
for i in range(1, len(p)):
    s.add(p[i])
print(len(set(s)))
# Judge status: Accepted
a,b = map(int,input().split())
if (a*b) % 2 == 1:
    print('Odd')
else:
    print('Even')
# Judge status: Accepted
a,b,c=map(int,input().split())
if a==b and a==c:
  print('No')
elif a!=b and a!=c and b!=c:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())

x=tx-sx
y=ty-sy

for i in range(x):
    print("R",end="")

for i in range(y):
    print("U",end="")


for i in range(x):
    print("L",end="")

for i in range(y):
    print("D",end="")
#iki
print("D",end="")
for i in range(x+1):
    print("R",end="")

for i in range(y+1):
    print("U",end="")
print("L",end="")




print("U",end="")
for i in range(x+1):
    print("L",end="")

for i in range(y+1):
    print("D",end="")
print("R",end="")
# Judge status: Accepted
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
from collections import Counter
A = list(map(int,input().split()))
A=Counter(A)
cnt = [(0,0) for _ in range(len(A)+M)]
i = 0
for _ in A.most_common():
  cnt[i]=_
  i+=1
for j in range(M):
  B,C = map(int,input().split())
  cnt[i]=(C, B)
  i+=1
cnt.sort(key=lambda x:x[0],reverse=True)
nn = 0
ans = 0
for k in range(len(cnt)):
  d = min(N-nn,cnt[k][1])
  nn += d
  ans += d * cnt[k][0]
  if nn == N:
    break
print(ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
for i in range(n-1):
    s = input()
    c &= Counter(s)
ans = ''
for i in sorted(c):
    ans += i*c[i]
print(ans)
# Judge status: Accepted
w,a,b = map(int,input().split())
if a + w <= b:
    print(b - (a + w))
elif b + w <= a:
    print(a - (b + w))
else:
    print(0)
# Judge status: Wrong Answer
a=int(input())
b=int(input())
print("Yes" if a%500 - b <0 else "No")
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
x = int(input())
x /= 50
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 10*i + 2*j + k == x:
                cnt += 1
print(cnt)
# Judge status: Accepted
N, M = map(int, input().split())
ss = [[] for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    ss[p-1].append((i, y))
ls = [''] * M
for p in range(N):
    s = ss[p]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(p+1).zfill(6)
        ds = str(d+1).zfill(6)
        ls[i] = ps+ds
for l in ls:
    print(l)
# Judge status: Accepted
x = int(input())
if x: print(0)
else: print(1)
# Judge status: Accepted
s = input()
a = s.replace('eraser','')
b = a.replace('erase','')
c = b.replace('dreamer','')
d = c.replace('dream','')
if d == '':
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N, M = map(int, input().split())
A = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    A[a][b] += 1
    A[b][a] += 1
for i in range(1, N+1):
    sum = 0
    for j in range(1, N+1):
        sum += A[i][j]
    print(sum)
# Judge status: Wrong Answer
x, y = map(int, input().split())
button = 0
if x<0 and y<0:
  button+=2
elif x<0 and y>=0:
  button+=1
elif y<0 and x>=0:
  button+=1
button+=abs(y)-abs(x)
print(button)
# Judge status: Accepted
#!/usr/bin/env python3

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

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


print(len(Base_10_to_n(N, K)))
# Judge status: Accepted
N=int(input())
B=[int(x) for x in input().rstrip().split()]
A=[B[0]]
for i in range(1,N-1):
    A.append(min(B[i-1],B[i]))
A.append(B[N-2])

print(sum(A))
# Judge status: Accepted
N,x=map(int, input().split())
A=sorted(list(map(int, input().split())))
cnt=0
for i in range(N):
  if i == N-1 and x > A[i]:
    break
  if x >= A[i]:
    x -= A[i]
    cnt+=1
  else:
    break
print(cnt)
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))

d={}

for x in range(n):
  if a[x] not in d:
    d[a[x]]=0
  d[a[x]]+=1
  
ans=0
ans1=[]
for g in d:
  ans1.append(d[g])
  
if len(ans1)<=k:
  print(0)
  
else:
  ans1.sort()
  r=len(ans1)-k
  for t in range(r):
    ans+=ans1[t]
    
  print(ans)
# Judge status: Accepted
l = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2
n = int(input())
print("".join([l[l.index(x)+n] for x in input()]))
# Judge status: Accepted
a, b, c = map(int, input().split())

flag = 0
ans = 0

if a == b == c and a%2 == 0:
  ans = -1

else:
  while flag == 0:
    if a%2 == 0 and b%2 == 0 and c%2 == 0:
      a_tmp = (b+c)/2
      b_tmp = (a+c)/2
      c_tmp = (a+b)/2
      
      a = a_tmp
      b = b_tmp
      c = c_tmp
      
      ans += 1
      
    else:
      flag = 1

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
  b[a[i]-1] = str(i+1)
print(" ".join(b))
# Judge status: Accepted
import math
N,D=map(int,input().split())
X=[list(map(int,input().split()))for i in range(N)]
ans=0
dist=0.0
for i in range(N):
    for j in range(i+1,N):
        dist=0.0
        for k in range(D):
            dist+=(X[i][k]-X[j][k])**2
        dist=math.sqrt(dist)
        if dist.is_integer() is True:
            ans+=1
print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
As = list(map(int, input().split()))
a=n-1
b=k-1
if a % b == 0:
  print(a//b)
else:
  print((a//b) + 1)
# Judge status: Accepted
n,k = map(int, input().split())
ab = []
for i in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))
ab.sort()
num = 0
for h in range(n):
    num += ab[h][1]
    if k <= num:
        print(ab[h][0])
        break
# Judge status: Accepted
def a():
    N,M = map(int,input().split())
    B = list(map(lambda x: int(x)//2,input().split()))

    def gcd(n,m):
        while n:
            m,n = [n,m%n]
        return m

    su = 1
    for b in B:
        su *= b // gcd(su,b)
        if su > M:
            return 0

    for _ in filter(lambda x:(su//x)%2==0,B):
        return 0

    return M//su - M//(su*2)

print(a())
# Judge status: Wrong Answer
S=input()
S+='0'
L=len(S)
cnt=0
for i in range(1,L):
  if S[i]==S[i-1]:
    cnt+=1
ans=L-cnt
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
print(sum(B)+sum(C[A[n]-1] for n in range(N-1) if A[n]+1==A[n+1]))
# Judge status: Wrong Answer
N, H = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
A.sort()
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= A[-1]:
    H -= B.pop()
    ans += 1
print(ans+(-(-H//A[-1])))
# Judge status: Accepted
k,a,b = map(int, input().split())
ans = 1+k
if b-a<=2:
    print(ans)
    exit()

ans = max(ans,(k-(a-1))//2*(b-a)+(k-(a-1))%2+a)

print(ans)
# Judge status: Accepted
n = int(input())
print((n / 3) ** 3)
# Judge status: Accepted
from math import log2
n, k = map(int, input().split())
To = []
A = list(map(int, input().split()))
A = list(map(lambda x: x - 1, A))
To.append(A)
for i in range(int(log2(k))):
    N = [0 for i in range(n)]
    for j in range(n):
        N[j] = To[i][To[i][j]]
    To.append(N)

v = 0
for i in reversed(range(int(log2(k)) + 1)):
    l = 1 << i
    if l <= k:
        v = To[i][v]
        k -= l
    else:
        pass

print(v + 1)
# Judge status: Accepted
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for idx, num in enumerate(A):
    a.append(a[idx] + num)
for idx, num in enumerate(B):
    b.append(b[idx] + num)

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)
# Judge status: Accepted
s=input()
if int(s[5]+s[6])<=4:
    print("Heisei")
else:
    print("TBD")
# Judge status: Accepted

import heapq

N,M = map(int,input().split())
A = [-int(_) for _ in input().split()]


#print(A)
heapq.heapify(A)

for i in range(M):
    heapq.heappush(A,-(-heapq.heappop(A)//2))
    
print(-sum(A))
# Judge status: Wrong Answer
n, m = map(int, input().split())
students = [list(map(int, input().split())) for i in range(n)]

targets = [list(map(int, input().split())) for i in range(m)]
x = 0
snumber = [(0, x)] * n
  
def md(s, t):
  d = abs(s[0] - t[0]) + abs(s[1] - t[1])
  return d

for i in range(n):
  x = 2 * 10 ** 8
  min_pos = 0
  for j in range(m):  
    dist = md(students[i], targets[j])
    if x > dist:
      x = dist
      min_pos = j + 1
      
    
  print(min_pos)
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))

lis=[0]*n
ans=0
i=0
while i<n-1:
    if i+1==p[i]:
        lis[i]=1
        if i+2==p[i+1]:
            lis[i+1]=1
            i+=1
        ans+=1
    i+=1
if lis[n-1]==0 and p[n-1]==n:
    ans+=1
print(ans)
# Judge status: Accepted
a=list(map(int, input().split()))
k=int(input())
print(max(a)*(2**k-1)+sum(a))
# Judge status: Accepted
N=int(input())
ans=0
t=0
for _ in range(N):
    A=int(input())
    if A==0:
        ans+=t//2
        t=0
    else:
        t+=A
ans+=t//2
print(ans)
# Judge status: Accepted
n=int(input())
a=[int(input()) for i in range(n)]
ans=0
for i in range(n-1):
  ans+=a[i]//2
  a[i]%=2
  if a[i]==1 and a[i+1]>=1:
    ans+=1
    a[i+1]-=1
ans+=a[-1]//2
print(ans)
# Judge status: Accepted
T = input()
T_len = int(len(T))
S = ""
for i in range(T_len):
  if T[i] == '?':
    S = "D"
  else:
    S = T[i]
  print(S, end = "")
# Judge status: Wrong Answer
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop(0)[1]

while ll:
  while ll and ll[0][0] < r:
    ans -= 1
    ll.pop(0)
  if ll:
    r = ll.pop(0)[1]

print(ans)
# Judge status: Accepted
s = input()
ans = 1
num = 1 #文字数

if len(s) == 1:
    print(1)
    exit()


for i in range(1, len(s)):
    if num == 1:
        if s[i - 1] != s[i]:
            ans += 1
        else:
            if i != len(s) - 1:
                num = 2
                ans += 1
    elif num == 2:
        num = 1.5
    elif num == 1.5:
        ans += 1
        num = 1
print(ans)
# Judge status: Accepted
N = int(input())
ans = 0
for i in range(1, N + 1):
    if i % 2 == 0:
        continue
    cnt = 2
    for j in range(2, i):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
print(ans)
# Judge status: Accepted
A = list(map(int, input().split()))
print(A[2], A[0], A[1])
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    if a[i] + a[i-1] > x:
        ans += min(a[i], a[i] + a[i-1] - x)
        a[i] = max(0, x - a[i-1])
    if a[i] + a[i-1] > x:
        ans += a[i-1] - x
        a[i-1] = x
print(ans)
# Judge status: Accepted
N = int(input())

a = list(str(N))
a = [int(s) for s in a]


Z = 10 ** (len(a) - 1)

Y = N - Z

X = list(str(Y))
X = [int(s) for s in X]
SUM = 0
for i in range(len(X)):
    SUM = SUM + X[i]

if Y != 0:
    print(SUM + 1)
else:
    print(10)
# Judge status: Wrong Answer

if __name__ == "__main__":
    S = input()
    if len(S) % 2 == 0:
        for i in range(0, len(S), 2):
            if S[i] == "h" and S[i+1] == "i":
                ret = "Yes"
            else:
                ret = "No"
                break
    else:
        ret = "No"
    print(ret)
# Judge status: Accepted
n = int(input())
cnt = 0

for i in range(1,n):
    b = n//i
    c = n%i
    if c:
        cnt += b
    else:
        cnt += b-1
    

print(cnt)
# Judge status: Wrong Answer
A, B = list(map(int, input().split()))

amax = (A + 1) / 8 * 100
amin = A / 8 * 100
bmax = (B + 1) / 10 * 100
bmin = B / 10 * 100

answer = amin if amin <= bmax and amin >= bmin else - 1

print(int(answer))
# Judge status: Accepted
# 入力の取得
S = input()

# 入力内容から次の天気を予測
if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
elif S == "Rainy":
    print("Sunny")
else:
    print("入力内容が間違っています。")
# Judge status: Wrong Answer
import sys
a, b = map(int, input().split())
s = input()
flag = True
for i in range(a + b - 1):
  if(s[a] != '-' or s[not a] == '-'): flag = False
print('Yes') if flag else print('No')
# Judge status: Accepted
H = int(input())
W = int(input())
N = int(input())

result = N // max(H, W)
if N % max(H, W) == 0: # 割り切れた場合
    print(result)
else:
    print(result + 1)
# Judge status: Accepted
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))

ans = 0
for k, v in d.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v-k
print(ans)
# Judge status: Accepted
S=input()
flag=True

if len(S)%2!=0:
  print("No")
else:
  for i in range(len(S)//2):
    if S[2*i]+S[2*i+1]=="hi":
      pass
    else:
      flag=False
      break
      
  if flag:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted
def main():
  n,k=map(int,input().split())
  s=input()
  
  A=(('L','L'),('L','R'),('R','L'),('R','R'))
  B=[]
  cnt=0
  for i in range(n-1):
    tmp=(s[i],s[i+1])
    cnt+=1
    if tmp==A[1]:
      B.append(cnt)
      cnt=0
    elif tmp==A[2]:
      B.append(cnt)
      cnt=0
  cnt+=1
  B.append(cnt)
  if len(B)//2<=k:
    unhappy=1
  else:
    unhappy=len(B)-2*k
   
  print(n-unhappy)
  
if __name__=='__main__':
  main()
# Judge status: Accepted
n = int(input())
a = 0
b = 0
for i in range(10):
  a = 2 ** i
  if a > n :
    print(b)
    break
  else:
    b = a
# Judge status: Accepted
s = input()
t =0 
for s in s:
  if s == "h":
    t=1
  elif s =="i":
    if t == 0:
      t = 0
      print("No")
      quit()
    t = 0
  else:
    print("No")
    quit()
if t == 1:
  print("No")
else:
  print("Yes")
# Judge status: Accepted
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
l = [0] * (N + 1)
r = [0] * (N + 1)
for i in range(N): l[i + 1] = gcd(l[i], a[i])
a.reverse()
for i in range(N): r[i + 1] = gcd(r[i], a[i])
res = 0
for i in range(N + 1): res = max(res, gcd(l[i], r[N - i - 1]))
print(res)
# Judge status: Accepted
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    ans.append(min(abs(l)+abs(l-r), abs(r)+abs(l-r)))

print(min(ans))
# Judge status: Wrong Answer
n, m = map(int, input().split())
a = []
flag = True
for i in range(m):
    l, r = map(int, input().split())
    if i == 0: 
        l1 = l
        r1 = r
    else:
        if l1 < l:
            l1 = l
        elif r1 > r:
            r1 = r
if flag: print(r1-l1+1)
else: print(0)
# Judge status: Accepted
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    # N に向かうことを考える
    A_to_N_dis = N - B + 1
    A_to_N = A + A_to_N_dis
    tmp_ans = (N - A_to_N) // 2 + A_to_N_dis

    # 1に向かうことを考える
    B_to_1_dis = A - 1 + 1
    B_to_1 = B - B_to_1_dis
    ans = (B_to_1 - 1) // 2 + B_to_1_dis
    print(min(tmp_ans, ans))
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B, C, D = mapint()
from math import gcd

m = C*D//gcd(C, D)
Ccnt = B//C-(A-1)//C
Dcnt = B//D -(A-1)//D
Mcnt = B//m - (A-1)//m

print((B-A)-(Ccnt+Dcnt-Mcnt)+1)
# Judge status: Accepted
inp=input()
ok=0
for i in range(len(inp)):
  if(inp[i]=='7'):
    print("Yes")
    ok=1
    break
if(ok==0):
  print("No")
# Judge status: Wrong Answer
b=int(input())
if b>=10:
      overall=b*2
      print(overall)
elif b<=9 and b>0:
      print(b)
elif b<=0:
      print(0)
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def main(n, x, a):
  cnt = 0
  for i in a:
    x -= i
    if x <= 0:
      break
    elif i == a[-1] and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))
# Judge status: Accepted
A,B=map(int,input().split())
S=list(input())

if S[A]!='-':
  print("No")
else:
  S.sort()
  #print(S)
  for i in range(1,len(S)):
    if S[i]=="-":
      print("No")
      break
  else:
    print("Yes")
# Judge status: Accepted
from bisect import bisect_left

N,A,c = int(input()),[],[]
for i in range(N):
	A.append(int(input()))
A.reverse()

for x in A:
	p = bisect_left(c, x+1)
	if p == len(c):
		c.append(x)
	else:
		c[p] = x
print(len(c))