Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

N = ni()
li = primes(10**7)
ans = li[:5]
#print(len(li))
now = 4
flag = 0
for i in range(N-5):
    while flag == 0:
        #print(li[now])
        kouho = li[now]
        flag = 1
        for x in itertools.combinations(ans, 4):
            if is_prime(sum(x) + kouho):
                now += 1
                flag = 0
                break
    ans.append(li[now])
    now += 1
print(*ans)



### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

N = ni()
li = primes(10**7)
ct = 0
ans = []
for num in li:
    if num % 10 == 7:
        ct += 1
        ans.append(num)
        if ct == N:
            break 
print(*ans)
### BUGGY CODE ###

#import sys
from collections import deque
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True  and False
BIG = 1234567890

def ddprint(x):
  if DBG:
    print(x)

n,m,l = inm()

distance = [ [BIG] * n for i in range(n) ]
hops = [ [(BIG,0)] * n for i in range(n) ]
for i in range(n):
  distance[i][i] = 0
  hops[i][i] = (0,0)

dst = [ [] for i in range(n) ]
for i in range(m):
  a,b,c = inm()
  if c>l:
    continue
  a -= 1
  b -= 1
  distance[a][b] = distance[b][a] = c
  dst[a].append(b)
  dst[b].append(a)

for i in range(n):
  q = deque([ (x,(0,distance[i][x])) for x in dst[i] ])
  while len(q)>0:
    y,e = q.popleft()
    #ddprint("y {} e {} {}".format(y,e[0],e[1]))
    if e>=hops[i][y]:
      continue
    #ddprint("upd i {} y {}".format(i,y))
    hops[i][y] = e
    for f in dst[y]:
      ds = distance[y][f]
      #ddprint("y {} f {} ds {}".format(y,f,ds))
      if e[1]+ds > l:
        newd = (e[0]+1, ds)
      else:
        newd = (e[0], e[1]+ds)
      if newd < hops[i][f]:
        q.append((f,newd))

if DBG:
  for i in range(n):
    print(hops[i])

B2 = BIG//2
#for i in range(n):
#  for j in range(n):
#    if hops[i][j][0] > B2:
#      hops[i][j] = (-1,0)

p = inn()
for i in range(p):
  s,t = inm()
  #ddprint("q {} s {} t {}".format(i,s,t))
  x = hops[s-1][t-1][0]
  print(x if x<B2 else -1)


### FIXED CODE ###

import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 9999999999

def ddprint(x):
  if DBG:
    print(x)

def ws(dist):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k]+dist[k][j])

n,m,l = inm()
dst = [ [] for i in range(n) ]
for i in range(m):
    a,b,c = inm()
    dst[a-1].append((b-1,c))
    dst[b-1].append((a-1,c))

dist1 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist1[i][i] = 0
    for j,c in dst[i]:
        dist1[i][j] = c

ws(dist1)

dist2 = [ [BIG]*n for i in range(n) ]
for i in range(n):
    dist2[i][i] = 0
    for j in range(n):
        if dist1[i][j] <= l:
            dist2[i][j] = 1

ws(dist2)

q = inn()
for i in range(q):
    s,t = inm()
    d = dist2[s-1][t-1]
    print(d-1 if d<BIG else -1)
### BUGGY CODE ###

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

for i in range(Q):
    B, C = map(int, input().split())
    newA = [C if i == B else i for i in newA]
    print(sum(newA))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
D = [0] * (10 ** 5 + 1)
for i in range(N):
    D[A[i]] += 1

Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    S += (C - B) * D[B]
    print(S)
    
    D[C] += D[B] 
    D[B] = 0
### BUGGY CODE ###

# coding = SJIS

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
pap = []

for i in range(n):
    if a[i] not in pap:
        pap.append(a[i])
    elif a[i] in pap:
        pap.remove(a[i])

print(len(pap))

### FIXED CODE ###

# coding = SJIS

n = int(input())
a = [int(input()) for i in range(n)]
ans = 0

a.sort()

i = 0

while i < n:
    ko = 1
    while (i + ko) < n and a[i] == a[i + ko]:
        ko += 1
    if ko % 2 == 1:
        ans += 1
    i += ko

print(ans)
### BUGGY CODE ###

a, b, k = map(int, input().split())
for i in range(k):
  if a > 0:
    a -= 1 
  elif b > 0:
    b -= 1
  else:
    break
print(str(a) + " " + str(b))

### FIXED CODE ###

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

if a > 0:
    if a > k:
        a -= k
        k = 0
    else:
        k -= a
        a = 0

if b > 0:
    if b > k:
        b -= k
    else:
        b = 0

print(str(a) + " " + str(b))
### BUGGY CODE ###

N,M,Q=map(int,input().split())
import numpy as np
trains=np.zeros((N+1,N+1),dtype=int)
for i in range(M):
  l,r=map(int,input().split())
  trains[l][r]+=1
  
np.cumsum(trains,axis=0,out=trains)
np.cumsum(trains,axis=1,out=trains)

for i in range(Q):
  p,q=map(int,input().split())
  print(trains[q][q]-trains[p-1][q]-trains[q][p-1]+trains[p-1][p-1])


### FIXED CODE ###

N,M,Q=map(int,input().split())
pos=[[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l,r=map(int,input().split())
  pos[l][r]+=1

for l in range(N+1):
  sums=0
  for r in range(N):
    pos[l][r+1]=pos[l][r]+pos[l][r+1]
    
for r in range(N+1):
  sums=0
  for l in range(N):
    pos[l+1][r]=pos[l][r]+pos[l+1][r]

for i in range(Q):
  p,q=map(int,input().split())
  print(pos[q][q]-pos[p-1][q]-pos[q][p-1]+pos[p-1][p-1])
### BUGGY CODE ###

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

L = sorted(L)
ans = 0
H = {}
for i in range(N-1):
    for j in range(i+1, N-1):
        H.update({(i,j): L[i]+L[j]})


for h, v in H.items():
    for j in range(N):
#        if h[0] == j or h[1] == j: continue
        if h[1]>=j: continue
        if v > L[j]:
            ans += 1
        else: break

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        b_i = bisect.bisect_left(L, L[i]+L[j]) # a+bより小さい数
        ans += b_i - (j+1)
print(ans)
### BUGGY CODE ###

from collections import deque

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

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

for _ in range(M) :
    x , y , z = map(int,input().split())

    edge[x-1].append(y-1)
    edge[y-1].append(x-1)

check = [False] * N

q = deque([0])
count = 1 # 連結成分の数

while True:
    while q :
        current = q.popleft()

        if not check[current] :
            check[current] = True

            for n in edge[current] :
                if not check[n] :
                    q.append(n)

    for v , status in enumerate(check) :
        if(not status) :
            q = deque([v])
            count += 1
            break
    else :
        break

print(count)




### FIXED CODE ###

from collections import deque

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

checked = [False] * N

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

for _ in range(M) :
    x , y , z = map(int,input().split())
    edge[x - 1].append(y-1)
    edge[y - 1].append(x-1)

component = 0

for c , check in enumerate(checked) :
    if check :
        continue

    stack = deque([c])
    component += 1

    while stack :
        current = stack.pop()

        if checked[current] :
            continue

        checked[current] = True
        for v in edge[current] :
            if not checked[v] :
                stack.append(v)

print(component)
### BUGGY CODE ###

a,b,k=(int(i)for i in input().split())
for i in range(k):
    if 0<a:a=a-1
    elif 0<b:b=b-1
print(a,b)


### FIXED CODE ###

a, b, k = map(int, input().split())
print(0,max(0,b+a-k)) if a<=k else print(a-k,b)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in range(1,n):
  if ans > abs(sum(a[:i]) - sum(a[i:])):
    ans = abs(sum(a[:i]) - sum(a[i:]))
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))
### BUGGY CODE ###

cnt = 0
N = int(input())
s = [0] * N
for i in range(N):
    s[i] = str(sorted(input()))

cnt = 0
for i in set(s):
    n = s.count(i)
    cnt += n * (n - 1) // 2
print(cnt)

### FIXED CODE ###

import collections

N = int(input())
s = [0] * N
for i in range(N):
    s[i] = sorted(input())
    s[i] = " ".join(s[i])

cnt = 0
for i in collections.Counter(s).values():
    cnt += i * (i - 1) // 2
print(cnt)
### BUGGY CODE ###

def main():
    N,K,Q=map(int,input().split())
    score=[K]*N
    for _ in range(Q):
        num=int(input())
        for j in range(num-1):
            score[j]-=1
        for k in range(num,N):
            score[k]-=1
    for s in score:
        if s>0:
            print('Yes')
        else:
            print('No')

if __name__=='__main__':
    main()


### FIXED CODE ###

n, k, q = map(int, input().split())
points = [k] * n
a = []
for i in range(q):
    a.append(int(input())-1)
for cand in a:
    points[cand] += 1
points = [i-q for i in points]
ans = ["Yes" if i > 0 else "No" for i in points]
print(*ans, sep="\n")
### BUGGY CODE ###

n,m=map(int,input().split())
s=input() ;a=len(s)
t=input() ;b=len(t)
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
L=lcm(len(s),len(t))

A=["" for i in range(L)]

now=0
for i in range(0,L,L//a):
    A[i]=s[now]
    now+=1
now=0
#print(A)
for i in range(0,L,L//b):
    if A[i]!="" and A[i]!=t[now]:
        print(-1);exit()
    A[i]=t[now]
    now+=1
print(L)

### FIXED CODE ###

n,m=map(int,input().split())
s=input() ;a=len(s)
t=input() ;b=len(t)
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
L=lcm(len(s),len(t))

d={}
now=0
for i in range(0,L,L//a):
    d[i]=s[now]
    now+=1
now=0
for j in range(0,L,L//b):
    if d.get(j, t[now])!=t[now]:
        print(-1);exit()
    now+=1
print(L)
### BUGGY CODE ###

K = int(input())

def gcd(a,b):
    if a % b == 0:
        return b
    return gcd(b, a%b)

ans = 0
for a in range(1,K+1):
    for b in range(1, K+1):
        ab = gcd(a,b)
        for c in range(1, K+1):
            ans += gcd(ab, c)

print(ans)


### FIXED CODE ###

K = int(input())

def gcd(a,b):
    if a % b == 0:
        return b
    return gcd(b, a%b)

dec = {}
for a in range(1,K+1):
    for b in range(1, K+1):
        if gcd(a,b) not in dec:
            dec[gcd(a,b)] = 1
        else:
            dec[gcd(a,b)] += 1
ans = 0
for c in range(1, K+1):
    for key in dec.keys():
        ans += gcd(c, key)*dec[key]

print(ans)
### BUGGY CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  n=len(s)

  dp=[[0]*13 for _ in range(n+1)]
  dp[0][0]=1
  for i in range(n):
    if s[i]=='?':
      for j in range(10):
        for k in range(13):
          dp[i+1][(k*10+j)%13]+=dp[i][k]
    
    else:
      a=int(s[i])
      for j in range(13):
        dp[i+1][(j*10+a)%13]+=dp[i][j]

    for j in range(13):
      dp[i+1][j]%=mod

  return dp[n][5]

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  n=len(s)

  dp=[[0]*13 for _ in range(n+1)]
  dp[0][0]=1
  for i in range(n):
    if s[i]=='?':
      for j in range(10):
        for k in range(13):
          dp[i+1][(k*10+j)%13]+=dp[i][k]
    
    else:
      a=int(s[i])
      for j in range(13):
        dp[i+1][(j*10+a)%13]+=dp[i][j]

    for j in range(13):
      dp[i+1][j]%=mod

  return dp[n][5]

# main()
print(main())
### BUGGY CODE ###

import collections

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

ans = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if field[i][j] == ".":
            tmp_field = [[0]*w for _ in range(h)]
            q = collections.deque([])
            q.append((i,j))
            while q:
                s = q.popleft()
                y,x =  s[0],s[1]
                c = tmp_field[y][x]
                for k in range(4):
                    newy = y + dy[k]
                    newx = x + dx[k]
                    if 0<= newy < h and 0<= newx < w:
                        if field[newy][newx] == "#":
                            ans = max(ans,c+1)
                            break
                        elif tmp_field[newy][newx] == 0:
                            tmp_field[newy][newx] = c+1
                            q.append((newy,newx))
                else:
                    continue
                break
print(ans)

### FIXED CODE ###

import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1
### BUGGY CODE ###

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

list.sort()
ans=list[k-1]
print(ans)

### FIXED CODE ###

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

count=0
for i in range(n):
    count+=list[i][1]
    if count>=k: ans=list[i][0]; break


print(ans)
### BUGGY CODE ###

import copy
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    list2 = copy.copy(a)
    list2.pop(i)
    print(max(list2))


### FIXED CODE ###

import copy
n = int(input())
a = [int(input()) for _ in range(n)]
sort_a = sorted(a,reverse=True)
for i in range(n):
    if sort_a[0] == a[i]:
        print(sort_a[1])
    else:
        print(sort_a[0])
### BUGGY CODE ###

n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
res=0
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
for r in dict["R"]:
  for g in dict["G"]:
      for b in dict["B"]:
        if 2*r!=g+b and 2*g!=r+b and 2*b!=r+g:
          res+=1           
print(res)

### FIXED CODE ###

n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
res=len(dict["R"])*len(dict["G"])*len(dict["B"])
for r in dict["R"]:
  for g in dict["G"]:
      if (r+g)%2==0:
        if s[(r+g)//2]=="B":
          res-=1
      try:
        if s[2*r-g]=="B" and 2*r-g>=0:
          	res-=1
      except:pass
      try:
        if s[2*g-r]=="B" and 2*g-r>=0:
          res-=1
      except:pass      
      
print(res)
### BUGGY CODE ###

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

count=0
for a in A:
  for b in B:
    if a>=b:
      continue
    num=0
    for c in C:
      if b<c:
        count+=(N-num)
        break
      num+=1


print(count)

### FIXED CODE ###

import bisect

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0
  for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
  print(ans)
  
if __name__=="__main__":
  main()
### BUGGY CODE ###

n=int(input())
s=list(input())
r=s.count("R")
b=s.count("B")
g=s.count("G")
ans=0
herasu=0
for i in range(n):
  if s[i]=="R":
    ab=s[:i].count("B")
    ag=s[:i].count("G")
    bb=b-ab
    bg=g-ag
    l=ab*bg+ag*bb
    ans+=l
  elif s[i]=="B":
    ar=s[:i].count("R")
    ag=s[:i].count("G")
    br=r-ar
    bg=g-ag
    l=ar*bg+ag*br
    ans+=l
  else:
    ab=s[:i].count("B")
    ar=s[:i].count("R")
    bb=b-ab
    br=r-ar
    l=ab*br+ar*bb
    ans+=l
for i in range(1,n):
  for e in range(i):
    if s[i]!=s[e]:
      if i*2-e<=n-1:
        if s[e]!=s[i*2-e] and s[i]!=s[i*2-e]:
          herasu+=1
print(ans-herasu)

### FIXED CODE ###

n=int(input())
s=list(input())
r=s.count("R")
b=s.count("B")
g=s.count("G")
ans=0
herasu=0
for i in range(n):
  if s[i]=="R":
    ab=s[:i].count("B")
    ag=s[:i].count("G")
    bb=b-ab
    bg=g-ag
    l=ab*bg+ag*bb
    ans+=l
  elif s[i]=="B":
    ar=s[:i].count("R")
    ag=s[:i].count("G")
    br=r-ar
    bg=g-ag
    l=ar*bg+ag*br
    ans+=l
  else:
    ab=s[:i].count("B")
    ar=s[:i].count("R")
    bb=b-ab
    br=r-ar
    l=ab*br+ar*bb
    ans+=l
for i in range(1,n):
  for e in range(i):
    if s[i]!=s[e]:
      if i*2-e<=n-1:
        if s[e]!=s[i*2-e] and s[i]!=s[i*2-e]:
          herasu+=1
print(ans-herasu)
### BUGGY CODE ###

n,s=map(int,input().split())
N=[i+1 for i in range(n)]
list1=[]
pattern=[]
A=list(map(int,input().split()))

ft=0  
for i in range(1,2**n):
    list2=[]
    for j in range(n):
        if (i >> j) &1 == 1:
            list2.append(N[j])
    pattern=[]
    for x in range(1,2**len(list2)):
        pt=[]
        for y in range(len(list2)):
            if (x>>y)&1==1:
                pt.append(list2[y])
        pattern.append(pt)
   # print(pattern)

    for p in pattern:
        sum=0
        for x in p:
            sum+=A[x-1]
        if sum==s:
            ft+=1
            ft=ft%998244353
print(ft%998244353)

### FIXED CODE ###

import numpy as np
def main():
    n,s=map(int,input().split())
    A=list(map(int,input().split()))
    dp=np.array([0 for i in range(min(3001,s+1))])
    dp[0]=1
    for ai in A:
        tmp=dp[:-ai].copy()
        #print(tmp)
        dp*=2
        dp[ai:]+=tmp
        dp%=998244353
    print(dp[s])
    

if __name__=="__main__":
    main()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
count=0
if a.count(1)==0:
    print(-1)
else:
    for i in range(n):
        if count+1 == a[count]:
            count+=1
        else:
            del a[count]
            ans+=1
    print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
count=0
if a.count(1)==0:
    print(-1)
else:
    for i in range(n):
        if count+1 != a[i]:
            ans+=1
        else:
            count+=1
    print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

tmp = 1
for i in range(q):
    x = input()
    if x[0]==str(1):
        tmp*=-1
    else:
        t,f,c = x.split()
        t,f = int(t),int(f)
        if tmp==-1:
            if f==1:
                s = s+c
            if f==2:
                s = c+s
        if tmp==1:
            if f==1:
                s = c+s
            if f==2:
                s = s+c

print(s[::tmp])




### FIXED CODE ###

from collections import deque
s = input()
q = int(input())
queue = deque([s])

tmp = 1
for i in range(q):
    x = input()
    if x[0]==str(1):
        tmp*=-1
    else:
        t,f,c = x.split()
        t,f = int(t),int(f)
        if tmp==-1:
            if f==1:
                queue.append(c)
            if f==2:
                queue.appendleft(c)
        if tmp==1:
            if f==1:
                queue.appendleft(c)
            if f==2:
                queue.append(c)

print(''.join(queue)[::tmp])
### BUGGY CODE ###

def solve():
    N = int(input())
    P = []
    for i in range(N):
        P.append(int(input()))

    # asc
    asc_num = 0
    target = 1
    P_tmp = []
    while target <= N:
        tmp_asc_num = 0
        for P_i in P:
            if P_i == target:
                target += 1
                tmp_asc_num += 1
            else:
                P_tmp.append(P_i)
        P = P_tmp[:]
        P_tmp = []
        asc_num = max(asc_num, tmp_asc_num)

    print(N-asc_num)



if __name__ == '__main__':
    solve()

### FIXED CODE ###

N = int(input())
P = []
Q = [0 for i in range(N+1)]
for i in range(1, N+1):
    Q[int(input())] = i

straight = 1
max_straight = 1
for i in range(1, N):
    if Q[i] < Q[i+1]:
        straight += 1
        max_straight = max(straight, max_straight)
    else:
        straight = 1

print(N - max_straight)