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

def find(e):
  if parent[e] == e:
    return e
  return find(parent[e])
n, m = map(int,input().split())
l = []
for _ in range(m):
  p, q = map(int,input().split())
  p -= 1
  q -= 1
  if (p,q) not in l:
    l.append((p,q))
parent = [i for i in range(n)]
rank = [0 for i in range(n)]
for i,j in l:
  x = find(i)
  y = find(j)
  if rank[x]<rank[y]:
      parent[x] = y
      rank[y] += 1
  else:
      parent[y] = x
      rank[x] += 1
dic = {}
for i in parent:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
mx = 0
for i in dic.values():
    mx = max(mx,i)
print(mx)


### FIXED CODE ###

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

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

n,m = map(int,input().split())
uf1=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf1.union(a-1,b-1)

for i in range(n):uf1.find(i)
X = uf1.par

ans = [0]*n
for i in range(n):
    ans[X[i]] += 1

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

def f(a,b):
  return max(len(str(a)),len(str(b)))

N = int(input())
n = N
ans = N

for _ in range(1,int(n/2)+1):
  if n % _ == 0:
#    print("{}: {} {}".format(f(_,N/_),_,int(N/_)))
    if ans >= f(_,int(N/_)):
      ans = f(_,int(N/_))
    else:
      break
print(ans)

### FIXED CODE ###

import math
def f(a,b):
  return max(len(str(a)),len(str(b)))

N = int(input())
n = N
ans = N

for _ in range(1,int(math.sqrt(n))+1):
  if n % _ == 0:
#    print("{}: {} {}".format(f(_,N/_),_,int(N/_)))
    if ans >= f(_,int(N/_)):
      ans = f(_,int(N/_))
    else:
      break
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

# a1,...,anがdivisorで割り切れる、すなわちdivisorはMの約数である
divisor=m//n
while m%divisor!=0:
    divisor-=1
print(divisor)


### FIXED CODE ###

# できなかった
# a1,...,anがdivisorで割り切れる、すなわちdivisorはMの約数である
n,m=map(int,input().split())

divisors=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        divisors.append(i)
        if i!=m//i:
            divisors.append(m//i)

divisors.sort(key=lambda x:-x)
# print(divisors)
for d in divisors:
    if d<=m//n:
        print(d)
        break
### BUGGY CODE ###

from collections import deque
n=int(input())
data=[deque(map(int,input().split())) for i in range(n)]
count=[[0]*(n-1) for i in range(n)]
last=n*(n-1)
count=0
while last:
	flag=0
	count+=1
	taisenzumi=[]
	for i in range(n):
		if i in taisenzumi:continue
		if data[i]:
			aite=data[i][0]
			# print(data[i],aite)
			if (aite-1) in taisenzumi:continue
			# print(data[i],aite)
			if data[aite-1][0]==i+1:
				data[i].popleft()
				data[aite-1].popleft()
				taisenzumi.append(aite-1)
				taisenzumi.append(i)
				last-=2
				flag=1
			else:continue
	if not flag:
		break
else:
	print(count)
	exit()
print(-1)




### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    M=[None]*n
    for i in range(n):
        M[i]=list(map(lambda x:int(x)-1,input().split()))[::-1]

    # i が誰かしらと対戦できるか
    def check(i):
        if(not M[i]): # 既に試合を終えている
            return False
        j=M[i][-1]
        if(not M[j]): # これは起こり得ない
            return False
        return i==M[j][-1]

    # 初日に対戦できる人をピックアップ
    # 重複が起こるが、後で unique を取る
    Q=[]
    for i in range(n):
        if(check(i)):
            j=M[i][-1]
            if(i>j): i,j=j,i # i<j
            Q.append((i,j))

    # 処理を行なっていく
    day=0
    nQ=[] # 次の試合相手
    while(Q):
        # Q には重複があるので unique
        Q=list(set(Q))
        # 先に全ての試合を終わらせる必要がある
        for i,j in Q:
            M[i].pop(); M[j].pop()
        # 試合を終えた人は次の試合を行える可能性がある
        for i,j in Q:
            if(check(i)):
                k=M[i][-1]
                nQ.append((min(i,k),max(i,k)))
            if(check(j)):
                k=M[j][-1]
                nQ.append((min(j,k),max(j,k)))
        Q,nQ=nQ,[]
        day+=1

    print(day if(all(M[i]==[] for i in range(n))) else "-1")
resolve()
### BUGGY CODE ###

s=input()
k=int(input())
str=[]
p=1
for i in range(len(s)):
    for j in range(len(s)):
        if j+i+1<=len(s):
            str.append(s[j:j+i+1])
    str=list(set(str))
str.sort()
print(str[k-1])

### FIXED CODE ###

s=input()
k=int(input())
str=[]
p=1
for i in range(k):
    for j in range(0,len(s)-i):
        str.append(s[j:j+i+1])
str=list(set(str))
str.sort()
print(str[k-1])
### BUGGY CODE ###

from collections import defaultdict
def solve():
    N = int(input())
    S2 = [0]*N
    for i in range(N):
        S2[i] = input()
    check = defaultdict(lambda: [[0]*(N+1) for _ in range(N+1)])
    cum = defaultdict(lambda: [[0]*(N+1) for _ in range(N+1)])
    for i in range(N):
        for j in range(N):
            for k in range(-N+1,i+1):
                check[k][i+1][j+1] = S2[i][j]==S2[(j+k)%N][(i-k)%N]
    for i in range(1,N+1):
        for j in range(1,N+1):
            for k in range(-N+1,N):
                cum[k][i][j] = cum[k][i-1][j]+cum[k][i][j-1]-cum[k][i-1][j-1]+check[k][i][j]
    ans = 0
    for k in range(-N+1,N):
        ans += (cum[k][-1][-1]==N*N)*N
    return ans
print(solve())

### FIXED CODE ###

def solve():
    N = int(input())
    S2 = [0]*N
    for i in range(N):
        S2[i] = input()
    ans = 0
    for k in range(N):
        cum = [[0]*(N+1) for _ in range(N+1)]
        for i in range(1,N+1):
            for j in range(1,N+1):
                cum[i][j] = cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+(S2[i-1][j-1]==S2[(j-1+k)%N][(i-1-k)%N])
                if i==N and j==N:
                    ans += (cum[i][j]==N*N)*N
    return ans
print(solve())
### BUGGY CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))

for a in A:
  A = np.delete(A,np.where((A%a==0) & ((A!=a) | (2<=len(np.where(A==a)[0])))))

print(len(A))

### FIXED CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
B = (10**6+1)*[0]

for a in A:
  B[a]+=1
  if B[a]==1:
    for n in range(2*a,10**6+1,a):
      B[n]+=10

print(B.count(1))
### BUGGY CODE ###

from collections import deque

def main():
    n, m = list(map(int, input().split(" ")))
    v_set = [set([]) for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split(" ")))
        v_set[a-1].add(b-1)
        v_set[b-1].add(a-1)

    max_num = 0
    seen = [0]*n
    for ni in range(n):
        if seen[ni]:
            continue
        checked = [0]*n
        stack = deque([ni])
        checked[ni] = 1
        while stack:
            cur = stack.pop()
            seen[cur]+=1
            for next_i in v_set[cur]:
                if seen[next_i] or checked[next_i]:
                    continue
                stack.append(next_i)
                checked[next_i] = 1
        max_num = max(max_num, sum(checked))

    print(max_num)

if __name__=="__main__":
    main()


### FIXED CODE ###

from collections import deque

def main():
    n, m = list(map(int, input().split(" ")))
    v_set = [set([]) for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split(" ")))
        v_set[a-1].add(b-1)
        v_set[b-1].add(a-1)

    max_num = 0
    checked = [0]*n
    for ni in range(n):
        if checked[ni]:
            continue
        stack = deque([ni])
        checked[ni] = 1
        f = 1
        while stack:
            cur = stack.pop()
            for next_i in v_set[cur]:
                if checked[next_i]:
                    continue
                stack.append(next_i)
                checked[next_i] = 1
                f+=1
        max_num = max(max_num, f)

    print(max_num)

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

N=int(input())
listA=list(map(int,input().split()))
ans=0
index=[]
for i in range(N):
  index+=[[listA[i],i]]
index.sort()
for i in range(N):
  if index[i][0]<N:
    for k in range(i+1,N):
      if index[k][0]<N:
        if abs(index[k][1]-index[i][1])==index[k][0]+index[i][0]:
          ans+=1
      else:
        break
  else:
    break
print(ans)        

### FIXED CODE ###

N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)
### BUGGY CODE ###

from collections import deque
import sys

N=int(input())
A=deque(map(int,input().split()))
setA=set(A)
number1={}#-1
number2={}
ans={}
if(len(setA)==1):
    answer= len(A) - 1
    q=(answer - 1) * answer //2
    for _ in range(len(A)):
        print(q)
    sys.exit()


if(len(setA)==len(A)):
    for _ in range(len(A)):
        print(0)
    sys.exit()


for i in setA:
    tmp=A.count(i) - 1
    souwa=(tmp - 1)*(tmp)//2
    number1[i]=souwa
    souwa=tmp*(tmp+1)//2
    number2[i]=souwa

t=sum(number2.values())

for a in setA:
    total=number1[a]
    total+=t
    total-=number2[a]
    ans[a]=total

for a in A:
    print(ans[a])




### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
d=Counter(A)
dic={}
total=0
for item in d.items():
    counter=item[1]
    s1=(counter - 1)*(counter - 2)/2 #1個少ない
    s2=(counter)*(counter - 1)/2
    dic[item[0]]=int(s1 - s2)
    total+=int(s2)

for a in A:
    print(total + dic[a])
### BUGGY CODE ###

import numpy as np
from collections import defaultdict
N,T = map(int,input().split())
A = list(map(int,input().split()))
d = defaultdict(lambda:0)
for i in range(N-1):
    a = A[i+1:]
    d[max(a)-A[i]] += 1
print(d[max(d.keys())])

### FIXED CODE ###

N,T = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
Min = A[0]
Profit = 0
for i in range(1,N):
    if A[i]-Min > Profit:
        Profit = A[i]-Min
        ans = 1
    elif A[i]-Min == Profit:
        ans += 1
    Min = min(A[i],Min)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)

def main():
    n=int(input())
    nodes=[[]for _ in range(n)]
    mod=10**9+7

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

    def pick(n,excep=-1):
        white=1
        black=1
        for node in nodes[n]:
            if excep==node:
                continue
            p=pick(node,n)
            white=(white*(p[0]+p[1]))%mod
            black=(black*p[0])%mod
        return [white,black]
    p=pick(0)
    print(sum(p)%mod)
main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

def main():
    n=int(input())
    nodes=[[]for _ in range(n)]
    mod=10**9+7

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

    def pick(n,excep=-1):
        white=1
        black=1
        for node in nodes[n]:
            if excep==node:
                continue
            p=pick(node,n)
            white=(white*(p[0]+p[1]))%mod
            black=(black*p[0])%mod
        return [white,black]
    p=pick(0)
    print(sum(p)%mod)
main()
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
def combination_to_index(a,b,n):
    if(b<a):
        a,b = b,a
    return (2*n-a)*(a-1)//2+b-a

def main():
    N = int(input())
    M = N*(N-1)//2
    gp = [[] for _ in range(M+1)]
    cnts = [0]*(M+1)
    for a in range(1,N+1):
        A = [int(x) for x in input().split()]
        for ind,b in enumerate(A[:-1]):
            fr = combination_to_index(a,b,N)
            to = combination_to_index(a,A[ind+1],N)
            gp[fr].append(to)
            cnts[to] += 1

    for ind,i in enumerate(cnts):
        if(i==0 and ind!=0):
            gp[0].append(ind)
            cnts[ind]+=1

    ans = 0
    cnt = 0
    stk = deque()
    stk.append((0,0))
    while stk:
        n,ans = stk.popleft()
        for x in gp[n]:
            cnts[x]-=1
            if(cnts[x]==0):
                stk.append((x,ans+1))
                cnt += 1
    if(cnt!=M):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
def combination_to_index(a,b,n):
    if(b<a):
        a,b = b,a
    return (2*n-a)*(a-1)//2+b-a

def main():
    N = int(input())
    M = N*(N-1)//2
    gp = [[] for _ in range(M+1)]
    cnts = [0]*(M+1)
    for a in range(1,N+1):
        A = [int(x) for x in input().split()]
        for ind,b in enumerate(A[:-1]):
            fr = combination_to_index(a,b,N)
            to = combination_to_index(a,A[ind+1],N)
            gp[fr].append(to)
            cnts[to] += 1

    for ind,i in enumerate(cnts):
        if(i==0 and ind!=0):
            gp[0].append(ind)
            cnts[ind]+=1

    ans = 0
    cnt = 0
    stk = deque()
    stk.append((0,0))
    while stk:
        n,ans = stk.popleft()
        for x in gp[n]:
            cnts[x]-=1
            if(cnts[x]==0):
                stk.append((x,ans+1))
                cnt += 1
    if(cnt!=M):
        print(-1)
    else:
        print(ans)

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
for i in range(m):
  a[-1] = a[-1] / 2
  a = sorted(a)
print(int(sum( i//1 for i in a)))

### FIXED CODE ###

def main():
  import heapq
  n,m = map(int,input().split())
  a =sorted(list(map(lambda x: int(x)*(-1),input().split())))
  heapq.heapify(a)
  for _ in range(m):
    x=heapq.heappop(a)/2
    heapq.heappush(a,x) 
  print(int(sum((-1)*i//1 for i in a)))
if __name__=='__main__':
  main()
### BUGGY CODE ###

import itertools
N = int(input())
A = [[int(i) for i in input().split()] for j in range(N)]
Node = [int(i) for i in range(N)]
Comb = list(itertools.combinations(Node, 2))

Possible = True
Total, count = 0, 0
while count < N * (N-1) // 2:
    for c in Comb:
        a, i, j = A[c[0]][c[1]], c[0], c[1]
        count += 1
        MinDist = float("inf")
        for k in range(N):
            if k != i and k != j:
                if a > A[i][k] + A[k][j]:
                    count = N**2
                    break
                else:
                    MinDist = min(MinDist, A[i][k] + A[k][j])
        else:
            Total += (a if MinDist > a else 0)
        
if count == N*(N-1)//2:
    print(Total)
else:
    print(-1)

### FIXED CODE ###

import sys
from itertools import permutations, combinations
  
def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [[int(a) for a in input().split()] for _ in range(N)]

    length = 0
    possible = True
    for a, b in combinations(range(N), 2):
        Lab = A[a][b]
        create_pass = True
        for k in range(N):
            if k != a and k != b:
                if Lab >  A[a][k] + A[k][b]:
                    possible = False
                    break
                elif Lab ==  A[a][k] + A[k][b]:
                    create_pass = False
                    break
        if create_pass: length += Lab
        if not possible:
            print(-1)
            break
    else: print(length)
    
    return 0
  
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

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

counter = 0
for i in range(10):
    str_i = str(i)
    for j in range(10):
        str_j = str(j)
        for k in range(10):
            str_k = str(k)

            ok_i = False
            ok_j = False

            for _s in s:
                if not ok_i:
                    if _s == str_i:
                        ok_i = True
                else:
                    if not ok_j:
                        if _s == str_j:
                            ok_j = True
                    else:
                        if _s == str_k:
                            counter += 1
                            break

print(counter)

### FIXED CODE ###

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

counter = 0
for i in range(10):
    str_i = str(i)
    i_dig = s.find(str_i)
    if i_dig == -1:
        continue

    for j in range(10):
        str_j = str(j)
        j_dig = s.find(str_j, i_dig+1)
        if j_dig == -1:
            continue
        
        for k in range(10):
            str_k = str(k)
            k_dig = s.find(str_k, j_dig+1)
            if k_dig != -1:
                counter += 1

print(counter)
### BUGGY CODE ###

def BinarySearch(lis, i, j):
    low, high = 0, len(lis)
    border = j-i
    while low < high:
        key = (low+high)//2
        value = lis[key]
        if value <= border:
            low = min([key, low]) + 1
        else:
            high = max([key, high]) - 1
    return low

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = i-BinarySearch(l, l[i], l[j])
        ans += max([key, 0])
print(ans)

### FIXED CODE ###

import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)
### BUGGY CODE ###

import itertools
import numpy

n = int(input())

seq = []
for _ in range(n):
  i = list(map(int, input().split(" ")))
  seq.append(i)
  
count = 0
results = []
for path in itertools.permutations(seq):
  pwd = None
  count += 1
  for p in path:
    if pwd is None:
      pwd = p
    else:
      a = numpy.array(pwd)
      b = numpy.array(p)
      u = b - a
      results.append(numpy.linalg.norm(u))
      pwd = p
print(sum(results) / count)

### FIXED CODE ###

import itertools
import numpy
import math

n = int(input())

seq = []
for _ in range(n):
  i = list(map(int, input().split(" ")))
  seq.append(i)
  
length = len(list(itertools.permutations(seq)))
results = []
paths = list(itertools.combinations(seq, 2))
factorial = math.factorial(n - 1)
for path in paths:
  a, b = path
  a = numpy.array(a)
  b = numpy.array(b)
  u = b - a
  results.append(numpy.linalg.norm(u) * (factorial * 2))
print(sum(results) / length)
### BUGGY CODE ###

import sys
H, W, M = map(int, input().split())
hList = {i+1: 0 for i in range(H)}
wList = {i+1: 0 for i in range(W)}
pList = set()
#print(hList, wList, pList)
for _ in range(M):
  h, w = list(map(int, input().split()))
  #print(h, w)
  hList[h] += 1
  wList[w] += 1
  pList.add((h, w))
#print(hList, wList, pList)

maxCount = max(hList.values())
maxHList = [h for h, count in hList.items() if count==maxCount]
if maxCount==0:
  print(0)
  sys.exit()


maxCount = max(wList.values())
maxWList = [w for w, count in wList.items() if count==maxCount]

#counterList = []
#for maxH in maxHList:
#  for maxW in maxWList:
#    counterList.append(hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0))
#print(max(counterList))
print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))

### FIXED CODE ###

import sys
H, W, M = map(int, input().split())
hList = {i+1: 0 for i in range(H)}
wList = {i+1: 0 for i in range(W)}
pList = set()
#print(hList, wList, pList)
for _ in range(M):
  h, w = list(map(int, input().split()))
  #print(h, w)
  hList[h] += 1
  wList[w] += 1
  pList.add((h, w))
#print(hList, wList, pList)

maxHCount = max(hList.values())
maxHList = [h for h, count in hList.items() if count==maxHCount]


maxWCount = max(wList.values())
maxWList = [w for w, count in wList.items() if count==maxWCount]

#counterList = []
#for maxH in maxHList:
#  for maxW in maxWList:
#    counterList.append(hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0))
#print(max(counterList))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))

#if M < len(maxHList)*len(maxWList):
#	print(maxHCount + maxWCount)
#	sys.exit(0)

for maxH in maxHList:
  for maxW in maxWList:
    if (maxH, maxW) not in pList:
      print(maxHCount + maxWCount)
      sys.exit(0)

print(maxHCount + maxWCount - 1)
### BUGGY CODE ###

n = int(input())
a_list = []

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

result = 1
for a in a_list:
    result *= a

if result > 10 ** 18:
    print(-1)
else:
    print(result)


### FIXED CODE ###

import sys

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

if 0 in a:
    print(0)
else:
    cur = 1
    for x in a:
        cur *= x
        if cur > 10 ** 18:
            print(-1)
            sys.exit()
    print(cur)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
c=[a[i]-i-1 for i in range(n)]
cum_c=[0]*n
c.sort()
cum_c[0]=c[0]
for i in range(1,n):
  cum_c[i]=cum_c[i-1]+c[i]
ans=min(cum_c[n-1]-n*c[0],n*c[n-1]-cum_c[n-1])
for i in range(1,n):
  for b in range(c[i-1],c[i]+1):
    ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*b)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=[a[i]-i-1 for i in range(n)]
cum_c=[0]*n
c.sort()
cum_c[0]=c[0]
for i in range(1,n):
  cum_c[i]=cum_c[i-1]+c[i]
ans=min(cum_c[n-1]-n*c[0],n*c[n-1]-cum_c[n-1])
for i in range(1,n):
  ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*c[i-1])
  ans=min(ans,cum_c[n-1]-2*cum_c[i-1]+(2*i-n)*c[i])
print(ans)
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
print(len([i for i in A if A.count(i)%2!=0]))

### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
dict = {}
for i in A:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
print(len([1 for i in dict.values() if i%2!=0]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n = int(raw_input())
spot = map(int, raw_input().split())

for i in range(n):
    ans = 0
    p = 0
    end = 0
    for j in range(n):
        if j != i :
            ans = ans + abs(spot[j] - p)
            p = spot[j]
    ans = ans + abs(p - end)
    print ans

### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(raw_input())
spot = [0] + map(int, raw_input().split()) + [0]

all_sum = 0
for j in range(n+1):
    all_sum = all_sum + abs(spot[j+1] - spot[j])

for i in range(n):
    ans = all_sum - abs(spot[i+1] - spot[i]) - abs(spot[i+2] - spot[i+1]) + abs(spot[i+2] - spot[i])
    print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
flag=[[0 for j in range(n)] for i in range(n)]
dp=[[0 for j in range(n)] for i in range(n)]
ru=[0]
for i in range(n):
    ru.append(ru[-1]+a[i])
def f(l,r):
    if flag[l][r]==1:
        return dp[l][r]
    flag[l][r]=1
    if l==r:
        return 0
    fans=10**20
    for m in range(l,r):
        fans=min(fans,f(l,m)+f(m+1,r))
    dp[l][r]=fans+ru[r+1]-ru[l]
    return dp[l][r]

ans=f(0,n-1)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
flag=[[0 for j in range(n)] for i in range(n)]
dp=[[0 for j in range(n)] for i in range(n)]
ru=[0]
for i in range(n):
    ru.append(ru[-1]+a[i])
def f(l,r):
    if flag[l][r]==1:
        return dp[l][r]
    flag[l][r]=1
    if l==r:
        return 0
    fans=10**20
    for m in range(l,r):
        fans=min(fans,f(l,m)+f(m+1,r))
    dp[l][r]=fans+ru[r+1]-ru[l]
    return dp[l][r]

ans=f(0,n-1)
print(ans)