Harryxun/stf_run huggingface dataset:
#揃える長さを決め打って二分探索
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst1.sort(reverse=True)
def func(mid): #ここが関数部分
    res = 0
    for i in range(n):
        if mid >= lst1[i]:
            continue
        res += math.ceil(lst1[i]/mid)-1
        if res > k:
            return False
    return True


def binary_search(): #2分探索
    ok = 10**9
    ng = -1
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    return ok

if k == 0:
    print(max(lst1))
else:
    print(binary_search())

### FIXED CODE ###

#揃える長さを決め打って二分探索
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst1.sort(reverse=True)
def func(mid): #ここが関数部分
    res = 0
    for i in range(n):
        if mid >= lst1[i]:
            continue
        res += math.ceil(lst1[i]/mid)-1
        if res > k:
            return False
    return True


def binary_search(): #2分探索
    ok = 10**9
    ng = 0
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if func(mid):
            ok = mid
        else:
            ng = mid

    return ok

print(binary_search())
mod = 10 ** 9 + 7

n, k = map(int, input().split())
edge = [[] for _ in range(n)]
parent = [0] * n
for _ in range(n):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
permutation_k2 = [1] * n
for i in range(n-1):
  permutation_k2[i+1] = permutation_k2[i] * (k - 2 - i) % mod
count = k * (k - 1) * permutation_k2[len(edge[0]) - 1] % mod
queue = edge[0]
while queue:
  vertex = queue.pop()
  count = count * permutation_k2[len(edge[vertex]) - 1] % mod
  p = parent[vertex]
  for v in edge[vertex]:
    if v == p:
      continue
    queue.append(v)
    parent[v] = vertex
print(count)

### FIXED CODE ###

mod = 10 ** 9 + 7

n, k = map(int, input().split())
edge = [[] for _ in range(n)]
parent = [0] * n
permutation_k2 = [1] * n
for i in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
  permutation_k2[i+1] = permutation_k2[i] * (k - 2 - i) % mod
count = k * (k - 1) * permutation_k2[len(edge[0]) - 1] % mod
queue = edge[0]
while queue:
  vertex = queue.pop()
  count = count * permutation_k2[len(edge[vertex]) - 1] % mod
  p = parent[vertex]
  for v in edge[vertex]:
    if v == p:
      continue
    queue.append(v)
    parent[v] = vertex
if n == 1:
  print(k)
else:
  print(count)
m = 10**9 + 7
n = input()
a = list(map(int,input().split()))
ans = 0
s = sum(a)

for i in range a:
s -=i
ans += s*i
s+=i

ans = ans%m

print(ans)

### FIXED CODE ###

m = 10**9 + 7
n = input()
a = list(map(int,input().split()))
ans = 0
s = sum(a)

for i in a:
  s -= i
  ans += s*i

ans = ans%m

print(ans)
n = int(input())
lst = list(map(int, input().split()))
output = 1
if 0 in lst:
    print(0)
    quit()
for x in lst:
    output = output * x
    if res > 10**18:
        print(-1)
        quit()
print(output)


### FIXED CODE ###

n = int(input())
ls = list(map(int, input().split()))
res = 1
if 0 in ls:
    print(0)
    quit()
for x in ls:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)
n,m,c=map(int,input().split())
count=0
for i in range(m):
    b=list(map(int,input().split()))
    for j in range(n):
        a=list(map(int,input().split()))
        combined=[x*y for (x,y) in zip(a,b)]
        if sum(combined)>c:
            count+=1
print(count)
    


### FIXED CODE ###

n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
    p=c
    a=list(map(int,input().split()))
    for j in range(m):
        p+=a[j]*b[j]
    if p>0:
        count+=1
print(count)
n=int(input())
x=[map(int,input().split())]
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:print(xr if i<=xl else xl)

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)
from bisect import bisect_left
from collections import deque
n = int(input())
A=[int(input()) for _ in range(n)]
q=deque()
for a in A:
    i=bisect_left(l,a)
    if not i:
        q.appendleft(a)
    else:
        q[i-1]=a
print(len(q))

### FIXED CODE ###

from bisect import bisect_left
from collections import deque
n = int(input())
A=[int(input()) for _ in range(n)]
q=deque()
for a in A:
    i=bisect_left(q,a)
    if not i:
        q.appendleft(a)
    else:
        q[i-1]=a
print(len(q))
n,k,s = map(int,input().split())
x = [0]*n
for i in range(k):
    x[i] = s
if s == 1000000000:
    for i in range(k,n+1):
        x[i] = s-1
else:
    for i in range(k,n+1):
        x[i] = s+1
for i in x:
    print(i,end = " ")

### FIXED CODE ###

n,k,s = map(int,input().split())
x = [0]*n
for i in range(k):
    x[i] = s
if s == 1000000000:
    for i in range(k,n):
        x[i] = s-1
else:
    for i in range(k,n):
        x[i] = s+1
for i in x:
    print(i,end = " ")
A = int(input())
B = int(input())
if len(A) > len(B):
    print('GREATER')
elif len(A) < len(B):
    print('LESS')
elif A == B:
    print('EQUAL')
else:
    a = [int(i) for i in str(A)]
    b = [int(j) for j in str(B)]
    for i in range(len(A)):
        if A[i] > B[i]:
            print('GREATER')
            break
        elif A[i] < B[i]:
            print('LESS')
            break

### FIXED CODE ###

A = int(input())
B = int(input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

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

N, i = map(int, readline())
print(N - i + 1)


### FIXED CODE ###

"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

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

N, i = map(int, readline().split())
print(N - i + 1)
from time import time
from random import randrange
start = time()
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
t = []
v = 0
last = [-1]*26
for i in range(d):
    bst = -10**10
    for j in range(26):
        tmp = s[i][j]
        for k in range(26):
            if j!=k:
                tmp -= c[k]*(i-last[k])
        if tmp>bst:
            bst = tmp
            bst_idx = j
    last[bst_idx] = i
    t.append(bst_idx+1)
    v += s[i][bst_idx]
    for j in range(26):
        v -= c[j]*(i-last[j])
mx = v
while time()-start<1.9:
    newt = t[:]
    nd = randrange(d)
    now = newt[nd]
    nq = randrange(25)
    newt[nd] = nq if nq<now else nq+1
    v = 0
    last = [-1]*26
    for i in range(d):
        v += s[i][newt[i]]
        last[newt[i]] = i
        for j in range(26):
            v -= c[j]*(i-last[j])
    if v>mx:
        mx = v
        t = newt
for i in t:
    print(i)

### FIXED CODE ###

d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
for i in range(d):
    print(i%26+1)
def rec(i,j):
    if i + j == N:
        return
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        dp[i+1][j] = tmp
    tmp_ = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp_ > dp[i][j+1]:
        dp[i][j+1] = tmp if tmp > dp[i][j+1] else dp[i][j+1]
    if tmp > dp[i+1][j]:
        rec(i + 1, j)
    if tmp_ > dp[i][j+1]:
        rec(i, j + 1)
    
N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]

dp = [[0 for _ in range(N)] for _ in range(N)]
rec(0, 0)
ans = -1
for i in range(4):
    for j in range(4):
        if dp[i][j] > ans:
            ans = dp[i][j]
print(ans)

### FIXED CODE ###

from collections import deque

N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]
d = deque([(0,0)])
dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
while(len(d)>0):
    i, j = d.pop()
    if i + j > N - 1:
        continue
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        if dp[i+1][j] == 0:
            d.appendleft((i+1,j))
        dp[i+1][j] = tmp
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp > dp[i][j+1]:
        if dp[i][j+1] == 0:
            d.appendleft((i,j+1))
        dp[i][j+1] = tmp
        
ans = -1
for i in range(N):
    for j in range(N):
        if dp[i][j] > ans:
            ans = dp[i][j]
print(ans)
n,k=map(int,input().split())
p=[int(i) for i in input().split()]


Msum=0
for i in range(n-k+1):
    tmp=sum(p[i:i+k])
    Msum = max(tmp,Msum)

print((Msum+k)/2)

### FIXED CODE ###

s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if u == s:
    a -= 1
else:
    b -= 1
print(a,b)
import math
a,b,x=map(int,input().split())
if a**2*b>=2*x:
  ans=math.degrees(math.atan(2*x/(a*b**2)))
  print(ans)
else:
  ans=math.degrees(math.atan(a**2/(2*a*b-2*x/a)))
  print(ans)
  



### FIXED CODE ###

import math
a,b,x=map(int,input().split())
A,B=a**2,b**2
print(math.degrees(math.asin((B/((2*x/(a*b))**2+B))**0.5) if 2*x<=a*a*b else math.acos((A/((2*(a*a*b-x)/A)**2+A))**0.5)))
from collections import deque

H, W = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

ch += 1
cw += 1
gh += 1
gw += 1

maze = ["#"*(W+4), "#"*(W+4)] + ["##" + input() + "##" for _ in range(H)] + ["#"*(W+4), "#"*(W+4)]
visited = [[-1]*(W+4) for _ in range(H+4)]
visited[ch][cw] = 0

walk = [[-1, 0], [1, 0], [0, -1], [0, 1]]
warp = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1], [-1, 0], [-1, 1], [-1, 2],
        [0, -2], [0, -1], [0, 1], [0, 2], [1, -2], [1, -1], [1, 0], [1, 1], [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]

stack_walk = [[ch, cw]]
stack_warp = [[ch, cw]]

while stack_walk or stack_warp:
    while stack_walk:
        h, w = stack_walk.pop()
        for dh, dw in walk:
            h_next = h + dh
            w_next = w + dw
            if maze[h_next][w_next]=="." and (visited[h_next][w_next]==-1 or visited[h_next][w_next] > visited[h][w]):
                visited[h_next][w_next] = visited[h][w]
                stack_walk.append([h_next, w_next])
                stack_warp.append([h_next, w_next])
    
    while stack_warp:
        h, w = stack_warp.pop()
        for dh, dw in warp:
            h_next = h + dh
            w_next = w + dw
            if maze[h_next][w_next]=="." and visited[h_next][w_next]==-1:
                visited[h_next][w_next] = visited[h][w] + 1
                stack_walk.append([h_next, w_next])
                stack_warp.append([h_next, w_next])

print(visited[gh][gw])


### FIXED CODE ###

N, X, T = map(int, input().split())

if (N%X==0):
    print(T * (N // X))
else:
    print(T * (N // X + 1))
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
a.sort()
b.sort()
j=0
for i in range(n):
	if a[i]==b[j]:
		j+=1
if j==m:
	print("YES")
else:
	print("NO")


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
a.sort()
b.sort()
j=0
for i in range(n):
	if a[i]==b[j]:
		j+=1
	if j==m:
		break
if j==m:
	print("YES")
else:
	print("NO")
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    s_arr = list(zip(*s_arr))
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>1:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>1:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


### FIXED CODE ###

from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>0:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>0:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)
from string import ascii_uppercase


def actual(n, s):
    answer = ''

    for char in s:
        # mod 26 で 26パターンに分類できる。 `-13` はidx調整項
        idx_shift_n = (ord(char) % 26) + n - 13

        answer += ascii_uppercase[idx_shift_n]

    return answer

n = int(input())
s = input()

print(actual(n, s))

### FIXED CODE ###

def actual(n, s):
    # 方針: 0->25 の世界で nだけシフトさせる → 65-90の世界に復元
    answer = ''

    ord_A = ord('A')

    for char in s:
        x = ord(char) - ord_A  # Aが0になるように初期化する
        y = (x + n) % 26  # mod 26 で 26パターンに分類できる
        z = y + ord_A  # 復元できるように補正する

        answer += chr(z)

    return answer


n = int(input())
s = input()
 
print(actual(n, s))
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

from scipy.special import comb

def main():
    N, M, K = LI()

    rows = M*M*sum([d * (N-d) for d in range(1, N)])
    cols = N*N*sum([d * (M-d) for d in range(1, M)])
    ans = (rows + cols) * comb(M*N-2, K-2, exact=True) % MOD

    print(ans)

main()

### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def main():
    N, M, K = LI()

    rows = M*M*sum([d * (N-d) for d in range(1, N)])
    cols = N*N*sum([d * (M-d) for d in range(1, M)])
    ans = (rows + cols) * cmb(M*N-2, K-2, MOD) % MOD

    print(ans)

main()
N = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    
    while l[j] == i and j < len(l):
        cnt += 1
        j += 1
    j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - 1
    elif cnt < i:
        ans += cnt
print(ans)

### FIXED CODE ###

N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)
from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include <bits/stdc++.h>
using namespace std;

constexpr const int maxs = 4096;
int dp[maxs];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	memset(dp, 0x3f, 16384);
	dp[0] = 0;
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b, s = 0;
		cin >> a >> b;
		while (b--) {
			int c;
			cin >> c;
			s ^= 1 << c - 1;
		}
		dp[s] = min(dp[s], a);
	}
	for (int i = 0; i != n; ++i) for (int all = (1 << n) - 1 ^ 1 << i, sub = all; sub; sub = sub - 1 & all)
		dp[sub] = min(dp[sub], dp[sub ^ 1 << i]);
	for (int s = 0; s != (1 << n); ++s) if (s != (s & -s))
		for (int t = s - 1 & s; t != s; t = t - 1 & s)
			dp[s] = min(dp[s], dp[t] + dp[s ^ t]);
	int mask = (1 << n) - 1;
	if (dp[mask] == 0x3f3f3f3f) dp[mask] = -1;
	cout << dp[mask] << endl;
}""")
call(('g++','e.cpp'))
call('./a.out')


### FIXED CODE ###

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
#show_flg=True

n,m=MI()
t=1<<n
key=[]
for i in range(m):
    a,b=MI()
    c=0
    for j in LI_():
        c+=1<<j
    key.append((a,c))
inf=float('inf')
dp=[[inf]*(m+1) for _ in range(t)]
#dp[stat][m] # min value using up to m and open stat
dp[0][0]=0

for j in range(1,m+1):
    for i in range(t):
        cost,ck=key[j-1]
        show(i,j,'|',dp[ck|i][j],min(dp[ck|i][j-1],dp[i][j-1]+cost))
        dp[ck|i][j]=min(dp[ck|i][j],dp[ck|i][j-1],dp[i][j-1]+cost)
        dp[i][j]=min(dp[i][j],dp[i][j-1])
        
for i in dp:
    show(*i)

ans=dp[t-1][m] if dp[t-1][m]!=inf else -1
print(ans)
import numpy as np
N=int(input())
A=[int(i) for i in input().split()]
A=[A[i]-i for i in range(N)]
#print(A)
b=np.median(A)
K=[abs(A[i]-b) for i in range(N)]
print(int(sum(K)))

### FIXED CODE ###

n=int(input())
al=list(map(int,input().split()))
t=[]
for i in range(n):
    t.append(al[i]-(i+1))
t=sorted(t)
if n%2==0:
    v=(t[n//2-1]+t[n//2])//2
else:
    v=t[n//2]
ans=0
for i in t:
    ans+=abs(i-v)
print(ans)
x = int(input())
x = list(x)

for idx in range(len(x)):
  if x[idx] == 0:
    print(idx + 1)
    break

### FIXED CODE ###

x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
  print(1)
elif x2 == 0:
  print(2)
elif x3 == 0:
  print(3)
elif x4 == 0:
  print(4)
else:
  print(5)
import numpy as np
N = int(input())
H = np.array(list(map(int,input().split())))

ans = 0
while np.max(H) != 0:
    min_h_p = 0
    for i in range(N):
        if H[i] == 0 and min_h_p > 0:
            ans += min_h_p
            H[st:i] -= min_h_p
            break
        elif i == N-1:
            if min_h_p == 0:
                min_h_p = H[i]
            if st == 0:
                H[i] -= min_h_p
                ans += min_h_p
            else:
                ans += min_h_p
                H[st:] -= min_h_p
            break
        else:
            if min_h_p == 0:
                min_h_p = H[i]
                st = i
            else:
                min_h_p = min(H[i],min_h_p)

print(ans)


### FIXED CODE ###

import numpy as np
N = int(input())
H = np.array(list(map(int,input().split())))

ans = 0
while np.max(H) != 0:

    min_h_p = 0
    st = -1
    for i in range(N):
        if st == -1:
            if H[i] > 0:
                st = i
            if i == N-1:
                ans += H[i]
                H[i] = 0
                break
        elif H[i] == 0:
            min_h_p = min(H[st:i])
            ans += min_h_p
            H[st:i] -= min_h_p
            break
        elif i == N-1:
            min_h_p = min(H[st:])
            ans += min_h_p
            H[st:] -= min_h_p
            break
print(ans)
import numpy as np
class AdjWeightedDiGraph:
    def __init__(self,g):
        lines = g.split("\n")
        self.size = int(lines[0])*3+3
        self.adjMatrix = np.full((self.size,self.size),float('inf'))
        for i in range(self.size):
            self.adjMatrix[i][i] = 0 # 対角成分は$0$とする。
        for s in lines[1:]:
            d1,d2 = s.split(" ")
            self.connect(3*int(d1),3*int(d2)+1)
            self.connect(3*int(d1)+1,3*int(d2)+2)
            self.connect(3*int(d1)+2,3*int(d2))
    def connect(self,x, y):
        self.adjMatrix[x][y] = 1
    def floyd(self):
        d = self.adjMatrix        # 距離行列dの初期値は隣接行列
        for k in range(self.size):   # 頂点kを経由したら短くいけるか調べる
            newd = np.copy(d)
            for i in range(self.size):
                for j in range(self.size):
                    if d[i][j] > d[i][k]+d[k][j]: # 頂点iから頂点jに行くとき頂点kを経由したら短くいけるなら、
                        newd[i][j] = d[i][k]+d[k][j] # それを新しい値とする。
            d = newd # 新しい距離行列を次の距離行列とする。
        return d

n,m=map(int,input().split())
g=[str(n),"\n"]
for i in range(m):
     g.append(input())
     g.append("\n")
graph = AdjWeightedDiGraph("".join(g[:-1]))

s,t=map(int,input().split())


dm = graph.floyd()[3*s][3*t]
if dm==float('inf'):
     print(-1)
else:
     print(int(dm)//3)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
def main():
     n,m=map(int,input().split())
     field=[[] for i in range(3*n)]
     for i in range(m):
          x,y=map(int,input().split())
          x,y=x-1,y-1
          field[3*x].append(3*y+1)
          field[3*x+1].append(3*y+2)
          field[3*x+2].append(3*y)
     
     s,t=map(int,input().split())
     s,t=s-1,t-1
     s,t=3*s,3*t
     
     d=[float('inf') for i in range(3*n)]
     d[s]=0
     
     que=[s]
     cnt=0
     while que!=[]:
          que2=[]
          cnt+=1
          for i in que:
               for j in field[i]:
                    if d[j]>cnt:
                         d[j]=cnt
                         que2.append(j)
          que=que2
     if d[t]==float('inf'):
          print(-1)
     else:
          print(d[t]//3)
     return 
 
if __name__ == '__main__':
    main()
a=int(input())
b=int(input())

if a==b : 
  print(a*2)
else :
  print(max(a,b)*2-1)

### FIXED CODE ###

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

if a==b : 
  print(a*2)
else :
  print(max(a,b)*2-1)
N = int(input())
HList = [int(i) for i in input().split(" ")]
stn = HList[0]

count = 0
for i in range(len(HList)) :
    if i == 0 :
        count += 1
    elif HList[i] >= stn and HList[i] >= HList[i-1] :
        count += 1
        if stn > HList[i] :
            stn = HList[i]

print(count + "\n")

### FIXED CODE ###

N = int(input())
HList = [int(i) for i in input().split(" ")]
stn = -1
count = 0

for i in range(len(HList)) :
    if HList[i] >= stn  :
        count += 1
    if stn < HList[i] :
        stn = HList[i]

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

count = 0
for i in range(n+1):
  b = a[i].rfind(1) - 1
  count += b

print(count)

### FIXED CODE ###

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

count = 0
for i in a:
  count += len(bin(i)) - bin(i).rfind("1") - 1

print(count)