peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
q, h, s, d = map(int,input().split())
n = int(input())
d = min(d,s*2,h*4,q*8)
s = min(s,h*2,q*4)

ans = n//2 * d + n%2 * s

print(ans)
# Judge status: Accepted
x, k, d = map(int, input().split())

def sgn(x):
  if x > 0:
    return 1
  if x < 0:
    return -1
  return 0

if x > 0:
  x1 = x - k * d
else:
  x1 = x + k * d

if sgn(x) == sgn(x1):
  print(abs(x1))
  exit()
  
xright = x % d
xleft = x % d - d
#0目前
xr = (abs(x - xright) // d) % 2
if k % 2 == xr:
  print(abs(xright))
elif k % 2 != xr:
  print(abs(xleft))
# Judge status: Wrong Answer
A, B, T = map(int, input().split())

print(int(B/A) * T)
# Judge status: Wrong Answer
import heapq

N, M = map(int, input().split())
jobs = [[] for i in range(M)]

for i in range(N):
    A, B = map(int, input().split())
    if A - 1 < M:
        jobs[A-1].append(B)

q = []
heapq.heapify(q)
ans = 0
for i in range(M):
    for j in jobs[i]:
        q.append(-j)
    if len(q) != 0:
        ans += -heapq.heappop(q)

print(ans)
# Judge status: Wrong Answer
X, K, D = map(int, input().split(" "))
K_s = str(K)
K2 = int(K_s[len(K_s) - 1])

if K2 % 2 == 1:
    if X < 0:
        ans = X + D
    else:
        ans = X - D
else:
        ans = X

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
s = set(sorted(a))
v = [i for i in s]
v.reverse()
print(v)
b_1 = 0
b_2 = 0
for i in v:
    n = a.count(i)
    if n >= 2 and b_1 != 0 and b_2 == 0:
        b_2 = i
    if n >= 2 and b_1 == 0:
        b_1 = i
    if n >= 4 and b_2 == 0:
        b_2 = i
print(b_1*b_2)
# Judge status: Accepted
n = int(input())
ans = []

for i in range(n):
    s, p = map(str, input().split())
    ans.append([s,int(p),i+1])


ans.sort(key = lambda x: x[1], reverse = True)
ans.sort(key = lambda x: x[0])

for i in ans:
    print(i[2])
# Judge status: Accepted
a, b = map(int, input().split())
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
    print('Possible')
else:
    print('Impossible')
# Judge status: Wrong Answer
k, a, b = map(int, input().split())

if k == 1:
    print(2)
elif k < a + 2:
    print(1 + k)
else:
    cnt = (k - (a - 1)) // 2
    mod = (k - (a - 1)) % 2
    ans_1 = (b - a)*cnt + a + mod
    ans_2 = 1 + k
    print(int(max(ans_1, ans_2)))
# Judge status: Wrong Answer
a = ['MON','TUE','WED','THU','FRI','SAT','SUN']

S = input() 

print( 6 - int(a.index(S)))
# Judge status: Accepted
n,l = map(int,input().split())
A = []
for i in range(1,n+1):
    A.append((abs(l+i-1),l+i-1))
A.sort()
# print(A)
ans = 0
for i in range(1,len(A)):
    ans += A[i][1]
print(ans)
# Judge status: Wrong Answer
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int,input().split())
    h=sorted([int(input()) for i in range(n)])
    ans=10**20
    for i in range(n-2):
        ans=min(ans,h[i+2]-h[i])
    print(ans)


resolve()
# Judge status: Accepted
n = int(input())

can = False
for i in range(26):
    for j in range(15):
        v = (i*4 + j*7)
        if v != 0:
            if n % v == 0:
                can = True
if can:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
k = int(input())
s = input()

if len(s) > k :
    print(s[:k]+'...')
else :
    print(s)
# Judge status: Accepted
#!/usr/bin/env python3

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

if B//A >= C:
    print(C)
else:
    print(B//A)
# Judge status: Accepted
import collections

N = int(input())
A = list(map(int,input().split()))
c = [0]*N
p = 0


c = collections.Counter(A)

for i in range(N):
  p += (c[i+1])*(c[i+1]-1)//2

for i in range(N):
  print(p-c[A[i]]+1)
# Judge status: Wrong Answer
N,K = map(int,input().split())
X = list(map(int,input().split()))
ls = []
rs = []
for x in X:
    if x < 0:
        ls.append(-x)
    else:
        rs.append(x)
ls.reverse()

ans = float('inf')
if len(ls) >= K:
    ans = min(ans, ls[K-1])
if len(rs) >= K:
    ans = min(ans, rs[K-1])

for l in range(1,K):
    if l >= len(ls): break
    r = K-l
    if r >= len(rs): continue
    ans = min(ans, ls[l-1]*2 + rs[r-1])
    ans = min(ans, rs[r-1]*2 + ls[l-1])
print(ans)
# Judge status: Accepted
import collections

n = int(input())
p = list(map(int,input().split()))
cnt = collections.Counter(p)

maxs = []
for k, v in cnt.items():
  if v > 1:
    maxs.append(k)
    
if len(maxs) > 1:
  maxs.sort()
  if cnt[maxs[-1]] > 3:
    print(maxs[-1] ** 2)
  else:
    print(maxs[-1] * maxs[-2])

else:
  print(0)
# Judge status: Accepted
L,R,D = list(map(int,input().split()))
ans=0
for i in range(L,R+1):
  if i % D ==0:
    ans+=1
print(ans)
# Judge status: Wrong Answer
if __name__ == "__main__":
    n = '0' + input()

    ans = 0
    flag = 0

    for i in range(len(n)-1, 0, -1):
        if int(n[i]) + flag == 10:
            flag = 1
        elif int(n[i]) + flag > 5 or (int(n[i-1]) == 9 and int(n[i]) + flag == 5):
            ans += 10 - int(n[i])
            flag = 1
        else:
            ans += int(n[i]) + flag
            flag = 0

    if flag == 1:
        ans += 1

    print(ans)
# Judge status: Accepted
from collections import defaultdict
s = input()
mod = 2019
dct = defaultdict(int)
dct[0] = 1
x = 0
d = 1
for c in s[::-1]:
    x = (x+int(c)*d)%mod
    d = d*10%mod
    dct[x] += 1
ans = 0
for v in dct.values():ans += v*(v-1)//2
print(ans)
# Judge status: Accepted

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

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

max_diff = 0
for i in range(1,n):
    if i != 0:
        max_diff = max(abs(An[i] - An[i-1]), max_diff)

max_diff = max(max_diff, k-An[n-1] + An[0])
print(k-max_diff)
# Judge status: Wrong Answer
S = input().strip()
L = len(S)
if len(set(list(S+"ATGC"))) == 4:
    print(L)
    exit()
l = L-1
while True:
    for i in range(L-l):
        if len(set(list(S[i:i+l]+"ATGC"))) == 4:
            print(l)
            exit()
    l -= 1
# Judge status: Accepted
S = input()

ans = 0
prev = ''
curr = ''
for s in S:
    curr += s
    if prev != curr:
        ans += 1
        prev = curr
        curr = ''
print(ans)
# Judge status: Wrong Answer
a, b, c, d = map(int,input().split())

x = c - a
y = d - b

z = []
z += y * 'U'
z += x * 'R'
z += y * 'D'
z += (x + 1) * 'L'
z += (y + 1) * 'U'
z += (1 + x) * 'R'
z += 'U'
z += 'R'
z += (y + 1) * 'U'
z += (1 + x) *'L'
z += 'U'


print(''.join(z))
# Judge status: Wrong Answer
N,K=map(int,input().split())
num=[list(map(int,input().split())) for _ in range(N)]
for i in range(N):
  K -= num[i][1]
  if K <= 0:
    print(num[i][0])
    exit()
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for k in range(60):
  t=1<<k
  z=o=0
  for i in a:
    if i&t:o+=1
    else:z+=1
  ans=(ans+(z*o*t))%mod
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
sum_a = 0
for a in A:
    a = a % mod
    sum_a = (sum_a + a) % mod
ans = 0
for a in A:
    sum_a = (sum_a - a) % mod
    ans += (a % mod) * sum_a
    ans = ans % mod
print(ans % mod)
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a <= 5:
    print(0)
else:
    if a <= 12:
        print(b/2) 
    else:
        print(b)
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n - k + 1):
  p = 1
  for j in range(k):
    p *= a[i + j]
  b.append(p)
x = 0
tf = True
for i in b:
  if i > x:
    if not(x == 0):
      print("Yes")
    x = i
  else:
    tf = False
    print("No")
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
for x in a:
    if not x % 2 and x % 3 and x % 5:
        print('DENIED')
        break
else:
    print('APROAVED')
# Judge status: Accepted
a = input("")
aa = a.split(" ")
aa = [int(s) for s in aa]
L = aa[0]
R = aa[1]
d = aa[2]
aaa = []
for i in range(L,R+1):
    aaa.append(i%d)
print(aaa.count(0))
# Judge status: Accepted
import collections

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

ac = collections.Counter(a)
for i in range(1,n+1):
    print(ac[i])
# Judge status: Wrong Answer
n = int(input())
p = list(map(int,input().split()))
seconds = []
for a in range(0,n-3):
    num = [p[a],p[a+1],p[a+2]]
    num.sort()
    seconds.append(num[1])

print(len(set(seconds)))
# Judge status: Wrong Answer
S=list(map(int,input().split()))
S.sort()
all=0
all += (S[2]+10*S[0]+S[1])
print(all)
# Judge status: Accepted
x, y = map(int, input().split())
print(min(y-x, abs(y+x)+1) if x<y else min(-y+x+2, abs(y+x)+1))
# Judge status: Accepted
a=int(input())
b=(sum(range(3,a+1,3)))
c=(sum(range(5,a+1,5)))
d=(sum(range(15,a+1,15)))
e=a*(a+1)/2
print(int(e-b-c+d))
# Judge status: Accepted
num = input()
length, res = len(num), 0
big, small = "9", "1"

for dig_len in range(1, length + 1, 2):
    if int(big) < int(num):
        res += int(big) - int(small) + 1
        big += "99"
        small += "00"
    else:
        res += int(num) - int(small) + 1

print(res)
# Judge status: Accepted
d,n=map(int,input().split())
print(n*100**d if n!=100 else 101*100**d)
# Judge status: Accepted
N, A, B = map(int,input().split())
if N == 1:
    print(1 if A==B else 0)
else:
    if A > B:
        print(0)
    else:
        m = A*(N-1)+B
        M = B*(N-1)+A
        print(M-m+1)
# Judge status: Wrong Answer
n,m=list(map(int,input().split(" ")))
a=[]
for i in range(m):
  a.append(int(input()))
dp=[float("inf") for i in range(n+1)]
dp[0]=1
if 1 in a:
  dp[1]=0
else:
  dp[1]=1
for i in range(2,n+1):
  if i in a:
    dp[i]=0
  else:
    dp[i]=dp[i-1]+dp[i-2]
print(dp[n])
# Judge status: Accepted
import sys
#input = sys.stdin.buffer.readline

def main():
    s = str(input())
    ans = 1
    now,bef = "",s[0]
    l = len(s)
    for i in range(1,l):
        now += s[i]
        if now != bef:
            ans += 1
            bef = now
            now = ""
            
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n = int(input())
A = [list(map(int,input().split())) for _ in range(2)]

ans = 0
for i in range(n):
  cnt = 0
  for j in range(n):
    if j <= i:
      cnt += A[0][j]
    if j >= i:
      cnt += A[1][j]
  ans = max(ans,cnt)
# Judge status: Accepted
import bisect
#素数リスト
n = 10**5+10
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
  primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

x = int(input())
idx = bisect.bisect_left(primes, x)
print(primes[idx])
# Judge status: Accepted
X=int(input())
 
x=100
for i in range(10**4):
    x += x//100
    if X <= x:
        print(i+1)
        break
# Judge status: Accepted
a,b=map(int,input().split())
if a*b%2!=0:
	print("Odd")
else:
	print("Even")
# Judge status: Wrong Answer
a=input()
n=input()
if a >= n%500: 
  print "Yes"
else: 
  print"No"
# Judge status: Accepted
def solve(ns):
    d = 0
    for s in ns:
        d += int(s)
        d %= 9
    if d == 0:
        return 'Yes'
    else:
        return 'No'


def main():
    ns = input()
    res = solve(ns)
    print(res)


def test():
    assert solve("123456789") == 'Yes'
    assert solve("0") == 'Yes'
    assert solve("31415926535897932384626433832795028841971693993751058209749445923078164062862089986280") == 'No'


if __name__ == "__main__":
    test()
    main()
# Judge status: Wrong Answer
import sys
import os

def file_input():
    f = open('ARC069/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    N,M=map(int, input().split())

    if N*2>=M:
        print(str(N))
    else:
        M-=N*2
        print(str(N+M//4))

if __name__ == '__main__':
    main()
# Judge status: Accepted
x = list(map(int,input().split()))
for i in range(5):
  if x[i] == 0:
    print(i+1)
  else:
    pass
# Judge status: Wrong Answer
a, b, c, k = map(int, input().split())


if k - a <= 0:
    print(k)
elif k - a > 0 and k - a - b <= 0:
    print(a)
else:
    s = k - a
    print(s - c)
# Judge status: Wrong Answer
n,m=map(int,input().split())
now=[tuple(map(int,input().split())) for i in range(n)]
p=[tuple(map(int,input().split())) for i in range(m)]
for a in now:
  ans=10**10
  for c in p:
    ans=min(ans,abs(c[0]-a[0])+abs(c[1]-a[1]))
  print(ans)
# Judge status: Wrong Answer
k=int(input())
f=-1
for i in range(1,1000):
    s=k*i
    l=len(str(s))
    d=0
    for i in range(l):
        if str(s)[i]!=7:
            d=d+1
            break
    if d<=0:
        f=l
print(f)
# Judge status: Wrong Answer
h,n = [int(x) for x in input().split()]

# dp[i] = min magic points to decrease i health points
maxmax = 99999999
dp = [maxmax for x in range(h+1)]
dp[0] = 0
for x in range(n):
    a,b = [int(r) for r in input().split()]
    
    for j in range(h):
        dp[min(j+a, h)] = min(dp[min(j+a, h)], dp[j]+b)

print(dp[h])
# Judge status: Wrong Answer
Alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
al=input()
for i in  Alphabet :
     if i==al:
         print(Alphabet[+1])
# Judge status: Accepted
a = int(input())
s = input()
if a >= 3200:
    print(s)
if a < 3200:
    print('red')
# Judge status: Accepted
import datetime

if __name__ == "__main__":
    H1, M1, H2, M2, K = [int(a) for a in input().split()]
    dt_start = datetime.datetime(year=2020, month=5, day=30, hour=H1, minute=M1, second=00)
    dt_end= datetime.datetime(year=2020, month=5, day=30, hour=H2, minute=M2, second=00)
    up_time = dt_end - dt_start
    sec = up_time.total_seconds()  - K * 60
    print(int(sec/60))
# Judge status: Wrong Answer
import sys
input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

s, t = input().split()
a, b = MAP()
u = input()

if u == s:
    a -= 1
if u == t:
    b -= 1
print(a, b)
# Judge status: Accepted
a,b,c=map(int,input().split())
print(['No','Yes'][a<c<b or b<c<a])
# Judge status: Accepted
nums = [int(e) for e in input().split()]

if nums[3] < nums[0]:
    M = nums[3]
elif nums[0] <= nums[3] <= nums[0] + nums[1]:
    M = nums[0]
elif nums[0] + nums[1] < nums[3]:
    M = nums[0] - (nums[3] - nums[0] - nums[1])

print(M)
# Judge status: Accepted
import numpy as np

N, M, X = [int(x) for x in input().split()]

data = [[] for _ in range(N)]

for i in range(N):
    data[i] = [int(x) for x in input().split()]

ans = 12 * (10 ** 5) + 1
ok = False
for i in range(2 ** N):
    v = np.array([0] * (M + 1))
    for j in range(N):
        if (i >> j) & 1:
            v += np.array(data[j])
    x = min(list(v)[1:])
    if X <= x:
        ok = True
        ans = min(ans, v[0])

if ok == True:
    print(ans)
else:
    print(-1)
# Judge status: Accepted
n,r = map(int, input().split( ))
if n>=10:
    print(r)
else:
    print(r+100*(10-n))
# Judge status: Wrong Answer
n,m = map(int,input().split())
sc = [tuple(map(int,input().split())) for i in range(m)]
l = [0]*n
ans = -1
for t in sc:
    l[t[0]-1] = t[1]
if l[0]==0:
    print(-1)
else:
    print("".join([str(s) for s in l]))
# Judge status: Wrong Answer
#!/usr/bin/env python
# coding: utf-8

# In[6]:


N = int(input())
sp = []
for i in range(N):
    sp.append([i]+input().split())


# In[9]:


mylist = sorted(sp, key=lambda x: x[2], reverse=True)
mylist = sorted(mylist, key=lambda x: x[1])
for i in range(len(mylist)):
    print(mylist[i][0]+1)


# In[ ]:
# Judge status: Accepted
X=int(input())
while True:  
  for i in range(2,X):
    if X%i==0:
      X+=1
      break
  else:
    print(X)
    break
# Judge status: Accepted
S = input()
count = {s: 0 for s in "NWSE"}
for s in S:
    count[s] += 1

if count["N"] == 0 and count["S"] >= 1 or count["N"] >= 1 and count["S"] == 0:
    print("No")
elif count["E"] == 0 and count["W"] >= 1 or count["E"] >= 1 and count["W"] == 0:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n = input()
    ans = 0
    for i in range(len(n)):
        ans += int(n[i])

    if ans % 9 == 0:
        print("Yes")
    else:
        print("No")


main()
# Judge status: Accepted
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
a_s = [int(i)-1 for i in sys.stdin.readline().split()]
cnt = 0
ind = 0
ls = [ind]
last_pos = {0:0}
_set = {ind}
while cnt < k:
    ind = a_s[ind]
    if ind in _set:
        break
    _set.add(ind)
    ls.append(ind)
    cnt += 1
if cnt == k:
    print(ind+1)
else:
    start = ls.index(ind)
    end = cnt+1
    print(ls[start:][(k - cnt) % (end - start)-1]+1)
# Judge status: Accepted
a,b=map(int,input().split())
ans=0
l=[]
for i in range(b):
  i=a
  l.append(str(i))
ans=','.join(l)
ans_1=ans.replace(',','')

new_l=[]
for i in range(a):
  i=b
  new_l.append(str(i))
new_ans=','.join(new_l)
ans_2=new_ans.replace(',','')

if a == b:
  print(ans_1)
  
elif a > b:
  print(ans_2)
  
else:
  print(ans_1)
# Judge status: Accepted
N=int(input())
s=input()
t=input()

ans=""
for i in range(N):
    ans=ans+s[i]

count=0

for i in range(N):
    flag=True
    for j in range(i+1):
        #print(s[N-1-i+j])
        if s[N-1-i+j]==t[j]:
            pass
        else:
            flag=False
    if flag:
        count=i+1
#print(count)
for i in range(count,N):
    ans=ans+t[i]

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

check = abs(a-b)

if check%2 == 0:
    print(check//2)
    exit()

temp1 = min(max(a,b) - 1, n - min(a,b))
temp2 = min(min(a,b) - 1, n - max(a,b))
ans = min(temp1, temp2 + 1 + (check)//2)

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
sat = b[a[0]-1]
for i in range(n-1):
    sat += b[a[i+1]-1]
    if a[i+1] == a[i] + 1:
        sat += c[a[i+1]-2]
print(sat)
# Judge status: Wrong Answer
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(N)]

A = []
for i in range(N):
    A.append((data[i][0],data[i][1]))

from operator import itemgetter

A = sorted(A,key = itemgetter(1))

ans = 0
r = M
for i in range(N-1,-1,-1):
    if A[i][0] <= r:
        ans += A[i][1]
        r -= 1

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

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

temp = A[0]

for a in A[1:]:
    temp ^= a

print(*[a^temp for a in A])
# Judge status: Wrong Answer
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    *A, d = nm()
    A = sorted(A)
    D = [A[i + 1] - A[i] for i in range(2)]
    if all([dd <= d for dd in D]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
def main():
    n, *p = map(int, open(0).read().split())
    res = []
    tmp = False
    for i, j in enumerate(p, 1):
        b = (i == j) ^ tmp
        res.append(b)
        tmp = b

    ans = sum(res)
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())

ans = []
for i in range(1,n+1):
    t = 0
    while i % 2 == 0:
        t += 1
        i //= 2
    ans.append(t)
a = ans.index(max(ans))
print(a+1)
# Judge status: Accepted
a=int(input())
List = list(map(int, input().split()))
List.sort(reverse=True)
res =List[0]
for i in range(1,a-1):
  if i%2 ==0:
    res += List[int(i/2)]
  else:
    res += List[int((i+1)/2)]
print(res)
# Judge status: Wrong Answer
import math


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

print("Yes" if a<=c and c<=a+b else "No" )
# Judge status: Wrong Answer
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(K):
    d=[0]*(N+1)
    for j,a in enumerate(A):
        d[max(0,j-a)]+=1
        d[min(N,j+a+1)]-=1
    b=-1
    for j in range(N):
        if b==-1:
            b=d[j]
        elif b!=d[j] or 1<b<N:
            b=0
        d[j+1]+=d[j]
    A=d[:-1]
    if b:
        break
print(*A)
# Judge status: Accepted
import numpy as np
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
A=np.array(A)

n=int(input())
for i in range(n):
    b=int(input())
    if b in A:
        A=np.where(A==b,0,A)
cross=0
if A[0][0]+A[1][1]+A[2][2]==0 or A[2][0]+A[1][1]+A[0][2]==0:
    cross=1
print("NYoe s"[0 in np.sum(A,axis=0) or 0 in np.sum(A,axis=1) or cross ::2])
# Judge status: Wrong Answer
N = int(input())
a = []
a = list(map(int,input().split()))
index = 0
count = 0
searchNum = 1
for j in range(N):
    if searchNum ==1:
        if not searchNum in a:
            searchNum = N +1
            break
    if not j + 1 in a:
        break
    if j <= N:
        if a[index + j] == searchNum:
            index = index + j
            searchNum += 1
            continue
    else:
        break

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

print(c,a,b)
# Judge status: Accepted
from collections import Counter
n, x, y = map(int, input().split())
c = Counter()
for i in range(1, n):
    for j in range(i+1, n+1):
        dist = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        c[dist] += 1

for k in range(1, n):
    print(c[k])
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
now=1
rtn=0
for i in range(n):
    if a[i]==now:
        rtn+=1
        now+=1
if rtn:
    print(n-rtn)
else:
    print(-1)
# Judge status: Accepted
N = int(input())

max_min = 0
cumsum = 0
while cumsum <= 10 ** 7:
    max_min += 1
    cumsum += max_min
    if N <= cumsum:
        break

ans = [i + 1 for i in range(max_min)]
rm_value = cumsum - N
if rm_value != 0:
    ans.remove(rm_value)

for i in ans:
    print(i)
# Judge status: Accepted
#AtCoder
X = int(input())

ans = 0
x = 0

while x < X:
    ans += 1
    x += ans 
    
print(ans)
# Judge status: Accepted
a = set(input())
print("Yes" if a == set("NEWS") or a == set("NS") or a == set("EW") else "No")
# Judge status: Accepted
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

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

lcm_a = 1

for i in A:
    lcm_a = lcm(lcm_a,i)

ans = 0
for i in A:
    ans +=lcm_a//i 
    
print(ans%int(1e9+7))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    A[i] -= i + 1

ave = sum(A) // N
ans1 = 0
ans2 = 0
for a in A:
    ans1 += abs(a - ave)
    ans2 += abs(a - (ave + 1))

print(min(ans1, ans2))
# Judge status: Accepted
import sys
read=sys.stdin.read
h,w,n=map(int, read().split())
m=max(h,w)
print(n//m+(n%m!=0))
# Judge status: Accepted
# from pprint import pprint
import math

# import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(lambda x: int(x) * (-1), input().split(' ')))
# a = sorted(a, reverse=True)
# b = [math.log2(_a) for _a in a]


import heapq

q_a = heapq.heapify(a)

for m in range(m):
    x = heapq.heappop(a) * (-1)
    heapq.heappush(a, (x // 2) * (-1))

print(sum(a) * (-1))
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = []

for i in range(1,n+1):
    ans.append(sum(a[:i])+sum(b[i-1:]))
print(max(ans))
# Judge status: Wrong Answer
from collections import defaultdict
N, M = map(int,input().split())
A = list(map(int,input().split()))
T = []
for _ in range(M):
  a, b = map(int,input().split()) 
  T.append((b,a))
A.sort()
T.sort(reverse = True)
# Judge status: Accepted
# B Some Sums

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

ans = 0
for ni in range(1, n+1):
  sum = 0
  for nij in str(ni):
    sum += int(nij)
  if sum >= a and sum <= b:
    ans += ni
    
print(ans)
# Judge status: Wrong Answer
n, m, x, y = map(int, input().split())
xn = list(map(int, input().split()))
ym = list(map(int, input().split()))

for z in range(1, 101):
    war = False
    if x < z and z <= y:
        for i in range(n):
            for j in range(m):
                if xn[i] >= z or ym[j] < z:
                    war = True
        if war == False:
            print("No War")
            exit()
print("War")