peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N,W = list(map(int,input().split()))
w = [0]*N
v = [0]*N

for i in range(N):
	w[i],v[i] = list(map(int,input().split()))

dp = [[0]*(W+1) for i in range(N)]
dp[0][w[0]] = v[0]

for i in range(1,N):
	for s in range(W+1):
		if s-w[i] >= 0:
			dp[i][s] = max(dp[i-1][s], dp[i-1][s-w[i]]+v[i])
		else:
			dp[i][s] = dp[i-1][s]
print(max(dp[N-1]))
# Judge status: Accepted
a,b=map(int,input().split())
s=input()
print("Yes"if s.count("-")==1 and s[a]=="-" else "No")
# Judge status: Wrong Answer
a, b, k = map(int, input().split())
if k <= a:
  print(a-k,b)
else:
  b=b-(k-a)
  print(0,b)
# Judge status: Accepted
print(['NO','YES'][int(''.join(list(input().split())))%4==0])
# Judge status: Accepted
s = input()
ans = "No"
kouho=["hi","hihi","hihihi","hihihihihi","hihihihi"]
if s in kouho:
    ans="Yes"
print(ans)
# Judge status: Accepted
N = int(input())
org = input().split()
for i in range(len(org)):
    org[i] = int(org[i])
A = sorted(org)

answer = A[0]
overl = False

for i in range(N-1):
    answer *= A[i+1]
    if answer > 10**18:
        overl = True
        break

if overl:
    print("-1")
else:
    print(answer)
# Judge status: Accepted
a, b, c = map(int, input().split())
if a + b == c or a + c ==b or b + c == a:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    t,a=INTM()
    hs=LIST()
    ct=0
    ans=100000000000
    for i,h in enumerate(hs):
        temp=t-h*0.006
        #print(temp)
        if abs(a-ans)>=abs(a-temp):
            ans=temp
            ct=i
    print(ct+1)
if __name__ == '__main__':
    do()
# Judge status: Accepted
#AGC 013 A - Sorted Arrays
#増加⇔減少に転じる際、Ai+1 - Aiは必ず符号反転することを利用
N = int(input())
A = list(map(int,input().split()))

count = 1
sign = 0
for i in range(N-1):
    if sign == 0:
        sign = A[i+1]-A[i]
    elif sign*(A[i+1]-A[i]) < 0:
        count += 1
        sign = 0
print(count)
# Judge status: Wrong Answer
K=int(input())
if K%2==0:
  print(K//2*K//2)
else:
  print((K//2+1)*K//2)
# Judge status: Wrong Answer
a, b, x = list(map(int, input().split()))

if a <= x:
    if x - a < b:
        print('Yes')
        exit()
print('No')
# Judge status: Wrong Answer
import math
n,d = map(int,input().split())
c = 0
for i in range(n):
    x,y = map(int,input().split())
    D = math.sqrt((x*x)+(y*y))
    if(int(D)<=d):
        c+=1
print(c)
# Judge status: Accepted
A= list(map(int, input().split()))
for i in range(5):
  if A[i] == 0:
    print(i+1)
# Judge status: Accepted
S = [int(n) for n in list(input())]
K = int(input())
c = 0
for i in range(len(S)):
	s = S[i]
	if s == 1:
		c += 1
	else:
		k = 0
		while c < K:
			c += k ** s
			k += 1
	if c >= K:
		print(s)
		break
# Judge status: Accepted
S=input()
dp=[0]*26
for i in S:
  dp[ord(i)-97]=1
for i in range(26):
  if dp[i]==0:
    print(chr(i+97))
    exit()
print('None')
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
cnt,i = 0,0
while i<n:
    while i+1<n and a[i]==a[i+1]: i+=1
    if i+1<n and a[i]<a[i+1]:
        while i+1<n and a[i]<=a[i+1]: i+=1
    elif i+1<n and a[i]>a[i+1]:
        while i+1<n and a[i]>=a[i+1]: i+=1
    cnt+=1
    i+=1
print(cnt)
# Judge status: Accepted
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=10**9
for i in range(n-k+1):
    l=x[i]
    r=x[i+k-1]
    a=abs(l)+abs(l-r)
    b=abs(r)+abs(l-r)
    c=min(a,b)
    ans=min(c,ans)
print(ans)
# Judge status: Accepted
#python3
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 1
    for i in range(n):
        if a[i] == k:
            k += 1
    k -= 1
    print(n - k) if k else print(-1)  

main()
# Judge status: Accepted
N,M=map(int,input().split())
if N%2==1:
    for i in range(1,M+1):
        a,b=i,N-i+1
        print(a,b)
else:
    t=0
    for i in range(1,M+1):
        a,b=i,N-i
        if (a-1)+(N+1-b)>=b-a:
            t=1
        a+=t
        print(a,b)
# Judge status: Wrong Answer
N,M=map(int,input().split())
a = [0]+list(map(int,input().split()))
a.sort(reverse=True)
for i in range(N):
    while M > 0 and 2*a[i]>=a[i+1]:
        a[i] //= 2
        M -= 1
    if M == 0:
        break
print(sum(a))
# Judge status: Accepted
n=int(input())
S=input()
print("".join(chr(65+(ord(s)-65+n)%26)for s in S))
# Judge status: Wrong Answer
from collections import Counter
S = str(input())
S_ = Counter(S)
v,c =zip(*S_.most_common())
ans = 0
if len(c) == 1 and len(S) == 1:
  ans = 0
elif len(c) == 1 and len(S) > 1:
  ans = c[0]//2
elif len(c) > 1 and abs(c[1]-c[0]) == 1:
  ans = 0
elif len(c) > 1 and abs(c[1]-c[0]) != 1:
  ans = abs(c[1] - c[0])
print(ans)
# Judge status: Wrong Answer
import numpy as np
N = int(input())
A = [0]
A += list(map(int,input().split()))


searchedMax = N
ans = 0
while searchedMax>=1:
    half = int(searchedMax/2)+1
    #ans += sum(A[half:searchedMax])
    for i,a in enumerate(A[half:searchedMax+1]):
        ind = i+half
        ans += a
        if ind%2 == 0:
            A[int(ind/2)] -= a
        if a<0:
            print(-1)
            exit()
    searchedMax = half-1

print(ans)
print(''.join(['1']*ans))
# Judge status: Accepted
import math

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

h.sort(reverse=True)

if n <= k:
    print(0)
else:
    x = n - k
    del h[0:k]
    ans = sum(h)
    print(ans)
# Judge status: Accepted
f = int(input())
s = int(input())

lst = [1, 2, 3]
lst.remove(f)
lst.remove(s)

print(lst[0])
# Judge status: Accepted
from fractions import gcd

N = int(input())
rows = [int(input()) for _ in range(N)]

def lcm(x, y):
    return (x * y) // gcd(x, y)

ans = 1
for num in rows:
    ans = lcm(ans,num)

print(ans)
# Judge status: Accepted
s = list(input().strip())
s.sort()
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print('no')
        exit()
print('yes')
# Judge status: Wrong Answer
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n,k = ip()
x = ip()
prev = 1
for i in range(k):
    prev *= x[i]
ans = []
for i in range(k,n):
    now = prev*x[i]//x[i-k-1]
    if now > prev:
        ans.append('Yes')
    else:
        ans.append("No")
    prev = now
for i in ans:
    print(i)
# Judge status: Accepted
N,K = map(int, input().split())
A=[]
d=[0 for i in range(K)]
recode={}
for i in range(K):
    d[i]=int(input())
    a=list(map(int, input().split()))
    A.append(a)
for i in range(K):
    for j in range(d[i]):
        recode[A[i][j]]=1
count=0
for i in range(1,N+1):
    if i in recode.keys():
        continue
    else:
        count+=1
print(count)
# Judge status: Accepted
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
bcs = []
for i in range(Q):
  j,k = map(int,input().split())
  bcs.append([j,k])
s = sum(A)
cnts = [0]*100000
for a in A:
  cnts[a-1]+=1
for b,c in bcs:
  t = cnts[b-1]
  s -= t * b
  cnts[b-1]=0
  cnts[c-1]+=t
  s += t*c 
  print(s)
# Judge status: Accepted
N = int(input())

ans = 0
for i in range(1, N + 1, 2):
    c = 0
    for j in range(1, i + 1):
        if i % j == 0:
            c += 1
    if c == 8:
        ans += 1
print(ans)
# Judge status: Accepted
N, M = map(int,input().split())

kameasi = 4 * N

if M == kameasi:
  print('Yes')
  exit()

for i in range(1,N+1):
    # 足の数
    f = kameasi - 2*i 
    if f == M:
        print('Yes')
        break
else:
    print('No')
# Judge status: Wrong Answer
n,y=map(int,input().split())

flag=0
total = 0
flag = 0


for i in range(n+1):
    for j in range(n+1):
        k=n-i-j
        if k<0:
            break

        total=10000*i-5000*j+1000*k
        if total==y:
            print(i,j,k)
            flag=1
            break 
    if flag == 1:
        break

if flag==0:
    print(-1, -1, -1)
# Judge status: Accepted
n=int(input())
p = input()
w, r = 0,0
for i in range(n):
  if p[i] == "W":
    w += 1
  else:
    r += 1
ans = n
noww , nowr = 0,0
for i in range(n+1):
  ans = min ( ans , max(noww , r - nowr))
  if i < n and p[i] == "W":
    noww += 1
  else:
    nowr += 1
print(ans)
# Judge status: Wrong Answer
n,m=map(int,input().split()) 
q=input() 
l=[list(map(int,input().split())) for _ in range(m)] 
print(n,m,q,l) 
ans=0 
lst_j=[0]*(n+1) 
for i in range(n-1): 
	cnt=0 
	if q[i]+q[i+1]=="AC": 
		cnt=1 
		lst_j[i+1]=cnt+lst_j[i] 
	else:lst_j[i+1]=lst_j[i] 
for i,j in l: 
	ans=lst_j[j-1]-lst_j[i-1] 
	print(ans)
# Judge status: Accepted
N,P=map(int, input().split())
*A,=map(int, input().split())

even=sum(1 for a in A if a&1==0)
odd =sum(1 for a in A if a&1==1)

def comb(n, r):
    p, q = 1, 1
    for i in range(min(r,n-r)):
        p *= n-i
        q *= i+1
    return p // q

ans=0
for i in range(P,odd+1,2):
    ans+=comb(odd, i)
ans *= 1<<even

print(ans)
# Judge status: Accepted
a,b,c,d,e=map(int,input().split())
hour = int(e/60)
mint = e-hour*60
f = c-hour
g = d-mint
if f<0:
    f=f-1
    g=g+60

res = f*60 + g - a*60 - b
print(res)
# Judge status: Wrong Answer
N, A, B = input().split(' ')
N = int(N)
A = int(A)
B = int(B)
S = []
S = list(input())
print(S)
JS = 0
AS = 0
OT = 0

for i in range(N):
  if S[i] == 'a' and A+B > JS+AS:
    print('Yes')
    JS += 1
  elif S[i] == 'b' and A+B > JS+AS and AS < B:
    print('Yes')
    AS += 1
  else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
A=[int(input()) for _ in range(n)]
B={}
for i in A:
    if i in B:
        B[i]=0
    else:
        B[i]=1
print(sum(B.values()))
# Judge status: Wrong Answer
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
x, y, a = zip(*xya)
xl, xr, yb, yt = 0, w, 0, h
for i in range(n):
    if a[i] == 1:
        xl = max(xl, x[i])
    elif a[i] == 2:
        xr = min(xr, x[i])
    elif a[i] == 3:
        yb = max(yb, y[i])
    else:
        yt = min(yt, y[i])
print(max(0, (xr-xl)*(yt-yb)))
# Judge status: Accepted
N = int(input())
s = {input() for i in range(N)}
print(len(s))
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    dic.setdefault(a[i],i+1)
ans = []
for i in range(1,n+1):
    print(str(dic[i]),end='')
    print(' ',end='')
# Judge status: Accepted
n, m = map(int, input().split())
ans = 1
for i in range(1,int(m**0.5)+1):
    if m%i: continue
    if m//i>=n and i>ans: ans=i
    if i>=n and m//i>=ans: ans=m//i
print(ans)
# Judge status: Accepted
a = list(map(int, input().split()))
b = a[0] + a[1]
print(b if b < 24 else b-24)
# Judge status: Accepted
s = str(input())
n = len(s)
print('x'*n)
# Judge status: Wrong Answer
def resolve():
    import heapq
    n = int(input())
    a = [int(input()) for i in range(n)]
    maxlist = [-1 * a[n-1]]
    heapq.heapify(maxlist)
    for i in range(n-2, -1, -1):
        maxel = heapq.heappop(maxlist)
        if -1 * a[i] > maxel:
            heapq.heappush(maxlist, -1*a[i])
        elif -1 * a[i] <= maxel:
            heapq.heappush(maxlist, -1 * a[i])
            heapq.heappush(maxlist, maxel)
    print(len(maxlist))
resolve()
# Judge status: Accepted
import re
ans = max(map(len, re.findall("[ACGT]*", input())))
print(ans)
# Judge status: Wrong Answer
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_a
# 15:17-15:22 done


def main():
    n, m = map(int, input().split())
    return (n-2)*(m-2)


print(main())
# Judge status: Accepted
N, A, B = [int(i) for i in input().split(" ")]
S = input()

cnt = 0
cnt_abroad = 0

for s in S:
  if A + B <= cnt:
    print("No")
    continue
  if s == "c":
    print("No")
    continue
  if s == "a":
    cnt += 1
    print("Yes")
    continue
  if s == "b":
    if B <= cnt_abroad:
      print("No")
      continue
    cnt += 1
    cnt_abroad += 1
    print("Yes")
    continue
# Judge status: Accepted
sd = input()
t = input()

n = len(sd)
m = len(t)
#s = []

for i in range(n - m, -1, -1):
    t_kamo = sd[i : i + m]
    for j in range(m + 1):
        if j == m:
            print((sd[: i] + t + sd[i + len(t):]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != t[j]:
            break
print('UNRESTORABLE')
# Judge status: Accepted
# 044A

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N <= K:
    print(X * N)
else:
    print(X * K + Y * (N - K))
# Judge status: Wrong Answer
x, y = map(int, input().split())

for i in range(x+1):
    for j in range(x+1):
        if i + j <= x:
            if i * 2 + j * 4 == y:
                print("Yes")
                exit()

print("No")
# Judge status: Accepted
#1<=A<=20
#1<=B<=20

a, b = map(int, input( ).split())
if a<=9 and b<=9:
    print(a*b)

#elseはifの条件ではないときに使う。
else:
    print(-1)
# Judge status: Accepted
import sys
a,b=map(int,input().split())
if a>=0:
  print("Positive")
  sys.exit()
if b>=0:
  print("Zero")
  sys.exit()
if abs(a-b)%2==0:
  print("Negative")
else:
  print("Positive")
# Judge status: Accepted
A,B = [ int(i) for i in input().split() ]

print(int((A+B)//2) if (A+B)%2 == 0 else "IMPOSSIBLE")
# Judge status: Accepted
s=input()
a=len(s)
b=str("x")*a 
print(b)
# Judge status: Accepted
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ans = float("inf")
def sub(x, base):
    if x==0:
        return 0
    i = 0
    while pow(base, i+1)<=x:
        i += 1
    return sub(x-pow(base,i), base) + 1
for i in range(n+1):
    ans = min(ans, sub(i,6)+sub(n-i,9))
print(ans)
# Judge status: Accepted
import string
abc = string.ascii_lowercase
s = list(input())
K = int(input())
index = 0
while K > 0:
    if index == len(s) - 1:
        s[index] = abc[(abc.index(s[index]) + K) % 26]
        break
    tmp = 26 - abc.index(s[index])
    if tmp == 26:
        index += 1
        continue
    if K >= tmp:
        s[index] = 'a'
        index += 1
        K -= tmp
    else:
        index += 1

for i in s:
    print(i, end='')
# Judge status: Accepted
n, a, b = map(int, input().split())

print(max(0,(a + (b * (n - 1))) - (b + (a * (n - 1))) + 1))
# Judge status: Accepted
s = input()
if s[-1] == "s":
  print(s + 'es')
else:
  print(s + 's')
# Judge status: Wrong Answer
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc155/tasks/abc155_e

n = int(input())
# n = 1198
# print(n)
d = []
keta = len(str(n))
cnt = 0
for i in range(1, keta + 1):
    # print(f"{i} keta")
    kazu = (n % (10 ** i)) // 10 ** (i -1)

    if 0 <= kazu <= 5:
        cnt += kazu
    else:
        cnt += (10 - kazu)
        if i > 0:
            n += 10 ** i
        else:
            cnt += 1
print(cnt)
# Judge status: Wrong Answer
S = [input()]

for i in range(len(S)-1):
    if s[i] != s[i+1]:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted

N = int(input())
S = list(input()) #１文字ずつ

ans=0
for i in range(1,N):
    X = S[0:i]
    Y = S[i:N]
    cnt=0
    # print('X.,Y:', X,Y)

    als=[chr(ord('a') + i) for i in range(26)]
    for al in als:
        if (al in X) and (al in Y):
            cnt+=1
    ans=max(ans,cnt)
print(ans)
# Judge status: Wrong Answer
x=list(map(int,input().split()))
for i in range(5):
    if x[i]==0:
        print(i)
# Judge status: Accepted
l, r = map(int, input().split())

mod = 2019

ans = 2222

if (r - l) // mod > 0:
	ans = 0

else:
	ans = 2020
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			ans = min(ans, (i % mod) * (j % mod) % mod)

print(ans)
# Judge status: Accepted
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=[list(mi()) for _ in range(3)]
ans=0
for i in range(a-1):
  ans+=l[1][l[0][i]-1]
  if l[0][i]+1==l[0][i+1]:
    ans+=l[2][l[0][i]-1]
print(ans+l[1][l[0][a-1]-1])
# Judge status: Accepted
N,K=map(int,input().split())
lst=[]
for i in range (N):
    h=int(input())
    lst.append(h)
lst.sort()
ans=10000000000
for i in range (N-K+1):
    ans=min(ans,lst[i+K-1]-lst[i])
print(ans)
# Judge status: Accepted
import sys
import math

sx,sy,tx,ty = list(map(int,input().split()))

dy=ty-sy
dx=tx-sx

a=""
a+="U"*dy
a+="R"*dx
a+="D"*dy
a+="L"*dx
a+="L"
a+="U"*(dy+1)
a+="R"*(dx+1)
a+="D"
a+="R"
a+="D"*(dy+1)
a+="L"*(dx+1)
a+="U"

print(a)
# Judge status: Wrong Answer
s = input()
N = len(s)
i = 0
count = 0
while i < N-1:
    if i == 0:
        word = s[i]
        i += 1
        count += 1
        last = 1
    if s[i-1] == s[i]:
        word = s[i:i+2]
        i += 2
        count += 1
        last = 2
    else:
        word = s[i]
        i += 1
        count += 1
        last = 1

if i+2 != N and ((last == 1 and word != s[N-1]) or last == 2):
    count += 1
print(count)
# Judge status: Wrong Answer
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
l=[0]*(n+1)
for i in range(n):
    l[i+1]=int(input())
ans=0
for i in range(1,n):
    num=min(l[i],l[i+1])
    l[i]-=num
    l[i+1]-=num
    ans+=num
for i in range(1,n+1):
    ans+=l[i]//2
print(ans)
# Judge status: Accepted
l= sorted(list(map(int,input().split())))
if l[0] + l[1] == l[2]:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n,k=map(int, input().split())
ans=0
import math
for i in range(1,n+1):
    sikou=math.ceil(math.log((k/i),2))
    if sikou<0:
        sikou=0
    ans+=(1/n)*0.5**sikou
print(ans)
# Judge status: Accepted
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input().rstrip())
a=[0]*(10**5+1)
now=0
for i in input().split():
    a[int(i)]+=1
    now+=int(i)
for _ in range(int(input().rstrip())):
    b,c=map(int,input().split())
    now-=b*a[b]
    now+=c*a[b]
    print(now)
    a[b],a[c]=0,a[c]+a[b]
# Judge status: Wrong Answer
n = int(input())
l = list(map(int, input().split()))

terms = (max(l) - (sum(l) - max(l)))

if terms:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
r = int(input())
pi = 3.1415926535
length = r * pi
print(length)
# Judge status: Accepted
import numpy as np

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])
I = np.array([1] * N)

L = np.max(A)

ans = L
low = 1
high = L
while 1:
    if low == high:
        ans = low
        break
    
    mid = (low + high) // 2
    if np.sum((A - I) // mid) <= K:
        high = mid
    else:
        low = mid + 1

print(ans)
# Judge status: Wrong Answer
n = int(input())
s = list(str(input()))
t = list(str(input()))
p = 0
ans = n * 2

for i in range(n):
    if s[i] == t[0]:
        for x in range(n-i):
            if s[i + x] == t[x]:
                p += 1
        else:
            ans -= p
            break

print(ans)
# Judge status: Accepted
N = input()
a = sorted(map(int, input().split()))[::-1]
print(sum(a[::2]) - sum(a[1::2]))
# Judge status: Wrong Answer
a,b=map(int,input().split())
c=[]
import sys
if a==1:
  print(b)
  sys.exit()
for i in range(a*2-1):
  c+=str(b-a+i+1)

for i in range(a*2-1):
  print(c[i],end=" ")
# Judge status: Wrong Answer
a = list(map(int,input().split()))
if a[0] != abs(a[0]) and a[1] != abs(a[1]):
    print("Negative")
elif a[0] == abs(a[0]) and a[1] == abs(a[1]):
    print("Positive")
elif a[0] == 0 or a[1] == 0:
    print("Zero")
# Judge status: Wrong Answer
def string(s, t):
	summ1 = 0
	summ2 = 0
	for i in range(len(s)):
		summ1 += ord(s[i])
	for j in range(len(t)):
		summ2 += ord(t[j])
	if summ1 > summ2:
		print(t, end="")
		print(s)
	else:
		print(s, end="")
		print(t)


s, t = map(str, input().split())
string(s, t)
# Judge status: Accepted
n = int(input())
s = input()
count = [0]*26
for i in s:
    count[ord(i)-ord("a")] += 1
mod = 10**9+7
ans = 1
for i in count:
    ans *= (i+1)
    ans %= mod
print(ans-1)
# Judge status: Accepted
import math
A,B,H,M = map(int,input().split())

c1 = (H/12+M/(60*12))*360
c2 = (M/60)*360

th = min(abs(c1-c2),abs(360-(c1-c2)))
th = (th / 180) * math.pi
print(math.sqrt((A**2)+(B**2)-2*A*B*math.cos(th)))
# Judge status: Wrong Answer
t = 25
if (t >= 30):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
# import collections
S = input()
# CS = collections.Counter(S)
# print(CS)
cn = S.count('N')
ce = S.count('E')
cs = S.count('S')
cw = S.count('W')
# print(cn, cs, cw, ce)
if cn > 0 and cs > 0 and ce == 0 and cw == 0:
    print('Yes')
elif cn == 0 and cs == 0 and ce > 0 and cw > 0:
    print('Yes')
elif cn > 0 and cs > 0 and ce > 0 and cw > 0:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
x,y=map(int,input().split())
if x>1:
    x=x-1
    f=x*2+(x-1)*4
    if f==y:
        print("Yes")
    else:
        print("No")
        exit()
if x==1:
    if x*2==y or x*4==y:
        print("Yes")
    else:
        print("No")
# Judge status: Wrong Answer
a,b,c,x,y=map(int,input().split())
ans=100000
for i in range(1,100001):
    tmp=i*2*c+max(0,x-i)*a+max(0,y-i)*b
    ans=min(ans,tmp)
print(ans)
# Judge status: Wrong Answer
N = int(input())
S = input()

cnt = S.count('E')
for i in S:
    if i == 'E':
        cnt += 1
    if i == 'W':
        cnt -= 1
print(cnt)
# Judge status: Accepted
n = int(input())
before = ''
said = set([])
f = True
for i in range(n):
    if i==0:
        before = input()
        said.add(before)
        continue
    s = input()
    if before[-1] != s[0] or s in said:
        f = False
    before = s
    said.add(s)
print('Yes' if f else 'No')
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if a==c or b==c or a+b==c:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N=int(input())
if N<=999:
    print("ABC")
else:
    print("ABD")
# Judge status: Wrong Answer
import math
n=int(input())
n=180-n
ans=360//(180-n)
print(ans)
# Judge status: Wrong Answer
N = int(input())
S = input()

if '.' not in S:
    print(0)
    exit()
elif '#' not in S:
    print(0)
    exit()

black_sum = 0
white_sum = 0
for i in range(N):
    if S[i] == '#':
        black_sum += 1
    else:
        white_sum += 1

left_black = 0
right_white = white_sum
min_sum = 10 ** 9
for i in range(N):
    if S[i] == '#':
        left_black += 1
    else:
        right_white -= 1

    min_sum = min(min_sum, left_black + right_white)
print(min_sum)
# Judge status: Wrong Answer
M, N = input().split()
M = int(M)
N = int(N)

if M == N:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
n,m = map(int,input().split())
h = list(map(int,input().split()))
ma = [0]*(n)
for i in range(m):
  a,b = map(lambda x: int(x)-1,input().split())
  ma[a] = max(ma[a], h[b])
  ma[b] = max(h[a], ma[b])
ans = 0
for i in range(n):
  if h[i]>ma[i]:
    ans+=1
print(ans)
# Judge status: Accepted
num = int(input())
s = input()

if len(s) <= num:
    print(s)
else:
    print(s[:num] + '...')
# Judge status: Accepted
def main():
    N, M = map(int, input().split())
    if N >= 3 and M >= 3:
        ans = (N-2)*(M-2)
    elif N == 2 or M == 2:
        ans = 0
    elif N == 1 and M == 1:
        ans = 1
    else:
        S = max(N, M)
        ans = max(0, S-2)
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n=int(input())
a=1
l=list(map(int,input().split()))
l.sort()
p=10**18
for i in l:
    a*=i
    if a>p:
        print(-1)
        exit()
print(a)
# Judge status: Accepted
a, b, c = map(int, input().split())
if a < c < b or b < c <a:
    print("Yes") 
else:
    print("No")