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

u_list = []
uo_list = []
e = int(input())

for i in range(e):
    u = input()
    uo_list.append(u)
    if u not in u_list:
        u_list.append(u)

print(len(u_list))

### FIXED CODE ###

s = set([])
things = int(input())

for i in range(things):
    p = input()
    s.add(p)

print(len(s))
### BUGGY CODE ###

N, K = map(int, input().split())
Nj = N
while True:
    Ni = Nj
    Nj = abs(Ni - K)
    if Ni > N:
        print(N)
        break
    elif Nj > Ni:
        print(Ni)
        break
    elif K == 1 or Nj == K:
        print(0)
        break
    else:
        continue

### FIXED CODE ###

N, K  = list(map(int, input().split()))
a = N % K
print(min(abs(a - K), a))
### BUGGY CODE ###

def sub():
    N, K = [int(e) for e in input().split(" ")]
    ss = [int(e) for e in input()]
    if len(set(ss)) == 1:
        print(len(ss))
        return

    dd = [ss[i+1] - ss[i] for i in range(N-1)]
    memIdx = 0
    buf = []
    memNbOne = 0
    memChange = None
    for i, d in enumerate(dd):
        if d > 0:
            e = [(memIdx, i+1), 0]
            buf.append(e)
            memIdx = i+1
            memChange = d
        elif d < 0:
            e = [(memIdx, i+1), 1]
            buf.append(e)
            memIdx = i+1
            memChange = d
    if memChange > 0:
        e = [(memIdx, N), 1]
        buf.append(e)
    else:
        e = [(memIdx, N), 0]
        buf.append(e)
    # print(buf)
    maxScore = 0
    for i in range(len(buf)):
        score = 0
        count = 0
        lastNext = None
        for j in range(i, len(buf)):
            lastNext = j + 1
            b, flag = buf[j]
            score = score + b[1]-b[0]
            if flag == 0:
                count = count + 1
            if count >= K:
                break
        if i-1 >= 0:
            b, flag = buf[i-1]
            if flag == 1:
                score = score + b[1] - b[0]
        if lastNext is not None:
            if lastNext < len(buf):
                b, flag = buf[lastNext]
                if flag == 1:
                    score = score + b[1] - b[0]

        if score > maxScore:
            maxScore = score
        # print(i, score)
    print(maxScore)
sub()


### FIXED CODE ###

def sub():
    N, K = [int(e) for e in input().split(" ")]
    ss = [int(e) for e in input()]
    # if len(set(ss)) == 1:
    #     print(len(ss))
    #     return

    dd = [ss[i+1] - ss[i] for i in range(N-1)]
    idd = [0] + [i+1 for i, d in enumerate(dd) if d != 0]
    # print(idd)
    maxScore = 0
    for i in range(len(idd)):
        if ss[idd[i]] == 0:
            ni = i + 2*K
            if ni < len(idd):
                score = idd[ni] - idd[i]
            else:
                score = N - idd[i]
            if score > maxScore:
                maxScore = score
        else:
            ni = i + 2*K + 1
            if ni < len(idd):
                score = idd[ni] - idd[i]
            else:
                score = N - idd[i]
            if score > maxScore:
                maxScore = score
        
    print(maxScore)

sub()
### BUGGY CODE ###

import sys
N, M = map(int, input().split())
routes = []
for i in range(M):
    a, b = map(int, input().split())
    routes.append([a, b])
m = []
for r in routes:
    if r[0] == 1:
        m.append(r[1])
for r in routes:
    if r[0] in m:
        if r[1] == N:
            print('POSSIBLE')
            sys.exit()
print('IMPOSSIBLE')

### FIXED CODE ###

import sys
N, M = map(int, input().split())
m = set()
m2 = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        m.add(b)
    if b == N:
        m2.add(a)
for me in m:
    if me in m2:
        print('POSSIBLE')
        sys.exit()
print('IMPOSSIBLE')
### BUGGY CODE ###

n = int(input())
a = [int(stdins) for stdins in input().split()]

a.sort()

ans = n
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif a[i] % a[j] == 0:
            ans -= 1
            break

print(ans)


### FIXED CODE ###

# ABC170

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

a.sort()
a_max = max(a)
dp = [True for _ in range(a_max+1)]

ans = 0
for i in range(n):
    if dp[a[i]]:
        for j in range(0, a_max+1, a[i]):
            dp[j] = False
        if i > 0:
            if a[i] == a[i-1]:
                continue
        if i < n-1:
            if a[i] == a[i+1]:
                continue
        ans += 1

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

from math import factorial

def modpow(a, n, mod):
    res = 1
    while(n > 0):
        if n&1:
            res = res * a % mod
            a = a * a % mod
            n >>= 1

    return res

def modinv(a, mod):
    return modpow(a, mod-2, mod)

mod = int(1e+9 + 7)

X, Y = map(int, raw_input().split())

X2 = 2*X - Y
Y2 = -X + 2*Y

if X2 < 0:
    print "0"
    exit()
elif Y2 < 0:
    print "0"
    exit()

if X2%3 != 0:
    print "0"
    exit()
elif Y2%3 != 0:
    print "0"
    exit()

X2 = X2/3
Y2 = Y2/3

ans = 1

n = X2+Y2
m = Y2

for i in range(n-m+1, n+1):
    ans = (ans*i)%mod

for i in range(2, m+1):
    new = i**(mod-2)%mod
    ans = ans*new%mod


print ans


### FIXED CODE ###

from math import factorial
mod = int(1e+9 + 7)

X, Y = map(int, raw_input().split())

X2 = 2*X - Y
Y2 = -X + 2*Y

if X2 < 0:
    print "0"
    exit()
elif Y2 < 0:
    print "0"
    exit()

if X2%3 != 0:
    print "0"
    exit()
elif Y2%3 != 0:
    print "0"
    exit()

X2 = X2/3
Y2 = Y2/3

ans = 1

n = X2+Y2
m = Y2

for i in range(n-m+1, n+1):
    ans = (ans*i)%mod


new = 1
for i in range(2, m+1):
    new = (new*i)%mod

new = pow(new, mod-2, mod)

ans = (ans*new)%mod

print ans
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, k = [int(i) for i in input().split()]
p = [0] * n
for i,v in enumerate(input().split()):
    p[i] = 1.0 + 0.5 * (float(v) - 1.0)

_max_sum = 0
for i in range(n-k+1):
    _sum = sum(p[i:i+k])
    if _sum >= _max_sum:
        _max_sum = _sum
print(_max_sum)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, k = [int(i) for i in input().split()]
p = [0] * n
for i,v in enumerate(input().split()):
    p[i] = 1.0 + 0.5 * (float(v) - 1.0)

_max_sum = 0
_prev_sum = 0
for i in range(0, n-k+1):
    if i == 0:
        _sum = sum(p[:k])
    else:
        _sum = _prev_sum - p[i-1] + p[i+k-1]
    if _sum >= _max_sum:
        _max_sum = _sum
    _prev_sum = _sum
print(_max_sum)
### BUGGY CODE ###

s = input()
t = input()

def func(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

t_max = 10000
for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        tmp = func(s[i:i+len(t)], t)
        if tmp < t_max:
            t_max = tmp
print(t_max)


### FIXED CODE ###

s = input()
t = input()

def func(a,b):
    cnt = 0
    for c1,c2 in zip(a, b):
        if c1 != c2:
            cnt += 1
    return cnt

t_max = 10000
for i in range(len(s) - len(t) + 1):
    tmp = func(s[i:i+len(t)], t)
    if tmp < t_max:
        t_max = tmp
print(t_max)
### BUGGY CODE ###

s = input()
s = s[::-1]
mod = 10 ** 9 + 7
table = [[0] * 13 for _ in range(len(s) + 2)]
table[0][0] = 1
dd = 1
for c in range(len(s)):
    dd = (10 ** c) % 13
    if s[c] == "?":
        for n in range(10):
            for i in range(13):
                table[c + 1][(i + n * dd) % 13] += table[c][i]
    else:
        num = int(s[c])
        for i in range(13):
            table[c + 1][(i + num * dd) % 13] += table[c][i]

    for i in range(13):
        table[c + 1][i] %= mod
print(table[c + 1][5])

### FIXED CODE ###

s = input()
s = s[::-1]
mod = 10 ** 9 + 7
table = [[0] * 13 for _ in range(len(s) + 2)]
table[0][0] = 1
dd = 1
for c in range(len(s)):
    if s[c] == "?":
        for n in range(10):
            for i in range(13):
                table[c + 1][(i + n * dd) % 13] += table[c][i]
                table[c + 1][(i + n * dd) % 13] %= mod
    else:
        num = int(s[c])
        for i in range(13):
            table[c + 1][(i + num * dd) % 13] += table[c][i]
            table[c + 1][(i + num * dd) % 13] %= mod
    dd = (dd * 10) % 13
print(table[c + 1][5])
### BUGGY CODE ###

import sys
from collections import deque

N = int(input())
A = [deque([int(i) for i in input().split()]) for i in range(N)]

ans=0
n=0
first_fight = set([i for i in range(N)])
record = set()
first = True

while True:
    change=False
    stamina=[1]*N
    if first is True:
        pre_fight = first_fight
    else:
        pre_fight = record
        record = set()
    for g in pre_fight:
        if A[g]!=deque() and stamina[g]==1 and stamina[A[g][0]-1]==1:
            if g+1 == A[A[g][0]-1][0]:
                _pop = A[g].popleft()
                A[_pop-1].popleft()
                stamina[g]=0
                stamina[_pop-1]=0
                record.add(g)
                record.add(_pop-1)
                change=True
                n+=1
    first=False
    ans+=1
    if change is False:
        break
    if n==N*(N-1)//2:
        print(ans)
        sys.exit()

print(-1)

### FIXED CODE ###

import sys
from collections import deque

N = int(input())
A = [deque([int(i) for i in input().split()]) for i in range(N)]

ans=0
empty = [deque() for i in range(N)]
pre_fight = set([i for i in range(N)])
record = set()

while True:
    for g in pre_fight:
        if A[g]!=deque():
            if g+1 == A[A[g][0]-1][0]:
                record.add(g)
                record.add(A[g][0]-1)
    if record==set():
        break
    else:
        for i in record:
            A[i].popleft()
    ans+=1
    pre_fight = record
    record = set()
    if A==empty:
        print(ans)
        sys.exit()

print(-1)
### BUGGY CODE ###

S=input()
T=input()
dp=[ [0]*(len(T)+1) for i in range(len(S)+1) ]
for i in range(len(S)):
  for j in range(len(T)):
    if S[i]==T[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max( dp[i+1][j], dp[i][j+1] )

i=len(S)
j=len(T)
ans=''
while(i>0 and j>0):
  if dp[i][j]==dp[i-1][j]:
    i-=1
  elif dp[i][j]==dp[i][j-1]:
    j-=1
  else:
    ans=S[i-1]+ans
    i-=1
    j-=1
print(ans)

### FIXED CODE ###

S=input()
T=input()
dp=[ [0]*(len(T)+1) for i in range(len(S)+1) ]
for i in range(len(S)):
  for j in range(len(T)):
    if S[i]==T[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max( dp[i+1][j], dp[i][j+1] )

i=len(S)
j=len(T)
ans=''
while(i>0 and j>0):
  if dp[i][j]==dp[i-1][j]:
    i-=1
  elif dp[i][j]==dp[i][j-1]:
    j-=1
  else:
    ans=S[i-1]+ans
    i-=1
    j-=1
print(ans)
### BUGGY CODE ###

S = str(input())
Q = int(input())

head = ""
tail = ""
main = S

status = 0

while Q:
  Q -= 1
  l = list(map(str,input().split()))
  if l[0] == "1":
    status = (status+1)%2
  else:
    letter = l[2]
    if l[1] == "1":
      if status == 0:
        head += letter
      else:
        tail += letter
    else:
      if status == 0:
        tail += letter
      else:
        head += letter

if status == 0:
  print(head[::-1]+main+tail)
else:
  print(tail[::-1]+main[::-1]+head)

### FIXED CODE ###

from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])
### BUGGY CODE ###

n, m = map(int, input().split())
cards = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    cards += ([c] * b)

cards.sort(reverse=True)

print(sum(cards[:n]))

### FIXED CODE ###

import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))
### BUGGY CODE ###

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

PreYear = [[] for i in range(N)]
PY = [input().split(' ') for i in range(M)]
for i in range(M):
    Pi, Yi = PY[i]
    PreYear[int(Pi)-1].append(int(Yi))
order = []
for i in range(N):
    order.append(sorted(PreYear[i]))

for i in range(M):
    Pi, Yi = map(int,PY[i])
    count = order[Pi-1].index(Yi)
    count+=1
    print('{0:06d}{1:06d}'.format(Pi,count))


### FIXED CODE ###

from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])
### BUGGY CODE ###

s = input()
t = input()

#dp[i+1][j+1]:Sのi文字目までとTのj文字目まででのLCSの長さ

dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

res = ""
i = len(s)
j = len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = s[i-1] + res
        i -= 1
        j -= 1

print(res)

### FIXED CODE ###

s = input()
t = input()

#dp[i+1][j+1]:Sのi文字目までとTのj文字目まででのLCSの長さ

dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])


#復元
res = ""
i = len(s)
j = len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = s[i-1] + res
        i -= 1
        j -= 1

print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
  h,w=map(int,input().split())
  a=[list(map(lambda x:0 if x=='#' else -1,list(input()))) for _ in range(h)]
  todo=[]
  from collections import deque
  for i in range(h):
    for j in range(w):
      if a[i][j]==0:
        todo.append([i,j])
  todo=deque(todo)
  ans=0
  while todo:
    i,j=todo.popleft()
    d=a[i][j]+1
    ans=d-1
    if i>0 and a[i-1][j]==-1:
      a[i-1][j]=d
      todo.append([i-1,j])
    if i<h-1 and a[i+1][j]==-1:
      a[i+1][j]=d
      todo.append([i+1,j])
    if j>0 and a[i][j-1]==-1:
      a[i][j-1]=d
      todo.append([i,j-1])
    if j<w-1 and a[i][j+1]==-1:
      a[i][j+1]=d
      todo.append([i,j+1])
  print(ans)
if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())

### FIXED CODE ###

h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))
### BUGGY CODE ###

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

if n < 2:
    print(0)
    exit(0)

cum_r = [0] * (n + 1)
cum_g = [0] * (n + 1)
cum_b = [0] * (n + 1)

for i in range(n):
    cum_r[i + 1] = cum_r[i]
    cum_g[i + 1] = cum_g[i]
    cum_b[i + 1] = cum_b[i]
    if s[i] == "R":
        cum_r[i + 1] += 1
    elif s[i] == "G":
        cum_g[i + 1] += 1
    else:  # s[i] == "b":
        cum_b[i + 1] += 1

sum = 0
for i in range(n - 2):
    for k in range(n - 1, i + 1, -1):
        if s[i] == s[k]:
            continue

        # check "b"
        if (s[i] == "R" and s[k] == "G") or (s[i] == "G" and s[k] == "R"):
            sum += cum_b[k] - cum_b[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "B":
                sum -= 1
        elif (s[i] == "R" and s[k] == "B") or (s[i] == "B" and s[k] == "R"):
            sum += cum_g[k] - cum_g[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "G":
                sum -= 1
        else:
            sum += cum_r[k] - cum_r[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "R":
                sum -= 1

print(sum)


### FIXED CODE ###

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

if n < 2:
    print(0)
    exit(0)

cum_r = [0] * (n + 1)
cum_g = [0] * (n + 1)
cum_b = [0] * (n + 1)

for i in range(n):
    cum_r[i + 1] = cum_r[i]
    cum_g[i + 1] = cum_g[i]
    cum_b[i + 1] = cum_b[i]
    if s[i] == "R":
        cum_r[i + 1] += 1
    elif s[i] == "G":
        cum_g[i + 1] += 1
    else:  # s[i] == "b":
        cum_b[i + 1] += 1

sum = 0
for i in range(n - 2):
    for k in range(n - 1, i + 1, -1):
        if s[i] == s[k]:
            continue

        # check "b"
        if (s[i] == "R" and s[k] == "G") or (s[i] == "G" and s[k] == "R"):
            sum += cum_b[k] - cum_b[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "B":
                sum -= 1
        elif (s[i] == "R" and s[k] == "B") or (s[i] == "B" and s[k] == "R"):
            sum += cum_g[k] - cum_g[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "G":
                sum -= 1
        else:
            sum += cum_r[k] - cum_r[i + 1]
            if (k + i) % 2 == 0 and s[(k + i) // 2] == "R":
                sum -= 1

print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n,k,q = map(int,input().split())
l = [int(input()) for _ in range(q)]
l.sort()
ll = set(l)
l2 = []

for _ in ll:
	l2.append(l.count(_))

lll = list(ll)

for _ in range(1,n+1):
	if _ in lll:
		if k - q + l2[lll.index(_)] > 0:
			print('Yes')
		else:
			print('No')
	else:
		if k - q > 0:
			print('Yes')
		else:
			print('No')

### FIXED CODE ###

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

import numpy as np
a, b, c, n = map(int, input().split())
aa =[a,b,c]
r = max(aa)
b = min(aa)
g = int(np.median(aa))
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int(n/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):

            count +=1

print(count)


### FIXED CODE ###

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[2]
g = aa[1]
b = aa[0]
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count = count + 1
 
print(count)
### BUGGY CODE ###

N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
NN = [[0 for i in range(N)] for j in range(N)]
NN2 = [[0 for i in range(N)] for j in range(N)]
 
  
for i in range(N):
  for j in range(i,N):
    NN[i][j] = j-i
for i in range(N):
  for j in range(i+1,N):
    NN2[i][j] = abs(i-X)+abs(j-Y)+1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    if NN[i][j]>NN2[i][j]:
      CNT[NN2[i][j]] += 1
    else:
      CNT[NN[i][j]] += 1
for i in range(1,N):
  print(CNT[i])

### FIXED CODE ###

N, X, Y = map(int,input().split())
X = X-1
Y = Y-1
CNT = [0]*(N)
for i in range(N):
  for j in range(i+1,N):
    nn1 = j-i
    nn2 = abs(i-X)+abs(j-Y)+1
    if nn1>nn2:
      CNT[nn2] += 1
    else:
      CNT[nn1] += 1
for i in range(1,N):
  print(CNT[i])
### BUGGY CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
a.sort()

s = sum(a)

q = ii()

from bisect import bisect_left, bisect_right
def bisect_find(a, x):
    i = bisect_left(a, x)
    if i == len(a):
        return -1
    elif a[i] != x:
        return -1
    return i

def bisect_r_find(a, x):
    i = bisect_right(a, x)
    # if i == len(a):
    #     return -1
    return i

for i in range(q):
    b,c = mi()


    # 左を探す
    l = bisect_find(a,b)
    # 右を探す
    if l != -1:
        r = bisect_r_find(a[l:],b) + l
        # 個数をカウント
        count = r-l
        # 前回の合計との差を求める
        s = s + (c-b)*count

        # 配列を上書き
        # a[l:r] = [c]*count

        # print('a_p',a)

        if b > c:
            # j = bisect_left(a[:l],c)
            jr = bisect_right(a[:l],c)  
            jl = bisect_left(a[:jr],c)
            a = a[:jr] + [c]*count + a[jr:l] + a[r:]
        else:
            jl = bisect_left(a[r:],c) + r
            jr = bisect_right(a[jl:],c) + jl 
            # print('j',jl,jr,l,r)
            a = a[:l] + a[r:jl] + [c]*count  + a[jl:]
            # print(a[:l] , a[r:jl] , [c]*count  , a[jl:])

        # print('a',a)

        # a.sort()
    # print('-------------ans----------------',s)
    print(s)



    

### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
q = ii()

s = sum(a)

m = [0] * (10**5 + 1)
for i in range(n):
    m[a[i]] += 1

for i in range(q):
    b,c = mi()

    if m[b] == 0:
        print(s)
    else:
        count = m[b]

        s = s + (c-b)*count
        print(s)

        m[c] += count
        m[b] = 0
### BUGGY CODE ###

n = int(input())
a = 0
for i in range(n):
  a += i
print(a)

### FIXED CODE ###

n = int(input())
a = n*(n-1)//2
print(a)
### BUGGY CODE ###

N,M=map(int,input().split())
A=set(i for i in range(1,N+1))
for i in range(M):
    l,r=map(int,input().split())
    A=set(j for j in range(l,r+1) if j in A)
print(len(A))

### FIXED CODE ###

N,M=map(int,input().split())
ml=0
mh=N
for i in range(M):
    l,r=map(int,input().split())
    ml=max(ml,l)
    mh=min(mh,r)
print(max(0,mh-ml+1))
### BUGGY CODE ###

n, m = map(int, input().split())
ans = set(range(1,n+1))
for i in range(m):
  l, r = map(int, input().split())
  x = set(range(l, r+1))
  ans = ans & x
print(len(ans))

### FIXED CODE ###

n, m = map(int, input().split())
x = [1, n]
for i in range(m):
  l, r = map(int, input().split())
  x[0] = max(x[0], l)
  x[1] = min(x[1], r)
print(max(x[1] - x[0] + 1, 0))
### BUGGY CODE ###

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

    # asc
    asc_num = 0
    target = 1
    _dict = {}
    for P_i in P:
        del_flag = False
        if P_i not in _dict.keys() and P_i not in _dict.values():
            _dict[P_i] = P_i + 1
        for k, v in _dict.items():
            if v == P_i:
                _dict[k] = P_i + 1 
    for k, v in _dict.items():
        asc_num = max(asc_num, v-k)

    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)