peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import math
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# ----------------------------------------
a, b, x = map(int, read().split())
'''
num = b - a + 1
arr = np.linspace(a, b, num)
div = np.where(arr % x == 0)
ans = div[0][0]
'''
if (b < x):
    ans = 0
else:
    if (a == 0):
        ans = b // x - a // x + 1
    else:
        ans = b // x - a // x


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

no_flag = True

for i in range((N//4)+1):
    if no_flag == False:
        break
    for j in range((N//7)+1):
        if no_flag == False:
            break
        if (4*i+7*j) == N:
            print("Yes")
            no_flag = False
            
if no_flag == True:
    print("No")
# Judge status: Wrong Answer
a,b = map(int,input().split())
c = [int(i) for i in input().split()]

result = c[-1] - c[0]

print(result)
# Judge status: Accepted
import math
r = int(input())
print(math.pi * r* 2)
# Judge status: Wrong Answer
l=list(map(int,input().split()))
print('Yes' if sum(l)%2 == 0  else 'No')
# Judge status: Accepted
N = int(input())
 
for i in range(1, N + 1):
  if i + (i * 8) // 100 == N:
    print(i)
    break
else:
  print(":(")
# Judge status: Wrong Answer
N = int(input())
n=int(N**0.5)
print(n)
cnt=0
for i in range(1,n+1):
    a=N//i
    if a-i-1>0:
        cnt+=(a-i-1)*2
    if i**2!=N:
        cnt+=1
    if a*i<=N-1:
        cnt+=2
print(cnt)
# Judge status: Accepted
A,B,C,K=map(int,input().split())
if K%2==0:
    print(A-B)
else:
    print(B-A)
# Judge status: Accepted
def resolve():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    a = sorted(a)
    for i in range(n):
        if x < 0:
            break
        x -= a[i]
        ans += 1
    if x != 0:
        ans -= 1
    print(ans)
resolve()
# Judge status: Accepted
s = input().rstrip('\r')
start = -1
end = -1
for i, c in enumerate(s):
    if c == 'A' and start == -1:
        start = i
    if c == 'Z':
        end = i
print(end-start+1)
# Judge status: Accepted
import bisect
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  P = set(map(int, input().split()))

  NP = sorted(list(set(range(102)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if left == -1 or abs(X - NP[left]) > abs(X - NP[right]):
    print(NP[right])
  else:
    print(NP[left])

main()
# Judge status: Accepted
A, B = map(int, input().split())

ans = A + B

if ans >= 24:
    ans -= 24

print(ans)
# Judge status: Accepted
import math
N = int(input())
if math.log10(N)%1 != 0:
  K = str(N)
  ans = 0
  for i in range(len(K)):
    ans += int(K[i])
  print(ans)
else:
  print(10)
# Judge status: Wrong Answer
N = int(input())
numbers = input().strip().split(' ')

boss_dict = [0] * N
for i in range(N - 1):
    boss_num = int(numbers[i])
    boss_dict[boss_num] += 1
    
for boss in boss_dict:
    print(boss)
# Judge status: Accepted
a, b, c = map(int, input().split())
ans = "NO"
 
for i in range(b):
    if (a*i)%b == c:
        ans = "YES"
 
print(ans)
# Judge status: Accepted
from collections import defaultdict as d
n, m = map(int, input().split())
dico = d(set)
tab = [-1] * n
for _ in range (m):
  s, c = map(int, input().split())
  dico[s].add(c)
  if len(dico[s]) == 2:
    print(-1)
    exit()
  tab[s - 1] = c
if n == 1:
  print(max(0, tab[0]))
else:
  if tab[0] == 0:
    print(-1)
  else:
    if tab[0] == -1:
      tab[0] = 1
    f = ''
    for i in tab:
      if i == -1:
        f += '0'
      else:
        f += str(i)
    print (f)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    ans=0
    for i in range(n,2*n):
        ans+=l[i]
    print(ans)
resolve()
# Judge status: Wrong Answer
ABC=list(map(int,input().split()))
K=int(input())

m=max(ABC)
s=sum(ABC)-m
print(m*2*K+s)
# Judge status: Accepted
n,x,t=map(int, input().split())
tako = n//x
amari = n%x
ans = tako*t
if amari != 0:
    ans += t
print(ans)
# Judge status: Wrong Answer
def sum_digits_string(str1):
    sum_digit = 0
    for x in str1:
        if x.isdigit() == True:
            z = int(x)
            sum_digit = sum_digit + z

    return sum_digit
s=input()    
ans=sum_digits_string(s)
if ans%9==0:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N, M = map(int, input().split())
lst = []

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        lst.append(b)
    elif b == N:
        lst.append(a)
        
lst.sort()
flg = 0

for i in range(len(lst) - 1):
    if lst[i] == lst[i + 1]:
        flg = 1
        break
        
if flg:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
#!/usr/bin/env python3

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

n = int(readline())
s = list(readline().rstrip())

r = s.count(ord('R'))
g = s.count(ord('G'))
b = s.count(ord('B'))

count = r * g * b
for i in range(n):
    for j in range(1, min(i + 1, n - i)):
        if s[i - j] != s[i] and s[i] != s[i + j] and s[i - j] != s[i + j]:
            count -= 1

print(count)
# Judge status: Accepted
x,y = map(int,input().split())
m = 10**9+7
n = (x+y)//3
c = 0
if x*0.5 <= y <= 2*x and (x+y)%3 == 0:
    r = x - n
    c = 1
    for i in range(1,r+1):
        c *= (n-i+1) % m
        c *= pow(i,m-2,m)
        c = c % m
else:
    ans = 0
print(c)
# Judge status: Accepted
temp=input()
temp=input()
A=[int(x) for x in temp.split()]
A.sort(reverse=True)

sum=0
for x in range(len(A)):
  sum=sum+(-1)**(x)*A[x]
print(sum)
# Judge status: Accepted
A, B, C = map(int, input().split())
if A <= C <= B:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
A = 'a'
S ='abcdefghij'
for _ in range(n-1):
    A = [a + s for a in A for s in S[:len(set(a))+1]]
print(*A, sep='\n')
# Judge status: Wrong Answer
N,M = map(int,input().split())
A = [0] * (N + 1)

for i in range(M):
    a,b = map(int,input().split())

    A[a] += 1
    A[b] += 1

for a in A:
    if a != 0:
        print(a)
# Judge status: Accepted
N=int(input())
ans=0
for i in range(1,N+1):
  count=0
  for j in range(1,i+1):
    if i%j==0:
      count+=1
  if i%2==1 and count==8:
    ans+=1
print(ans)
# Judge status: Accepted
ABC=list(map(int,input().split()))
K=int(input())

m=max(ABC)
s=sum(ABC)-m
print(m*(2**K)+s)
# Judge status: Accepted
k,x=[int(s) for s in input().split()]
print(*range(x-k+1,x+k))
# Judge status: Accepted
S = input()
ans = "NO"
if S[:7] == "keyence" or S[-7:] == "keyence":
  ans = "YES"
else:
  w = "keyence"
  for i in range(len(S)):
    if w[i] == S[i]: continue
    break
  if w[i:] == S[-len(w[i:]):]: ans = "YES"
print(ans)
# Judge status: Accepted
N = int(input())
S = input()
black_cnt = 0
white_cnt = 0
for i in range(N):
    if S[i] == '#':
        black_cnt += 1
    else:
        white_cnt += 1
ans = min(black_cnt, white_cnt)
tmp_ans = white_cnt
for i in range(N):
    if S[i] == '#':
        tmp_ans += 1
    else:
        tmp_ans -= 1
    ans = min(ans, tmp_ans)
print(ans)
# Judge status: Accepted
mylist = []
for i in range(0, 2):
    val = input()
    if ' ' in val:
        mylist.append(val)
a = list((map (int,mylist[0].split(' '))))

cnt = 0
while True:
    map (int,a)
    if all(map(lambda x: x % 2 == 0, a)) == False:
        break
    a = list(map(lambda x:x//2,a))
    cnt +=1
print (cnt)
# Judge status: Accepted
a, b = map(int, input().split())
if a*b%2 == 0:
    print("Even")
else:
    print("Odd")
# Judge status: Accepted
#!/usr/bin/env python3
import sys
from bisect import bisect_left
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(bisect_left(dp, INF))


if __name__ == '__main__':
    main()
# Judge status: Accepted
H, A = map(int, input().split())
print((H + A - 1) // A)
# Judge status: Accepted
s=list(input())
t=list(input())
n=len(s)
for _ in range(n):
        s=[s[n-1]]+s[:n-1]
        if s==t:
            print("Yes")
            break
else:
    print("No")
# Judge status: Accepted
a,b,c = map(int,input().split())
count = int(b / a)

if count >= c:
  print(c)
else:
  print(count)
# Judge status: Accepted
x = 0
mx = 0
n = int(input())
s = input()

for c in s:
    if c == 'I':
        x += 1
    else:
        x -= 1
    mx = max(mx, x)

print(mx)
# Judge status: Accepted
def calc(b, e):
    cnt = e // b
    return (b + e) * cnt // 2



n = int(input())

ans = 0

for i in range(1, n+1):
    ans += calc(i, n//i * i)

print(ans)
# Judge status: Accepted
N,K = map(int, input().split())
S = input()
T = ""
for i in range(N):
    if i == K-1:
        T += S[i].lower()
    else:
        T+= S[i]
print(T)
# Judge status: Accepted
def primes(n,thr):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(thr, n + 1) if is_prime[i]]

def main():
    X = int(input())
    arr = primes(X+1000000, X)
    print(arr[0])

main()
# Judge status: Wrong Answer
N=int(input('子供は何人？'))

a=N*(N+1)/2

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

high = (b-a+1)*(b-a)//2
print(high-b)
# Judge status: Accepted
N = int(input())
D = {}
ans = []
ansval = 0
for _ in range(N):
    s = input()
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    if ansval == D[s]:
        ans.append(s)
    elif ansval < D[s]:
        ans = [s]
        ansval = D[s]
ans.sort()
for a in ans:
    print(a)
# Judge status: Accepted
n,m=map(int,input().split())
import math
a=math.factorial(n)
b=math.factorial(m)
if abs(n-m) > 1:
    print(0)

elif abs(n-m)==1:

    print((a*b)%(10**9+7))
else:
    print((a*b*2)%(10**9+7))
# Judge status: Accepted
s = input()
a = int(s[:2])
b = int(s[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
  print('AMBIGUOUS')
elif 0 <= a <= 99 and 1 <= b <= 12:
  print('YYMM')
elif 0 <= b <= 99 and 1 <= a <= 12:
  print('MMYY')
else:
  print('NA')
# Judge status: Wrong Answer
# coding:utf-8

S = input()
n = S.count('N')
s = -(S.count('S'))
e = S.count('E')
w = -(S.count('W'))

if n + s + e + w == 0:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
N,K = map(int,input().split())

def replace(N,K):
    if(N<K):
        return N
    else:
        a = N%K
        if (abs(a-K)<K and abs(a-K)<a):
            a = abs(a-K)
    return a

print(replace(N,K))
# Judge status: Accepted
n = input()

if n[-1]=="3":
    print("bon")
elif n[-1]=="0" or\
     n[-1]=="1" or\
     n[-1]=="6" or\
     n[-1]=="8" :
    print("pon")
else:
    print("hon")
# Judge status: Accepted
#def main(S, b):

if __name__ == '__main__':
    s = input()
    flag = 1
    while (len(s) > 0):
        if (s[:2] == "hi"):
            s = s[2:]
        else:
            flag = 0
            s = ""
    if (flag):
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n, A, B = map(int, input().split())
if A > B:
  print(0)
elif n == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((B - A) * (n - 2) + 1)
# Judge status: Wrong Answer
import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    ans=max(ans,val)
print(ans)
# Judge status: Accepted
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]

at = AB[-1][0]
bt = AB[-1][1]
if at % bt == 0:
    cnt = 0
elif at > bt:
    cnt = bt - (at % bt)
else:
    cnt = bt - at

res = cnt
for tmp, b in reversed(AB[:-1]):
    a = tmp + res
    if a % b == 0:
        continue
    if a > b:
        res += b - (a % b)
    elif a < b:
        res += b - a
    # res += cnt

print(res)
# Judge status: Wrong Answer
from scipy.misc import comb
n, a, b = map(int, input().split())
sum = 0
for i in range(1, n+1):
  if i in (a, b):
    continue
  else:
    sum += comb(n, i)
print(int(sum))
# Judge status: Wrong Answer
def main():
    line = input()
    lista = [int(n) for n in line.split()]
    k = int(input())
    index = lista.index(max(lista))
    lista[index] *= 2*k
    soma = 0
    for i in range(len(lista)):
        soma += lista[i]
    print(soma)
main()
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 12:32:15 2020

@author: shinba
"""
import sys

n,m = map(int,input().split())

if n >= int(m/2):
    print(int(m/2))
    sys.exit()
else:
    m -= 2*n
    print(n+int(m/4))
# Judge status: Accepted
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_right

sys.setrecursionlimit(10**7)
N = int(input())
P = list(map(int, input().split()))

cnt = 0
minv = P[0]
for p in P:
    minv = min(minv, p)
    if p == minv:
        cnt += 1

print(cnt)
# Judge status: Accepted
s = input()
s_num = len(list(s))
result = ""
for i in range(s_num):
  result += "x"
print(result)
# Judge status: Wrong Answer
N = int(input())
Height = list(map(int, input().split()))
judge = 'Yes'

if (N == 1):
    print(judge)
    exit()

for i in range(N-2):
    # if (Height[i] > Height[i+1]+1 or Height[i]+1 < Height[i+1]):
    if (abs(Height[i]-Height[i+1]) >= 2):
        judge = 'No'

if (Height[-2] > Height[-1]+1):
    judge = 'No'

print(judge)
# Judge status: Accepted
N, K = map(int,input().split())
A = list(map(int,input().split()))
li = {}
for i in A:
    c = li.setdefault(i,0)
    li[i] = c + 1
    # print(c)
w = len(li.keys()) - K
# print(w)
# print(len(li.keys()))
ans = sorted(li.values())
# print(ans)
if w > 0:
    print(sum(ans[:w]))
else:
    print(0)
# Judge status: Accepted
N, K = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H)[::-1]
ans = sum(H[K:])
print(ans)
# Judge status: Accepted
a, b, k = map(int, input().split())

if k > a:
	k -= a
	a = 0
else:
	a -= k
	k = 0

if k > b:
	b = 0
else:
	b -= k

print("{} {}".format(a, b))
# Judge status: Accepted
N = int(input())
List = list(map(int,input().split()))
ans = 1000
stock = 0
for i in range(1,N):
  if List[i] > List[i-1]:
    temp = ans
    ans = temp%List[i-1]
    stock += temp//List[i-1]
  if List[i] < List[i-1]:
    ans += stock*List[i-1]
    stock = 0
if stock != 0:
  ans += stock*List[-1]
print(ans)
# Judge status: Accepted
a,b,c = map(int, input().split())
l = 4 * a * b
r = (c - a - b) * (c - a - b)

if c - a - b <= 0:
    print("No")
elif c < a or c < b:
    print("No")
elif l < r:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import numpy as np
import sys
input = sys.stdin.readline

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

dp = np.zeros((N+1,W+1), int)
r = W+1
for i in range(1,N+1):
    w, v = map(int, input().split())
    dp[i,:w] = dp[i-1,:w]
    dp[i,w:r] = np.maximum(dp[i-1,w:r], dp[i-1,:r-w]+v)
    
print(dp[N,W])
# Judge status: Wrong Answer
def resolve():
    n = int(input())
    b = list(map(int, input().split()))
    b = b[::-1]
    blist = [0]*n
    blist[0] = b[0]
    for i in range(1,n-1):
        if b[i] < blist[i-1]:
            blist[i] = b[i]
        else:
            blist[i] = blist[i-1]
    blist[n-1] = blist[n-2]
    print(sum(blist))
resolve()
# Judge status: Accepted
N = int(input())

a_num = 97

def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
    if n == 0:
        print(s)
        return
    for i in range(ord("a"), ord(max(s))+2):
        dfs(s+chr(i), n-1)

dfs("a", N-1)
# Judge status: Wrong Answer
n = int(input())
t = [int(input()) for _ in range(n)]
ans = t[0]

for v in t:
    if ans % v != 0:
        if ans < v:
            ans = v
        else:
            ans *= v

print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A, B = map(int, input().split())
    if A >= 13:
        print(B)
    elif A >= 6:
        print(int(B / 2))
    else:
        print(0)


if __name__ == "__main__":
    main()
# Judge status: Accepted
N=int(input())
A=sorted(list(map(int, input().split())), reverse=True)

bob=sum(A[1::2])
alice=sum(A[::2])


print(alice-bob)
# Judge status: Wrong Answer
N = int(input())
min_value=float('inf')
value=0
check=True
for i in range(2,10^6):
    if((N%i)==0):
        value=(N/i)+i-2
        if(min_value>value):
            min_value=value
            check=False
if(check):
    print(N-1)
else:
    print(int(min_value))
# Judge status: Accepted
from collections import Counter
import sys
MOD = 998244353


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    e = [0]*n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans *= e[i-1]
        ans %= MOD
    print(ans)


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

a = int(N/2)
b = a-1

for i in range(a):
  print(X[a])
for i in range(a):
  print(X[b])
# Judge status: Accepted
A, B = map(int, input().split())
S = input()
X = {str(i) for i in range(0, 10)}
f = 0
for i in range(A+B+1):
  if i != A and S[i] not in X:
    f = 1
    break
  if i == A and S[i] != "-":
    f = 1
    break
if f == 0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N = int(input())

d = {'AC':0,'WA':0,'TLE':0,'RE':0}

for i in range(N):
  wrk = input()
  d[wrk] = d[wrk]+1

print('AC x ',d['AC'])
print('WA x ',d['WA'])
print('TLE x ',d['TLE'])
print('RE x ',d['RE'])
# Judge status: Accepted
sa = list(input())
sb = list(input())
sc = list(input())

tmp = sa.pop(0)
while True:

  if tmp == "a":
    if len(sa) == 0:
      print("A")
      exit()
    else:
      tmp = sa.pop(0)
  elif tmp == "b":
    if len(sb) == 0:
      print("B")
      exit()
    else:
      tmp = sb.pop(0)
  elif tmp == "c":
    if len(sc) == 0:
      print("C")
      exit()
    else:
      tmp = sc.pop(0)
# Judge status: Accepted
n=int(input())
d=[int(x) for x in input().split()]

d=sorted(d)

l=d[int(len(d)/2)-1]
r=d[int(len(d)/2)]

print(r-l)
# Judge status: Accepted
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
bc = []
for _ in range(m): bc.append([int(i) for i in input().split()])
a.sort()
bc.sort(key=lambda x:x[1])
bc = bc[::-1]
idx = 0
for b, c in bc:
    for bi in range(b):
        if idx + bi == n or a[idx+bi] >= c:
            idx = "e"
            break
        else: a[idx+bi] = c
    if idx == "e": break
    else: idx += b
print(sum(a))
# Judge status: Accepted
a,b,c,d = map(int,input().split())
print(max(max(a*c,b*d),max(a*d,b*c)))
# Judge status: Accepted
import collections
n = int(input())
a = list(map(int, input().split()))
if (n==1):
    print(0)
    exit()
for i in range(n):
    a[i] -= i+1
a.sort()
ans1 = 0
ans2 = 0
x = a[n//2]
y = a[n//2-1]
for i in range(n):
    ans1 += abs(a[i]-x)
    ans2 += abs(a[i]-y)
print(min(ans1,ans2))
# Judge status: Accepted
a, b, t = map(int, input().split())
print(b * (t//a))
# Judge status: Wrong Answer
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
a_list = list(map(int, input().split()))
count = 0
for i in range(1, n, 2):
    if a_list[i] % 2 == 1:
        count += 1
print(count)
# Judge status: Accepted
from collections import Counter
N=int(input())
d={chr(i):100 for i in range(ord("a"),ord("z")+1)}
for i in range(N):
  A={chr(i):0 for i in range(ord("a"),ord("z")+1)}
  A.update(Counter(list(input())))
  for i in A:
    if d[i]>A[i]:
      d[i]=A[i]
for i in d:
  if d[i]==100:
    d[i]=0
ans=""
key=sorted(d.keys())
for i in key:
  ans+=i*d[i]
print(ans)
# Judge status: Wrong Answer

X, Y = map(int, input().split())
print(X+(Y/2))
# Judge status: Wrong Answer
h,n = (int(x) for x in input().split())

a_list = [int(x) for x in input().split()]
  
a_list.sort(reverse=True)

if h <= sum(a_list[:2]):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
T=input()
ans=T.count("PD")+T.count("P?")+T.count("D")+T.count("?")
print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    ans += i*n-i**2+i+1
mod = 10**9+7
print(ans%mod)
# Judge status: Accepted
n, l = map(int, input().split())

apple = []
diff = 1001001001
minus = False
for i in range(1, n+1):
    apple.append(l+i-1)
    if abs(l+i-1) < diff:
        diff = abs(l+i-1)
        if l+i-1 < 0:
            minus = True
        else:
            minus = False

if minus:
    print(sum(apple) + diff)
else:
    print(sum(apple) - diff)
# Judge status: Accepted
k, a, b = map(int, input().split())
diff = b - a
if diff <= 2:
    print(1 + k)
    exit()
times = a - 1
print(a + (k-times) // 2 * diff + (k-times) % 2)
# Judge status: Accepted
n,y=map(int,input().split())
Y=y//1000
a,b,c=0,0,0
for i in range(Y//10+1):
    rest=n-i
    for j in range(rest+1):
        k=rest-j
        if 10*i+5*j+k==Y:
            print(i,j,k)
            exit()
            
print('-1 '*3)
# Judge status: Accepted
A = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()
print(7-A.index(S))
# Judge status: Accepted
nim = input()
sam = input()
print('YES' if nim[::-1] == sam else'NO' )
# Judge status: Accepted
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, a, b, c, d = inintm()
s = input()

if c < d:
    if "##" not in s[a-1:d-1]:
        print("Yes")
    else:
        print("No")
else:
    if ("..." in s[b-2:d+1]) and ("##" not in s[a-1:c-1]):
        print("Yes")
    else:
        print("No")
# Judge status: Wrong Answer
s = input()
s = input()
x = 0
l_x = []
for c in s:
  x += 1 if c == 'I' else -1
  l_x.append(x)
    
print(l_x)
print(max(l_x))
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

a = sorted(a)
m1 = n // 3
m2 = 2 * m1
print(sum(a[m1:m2]))
# Judge status: Accepted
A, B, M = map(int, input().split())
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
c = {}
m = 2000000
for i in range(M):
    x, y, c2 = map(int, input().split())
    c[(x, y)] = c2
    value = a[x-1] + b[y-1] - c2
    if m > value:
        m = value

if (min(a), min(b)) in c:
    print(m)
else:
    if m > min(a) + min(b):
        print(min(a) + min(b))
    else:
        print(m)
# Judge status: Accepted

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

ave = round(sum(a) / n)
result = 0
for i in a:
    result += (i-ave) ** 2
print(result)
# Judge status: Wrong Answer

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

temp = ls[0]
ls[0] = ls[1]
ls[1] = temp

temp = ls[0]
ls[0] = ls[2]
ls[2] = temp

print(ls)
# Judge status: Accepted
n=int(input())
r=[]
cnt=1

for _ in range(n):
    x,l=map(int,input().split())
    s=x-l
    t=x+l
    r.append([s,t])
    
r=sorted(r,key=lambda x: x[1])
t0=r[0][1]

for s,t in r[1:]:
    if t0<=s:
        cnt+=1
        t0=t

print(cnt)
# Judge status: Accepted
s = input()
ans = 'No'
index = s.find(s[0], 1)
if index >= 1:
    s = s.replace(s[0], '')
    if (len(s) == 2):
        if (s[0] == s[1]):
            ans ='Yes'
    
print(ans)
# Judge status: Wrong Answer
n, k = map(int, input().split())

print(n%k)
# Judge status: Accepted
n, x = map(int, input().split())
*a, = map(int, input().split())

b = a[:]
if b[0] > x:
    b[0] = x

for i in range(n-1):
    if b[i]+b[i+1] > x:
        b[i+1] = abs(b[i]-x)

print(sum(map(lambda x: abs(x[0] - x[1]), zip(a, b))))
# Judge status: Accepted
n, m = map(int, input().split())

if n == 1 and m == 1:
    print("1")
elif m == 1:
    print(n - 2)
elif n == 1 and m != 1:
    print(m - 2)
else:
    print((n - 2) * (m - 2))
# Judge status: Accepted
# C - Skill Up

N, M, X = map(int, input().split())
C, A = [], []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)

costs = []
def f(i, cost, points):
    if X <= min(points):
        costs.append(cost)
        return
    if N <= i:
        return
    f(i + 1, cost, points)
    tmp = [p for p in points]
    for j in range(M):
        tmp[j] += A[i][j]
    f(i + 1, cost + C[i], tmp)

f(0, 0, [0] * M)
print(min(costs) if len(costs) != 0 else -1)