peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - 10 * k * i + j) // 10)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))
# Judge status: Wrong Answer
N = int(input())
a = list(map(int,input().split()))

g = [0]*10
 
for i in range(10):
    g[i] = a.count(i)
    
ans = 1
    
for i in range(10):
    if i == 0:
        tmp = g[i] + g[i+1]
    elif i == 9:
        tmp = g[i-1] + g[i]
    else:
        tmp = g[i-1] + g[i] + g[i+1]
        
    ans = max(ans,tmp)
    
print(ans)
# Judge status: Accepted
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k,a,b = MAP()
if(b-a<=1):
    ans = 1 + k
else:
    n = (1+k-a)//2
    ans = 1 + k - 2*n + (b-a)*n
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
print(min(c, b // a))
# Judge status: Wrong Answer
X = int(input())
a, b = 0, 0

a = X // 500
b = (X - 500 * a) % 5

print(1000 * a + 5 * b)
# Judge status: Accepted
s = input()
rs = s[::-1]
n = len(s) // 2
for i in range(1, n):
  r = rs[i*2:]
  rn = len(r)
  if r[:rn//2] == r[rn//2:]:
    print(rn)
    exit()
print(0)
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()
cnt =0
for i in range(N-1):
    p = S[i]+S[i+1] 
    if p =='RL':
        cnt += 1
cnt2 = 0
if S[0] == 'L':
    cnt2 += 1
if S[-1] == 'R':
    cnt2 += 1
n =N- cnt *2-cnt2
if cnt - 1 >= K:
    print(n+2*K)
else:
    print(N-1)
# Judge status: Wrong Answer
n,m=map(int,input().split())
xy = [list(map(int, input().split())) for _ in range(m)]
l=[1]*n
out_=[0]*n
in_=[0]*n#入れられたことがある履歴。0番目だけは初期値1
in_[0]=1
c=0
#print(in_)
for i in range(m):
    l[xy[i][0]-1]-=1
    l[xy[i][1]-1]+=1
    if in_[xy[i][0]-1]!=0:
        c+=1
    in_[xy[i][1]-1]+=1
#print(l,in_,c)
c2=0
for i in l:
    if i!=0:
        c2+=1
print(min(c,c2))
# Judge status: Wrong Answer
k, s =map(int,input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        if 0<=s-i-j<=k:
            cnt += 1
            print(i,j,s-i-j)
print(cnt)
# Judge status: Wrong Answer
n, a, b = list(map(int, input().split()))

print (a* (n//(a+b)) + n%(a+b))
# Judge status: Accepted
from collections import Counter
import math
n = int(input())
s_list = ["".join(map(str,sorted(input()))) for i in range(n)]
s_counter = Counter(s_list)
s_len = len(s_counter)
s_most = s_counter.most_common()
#print(s_counter)
ans = 0
for i in range(s_len):
    if s_most[i][1] != 1:
        dum = s_most[i][1]
        ans += (dum * (dum-1)) // 2
    else:
        break
print(ans)
# Judge status: Wrong Answer
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    cnt = [False] * 8
    tuyo = 0
    for i in range(N):
        if 1 <= A[i] <= 3199:
            cnt[A[i] // 400] = True
        else:
            tuyo += 1

    val = 0
    for i in cnt:
        if i:
            val += 1
    if val==0 and tuyo>0:
        val=1

    print(val, val + tuyo)


resolve()
# Judge status: Accepted
n = int(input())
A = [int(input()) for _ in range(n)]

#%%
idx = 0
visited = set()
count = 0
flag = False

for i in range(n):
    next_idx = A[idx]
    next_idx -= 1
    visited.add(idx)

    if idx == 1:
        flag = True
        break
    elif next_idx in visited:
        break
    count += 1
    idx = next_idx

if flag:
    print(count)
else:
    print(-1)
# Judge status: Accepted
a, b, k = map(int, input().split())

res = []

for i in range(1, 101):
    if a%i == 0 and b%i == 0:
        res.append(i)
print(res[-k])
# Judge status: Accepted
import math

N = int(input())
for x in range(N, 0, -1):
    sq = math.sqrt(x)
    div, mod = divmod(sq, 1)
    if mod == 0:
        print(x)
        break
# Judge status: Accepted
s = input()
if s[2]==s[3] and s[4]==s[5]: print("Yes")
else: print("No")
# Judge status: Wrong Answer
import collections

def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(m)]
    ab_f = [flatten for inner in  ab for flatten in inner]
    c = collections.Counter(ab_f)
    c_s = sorted(c.items())
    for i in (c_s):
        print(i[1])
if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

# A - Digits Sum
def digits_sum(num):
	sum = 0
	
	for s in str(num):
		sum += int(s)
	
	return sum


N = int(input())
ans = sys.maxsize

for A in range(1, N//2):
	B = N - A
	sum = digits_sum(A) + digits_sum(B)
	ans = min(ans, sum)
	
print(ans)
# Judge status: Accepted
n = int(input())
sp = []
for i in range(n):
    s, p = input().split()
    sp.append((i+1, s, int(p)))
sp.sort(key=lambda x: (x[1], -int(x[2])))
for i, _, _ in sp:
    print(i)
# Judge status: Accepted
L, R = map(int, input().split())
# R-L>=2019なら、[L,R]に2019の倍数が必ず存在する
if R - L >= 2019:
    print(0)
else:
    ans = 10**9
    for i in range(L, R + 1):  # L<=i<=R
        for j in range(i + 1, R + 1):  # i<j<=R
            ans = min(ans, (i * j) % 2019)
    print(ans)
# Judge status: Accepted
import sys
x=int(input())
for a in range(-1000,1000):
  for b in range(-1000,1000):
    if a**5 - b**5 == x:
      print(a,b)
      sys.exit()
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
flg = True
cnt = 0
total = 0

while flg:
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] // 2
            cnt += 1
    if cnt == N:
        total += 1
    else:
        flg = False
    cnt = 0
print(total)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
count = 1
broke = 0

if 1 not in a:
    print(-1)
    exit()

for x in range(N):
    if a[x] == count:
        count += 1

print(N - count + 1)
# Judge status: Wrong Answer
N = int(input())
S = input()
if S[:3] == S[3:]:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
from fractions import gcd
from functools import reduce

N, M, *A = map(int, open(0).read().split())

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))
# Judge status: Accepted
n = str(input())
a = "10" * int(len(n)/2) 
b = "01" * int(len(n)/2) 
if int(len(n)) % 2 !=0:
    a +="1"
    b +="0"
s = int(n) + int(a)
t = int(n) + int(b)
p = str(s)
q = str(t)
print(min(p.count("1"),q.count("1")))
# Judge status: Accepted
N, R = map(int, input().split())
if N >= 10:
    print(R)
else:
    print(R+100*(10-N))
# Judge status: Accepted

W,H,x,y = map(int,input().split())

if ((W/2 == x) and (H/2 == y)) or ((W/2 == y) and (H/2 == x)):
    print(W*H/2,end="")
    print(" ",end="")
    print(1)
else:
    print(W*H/2,end="")
    print(" ",end="")
    print(0)
# Judge status: Accepted
N,R=map(int,input().split())
if N<10:
  print(R+(100*(10-N)))
else:
  print(R)
# Judge status: Accepted
n = int(input())
a = list(input())
#print(a)
w = a.count("W")
r = a.count("R")
aa = a[:r]
#print(aa)
r2 = aa.count("R")
print(r-r2)
# Judge status: Wrong Answer
a, b = map(int, input().split())
print(-((-a+b)//2))
# Judge status: Wrong Answer
if __name__ == '__main__':
    k = input()
    k = int(k)
    ab = input()
    ab = ab.split()
    a = int(ab[0])
    b = int(ab[1])
    flag = False
    sum = k
    while k<b:
        if a<=k and k<=b:
            flag = True
        k += sum
    if flag:
        print("OK")
    else:
        print("NG")
# Judge status: Accepted
import bisect

N = int(input())
A = list(map(int, input().split()))

A.sort()

# 組み合わせの片方は最大値
n = A[-1]

# もう片方はnの半分に近い値
# 二分探索で最も近い値を見つける
mid = bisect.bisect(A, n/2)

# 一つ手前の値とどちらが近いかチェックして、近い方を出力する
if abs(n/2-A[mid-1]) > abs(n/2-A[mid]):
    print(n, A[mid])
else:
    print(n, A[mid-1])
# Judge status: Accepted
from fractions import gcd
from functools import reduce

# 2つの数の最小公倍数
def lcm(x,y):
    return (x*y) // gcd(x,y)

# リストを引数にして最小公倍数を表示
def lcm_of_list(a):
    return reduce(lcm, a)

def waruni(a):
    return a//2


n,m = map(int, input().split())
b = list(map(waruni, map(int, input().split())))

L = lcm_of_list(b)

for i in range(n):
    if (L//b[i])%2==0:
        print(0)
        exit()

ans = (m//L+1)//2

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
allsum = 0
for i in a:
    allsum = allsum ^ i
 
for i in range(n):
    ans[i] = allsum ^ a[i]
print(*ans)
# Judge status: Accepted
N, K = map(int,input().split())
t = list(map(int,input().split()))


visited = [0] * N

idx = 0

town = 0

if K <= N:
    for i in range(K):
        idx = t[idx] -1
    print(idx+1)
else:
    for i in range(K):
        if visited[idx]:
            cycle = i - visited[idx]
            rem_step = (K - i) % cycle
            town = visited.index(visited[idx] + rem_step)
            break


        visited[idx] = i
        idx = t[idx] - 1


    print(town+1)
# Judge status: Accepted
mod = 10**9+7
def comb(n, k):
    c = 1
    for i in range(k):
        c *= n - i
        c %= mod
    d = 1
    for i in range(1, k + 1):
        d *= i
        d %= mod
    return (c * pow(d, mod - 2, mod)) % mod
x,y=map(int,input().split())

ans=0

z=x//2

for q in range(z,x+1):
  w=2*q-x
  if w*2+(q-w)==y:
    t=comb(q,w)
    ans+=t
    
  
  
print(ans)
# Judge status: Accepted
s = input().split()
k = int(s[0])
x = int(s[1])
if(k*500>=x):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N = int(input())
la =  list(map(int,input().split()))
cnt=0
for i in range(N):
  if (i+2)%2==0 and la[i]%2==1:
    cnt+=1
print(cnt)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

codd = 0
cfour = 0

for i in range(n):
	if a[i]%2 != 0:
		codd += 1
	if a[i]%4 == 0:
		cfour += 1
ceven = n - cfour - codd

if cfour >= codd:
	print('Yes')
elif ceven == 0 and cfour + 1 == codd:
	print('Yes')
else:
	print('No')
# Judge status: Accepted
N = int(input())
v = list(map(int, input().split()))
v = sorted(v)
total = v[0]
for i in range(1, N):
    total = (total + v[i])/2
print(total)
# Judge status: Accepted
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X = read().rstrip().decode()

s, t = 0, 0
for x in X:
    if x == 'S':
        s += 1
    else:
        if s == 0:
            t += 1
        else:
            s -= 1

print(s+t)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

if N == 2:
    print(*a[::-1])
else:
    product = a[0]
    for i in range(N):
        if i == 0:
            product = a[i]
        else:
            product = product ^ a[i]
    ans = []
    for i in range(N):
        product = product ^ a[i]
        ans.append(product)
        product = product ^ a[i]
    print(*ans)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
summary = sum(A)
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
    
Q = int(input())
for _ in range(Q):
  B, C = list(map(int,input().split()))
  if B not in d:
    b = 0
  else:
    b = d[B]
    d[B] = 0
  if C in d:
    d[C] += b
  else:
    d[C] = b
  summary = summary + b * (C - B)
  print(summary)
# Judge status: Accepted
from collections import Counter
s=Counter(list(input()))
t=Counter(list(input()))
s, t=list(s.values()),list(t.values())
print("Yes" if sorted(s)==sorted(t) else "No")
# Judge status: Accepted
N,M = map(int,input().split())
H = list(map(int,input().split()))
T = [[] for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    T[a].append(b)
    T[b].append(a)

ans = [1]*(N+1)
for i in range(1,N+1):
    h = H[i-1]
    for c in T[i]:
        if h<=H[c-1]:
            ans[i] = 0
            break
print(sum(ans)-1)
# Judge status: Wrong Answer
n = int(input())
A = tuple(map(int, input().split()))

CO = [0] * 8
o32 = 0
for a in A:
    for i in range(8):
        if 4*i*100 <= a < 4*(i+1)*100: 
            CO[i] += 1
    else:
        if a >= 3200:
            o32 += 1
ans = 0
for count in CO:
    if count > 0:
        ans += 1
print(ans, ans+o32 if ans+o32 <= 8 else 8)
# Judge status: Wrong Answer
# ここにコード書く
n, m = map(int, input().split())
# combination nC2 mC2
ans = n * (n - 1) / 2 + m * (m - 1) / 2
print(ans)
# Judge status: Accepted
n, x, t = map(int, input().split())
m = (n+x-1)//x
print(t*m)
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
lst = [input() for i in range(n)]
c = Counter(lst)
c2 = c.most_common()
m = c2[0][1]
ans = [i[0] for i in c2 if i[1] == m]
print('\n'.join(sorted(ans, key=lambda x:x[0])))
# Judge status: Accepted
S = input()
N = S.count("hi")
L = len(S)
if int(N)*2 == int(L):
	print("Yes")
else:
	print("No")
# Judge status: Accepted
N = input()
keta = len(N)
N = list(N)
c = int(N[0])
if all(c=="9" for c in N[1:keta]):
    print(c+9*(keta-1))
else:
    print(c-1+9*(keta-1))
# Judge status: Accepted
l,r = map(int, input().split())

if r-l >= 2019: print(0)
else:
  ans = float("inf")
  for i in range(l, r):
    for j in range(i+1, r+1):
      t = i*j%2019
      if t < ans: ans = t
  print(ans)
# Judge status: Accepted
a,b,c = map(int,input().split())
if (a*b*c)%2 == 1:
    print(min(a*b,b*c,a*c))
else:
    print(0)
# Judge status: Wrong Answer
n = int(input())

def dfs(s):
  if len(s) == n:
    print(s)
  else:
    for i in range(ord(s[len(s) - 1]) - ord('a') + 2):
      dfs(s + chr(i + ord('a')))
      
s = 'a'
dfs(s)
# Judge status: Accepted
A, B = map(int, input().split())
if A < 10 and B <10:
  print(A*B)
else:
  print('-1')
# Judge status: Accepted
a, b, c, d = map(int, input().split())

if a>c:
    if d<a:
        print(0)
    elif a<=d<b:
        print(d-a)
    else:
        print(b-a)

elif a==c:
    if d<b:
        print(d-c)
    else:
        print(b-a)

else:
    if b<c:
        print(0)
    elif c<=b<d:
        print(b-c)
    else:
        print(d-c)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
S = input()
for x in S:
    # print(x)
    if x == "a" and A > 0:
        A -= 1
        print("Yes")
    elif x == "b" and B > 0:
        B -= 1
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
from sys import stdin
data = stdin.read().splitlines()

a = int(data[0])
b = int(data[1])
c = int(data[2])
x = int(data[3])

count = 0

l = min(x//500, a)

while l >= 0:
    x = x - 500*l
    m = min(x//100, b)
    while m >= 0:
        x = x - 100*m
        if c >= x//50:
            count += 1
        x = x + 100*m
        m -= 1
    x = x + 500*l
    l -= 1
print(count)
# Judge status: Accepted
N = int(input())
ans = 0
min_v = 10 ** 4 + 1
for i in range(N):
    s = int(input())
    ans += s
    if s % 10 != 0 and min_v > s:
        min_v = s
if ans % 10 == 0:
    print(max(0, ans - min_v))
else:
    print(ans)
# Judge status: Wrong Answer
import sys


def solve():
    n = int(input())
    h = list(map(int, input().split()))
    up_h = [0]
    for i in range(len(h)-1):
        if h[i] < h[i+1]:
            up_h.append(i+1)
    up_h.append(len(h)-1)
    h_max = 0
    for i in range(len(up_h)-1):
        if h_max < up_h[i+1]-up_h[i]-1:
            h_max = up_h[i+1]-up_h[i]
    print(up_h)
    print(h_max)


solve()
# Judge status: Accepted
l, r = map(int, input().split())

if r//2019 != l//2019:
    print(0)

else:
    lm = list()
    for i in range(l, r):
        for j in range(i+1, r+1):
            lm.append((i*j)%2019)
    print(min(lm))
# Judge status: Wrong Answer
n = int(input())
c = input()
count = 0

while "WR" in c:
    c = c.replace("W", "R", 1)
    c = c.replace("WR", "WW", 1)
    count += 1
print(count)
# Judge status: Wrong Answer
S=input()
N=len(S)
from collections import Counter
C=Counter(S)
mn=N
mx=0
for c in ['a','b','c']:
    mx=max(mx,C[c])
    mn=min(mx,C[c])
print('YES' if mx-mn<=1 else 'NO')
# Judge status: Wrong Answer
a,b,c = map(int, input().split())
if a+2*b >= c:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
X,Y=map(int,input().split())
flg=False
for i in range(1,X+1):
    for j in range(X+1-i):
        if i*2+j*4 == Y or j*2+i*4 == Y:
            print("Yes")
            flg=True
            break
    if flg:
        break

if flg==False:
    print('No')
# Judge status: Accepted
S = input()

if S[0::2].count('0') > S[1::2].count('0'):
    print(S[0::2].count('1') + S[1::2].count('0'))
else:
    print(S[0::2].count('0') + S[1::2].count('1'))
# Judge status: Accepted
a,b=map(int, input().split())
c=a*b

if c%2==0:
  print("Even")
else:
  print("Odd")
# Judge status: Accepted
n, k = map(int, input().split())
s = input()
score = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        score += 1
print(min(score + 2*k, len(s) - 1))
# Judge status: Wrong Answer
n,k=map(int,input().split())
s=input()
x=s.count('RL')
y=0
cnt=0
for i in range(n-1):
  if s[i]==s[i+1]:
    cnt+=1
if s[0]=='L' and s[n-1]=='R':
  y+=1
while k>0:
  if x>0:
    x-=1
    cnt+=2
    k-=1
  else:
    if y>0:
      cnt+=1
      y-=1
      k-=1
    else:
      break
print(cnt)
# Judge status: Accepted
a,b,c,d = list(map(int, input().split()))

def num_fact_in(begin, end):
    def f(div):
        return end//div - (begin-1)//div
    return f

import math
lcm = c * d // math.gcd(c, d)

f = num_fact_in(a, b)
print(b - a + 1 - (f(c) + f(d) - f(lcm)))
# Judge status: Wrong Answer
m,c = 0,0
for l in raw_input():
	c += 1 if l == 'I' else -1
	m = max(c,m)
print m
# Judge status: Wrong Answer
N = int(input())

ans = False

for i in range(2,10):
    if N % i == 0 and N / i <= 9:
        ans = True

if ans:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
A,B = (int(x) for x in input().split())
ans = 0
for i in range(2):
  if A > B:
    ans += A
    A -= 1
  else:
    ans += B
    B -= B
print(ans)
# Judge status: Accepted
def gcd(a, b):
  if b == 0: return a
  return gcd(b, a%b)

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

MOD = 1000000000 + 7

N = int(input())
A = list(map(int,input().split()))

L = 1
for a in A:
  L = lcm(L, a)
ans = 0
for a in A:
  ans += L // a
ans %= MOD
print(ans)
# Judge status: Accepted
n = int(input())

if n%2 == 0:
    print(n//2)
else:
    print(n//2 + 1)
# Judge status: Accepted
n,a,b=map(int,input().split())
s=input()
cnt=0
foreign=0
for i in range(n):
  if s[i]=="a":
    if cnt<a+b:
      print("Yes")
      cnt+=1
    else:
      print("No")
  elif s[i]=="b":
    foreign+=1
    if cnt<a+b and foreign<=b:
      print("Yes")
      cnt+=1
    else:
      print("No")
  elif s[i]=="c":
    print("No")
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))

cnt=0
if p[0]==1:
    p[1],p[0]=p[0],p[1]
    cnt+=1

for i in range(1,n-1):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        cnt+=1
    else:
        continue
if p[-1]==n:
    cnt+=1
print(cnt)
# Judge status: Accepted
line = int(input())
if line > 999:
    print("ABD")
else:
    print("ABC")
# Judge status: Accepted
a, b = map(int, input().split())

if a >= 13:
    print(b)
elif 6 <= a <= 12:
    print(b // 2)
else:
    print(0)
# Judge status: Wrong Answer
def main():
    ABC = list(map(int,input().split()))
    if ABC[0]%2 == 0 or ABC[1]%2 == 0 or ABC[2]%2 == 0:
        print(0)
    else:
        tmp = [0,0,0]
        cube = ABC[0]*ABC[1]*ABC[2]
        for i in range(3):
            base = cube/ABC[i]
            tmp[i] = abs((ABC[i]//2*base)-((ABC[i]-ABC[i]//2)*base))
        print(int(min(tmp)))

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
H,W = map(int, input().split())
if H*W%2 == 0:
  print(H*W/2)
else:
  print(H*W//2+1)
# Judge status: Wrong Answer
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
ans_list = []
end = 0
stpos = 0


for i in range(K):
    ans = A[ans] - 1
    ans_list.append(ans)
    if len(set(ans_list)) != i+1:
        end = i - 1
        stpos = ans_list.index(ans)
        break
    if i == K:
        print(ans)
        exit()


print(ans_list[stpos:end+1][(K-(stpos+1)) % (end-stpos+1)]+1)
# Judge status: Accepted
import math 
N  = int(input())
print(math.ceil(N/2)/N)
# Judge status: Wrong Answer
N = int(input())-1


print((1+N)*(N/2))
# Judge status: Accepted
import sys
import math
input = sys.stdin.readline

k, a, b = map(int, input().split())
if b > a and k + 1 > a:
    ans = max(k + 1, (b - a) * math.floor((k + 1 - a) / 2) + (k + 1 - a) % 2 + a)
else:
    ans = k + 1
print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
res=(n+2)*(n+1)**2/2+n+1-(n+1)*(n+2)*(2*n+3)/6
re=(n+1)*k*(k-1)/2+k-1-k*(k-1)*(2*k-1)/6
res=(res-re)%(10**9+7)
print(int(res))
# Judge status: Accepted
L=lambda:list(map(int,input().split()))
n,k=L()
for a,b in sorted([L() for _ in range(n)]):
  k-=b
  if k<=0:print(a);exit()
# Judge status: Accepted
x,k,d=map(int,input().split())

x=x if x>0 else -x
print(x-k*d if k<=x//d else (d-x%d if (k-x//d)%2 else x%d))
# Judge status: Accepted
a,b,c,d= map(int, input().split())
alice=[0]*(b-a+1)
bob=[0]*(d-c+1)
ct=0
for i in range (a,b+1):
    alice[ct]=i
    ct+=1
ct=0
for i in range (c,d+1):
    bob[ct]=i
    ct+=1
ans=len(set(alice)&set(bob))
if ans==0:
    print(ans)
else:
    print(ans-1)
# Judge status: Wrong Answer
N_1 = int(input())
A = [str(input()) for i in range(N_1)]
N_2 = int(input())
B = [str(input()) for i in range(N_2)]

C = A+B
D = list(set(C))
E=[]
for i in range(len(D)):
    NN = A.count(D[i]) - B.count(D[i])
    E.append(NN)
print(max(E))
# Judge status: Accepted
N,K = map(int,input().split())
a = input().split()
a = [int(i) for i in a]
la = sorted(a)
print(sum(la[:K]))
# Judge status: Wrong Answer
nu = int(input())

lis = []
ans = 0

for i in range(nu):
    t = int(input())
    lis.append(t)

lis.sort()
print(lis)

for i in range(10*18):
    tes = lis[-1] * (i+1)
    for f in lis:
        if tes % f == 0:
            ans = 1
        else:
            ans = -1
            break
    if ans == 1:
        break

print(tes)
# Judge status: Accepted
import math
N = int(input())
nuki = math.ceil(N/1.08)
print(nuki if math.floor(nuki*1.08) == N else ':(')
# Judge status: Accepted
N = int(input())

modsum = ((1+(N-1))*(N-1))//2

print(modsum)
# Judge status: Accepted
n,m = map(int, input().split())
if n == m== 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n,m)-2)
else:
    print((n-2)*(m-2))
# Judge status: Accepted
def z(x,y):
    if x > y:
        return(x-y)
    else:
        return(y-x)
N,X,Y = map(int,input().split())
X -= 1
Y -= 1
A = [0] * N
for i in range(N):
    for j in range(i+1,N):
        a = min(j-i,z(i,X) + 1 + z(j,Y))
        A[a] += 1
for i in range(N-1):
    print(A[i+1])
# Judge status: Accepted
a,b,c,k = map(int,input().split())
if k%2 == 0 and a-b <= 10**18:
    print(a-b)
elif k%2 != 0 and a-b <= 10**18:
    print(b-a)
"""
else:
    print("Unfair")
"""
# Judge status: Accepted
a,b,c = map(int, input().split())

ans = "NO"
for i in range(b):
  if a * i % b == c:
    ans = "YES"
    break
print(ans)
# Judge status: Accepted
from math import inf

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

costs = [inf]*n
costs[0] = 0

for i in range(n):
	for j in (i+1, i+2):
		if j < n:
			costs[j] = min(costs[j], costs[i]+abs(h[i]-h[j]))
print(costs[-1])
# Judge status: Wrong Answer
import collections
N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
print(c)

for i in range(N):
    print(c[i+1])
# Judge status: Accepted
import itertools

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

d = []
A = []

for i in range(K):
  d.append(int(input()))
  A.append(list(map(int,input().split())))
  
A = list(itertools.chain.from_iterable(A))
A = list(set(A))
kotae = N - len(A)
print(kotae)
# Judge status: Accepted
x = int(input())
ans = 1
cnt = 1
for i in range(1,x):
    cnt = i
    for j in range(9):
        cnt *= i
        if cnt > x:
            break
        if cnt > ans:
            ans = cnt
print(ans)
# Judge status: Accepted
n = int(input())
if n == 1:
    print(1)
elif n <= 3:
    print(2)
elif n <= 7:
    print(4)
elif n <= 15:
    print(8)
elif n <= 31:
    print(16)
elif n <= 63:
    print(32)
else:
    print(64)