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

n = int(input())
p = [0 for i in range(n)]
for i in range(n):
    p[i] = int(input())

visited = [0 for i in range(n)]
n_range = range(n)
for i in reversed(n_range):
    if visited[i] == 0:
        visited[i] = 1
        count = 1
        target = p[i] - 1
        for j in reversed(range(i)):
            if p[j] == target:
                count += 1
                visited[j] = count
                target -= 1
print(n - max(visited))


### FIXED CODE ###

n = int(input())
p = [0 for i in range(n)]
for i in range(n):
    p[i] = int(input())

visited = [0 for i in range(n+1)]

"""
for i in reversed(range(n)):
    if visited[i] == 0:
        visited[i] = 1
        count = 1
        target = p[i] - 1

        for j in reversed(range(i)):
            if p[j] == target:
                count += 1
                visited[j] = count
                target -= 1
"""
for i in range(n):
    visited[p[i]] = visited[p[i] - 1] + 1
print(n - max(visited))
### BUGGY CODE ###

import queue
def main():
    n,m,k=map(int,input().split())
    root={}
    ng={}
    for i in range(n):
        root[i]=[]
        ng[i]=[i]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
    for i in range(k):
        a,b=map(int,input().split())
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    
    Vstd=[]
    checkVst=[0]*n
    num=[0]*n
    ToVst=queue.Queue()
    for i in range(n):
        Vstd=[]
        if checkVst[i]==1:
            continue
        now=i
        Vstd.append(now)
        checkVst[now]=1
        for kouho in root[now]:
            if checkVst[kouho]!=1:
                ToVst.put(kouho)
                checkVst[kouho]=1
        while ToVst.empty()==False:
            now=ToVst.get()
            Vstd.append(now)
            checkVst[now]=1
            for kouho in root[now]:
                if checkVst[kouho]==1:
                    continue
                ToVst.put(kouho)
                checkVst[kouho]=1

        l=len(Vstd)
        for x in Vstd:
            num[x]=l
            for y in Vstd:
                if y in ng[x] or y in root[x]:
                    num[x]-=1
    print(*num)
    #print(" ".join(map(str,num)))
   

if __name__=="__main__":
    main()
    
        

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m,k=map(int,input().split())
uf=UnionFind(n)
block={}
for i in range(n):
    block[i]=[i]
for i in range(m):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
    block[a-1].append(b-1)
    block[b-1].append(a-1)
    
for i in range(k):
    a,b=map(int,input().split())
    block[a-1].append(b-1)
    block[b-1].append(a-1)
ans=[]
#print(block)
for i in range(n):
    res=uf.size(i)
 #   print(res)
    for value in block[i]:
        if uf.same(value,i):
            res-=1
    ans.append(res)
print(*ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
sum=int(0)
for i in range(Q):
    B.append(list(map(int,input().split())))
for i in range(Q):
    for j in range(N):
        if A[j]==B[i][0]:
            A[j]=B[i][1]
    for k in range(N):
        sum += int(A[k])
    print(sum)
    sum=int(0)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for i in range(Q):
    B.append(list(map(int,input().split())))
sum=int(0)
AA=[int(0)]
for i in range(100000):
    AA.append(int(0))
for i in A:
    AA[i]+=1 #A.count(int(i))
#for i in range(5):
#    print(AA[i])
sum=int(0)
for i in range(N):
    sum += A[i]
for i in range(Q):
#    AA[(B[i][0])]=A.count(int((B[i][0])))
#    A.replace(B[i][0],B[i][1])
#    AA[(B[i][1])]=A.count(int((B[i][1])))
    sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]
    AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]
    AA[(B[i][0])] = 0
    print(sum)
### BUGGY CODE ###

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

for k in range(n-1):
    for j in range(k,n): #nC2通りを再現
        if (j+1)-a[j] == a[k]+k+1:
            count += 1
            
print(count)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
count = 0
b = []
c = []

for i in range(n):
    b.append(a[i]+i)
    c.append(i-a[i])
t = Counter(c) 
for s in b:
    count += t[s]

print(count)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if i == 0:
        ans = a[1:]
    if i == n:
        ans = a.pop(n)
    ans = a[:i] + a[i+1:]
    print(max(ans))

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
s = sorted(a)
for j,k in enumerate(a):
    print(s[-2]) if k == s[-1] else print(s[-1])
### BUGGY CODE ###

# D - AtCoder Express 2

import bisect

N, M, Q = map(int, input().split())
LRidx = [list(map(int, input().split())) + [i] for i in range(M)]
p, q = [], []
for _ in range(Q):
    tmp_p, tmp_q = map(int, input().split())
    p.append(tmp_p)
    q.append(tmp_q)
    
LRidx = sorted(LRidx, key = lambda x: x[0])
tmp_L = [LRidx[idx][0] for idx in range(M)]
l_ok_idx = [[] for _ in range(Q)]
for i in range(Q):
    try:
        for j in range(bisect.bisect_left(tmp_L, p[i]), M):
            l_ok_idx[i].append(LRidx[j][2])
    except:
        pass
    
LRidx = sorted(LRidx, key = lambda x: x[1])
tmp_R = [LRidx[idx][1] for idx in range(M)]
r_ok_idx = [[] for _ in range(Q)]
for i in range(Q):
    if bisect.bisect_right(tmp_L, p[i]) > 0:
        for j in range(bisect.bisect_right(tmp_R, q[i])):
            r_ok_idx[i].append(LRidx[j][2])
    
for i in range(Q):
    print(len(set(l_ok_idx[i]) & set(r_ok_idx[i])))

### FIXED CODE ###

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
LR = np.zeros((N+1, N+1))

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

np.cumsum(LR, axis = 0, out = LR)
np.cumsum(LR, axis = 1, out = LR)
    
for _ in range(Q):
    p, q = map(int, input().split())
    print(int(LR[q,q] - LR[p-1,q] - LR[q,p-1] + LR[p-1,p-1]))
### BUGGY CODE ###

R,G,B,N=(int(x) for x in input().split())
count=0
for r in range(0,N+1):
    if (r*R>N):
        break
    for g in range(0,N-r*R+1):
        if((N-r*R-g*G)%B==0 and (N-r*R-g*G)/B>=0):
            count+=1
print(count)

### FIXED CODE ###

R,G,B,N=(int(x) for x in input().split())
count=0
for r in range(0,N+1):
    if (r*R>N):
        break
    for g in range(0,N-r*R+1):
        if(r*R-g*G>N):
            break
        elif((N-r*R-g*G)%B==0 and (N-r*R-g*G)/B>=0):
            count+=1
print(count)
### BUGGY CODE ###

K, S = map(int,input().split())

answer = 0

for i in range(K + 1):
    for j in range(K + 1):
        for k in range(K + 1):
            if i + j + k == S:
                answer += 1

print(answer)

### FIXED CODE ###

K, S = map(int,input().split())

answer = 0

for i in range(K + 1):
    for j in range(K + 1):
        if 0 <= S - i - j <= K:
            answer += 1

print(answer)
### BUGGY CODE ###

import numpy as np

#def f(x,a):
#  return np.array([ c^x for c in a ],dtype=np.int64).sum()

def g(y,s):
  return np.array([s[m,y[m]] for m in range(M)]).sum()

(N,K) = map(int,input().split())
A = np.array(list(map(int,input().split())),dtype=np.int64)
M=40

B = np.empty((M,N),dtype=np.int)
Y = np.empty(M,dtype=np.int)

for n in range(N):
  for m in range(M):
    B[m,n] = (A[n] >> m) & 1

S = np.empty((M,2),dtype=np.int64)
for m in range(M):
  s = B[m].sum()
  S[m] = [s<<m,(N-s)<<m]
  if 2*s < N:
    Y[m] = 1
  else:
    Y[m] = 0

Kb = np.array([ ((K+1) >> m) & 1 for m in range(M)],dtype=np.int)

ans = 0
for m in range(M):
  if Kb[m] == 0:
    continue
  else:
    Z = np.concatenate((Y[:m],np.array([0],dtype=np.int),Kb[m+1:]))
    ans = max(ans,g(Z,S))

print(ans)

### FIXED CODE ###

inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()

L = K+1
M = len(bin(L))-2
MM = max(M, len(bin(max(A)))-2)
best = []
ones_num = []
zeros_num = []
for m in range(MM):
    ones = sum([ (A[i]>>m)&1 for i in range(N) ])
    zeros = N - ones
    ones_num.append(ones)
    zeros_num.append(zeros)
    if ones >= zeros:
        best.append(0)
    else:
        best.append(1)
cur = sum([ (N-ones_num[m] if (best[m] and m < M-1) else ones_num[m])<<m for m in range(MM)])
ans = cur
m = M - 1
while m > 0:
    cur += (zeros_num[m]-ones_num[m])<<m
    m -= 1
    while (L >> m)&1 == 0:
        if best[m] == 1:
            cur += (ones_num[m]-zeros_num[m])<<m
        m -= 1
        if m < 0:
            break
    else:
        if best[m] == 1:
            cur += (ones_num[m]-zeros_num[m])<<m
        if cur > ans:
            ans = cur
print(ans)
### BUGGY CODE ###

import sys
import heapq
from collections import defaultdict
N, Q = map(int, input().split())
events = []

for i in range(N):
    s, t, x = map(int, sys.stdin.readline().split())
    events.append([s - x, '2-add', x])
    events.append([t - x, '1-delete', x])

events.sort()
events.append([float('inf'), 'guard', None])

i = 0
closing = set()
hq = []  # 最小値を高速に入手するため
for q in range(Q):
    d = int(input())
    while d >= events[i][0]:
        time, event, x = events[i]
        if event == '2-add':
            closing.add(x)
            heapq.heappush(hq, x)

        elif event == '1-delete':
            closing.remove(x)

        i += 1

    while hq and (hq[0] not in closing):
        heapq.heappop(hq)

    if hq:
        print(hq[0])
    else:
        print(-1)


### FIXED CODE ###

def main():

    import sys
    import heapq

    N, Q = map(int, sys.stdin.readline().split())
    events = []

    for i in range(N):
        s, t, x = map(int, sys.stdin.readline().split())
        events.append((s - x, 1, x))  # 通行止め追加
        events.append((t - x, -1, x))  # 通行止め削除

    for i in range(Q):
        d = int(input())
        events.append((d, 2, 0))

    events.sort()
    events.append([float('inf'), 'guard', None])

    i = 0
    closing = set()
    hq = []  # 最小値を高速に入手するため
    while d >= events[i][0]:
        time, event, x = events[i]
        if event == 1:
            closing.add(x)
            heapq.heappush(hq, x)

        elif event == -1:
            closing.remove(x)

        else:
            while hq and (hq[0] not in closing):
                heapq.heappop(hq)

            if hq:
                print(hq[0])
            else:
                print(-1)

        i += 1


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

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

Al = 0
cnt = 0
def solution(N,A,B,Al,cnt):
  for a in B:
      cnt = A.count(a)
      Al +=  cnt*(cnt-1)//2

  for k in range(N):
      cnt = A.count(A[k])
      print(Al - cnt +1)
solution(N,A,B,Al,cnt)


### FIXED CODE ###

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

from collections import Counter
cnt_A = Counter(A)

All = 0
cnt = 0
for a in B:
    cnt = cnt_A[a]
    All +=  cnt*(cnt-1)//2

for k in range(N):
    ans_k = 0
    cnt = cnt_A[A[k]]
    ans_k = cnt - 1
    Ans = All - ans_k
    print(Ans)
### BUGGY CODE ###

n,w = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= WV[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-WV[i][0]]+WV[i][1])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])

### FIXED CODE ###

n,w = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= WV[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-WV[i][0]]+WV[i][1])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])
### BUGGY CODE ###

def get_subordinate(n, members):

    for i in range(1, n+1):
        occur = members.count(i)
        print(occur)
        

if __name__ == '__main__':
    n = int(input())
    members = list(map(int, input().rstrip().split()))
    get_subordinate(n, members)



### FIXED CODE ###

def get_subordinate(n, members):
    new_dict = {}

    for i in range(1, n+1):
        new_dict[i] = 0

    for member in members:
        if member in new_dict:
            new_dict[member] += 1

    print(*new_dict.values(), sep="\n")


if __name__ == '__main__':
    n = int(input())
    members = list(map(int, input().rstrip().split()))
    get_subordinate(n, members)
### BUGGY CODE ###

n,m=map(int,input().split())
edges=[[] for i in range(1+n)]
for i in range(m):
    """#weighted->erase_,__,___=map(int,input().split())
    edges[_].append((__,___))
    #undirected->erase#edges[__].append((_,___))
    """
    _,__=map(int,input().split())
    edges[_].append(__)
    #undirected->erase#edges[__].append(_)
    """
"""#weighted->erase
s,t=map(int,input().split())
r1,r2,r0=set(),set(),set()
from collections import deque
d0=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
d1=deque([])
d2=deque([])
d0.append((s,0))
r0.add(s)
while d0 :
    while d0:
        a,c=d0.pop()
        for ne in edges[a]:
            if ne not in r1:d1.appendleft((ne,c))
    while d1:
        a,c=d1.pop()
        for ne in edges[a]:
            if ne not in r2:d2.appendleft((ne,c))
    while d2:
        a,c=d2.pop()
        for ne in edges[a]:
            if ne not in r0:
                if ne != t:d0.appendleft((ne,c+1))
                else:print(c+1);exit()
print(-1)

### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")
### BUGGY CODE ###

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
A = []
for a in map(int,input().split()):
    A.append(a)
A.sort()
c = 0
lenA = len(A)
for i in range(lenA):
    Ai = A[i]
    if i < lenA - 1:
        if Ai == A[i + 1]:
            continue
    Ad = make_divisors(Ai)
    sAd = set(Ad)
    l = A[:i]
    sl = set(l)
    s = sl - sAd
    if len(sl) == len(s):
        c += 1
print(c)

### FIXED CODE ###

N = int(input())
c=[0]*8**7
for a in input().split():
    c[int(a)] += 1
i=r=0
for t in c:
    if t:
        c[::i]=[0]*-(-8**7//i)
    i+=1
    r+=t==1
print(r)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1001001001001001001] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1001001001001001001] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])
### BUGGY CODE ###

N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)

for r in R:
  for g in G:
    for b in B:
      i=min(min(r,g),b)
      k=max(max(r,g),b)
      if r!=i and r!=k:
        j=r
      elif g!=i and g!=k:
        j=g
      else:
        j=b
      
      if j-i!=k-j:
        ans+=1
print(ans)
      
      

### FIXED CODE ###

import math
N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)
ans=len(R)*len(G)*len(B)

for r in R:
  for g in G:
    if (r+g)%2==0:
      if S[(r+g)//2]=="B":
        ans-=1
    
for r in R:
  for b in B:
    if(r+b)%2==0:
      if S[(r+b)//2]=="G":
        ans-=1
    
for g in G:
  for b in B:
    if (g+b)%2==0:
      if S[(g+b)//2]=="R":
        ans-=1
    
print(ans)
### BUGGY CODE ###

import heapq

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

ab = [None] * N

for i in range(N):
    a,b = map(int, input().split())
    ab[i] = [a,-b]

q = []
ans = 0
for day in range(1, M+1):
    for i in range(N):
        if ab[i][0] == day:
            heapq.heappush(q, ab[i][1])

    if q != None and len(q) != 0:
        ans += -1 * heapq.heappop(q)

print(ans)

### FIXED CODE ###

import heapq

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

ab = {}

for i in range(N):
    a,b = map(int, input().split())
    if not a in ab:
        ab[a] = [-b]
    else:
        ab[a].append(-b)


q = []
ans = 0
for day in range(1, M+1):
    if day in ab:
        for i in ab[day]:
            heapq.heappush(q, i)

    if q != None and len(q) != 0:
        ans += -1 * heapq.heappop(q)

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

def resolve():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    A = [[]] * N
    for i in range(M):
        pp, ss = map(int, input().split())
        ss -= 1
        pp -= 1
        A[pp] = A[pp] + [H[ss]]
        A[ss] = A[ss] + [H[pp]]

    ans = 0
    for j in range(N):
        now = H[j]
        if not A[j] or now > max(A[j]):
            ans += 1

    print(ans)


resolve()

### FIXED CODE ###

def resolve():
    n, m = map(int, input().split())
    hhh = list(map(int, input().split()))
    nice = [1] * n

    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        ha = hhh[a]
        hb = hhh[b]
        if ha <= hb:
            nice[a] = False
        if ha >= hb:
            nice[b] = False

    print(sum(nice))


resolve()
### BUGGY CODE ###

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

import sys
sys.setrecursionlimit(2147483647)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans=1
for i in range(1,k+1):
    ans+=(cmb(n, i, p)*cmb(n-1,n-i-1,p))%p
    
    #print(i,cmb(n, i, p),cmb(n-1,n-i-1,p))

print(ans%p)
    


### FIXED CODE ###

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

import sys
sys.setrecursionlimit(2147483647)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 #割る数
N = 2*n+1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans=1

if k>n:
    ans=cmb(n+n-1,n,p)

else:

    for i in range(1,k+1):
        ans+=(cmb(n, i, p)*cmb(n-1,n-i-1,p))%p
        
        #print(i,cmb(n, i, p),cmb(n-1,n-i-1,p))

print(ans%p)
### BUGGY CODE ###

import collections
from scipy.special import comb

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

cc = collections.Counter(a)
b = [c[1] for c in cc.items()]
x = len(b)
t = 0
for i in range(x):
  t += comb(b[i], 2)

for i in range(n):
  y = a.count(a[i])
  if y >=2:
    ans = t - comb(y,2) + comb(y-1,2)
  else:
    ans = t
  print(int(ans))

### FIXED CODE ###

import collections

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

c = collections.Counter(a)
for i in c:
  cnt += c[i]*(c[i]-1)//2



for i in range(n):
	print(cnt-c[a[i]]+1)
### BUGGY CODE ###

# TLE
def test():
    duplication = {}
    ans = 0
    for x in A:
        if x in duplication:
            continue
        count = A.count(x)
        if count > 0:
            duplication[x] = count
            ans += count*(count-1)//2
    for x in A:
        print(ans -(duplication[x]-1))

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
def test2():
    sum = 0
    count_dic = defaultdict(int)
    for x in A:
        count_dic[x] +=1
    for v in count_dic.values():
        sum += v*(v-1)//2
    for x in A:
       print(sum -(count_dic[x]-1))
test()

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
# TLE
def test():
    duplication = {}
    ans = 0
    for x in A:
        if x in duplication:
            continue
        count = A.count(x)
        if count > 1:
            duplication[x] = count
            ans += count*(count-1)//2
    for x in A:
        if x not in duplication:
            print(ans)
        else:
            print(ans -(duplication[x]-1))
from collections import defaultdict

sum = 0
count_dic = defaultdict(int)
for x in A:
    count_dic[x] +=1
for v in count_dic.values():
    sum += v*(v-1)//2
for x in A:
    print(sum -(count_dic[x]-1))
### BUGGY CODE ###

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

X = sum(a)

ans = []
for i in range(1, N):
    ans.append(abs(X - 2*sum(a[:i])))

print(min(ans))


### FIXED CODE ###

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

X = sum(a)
b = [a[0]]
for i in range(1, N - 1):
    b.append(b[i-1] + a[i])

ans = []
for i in range(0, N - 1):
    ans.append(abs(X - 2*b[i]))

print(min(ans))