peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def main():
    s_shaped_piece, c_shaped_piece = map(int, input().split())
    answer = min(s_shaped_piece, c_shaped_piece // 2)
    c_shaped_piece -= answer * 2
    answer += c_shaped_piece // 4
    print(answer)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

MAX = []
MIN = []
e = 1
for a in A:
    if e > 0:
        MAX.append(e)
        MIN.append(e//2)
        e -= a
        e *= 2
    else:
        print(-1)
        exit()

A.reverse()
MAX.reverse()
MIN.reverse()

ans = 0
s = 0
for i,a in enumerate(A):
    s += a
    s = min(MAX[i],s)
    
    ans+= max(MIN[i],s)

print(ans)
# Judge status: Accepted
n,a,b = map(int, input().split())
s = input()
cnt = 0
x = 0
for i in range(n):
    if s[i] == "a":
        if cnt < a+b: 
            cnt += 1
            print("Yes")
        else: print("No")
    elif s[i] == "b":
        if cnt < a+b and x+1 <= b:
            cnt += 1
            x += 1
            print("Yes")
        else: print("No")
    else: print("No")
# Judge status: Wrong Answer
n=int(input())
if n%2==0:
  print(n/2)
else:
  print(int(n/2)+1)
# Judge status: Wrong Answer
import numpy as np
import fractions

from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

def LI():
  return [int(s) for s in input().split()]

N = int(input())
A_s = np.array(LI())

mod = 10**9 + 7

l = lcm_list(A_s)

print(sum(map(lambda x:l//x, A_s)) % mod)
# Judge status: Wrong Answer
a, b = map(int, input().split())
ans = 10**100
for i in range(min(a, b), 1, -1):
    if a % i == 0 and b % i == 0:
        ans = i * (a // i) * (b // i)
        break
print(a * b, ans)
print(min(a * b, ans))
# Judge status: Accepted
n,m,k = map(int,input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( acum1[-1] + arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1] + arr2[i])

ans = 0
j = m
for i in range(n+1):
    if acum1[i]>k:
        break
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)
# Judge status: Accepted
def main():
  n = int(input())

  i = 1
  for a_i in input().split():
    if i == int(a_i):
      i += 1
  
  if i == 1:
    i = n + 2
    
  print(n - i + 1)


if __name__ == "__main__":
  main()
# Judge status: Accepted
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())))
if N <= K:
    print('0')
elif K == 0:
    print(sum(H))
else:
    print(sum(H[:N - K]))
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
cfs = [list(map(int, readline().split())) for i in range(n - 1)]
for i in range(n - 1):
    cnt = cfs[i][1] + cfs[i][0]
    for j in range(i + 1, n - 1):
        if cnt < cfs[j][1]:
            cnt = cfs[j][1] + cfs[j][0]
        else:
            cnt += (cnt - cfs[j][1]) % cfs[j][2] + cfs[j][0]
    print(cnt)
print(0)
# Judge status: Wrong Answer
import fractions
n = int(input())
a = list(map(int, input().split()))
l = [0]*(n+1)
l[1] = a[0]
r = [0]*(n+1)
r[n-1] = a[n-1]
for i in range(1, n):
  l[i+1] = fractions.gcd(l[i], a[i])
  r[n-1-i] = fractions.gcd(r[n-i], r[n-i])

m = 0
for i in range(n):
  m = max(m, fractions.gcd(l[i], r[i+1]))
print(m)
# Judge status: Accepted
a = list(map(int, input().split()))
if sum(a) >= 22:
  print('bust')
else:
  print('win')
# Judge status: Wrong Answer
import math
A,B,N = (int(i) for i in input().split())
if N > B:
  print(A-1)
else:
  print(math.floor(A*N/B) - A*math.floor(N/B))
# Judge status: Accepted
import sys

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

cnt = 0
if a == 0:
    cnt = b // x + 1
else:
    cnt = b // x - (a - 1) // x

print("{}".format(cnt))
# Judge status: Wrong Answer
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

first = K*X
after = Y*(N-K)

print(first + after)
# Judge status: Accepted
N = int(input())
pList = list(map(int, input().split()))

ans = 0
for i in range(1, N-1):
    if pList[i-1] < pList[i] < pList[i+1] or pList[i-1] > pList[i] > pList[i+1]:
        ans += 1

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

middle = b.capitalize()

print("A{}C".format(middle))
# Judge status: Wrong Answer
a, b = map(int, input().split())

ans = a+b

if ans > 24:
    ans = ans - 24

print(ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)

if c.most_common()[0][1] == 1:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
S, T = input().split(" ")
print(T+S)
# Judge status: Accepted
x, y = map(int, input().split())
if x >= 0 and y >= 0 and x <= y:
  ans = y - x
elif x >= 0 and y > 0 and x >= y:
  ans = x -  y + 2
elif x <= 0 and y <= 0 and x <= y:
  ans = y - x
elif x < 0 and y <= 0 and x >= y:
  ans = x - y + 2
elif x >= 0 and y <= 0:
  ans = abs(x - abs(y)) + 1
elif x <= 0 and y >= 0 and abs(x) <= y:
  ans = y - abs(x) + 1
elif x <= 0 and y >= 0 and abs(x) > y:
  ans = abs(x) - y + 1
print(ans)
# Judge status: Accepted
N, K = map(int,input().split())
S = list(input())

S[K-1] = S[K-1].lower()
print(''.join(S))
# Judge status: Wrong Answer
Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1, -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		print(i)
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE")
# Judge status: Accepted
s=input()
x=int(s[0])+int(s[1])+int(s[2])
print(x)
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(k):
  ans+=min(a)
  a.remove(min(a))
print(ans)
# 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)

cnt = 0
for i in range(N-1,-1,-1):
    if (A[i]+cnt)%B[i] == 0:
        continue
    cnt += B[i] - ((A[i]+cnt)%B[i])
print(cnt)
# Judge status: Wrong Answer
# 入力値の代入
x = int(input("入力: "))

# xが30以上か否かで出力結果を買える
if x >= 30:
    print("Yes")
elif x < 30:
    print("No")
else:
    print("エラー")
# Judge status: Accepted
n, a, b=map(int, input().split())
mod = 10 ** 9 + 7 
def cmb(n, r, mod):
    r = min(r, n -r)
    if r == 0: return 1
    over, under = 1, 1
    for i in range(1, r+1):
        over = over * (n-i+1) % mod
        under = under * i % mod
    
    inv=pow(under, mod-2, mod)
    
    return over*inv % mod
  
print((pow(2,n,mod)-1 - cmb(n, a,mod)-cmb(n,b,mod))%mod)
# Judge status: Accepted
S = list(input())

if len(S)%2 != 0:
  print("No")
else:
  for i in range(len(S)):
    if (i%2 == 0 and S[i] != "h") or (i%2 == 1 and S[i] != "i"):
        print("No")
        break
  else:
   	print("Yes")
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
ans = 3

if a == b:
  ans -= 1
if a == c:
  ans -= 1
  
if c == b:
  ans -= 1
  
print(ans)
# Judge status: Wrong Answer
a, b = list(map(int, input().split()))
s = list(input())
na = "".join(s[: a - 1]).isdigit()
nb = "".join(s[a + 1 :]).isdigit()
hf = s[a]
print("Yes") if na and nb and hf == "-" else print("No")
# Judge status: Accepted
N = int(input())

if N % 10 == 3:
  print('bon')
elif N % 10 == 0 or N % 10 == 1 or N % 10 == 6 or N % 10 == 8:
  print('pon')
else:
  print('hon')
# Judge status: Accepted
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()
# Judge status: Accepted
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N-1, -1, -1):
    remain = B[i]
    if remain <= A[i+1]:
        ans += remain
        remain = 0
    else:
        ans += A[i+1]
        remain -= A[i+1]
    if remain <= A[i]:
        ans += remain
        A[i] -= remain
    else:
        ans += A[i]
        A[i] = 0

print(ans)
# Judge status: Accepted
MOD=10**9+7
S=int(input())

def invmod(a):
  return pow(a,MOD-2,MOD)
  #return powmod(a,MOD-2)
def comb_mod(n,r):
  r=min(r,n-r)
  nPr=1
  fact_r=1
  for i in range(r):
    nPr*=n-i
    nPr%=MOD
    fact_r*=r-i
    fact_r%=MOD  
  return (nPr*invmod(fact_r))%MOD

limit=S//3
#print(limit)

answer=0
for i in range(1,limit+1):
  rest=S-3*i
  #print(i,rest)
  # deliver rest for i-term
  answer+=comb_mod(i+rest-1,rest)
  answer%=MOD
  
print(answer)
# Judge status: Accepted
n,m,q=map(int,input().split())
l=[]
for i in range(q):
  l.append(list(map(int,input().split())))
li=[]
for i in range(m):
  li.append(i+1)
import itertools
ans=0
for lis in itertools.combinations_with_replacement(li, n):
  lis=list(lis)
  an=0
  for z in l:
    a,b,c,d=z
    if lis[b-1]-lis[a-1]==c:
      an+=d
  ans=max(an,ans)
print(ans)
# Judge status: Wrong Answer
n = int(input())


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

a.sort()


print(sum(a[::-1][n:2*n]))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
d = dict()
for n in a:
    d[n] = d.get(n, 0) + 1

ans = 0
for k, v in d.items():
    if k < v:
        ans += v-k
    if k > v:
        ans += v

print(ans)
# Judge status: Wrong Answer
N = int(input())
 
sum = 0
ro = 1
for n in range(1,N+1):
    num = int(N/n)
    if num == 1:
        record = n
        break
    s = int(((1+num)*num)/2)
    sum += ro*s
    ro += 1

print(record)
print(sum)

sum += int(((record+N)*(N-record+1))/2)
print(sum)
# Judge status: Accepted
H,W=map(int,input().split())
if H==1 or W==1:
  print(1)
  exit()
print((H*W+1)//2)
# Judge status: Accepted
def main():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
  
  ans = 1
  for i in a:
    ans *= i
    if ans > (10 ** 18):
      print(-1)
      return
  print(ans)
  
main()
# Judge status: Accepted
A,B,C = tuple(map(int, input().split()))
if B >= C >= A:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
A, B = map(int, input().split())
print((A * B + 1) // 2)
# Judge status: Wrong Answer
S = input()

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print("Bad")
else:
    print("Yes")
# Judge status: Wrong Answer
n, m = map(int, input().split())

if n and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
elif n>= 2 and m>=2:
    print((n-2)*(m-2))
# Judge status: Accepted
n = int(input())
r1 = tuple(int(x) for x in input().split())
r2 = tuple(int(x) for x in input().split())
# If d == 0, first it moves down, then it moves right.
candies = (sum(r1[:d+1]) + sum(r2[d:]) for d in range(n))
print(max(candies))
# Judge status: Wrong Answer
print("YNEOS"[max(int(input().replace(" ",""))%4,1)::2])
# Judge status: Wrong Answer
def answer(n, m, k):
    YES = 'Yes'
    NO = 'No'
    if k%n == 0 or k%m == 0:
        return YES
    j = 1
    for i in range(m-1, 0, -1):
        if k == (i + (n-1)*j):
            return YES
        j += 1
    if (n-2)*2 + (m-2)*2 == k:
        return YES
    return NO

n, m, k = map(int, input().split())
print(answer(n, m, k))
# Judge status: Accepted
import math
import statistics

ab = list(map(int, input().split()))
print(math.ceil(statistics.mean(ab)))
# Judge status: Accepted
n = int(input())
X = []
for i in range(n):
  x, l = map(int, input().split())
  X.append([x-l, x+l])
X.sort()
temp = X[0][1]
count = n
for i in range(1,n):
  if temp>X[i][0]:
    count -= 1
    temp = min(temp, X[i][1])
  else:
    temp = X[i][1]
print(count)
# Judge status: Accepted
N,M = map(int, input().split())
if N == 1 and M == 1:
  print(1)
elif N == 1 :
  print(M-2)
elif M == 1:
  print(N-2)
else:
  print(int(N-2)*(M-2))
# Judge status: Accepted
a,b,_ = map(int, input().split()) # 3 4 5
print(a*b//2)
# Judge status: Wrong Answer
n,k=map(int,input().split())
a,b,c=map(int,input().split())
s=input()
l=['a']*k
for i in range(n):
  l[i%k]+=s[i]
ans=0
d={'s':a,'p':b,'r':c}
for i in range(k):
  x=l[i]
  for j in range(len(x)-1):
    if x[j+1]==x[j]:
      ans+=d[x[j+1]]
print(ans)
# Judge status: Accepted
n,a,b = map(int,input().split())
 
def modComb(n,r,mod):
    tmp = 1
    for i in range(1,r+1):
        tmp = tmp * (n-i+1) % mod
        tmp = tmp * pow(i,mod-2,mod) % mod
    
    return tmp % mod
 
 
mod = 10**9+7
ans = pow(2,n,mod) - 1
 
print((ans-modComb(n,a,mod)-modComb(n,b,mod)) % mod)
# Judge status: Wrong Answer
import numpy as np
import sys
readline = sys.stdin.buffer.readline
a, b, h, m= list(map(int,readline().rstrip().split()))
th = (5*h-m)/30
if th > 1:
  th = 1-th
print(np.sqrt(float(a**2)+float(b**2)-2*a*b*np.cos(np.pi*th)))
# Judge status: Accepted
s=input()
n=len(s)
for i in range(n):
    for j in range(n):
        if 'keyence'==s[:i]+s[i+j:]:print("YES");exit()
print("NO")
# Judge status: Wrong Answer
#2問目
MAX = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
result = 1

if 0 in A:
    result = 0
else:
    for i in range(N):
        result *= A[i]
        if i+1 < N and result >= 5e+17:
            result = -1
            break
        if result > MAX:
            result = -1
            break
print(result)
# Judge status: Accepted
#!/usr/bin/env python3
import sys
from bisect import bisect_right

INF = float("inf")


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    dp = [INF]*N
    for i in range(N):
        j = bisect_right(dp, -A[i])
        dp[j] = -A[i]

    print(sum([1 for d in dp if d < INF]))
    # print(dp)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N,M = map(int,input().split())

n = min(N,M)
m = max(N,M)

if n*m == 1:
  print(1)
if n == 1:
  print(m-2)
  exit()
print((n-2)*(m-2))
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = list(input())

if S[K-1] == 'A':
  S[K-1] = 'a'
elif S[K-1] == 'B':
  S[K-1] = 'b'
else:
  S[K-1] = 'c'
  
print(S)
# Judge status: Accepted
D = int(input())


print("Christmas" + " Eve" * (25 - D) )
# Judge status: Accepted
s = input()
ans = 0
l = len(s)

while True:
    s = s[:l-2]
    l -= 2
    if s[:l//2] == s[l//2:]:
        ans = l
        break

print(ans)
# Judge status: Wrong Answer
if sum(list(map(int,input().split())))>=22:
  print("win")
else:
  print("burst")
# Judge status: Accepted
S = input().strip()
K = int(input())

ans = ""
for i, s in enumerate(S):
    if i == len(S) - 1:
        if ord(s) + K <= ord("z"):
            ans += chr(ord(s) + K)
        else:
            ans += chr(ord("a") + (ord(s) + K - ord("z") - 1) % 26)
    elif s == "a":
        ans += "a"
        continue
    elif ord("z") + 1 - ord(s) <= K:
        ans += "a"
        K -= (ord("z") + 1 - ord(s))
    else:
        ans += s

print(ans)
# Judge status: Accepted

a,b,c=map(str, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき


print('A'+b[0]+'C')
# Judge status: Wrong Answer
S = list(input())
sum = len(S)
S.sort()
suma = 1
for i in range(sum-1) :
    if S[i] != S[i+1] :
        suma +=1
if sum == suma :
    print("yes")
else :
    print("No")
# Judge status: Accepted
S = input()
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
  print("Bad")
else:
  print("Good")
# Judge status: Accepted
N, T = map(int,input().split())
MIN = 10 ** 8
for _ in range(N):
    c, t = map(int,input().split())
    if t <= T:
        MIN = min(MIN, c)
if MIN == 10 ** 8:
    print('TLE')
else:
    print(MIN)
# Judge status: Wrong Answer
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ay = list(map(int,input().split()))
  ab.append(ay)
ans = []
for i in range(n):
  ans.append(0)
for i in range(m):
  for j in range(1,n+1):
    #print(i,j)
    if j in ab[i]:
      ans[j-1] += 1
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
if a + b >= c:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
x=int(input())
c=2*((x-1)//11)
#print(c)
y=x-11*c//2
#print(y)
if y<=6:
    ans=c+1
else:
    ans=c+2
print(ans)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

a, b = mapint()
print(-round(-(a+b)/2))
# Judge status: Accepted
n=int(input())
print((n//100+(1 if (n//100)*111<n else 0))*111)
# Judge status: Wrong Answer
data = input()

dataa,datab,datac,datad = data.split(' ')

dataa = int(dataa)
datab = int(datab)
datac = int(datac)
datad = int(datad)

length1 = dataa - datab
length2 = datab - datac
length3 = dataa - datac
datadd = datad * -1

if length1 <= datad:
    print('Yes')
elif length2 <= datad:
    print('Yes')
elif length3 <= datad:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
s = input()

ans = float("inf")
for i in range(len(s)-2):
    ans = min(ans, abs(753 - int(s[i:i+3])))

print(ans)
# Judge status: Accepted
import sys
def factors(n):
  a = []
  x = 1
  while x * x <= n :
    if n % x == 0:          
      a.append(x)
      a.append(n//x)
    x += 1
  return a
n,m=map(int,input().split())
fac=factors(m)
fac.sort()
for i in range(len(fac)-1,-1,-1):
  if n*fac[i]<=m:
    print(fac[i])
    sys.exit()
# Judge status: Wrong Answer
import sys

n, blue, red = map(int, input().split())
ball = blue + red

if blue == 0:
    print(0)
    sys.exit()
if n <= blue or red == 0:
    print(n)
    sys.exit()
if n <= ball:
    print(blue)
    sys.exit()

ans = n // ball
additional = n % ball

if additional == 0:
    print(ans * blue)
#elif additional <= blue:
#    print(ans * blue + additional)
else:
    print(ans * blue + additional)
# Judge status: Wrong Answer
A, B, C = list(map(int, input().split()))
if A == B == C:
    print(-1)
    exit()
ans = 0
while True:
    if A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        ans += 1
        A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
    else:
        break
print(ans)
# Judge status: Wrong Answer
K=int(input())
fiz=[0]
for i in range(K):
    if i%3==0 or i%5==0:
        k=1
    else:
        fiz.append(i)
print(sum(fiz))
# Judge status: Accepted
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, K = map(int, input().split())
    print(min(N%K, K - N%K))


if __name__ == '__main__':
    main()
# Judge status: Accepted
from itertools import accumulate


N = int(input())
S = input()
black = [0] * N
white = [0] * N
for i in range(N):
    if S[i] == "#":
        black[i] = 1
    else:
        white[i] = 1
black = list(accumulate(black, initial=0))
white = list(accumulate(white, initial=0))
ans = float("inf")
for i in range(N + 1):
    ans = min(ans, black[i] + white[N] - white[i])
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = list(map(int, input().strip()))

ans1 = 0
ans2 = 0
for i, v in enumerate(s):
    if v != (i % 2):
        ans1 += 1
    else:
        ans2 += 1

print(min(ans1, ans2))
# Judge status: Accepted
ab, bc, ca = map(int, input().split())
print(int(ab * bc / 2))
# Judge status: Accepted
w, h, n = map(int, input().split())
b = 0
l = 0

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        b = max(b, y)
    else:
        h = min(h, y)

print(max(h - b, 0)*max(w - l, 0))
# Judge status: Accepted
x,k,d = map(int,input().split())
x = abs(x)
n = x//d
#print(k-n,(abs(x-d*k)),(abs(x-(x//d)*d-d)),abs(x-(x//d)*d))
if n >= k:
    print(abs(x-d*k))
elif n < k:
    if (k-n)%2 == 1:
        print((abs(x-(x//d)*d-d)))#,abs(x-(x//d)*d)))
    else:
        print(abs(x-(x//d)*d))
        #print(min(abs(x%d),abs(x%d-d)))
# Judge status: Wrong Answer
s = int(input())
lis = [s]

def func(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
 
while func(s) !=4:
    s = func(s)
    lis.append(s)
    
print(len(lis)+4)
# Judge status: Wrong Answer
N, M = map(int, input().split())

if N % 2 == 0:
    N += 2
else:
    N += 1

ans = [[] for _ in range(N)]

K = 0
for i, n in enumerate(range(1, N // 2)):
    ans[i].append(n)
    K += 1
for i, n in enumerate(range(N // 2, N - 1)):
    ans[K - 1 - i].append(n)

for a in ans[:M]:
    print(*a)
# Judge status: Wrong Answer
def main():
    n = int(input())
    s = []
    ans = 0
    for i in range(n):
        si = input()
        if si in s:
          break
        else:
            ans += 1
        s.append(si)
    print(ans)
main()
# Judge status: Accepted
num = (int)(input())
button = []
for i in range(num):
  button.append(list(map(int, input().split(" "))))
count = 0
for i in range(num - 1, -1, -1):
  button[i][0] += count
  tasu = button[i][1] - (button[i][0] % button[i][1]) if button[i][0] % button[i][1] != 0 else 0
  #print(tasu, count)
  count += tasu
print(count)
# Judge status: Accepted
S = input()

if S=='ABC':
    print('ARC')
else:
    print('ABC')
# Judge status: Wrong Answer
from collections import deque

s = input()

r = False
d = deque()
d.append(s)

q = int(input())
for i in range(q):
    t = input()
    if t == "1":
        r = not r
    else:
        t, f, c = list(t.split())
        f = False if f=="1" else True

        if r == f:
            d.appendleft(c)
        else:
            d.append(c)

if r:
    d.reverse()

print("".join(d))
# Judge status: Accepted
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, k = nm()
a = nl()

print(math.ceil((n - 1) / (k - 1)))
# Judge status: Accepted
# -*- coding: utf-8 -*-
print(['A', 'a'][ord(input()) >= 97])
# Judge status: Accepted
a,b,n = map(int, raw_input().split(' '))
m = 0
print min(b-1,n) * a /b
"""
for t in range(0, min(b,n) + 1):
	print t*a/b
	m = max(m,t * a / b)
	#print int(t * a / b)
print m
"""
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
if b-a == c-b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
if __name__=='__main__':
    s = input()
    t = 'ABC' if s == 'ARC' else 'ARC'
    print(t)
# Judge status: Accepted
a,b,c,d = map(int, input().split())
ans=""

first  = (c-a)*"R"+(d-b)*"U"
second = (c-a)*"L"+(d-b)*"D"
third  = "D"+(c-a+1)*"R"+(d-b+1)*"U"+"L" 
fourth = "U"+(c-a+1)*"L"+(d-b+1)*"D"+"R"

ans=first+second+third+fourth
print(ans)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    ans = [0, 0]  # 偶数番目、奇数眼目の1の個数
    for i in range(N):
        if S[i] == "1":
            ans[i % 2] += 1
    
    return min(ans[0]+N//2+N%2-ans[1], N//2-ans[0]+ans[1])


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))
# Judge status: Accepted
N, L = map(int, input().split())
if L >= 0:
    print(sum([L+i-1 for i in range(2, N+1)]))
else:
    apple = [L+i-1 for i in range(1, N+1)]
    apple.pop(min(N-1, -L))
    print(sum(apple))
# Judge status: Wrong Answer
n, k = map(int, input().split())
MOD = 1e9+7

s = [0] * (n+2)
s[1] = (n+1)
for i in range(2,n+2):

    s[i] = (s[i-1] + ( i * (n-i+1) + 1 )) % MOD
    if s[i] < 0:
        s[i] %= MOD

print(int(s[n+1] - s[k-1]))
# Judge status: Wrong Answer
x,y=map(int,input().split())
print(x + y/2)