peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

if a[0] == 1:
    if n == 0:
        print(1)
    else:
        print(-1)
else:
    lefts = [sum(a)]
    for i in range(1, len(a)):
        lefts.append(lefts[-1] - a[i])

    b = [0] * (n + 1)
    b[0] = 1

    for i in range(1, n + 1):
        b[i] = min(b[i-1] * 2 - a[i], lefts[i])

    if min(b) < 0:
        print(-1)
    else:
        print(sum(b) + sum(a))
# Judge status: Wrong Answer
S = input()
n = len(S) + 1
num = [0] * n
for i in range(n-1):
    if S[i] == '<':
        num[i + 1] = max(num[i] + 1, num[i + 1])
for i in range(n - 2, 0, -1):
    if S[i] == '>':
        num[i] = max(num[i + 1] + 1, num[i])
print(sum(num))
# Judge status: Accepted
# ans

N, K = map(int, input().split())
H = [int(input()) for i in range(N)]
H.sort()

print(min(H[i+K-1] - H[i] for i in range(N-K+1)))
# Judge status: Wrong Answer
a , b = map(int,input().split())
s = max(a,b)
t = min(a,b)
k = 0
for i in range(1,s+1):
  k += t*(10**i)
  
  
print(k)
# Judge status: Accepted
s=input()
if s.count(s[0])==2:
  if s[1]==s[2] or s[1]==s[3] or s[2]==s[3]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
# Judge status: Accepted
a=input()
b=input()
h=input()
print((int(a)+int(b))*int(h)//2)
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a <= k:
	print("Yay!")
else:
	print(":(")
# Judge status: Accepted
#https://atcoder.jp/contests/abc162/tasks/abc162_c
# -*- coding: utf-8 -*-
import math
ans = 0
K = int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    tmp = math.gcd(i,j)
    for k in range(1,K+1):
      ans += math.gcd(tmp,k)
print(ans)
# Judge status: Accepted
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
mod=10**9+7

n=int(input())
a=list(map(int,input().split()))
l=a[0]
for i in range(1,n):
  l=lcm(l,a[i])
l%=mod

ans=0
for i in range(n):
  ans+=l*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)
# Judge status: Accepted
# solution
import io
import math

data = int(input())
inin = input()

a1 = 0
a2 = 0

for i in range(data):
    if inin[i] == '(':
        a1 += 1
    else:
        if a1 > 0:
            a1 -= 1
        else:
            a2 += 1
print('('*a2+inin+')'*a1)
# Judge status: Accepted
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N, T = M()
ans = 100000
for _ in range(N):
    c, t = M()
    if t <= T:
        ans = min(ans, c)
if ans == 100000:
    print('TLE')
else:
    print(ans)
# Judge status: Accepted
N=int(input())
inf=100000
dp=[inf for _ in range(N+1)]
dp[0]=0
for n in range(1,N+1):
    num=100000
    i=0
    j=0
    while 9**(i+1)<=n:
        i+=1
    while 6**(j+1)<=n:
        j+=1
    for k in range(i+1):
        num=min(num,dp[n-9**k]+1)
    for k in range(j+1):
        num=min(num,dp[n-6**k]+1)
    dp[n]=min(dp[n],num)
print(dp[N])
# Judge status: Accepted
S = input()
s = S.index('A')
e = [i for i, x in enumerate(S) if x == 'Z']

print(max(e) - s + 1)
# Judge status: Accepted
S = input()
for c in "abcdefghijklmnopqrstuvwxyz":
    if c not in S:
        print(c)
        break
else:
    print("None")
# Judge status: Wrong Answer
x=int(input())
print(int(360/x))
# Judge status: Accepted
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B, C = map(int, readline().split())

    if (A < C < B) or (B < C < A):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a,b,c,d = map(int,input().split())

import math
k = math.ceil(c/b)
l = math.ceil(a/d)

if k >= l:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N = int(input())

la = list()
for i in range(N):
    la.append(int(input()))

lnum = [0]*N

i = 1
cnt = 0
while lnum[i-1] == 0 and i != 2:
    lnum[i-1] += 1
    i = la[i-1]
    cnt += 1

if i == 2:
    print(cnt)

else:
    print("-1")
# Judge status: Accepted
a, b, c = map(int, input().split())
k = int(input())
while b <= a:
    k -= 1
    b *= 2
while c <= b:
    k -= 1
    c *= 2
print("Yes" if k>=0 else "No")
# Judge status: Wrong Answer
s=input()
l=['Sunny', 'Cloudy', 'Rainy']
print(l.index(s)-1)
# Judge status: Wrong Answer
N,R=map(int,input().split())
if N<10:
  print(R-100*(10-N))
else:
  print(R)
# Judge status: Accepted
if input() == "1":
	print(0)
else:
	print(1)
# Judge status: Wrong Answer
x,y = map(int,input().split())
print(x + y/2)
# Judge status: Wrong Answer
n,m = map(int,input().split())
MIN = 0
MAX = 10**5
for i in range(m):
    l,r = map(int,input().split())
    MIN = MIN if MIN > l else l
    MAX = MAX if MAX < r else r
if MIN > n:
    print(0)
else:
    MAX = MAX if MAX <= n else n
    print(MAX-MIN+1)
# Judge status: Wrong Answer
n = int(input()) % 1000
print(1000 - n if n else 0)
# Judge status: Accepted
w = input()
ws = set(w)
for i in ws:
    if w.count(i)%2 == 1:
        print('No')
        exit()
print('Yes')
# Judge status: Wrong Answer
a, b = map(int,input().split())

c = a+b
ans = (c+1)/2

print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
a.sort()
y=a[-1]
diff=10**9+2
for i in a[:-1]:
    diff=min(diff,max(i,y-i))
x=-1
for i in a[:-1]:
    if max(i,y-i)==diff:
        x=i
        break
print(y,x)
# Judge status: Wrong Answer
s = input()
t = input()
t2 =t.strip(t[-1])
if(t2 == s):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = [0] * ((10 ** 6) + 1)

for elem in a:
    cnt[elem] += 1

unique = []

for i in range((10 ** 6) + 1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0] * ((10 ** 6) + 1)

for elem in unique:
    for m in range(elem * 2, (10 ** 6) + 1, elem):
        cnt[m] = 1

ans = 0
        
for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)
# Judge status: Accepted
X = int(input())
x = int(X / 500)
Y = X % 500
y = int(Y / 5)
print(1000 * x + 5 * y)
# Judge status: Accepted
S = input()
K = int(input())
ans = 1

for i in range(K):
    if (S[i] != '1'):
        ans = int(S[i])
        break

print(ans)
# Judge status: Accepted
X=int(input())
while any(X%i==0 for i in range(2,X)):X+=1
print(X)
# Judge status: Accepted
x,y=map(int,input().split())
cnt=1
while True:
  x*=2
  if x>y:
    break
  else:
    cnt+=1
print(cnt)
# Judge status: Accepted
k,x=map(int,input().split())
ans=[i for i in range(x-(k-1), x+(k-1)+1)]
print(*ans,sep=' ')
# Judge status: Wrong Answer
x=int(input())
y=int(input())
z=int(input())
result=int(input())
count=0
for i in range(x):
        for j in range(y):
            for k in range(z):
                    if i*500+j*100+k*50==result:
                        count+=1
                 
              
print(count)
# Judge status: Accepted
def main():
    n = int(input())
    s, t = input(), input()

    for i in range(n, -1, -1):
        u = s[-i:]
        v = t[:i]
        if u == v:
            ans = 2 * n - i
            print(ans)
            break
    else:
        print(2 * n)


if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b,c,k=map(int,input().split())
ct=k
result = 0
if a>0:
  if ct>a:
    result=1*a
  elif a>=ct:
    result=1*ct
  ct=k-a
if ct>0 and b>0:
  ct=ct-b
if ct>0 and c>0:
  result=result+(-1*ct)
print(result)
# Judge status: Wrong Answer
n,k=map(int,input().split())
hp=list(map(int,input().split()))
sorted(hp)
re=sum(hp[:n-k])
print(re)
# Judge status: Accepted
n = int(input())
d = list(map(int, input().split()))

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

if d[0] != 0 or l[0] != 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)
# Judge status: Accepted
x = int(input())
dp = [0]*(x+105)
dp[0] = 1
for i in range(x):
    for j in range(6):
        dp[i+100+j] = dp[i+100+j] | dp[i]
print(dp[x])
# Judge status: Wrong Answer
n, y = map(int, input().split())
count = 0
for i in range(n+1):
    for j in range(n+1):
        k = n - i - j
        if 0<=k<=2000 and 10000*i + 5000*j + 1000*k == y :
            print(i, j, k)
            count += 1
        break
if count == 0:
    print(-1,-1,-1)
# Judge status: Accepted
a = list(map(int,input().split()))
print(sum(sorted(a)[0:2]))
# Judge status: Accepted
S = input()

result = 0
# 入力例1なら3文字目まで
for i in range(len(S) // 2):
  # sの1(2番目)がsの最後尾と一緒ならカウント
  if S[i] != S[-(i + 1)]:
    result += 1
print(result)
# Judge status: Accepted
N,M = map(int,input().split())
C = {i:[0,1] for i in range(1,N+1)}
C[1] = [1,1]
for _ in range(M):
    x,y = map(int,input().split())
    if C[x][0]==1:
        C[y][0]=1
    C[y][1] += 1
    C[x][1] -= 1
    if C[x][1]==0:
        C[x][0]=0
cnt = 0
for i in range(1,N+1):
    if C[i][0]==1:
        cnt += 1
print(cnt)
# Judge status: Accepted
n=int(input())
s=input()
ans=10**9
w=[0]*n
b=[0]*n
cw,cb=0,0
for i in range(n):
  if s[i]==".":
    cw+=1
  else:
    cb+=1
  w[i]=cw
  b[i]=cb

for i in range(n):
  ans=min(ans,b[i]+w[-1]-w[i])
ans=min(ans,b[-1],w[-1])
print(ans)
# Judge status: Wrong Answer
K = int(input())
A, B = [int(i) for i in input().split()]

if B - A >= K:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())
point = []
for _ in range(n):
    point.append((tuple(map(int, input().split()))))
point = list(set(point))
point = sorted(point)
if len(point) == 1: print(0)
else:  
    d1 = max([(x+y) for x,y in point])- min([(x+y) for x,y in point])
    d2 = max([(x-y) for x,y in point]) - min([(x-y) for x,y in point])
    print(max(d1,d2))
# Judge status: Accepted
h1,m1,h2,m2,k = map(int,input().split())
H_min = (h2-h1)*60
M_min = m2-m1
time = H_min + M_min
ans = time - k
print(ans)
# Judge status: Wrong Answer
a,x,c = input().split()
X = x[0]
list = ['A',X,'C']
ans = ','.join(list)
print(ans)
# Judge status: Accepted
import sys
n, k = map(int, sys.stdin.readline().strip('\n').split())
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(1, n):
  for j in range(k+1):
    if i-j>=0: dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]))
print(dp[n-1])
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before_a = -2
ans = 0
for a in A:
    ans += B[a - 1]
    if before_a + 1 == a:
        ans += C[a - 2]
    before_a = a
print(ans)
# Judge status: Wrong Answer
a,b,c,d=list(map(int,input().split()))
import math
def yakusuu(n):
  return n//c+n//d-n//(c*d/math.gcd(c,d))

print(int(b-a+1-(yakusuu(b)-yakusuu(a-1))))
# Judge status: Accepted
alpha = input()
if alpha.isupper():
  print('A')
else:
  print('a')
# Judge status: Accepted
N=int(input())
a=map(int,input().split())
c=0
d=0
e=0
f=0
for i in a:
  if i%4==0:
    c=c+1
  elif i%2==0:
    d=d+1
  e=N-c-d
if d==0:
  if (c+1)>=e:
    print('Yes')
  else:
    print('No')
    
else:
  if c>=e:
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
s = input()
num = len(s)
A = s.find("A")
Z = s.rfind("Z")
ans = Z - A + 1
print(ans)
# Judge status: Accepted
S = input()
min = 1000
for i in range(len(S) - 2):
	x = int(S[i:i+3])
	x = abs(753 - x)
	if min > x:
		min = x
print(min)
# Judge status: Accepted
N = int(input())
job = [[0]*2 for i in range(N)]
time = 0
for i in range(N):
    l = list(map(int, input().split()))
    job[i][0], job[i][1] = l[1], l[0]
job = sorted(job)
for i in range(N):
    time += job[i][1]
    if time > job[i][0]:
        print("No")
        break
    elif i == N-1:
        print("Yes")
# Judge status: Accepted
a, b = map(int, input().split())

ans = 0
for i in range(2):
  if a < b:
    ans += b
    b -= 1
  else:
    ans += a
    a -= 1

print(ans)
# Judge status: Wrong Answer
from collections import Counter
n=int(input())
List=[list(input()) for i in range(n)]
ans=0
for i in range(n-1):
    List1=Counter(List[i])
    for j in range(1,n):
        List2=Counter(List[j])
        if List1==List2:
            ans+=1
print(int(ans/2))
# Judge status: Accepted
MOD = 10**9+7

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

A_sum = sum(A)

r = 0
for i, a in enumerate(A):
    x = A[i]*(A_sum - a)
    r = (r+x) % MOD

# print(r)

r = (r * pow(2, MOD-2, MOD)) % MOD

print(r)
# Judge status: Accepted
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

score = 0

last_lst = [""]*K

for i in range(N):
    if T[i] == last_lst[i%K]:
        last_lst[i%K] = ""
        continue
    else:
        if T[i] == "r":
            score += P
        elif T[i] == "p":
            score += S
        else:
            score += R
        last_lst[i%K] = T[i]
print(score)
# Judge status: Accepted
import sys
from collections import Counter
def main():
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))

    col = max(0, len(set(a)) - k)
    if col == 0:
        print(0)
        sys.exit()

    ac = Counter(a)
    acl = ac.most_common()[::-1]
    acll = [ace[1] for ace in acl[:col]]

    r = sum(acll)
    print(r)

if __name__ == '__main__':
    main()
# Judge status: Accepted
o=input()
e=input()+' '
print((''.join(['{}{}'.format(a,b) for a,b in zip(o,e)])).replace(' ',''))
# Judge status: Accepted
N,D = map(int,input().split())
ans = 0
for i in range(N):
    x,y = map(int,input().split())
    if x*x+y*y <= D*D:
        ans += 1
print(ans)
# Judge status: Wrong Answer
#!/usr/bin/env python3

A, B, K = map(int, input().split())

if A >= K:
    print(A - K, B)
else:
    print(0, A + B - K)
# Judge status: Accepted
A,B,T = map(int,input().split())

print("{}".format((T//A)*B))
# Judge status: Wrong Answer
input_line = input().split(" ")
X=input_line[0]
Y=input_line[1]
Z=input_line[2]

ram=X
X=Y
Y=ram

ram=X
X=Z
Z=ram


input_line=' '.join(input_line)
print(input_line)
# Judge status: Wrong Answer
s=input()
if s.islower():
  print("A")
else:
  print("a")
# Judge status: Wrong Answer
N,A,B=map(int, input().split())
ans=(N-N%(A+B))*A/(A+B)+min(A,N%(A+B))
print(ans)
# Judge status: Wrong Answer
N,L=map(int,input().split())
ans=0
if L>0:
    for i in range(L+1,L+N):
        ans+= i
elif L<0 and N+L>=0:
    for i in range(L,L+N):
        ans+=i
elif L<0 and N+L<=0:
    for i in range(L,L+N-1):
        ans +=i
print(ans)
# Judge status: Accepted
N, M = map(int, input().split())
d = (N-1)//2
ans = []
ans.append((1, 1+d))

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

d2 = d-1
ans.append((2+d, 2+d+d2))

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

for a, b in ans[:M]:
    print(a, b)
# Judge status: Accepted
num = int(input())
weight = list(map(int, input().split()))

d = []
for i in range(len(weight)):
  d.append(abs(sum(weight[:i])-sum(weight[i:])))
  
print(min(d))
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    if W >= V:
        print('NO')
    elif abs((A - B) / (W - V)) <= T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import random
a = input()
print(random.randint(0,3))
# Judge status: Accepted
S = input()

a = S.count('a')
b = S.count('b')
c = S.count('c')
n = len(S)//3
k = len(S)-n*3
if a >= n and b >= n and c >= n:
  if k == 2 and max(a-n,b-n,c-n) == 2:
    print('NO')
  else:
    print('YES')
else:
  print('NO')
# Judge status: Accepted
c = [[] for _ in range(3)]
for i in range(3):
    c[i] = list(map(int,(input().split())))
a1 = c[1][0] - c[0][0]
a2 = c[2][0] - c[0][0]
b1 = c[0][1] - c[0][0]
b2 = c[0][2] - c[0][0]

if c[1][1]-c[0][0] == a1+b1 and c[2][1]-c[0][0] == a2+b1 and c[1][2]-c[0][0] == a1+b2 and c[2][2]-c[0][0] == a2+b2:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import fractions
from functools import reduce
n=int(input())
numbers=list(map(int,input().split()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=0
x=lcm_list(numbers)
for i in range(n):
    l+=(x//numbers[i])
print(l%(10**9+7))
# Judge status: Accepted
K = int(input())
if (K%2==0)or(K%5==0):
  print(-1)
  
else:
  x = 7
  i = 1
  x %= K
  while (x!=0)or(i>=10**7):
    x += (7%K) * pow(10,i,K)
    x %= K
    i += 1
  if i<10**7:  
    print(i)
  else:
    print(-1)
# Judge status: Accepted
*X, = map(int, input().split())
if len(set(X)) == 2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n,x = readInts()
xs = readInts()
xs.append(x)
xs.sort()

ans = xs[1]-xs[0]
for i in range(n):
  ans = math.gcd(ans,xs[i+1]-xs[i])

print(ans)
# Judge status: Wrong Answer
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)
for i in range(n-1):
    tmp=s[i]
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif tmp>s[i]:
            a=tmp+(tmp-s[i])%f[i]
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
nC2 = [0 for i in range(n + 1)]
for i in range(2, n + 1):
    nC2[i] = i * (i - 1) // 2
cnt = [0]*n
for i in a:
    cnt[i - 1] += 1
res = 0
for i in cnt:
    res += nC2[i]
for i in a:
    print(res - nC2[cnt[i - 1]] + nC2[cnt[i - 1] - 1])
# Judge status: Wrong Answer
n = int(input())
l = list(map(int, input().split()))
diff = 0
prev = l[0]
i = 1
while(i < n-1):
    diff += abs(prev-min(l[i],l[i+1]))
    prev = min(l[i],l[i+1])
    if(prev == l[i]):
        i += 1
    else:
        i += 2
print(diff)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
BA = []
for _ in range(N):
    ab = list(map(int, input().split()))
    a = ab[0]
    b = ab[1]
    BA.append((b,a))
BA.sort(reverse=True)

now = 0
ans = 0
for ba in BA:
    a, b = ba[1], ba[0]
    if a > M - now:
        continue
    ans += b
    now += 1
print(ans)
# Judge status: Wrong Answer
N=int(input())
s=input()
t=input()
i=0
count=0
while i<=N-1:
   if s[-i-1]==t[i]:
       count+=1
       i+=1
   else:
       break

ans=s[:N-count]+t
print(ans)
# Judge status: Accepted
s = input()

flag = [0, 0]

if ("N" in s and "S" in s) or ("N" not in s and "S" not in s):
    flag[0] = 1
if ("W" in s and "E" in s) or ("W" not in s and "E" not in s):
    flag[1] = 1

if sum(flag) == 2:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
A, B, C = map(int, input().split())

count = 1
while B > count:
  if A * count % B == C:
    print("YES")
    exit(0)
  count += 1
print("NO")
# Judge status: Accepted
from collections import Counter

input()
ans = []
for i, j in Counter(map(int, input().split())).items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    ans.sort()
    print(ans[-1] * ans[-2])
else:
    print(0)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
  while y:
    x, y = y, x % y
  return x

answer = A[0]
for i in range(1, N):
  answer = gcd(A[i], answer)
  
print(answer)
# Judge status: Accepted
H, W = map(int, input().split())
if H==1 or W==1:
    print(1)
else:
    print((H*W+1)//2)
# Judge status: Accepted
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
if x>y:
    p=2*y*c+(x-y)*min(a,2*c)
    ans=min(ans,p)
if x<=y:
    p=2*x*c+(y-x)*min(b,2*c)
    ans=min(ans,p)
print(ans)
# Judge status: Accepted
import bisect

n,m = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(m):
    b,c = map(int,input().split())
    s.append((c,b))

a.sort()
s.sort(reverse=True)

for i in range(m):
    b = s[i][1]
    c = s[i][0]
    idx = bisect.bisect_left(a,c)
    if idx == 0:
        break
    del a[0:min(b,idx)]
    for j in range(min(b,idx)):
        a.insert(bisect.bisect_left(a,c),c)

print(sum(a))
# Judge status: Wrong Answer
n, a, b = map(int, input().split())

mmod = 10**9 + 7


def comb_mod(n, r, mod=mmod):
    nume = 1
    deno = 1

    for i in range(r):
        nume = (nume * (n - i)) % mod
        deno = (deno * (i + 1)) % mod

    return (nume * pow(deno, mod - 2, mod)) % mod


if n == 2:
    print(0)
    exit

total = (pow(2, n, mmod) - comb_mod(n, a) - comb_mod(n, b) - 1) % mmod

print(total)
# Judge status: Accepted
n,m=map(int,input().split())
a=[]
for i in range(m):
    b,c=map(int,input().split())
    a.append(b)
    a.append(c)

for i in range(1,n+1):
    print(a.count(i))
# Judge status: Accepted
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)
# Judge status: Wrong Answer
S = list(input())
p_s = None
ans = 0

for s in S:
    if (s == '1' and p_s == '0') or (s == '0' and p_s == '1'):
        ans += 2
    else:
        p_s = s

print (ans)
# Judge status: Wrong Answer
n = int(input())
dic = {}
cnt =0
for i in  range(n):
    get = input()

    if get not in dic:
        dic[get] = 1

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

if N <= 2:
    print(N)
else:
    s = 0
    l = []
    for i in range(1, N):
        s += i
        l.append(i)
        if s > N:
            break
    # print(l)

    for i in range(len(l)):
        if s-l[i] == N:
            l.pop(i)
            break

    for i in l:
        print(i)
# Judge status: Accepted
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    zero, one = 0, 0
    for i in range(len(S)):
        if S[i] == "0": zero += 1
        else: one += 1
    print(2 * min(zero, one))

    return 0

if __name__ == "__main__":
    solve()
# Judge status: Wrong Answer
N,K = map(int,input().split())
L=list(map(int,input().split()))
A=[0]*N


for i in range(N):
    t=(L[i]+1)*L[i]/2*(1/L[i])
    A[i]=t
s=0
t=sum(A[:K])
for i in range(N-K):
    t+=(A[i+K]-A[i])
    s=max(s,t)

print(s)
# Judge status: Accepted
n=int(input())

while(1):
  a=str(n)
  if a.count(a[0])==3:
    break
  n+=1
print(n)
# Judge status: Wrong Answer
import math
a,b,x=map(int,input().split())
if a*b**2>=2*x:
    print(math.atan(a*b**2/(2*x))*180/math.pi)
else:
    print(math.atan((2*b/a)-(2*x/(a**3)))*180/math.pi)
# Judge status: Accepted
N,K = map(int,input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())
h = sorted(h)
ans = 10**10
for i in range(N-(K-1)):
    tmp = h[i+K-1] - h[i]
    ans = min(tmp,ans)
print(ans)
# Judge status: Accepted
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(i) for i in input().split()]
    q = [x]
    for i in range(200):
        q.append(x - 1 - i)
        q.append(x + 1 + i)
    for i in q:
        if i not in p:
            print(i)
            break
# Judge status: Accepted
a,b = map(int, input().split())
a,b = (a,b) if a<=b else (b,a)
if (a == 1) :
  if (b == 1):
    print(1)
  else:
    print(b -2)
else :
  print((a-2)*(b-2))
# Judge status: Accepted
from bisect import bisect_right
from itertools import accumulate

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

a_ac=[0]+list(accumulate(a))
b_ac=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    break
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)
# Judge status: Accepted
from math import sqrt
N = int(input()) # 2 <= N <= 10^12
# (1,1) (x,y) = x*y
a = N-1
for x in range(2, int(sqrt(N))+1):
  q, r = divmod(N, x)
  if r == 0:
    a = min(x-1 + q - 1, a)
print(a)