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

N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())
B = []
C = []

for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    s = 0
    e = N
    h = int((s+e)/2)
    while A[h] != B[i] and s != h :
        if A[h] < B[i]:
            s = h
            h = int((s+e)/2)
        elif A[h] > B[i]:
            e = h
            h = int((s+e)/2)
    for j in range(s, e):
        if A[j] == B[i]:
            A[j] = C[i]
    A.sort()
    print(sum(A))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
X = [0] * (10**5)

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

ans = sum(A)

for j in range(Q):
    b, c = map(int, input().split())
    a = X[b-1]
    X[b-1] = 0
    X[c-1] += a
    ans = ans - a*b + c*a
    print(ans)
### BUGGY CODE ###

H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
cnt = 0
while pos != []:
  n = len(pos)
  cnt += 1
  for i in range(n):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
  pos = pos[n:]
print(cnt-1)

### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
cnt = 0
while pos != []:
  n = len(pos)
  cnt += 1
  for i in range(n):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
  pos = pos[n:]
print(cnt-1)
### BUGGY CODE ###

N = int(input())
a_str = input().split()
sum = 0
for i in range(N):
  for j in range(N-i-1):
    sum += int(a_str[i]) * int(a_str[i+j+1])
print(sum%(pow(10,9)+7))


### FIXED CODE ###

import itertools
import math

N = int(input())
a_list = list(map(int, input().split()))
a_accumulate = list(itertools.accumulate(a_list))
a_sum = sum(a_list)
result = 0
i = 0
for a in a_list:
  result += a * (a_sum - a_accumulate[i])
  i += 1
print(result%(pow(10,9)+7))
### BUGGY CODE ###

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

#まとめる
a_set = list(set(a))

#数えてソートする
a_cnt =[0 for i in range(len(a_set))]
for i in range(len(a_set)):
    a_cnt[i] = a.count(a_set[i])
a_cnt.sort() 
#種類の数はa_setの要素数
num_typ = len(a_set)
#数が少ない数値から書き換えていく
if num_typ <= k:
    print(0)
else:
    print(sum(a_cnt[:len(a_cnt)-k]))


### FIXED CODE ###

import collections

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

#数える
a = collections.Counter(a)

#ソートする
a_sort = sorted(a.items(), key=lambda x:x[1])

#必要な分だけ足す
out = 0
if len(a_sort) <= k:
    print(0)
else:
    for i in range(len(a_sort)-k):
        out += a_sort[i][1]
    print(out)
### BUGGY CODE ###

K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    while(cookie < A):
        if(action <= 0):
            break
        action += -1
        cookie += 1
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)


### FIXED CODE ###

K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    init_break_n = min(action, A - cookie)
    action += -(init_break_n)
    cookie += init_break_n
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)
### BUGGY CODE ###

s = input()
q = int(input())
mode = True
for _ in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        mode = not mode
    else:
        if mode == 1:
            s = tfc[2]+s if int(tfc[1]) == 1 else s+tfc[2]
        else:
            s = s+tfc[2] if int(tfc[1]) == 1 else tfc[2]+s
print(s if mode else s[::-1])

### FIXED CODE ###

s = input()
q = int(input())
mode = True
l = ''
r = ''
for _ in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        mode = not mode
    else:
        if mode:
            if int(tfc[1]) == 1:
                l += tfc[2]
            else:
                r += tfc[2]
        else:
            if int(tfc[1]) == 1:
                r += tfc[2]
            else:
                l += tfc[2]
print(l[::-1]+s+r if mode else r[::-1]+s[::-1]+l)
### BUGGY CODE ###


N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

for LR in LRs:
    s = S[LR[0]-1 : LR[1]]
    count = 0
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1
    print(count)

### FIXED CODE ###


N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

rev_counts = [0]
for i in reversed(range(len(S)-1)):
    rev_counts.append(rev_counts[-1] + counts[i])
rev_counts = list(reversed(rev_counts))
# print(counts)
# print(rev_counts)


for LR in LRs:
    start = LR[0] - 1
    end = LR[1]  -1
    print(rev_counts[start] - rev_counts[end])
### BUGGY CODE ###

N,K = map(int, input().split())
x0 = N #7
x1 = abs(x0-K) #3
while True:
    if x0 < x1:
        print(x0)
        break
    else:
        x0,x1 = x1,abs(x0-K)
        continue

### FIXED CODE ###

N,K = map(int, input().split())
if N == 0:
    print(0)
else:
    for i in range(18):
        while True:
            if N > K*10**(18-i):
                N = N-(K*10**(18-i))
            else:
                break

    x0 = N #7
    x1 = abs(x0-K) #3
    while True:
        if x0 < x1:
            print(x0)
            break
        else:
            x0,x1 = x1,abs(x0-K)
            continue
### BUGGY CODE ###



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N, W = map(int, input().split())
w = [0] * N
v = [0] * N

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

dp = [ [0 for _ in range(W+1)] for _ in range(N+1) ]

for i  in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[N][W])


### FIXED CODE ###



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N, W = map(int, input().split())
w = [0] * N
v = [0] * N

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

dp = [ [0 for _ in range(W+1)] for _ in range(N+1) ]

for i  in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[N][W])
### BUGGY CODE ###

s = input()
length = len(s)
count_dict = {}

'''for i in range(length-4):
    for j in range(i+4,length+1):
        num = int(s[i:j])
        if num%2019 == 0:
            count += 1'''

num = int(s)%2019
count_dict[num] = 1

# num = int(s[-1])
# count_dict[num] = 1

for i in range(1,length):
    num = (num-int(s[-i])*(10**(i-1)%2019))%2019
    # num = num+int(s[-i])
    if num not in count_dict:
        count_dict[num] = 1
    else:
        count_dict[num] += 1


count = 0
for k,v in count_dict.items():
    count += v*(v-1)/2
    if k == 0:
        count += v

print(int(count))

### FIXED CODE ###

s = input()
length = len(s)
count_dict = {}

'''for i in range(length-4):
    for j in range(i+4,length+1):
        num = int(s[i:j])
        if num%2019 == 0:
            count += 1'''

num = int(s)%2019
count_dict[num] = 1

# num = int(s[-1])
# count_dict[num] = 1

for i in range(1,length):
    num = (num-int(s[-i])*pow(10,(i-1),2019))%2019
    # num = num+int(s[-i])
    if num not in count_dict:
        count_dict[num] = 1
    else:
        count_dict[num] += 1


count = 0
for k,v in count_dict.items():
    count += v*(v-1)/2
    if k == 0:
        count += v

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

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def main():
  MOD = 10**9+7
  N = int(input())
  edge = [[] for _ in range(N+1)]
  dp = [[0]*2 for i in range(100005)]
  # dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
  # 葉が決まると順々に求まっていく
  for i in range(N-1):
      x,y = map(int,input().split())
      edge[x].append(y)
      edge[y].append(x)

  # 0:white,1:black
  def dfs(v,last=-1):
      dp[v][0] = 1
      dp[v][1] = 1
      for nv in edge[v]:
          if nv == last:
              continue
          dfs(nv, v)
          dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
          dp[v][1] = dp[v][1] * dp[nv][0] % MOD


  dfs(1)
  print((dp[1][0] + dp[1][1])%MOD)
if __name__ == '__main__':
  main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def main():
  MOD = 10**9+7
  N = int(input())
  edge = [[] for _ in range(N+1)]
  dp = [[0]*2 for i in range(100005)]
  # dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
  # 葉が決まると順々に求まっていく
  for i in range(N-1):
      x,y = map(int,input().split())
      edge[x].append(y)
      edge[y].append(x)

  # 0:white,1:black
  def dfs(v,last=-1):
      dp[v][0] = 1
      dp[v][1] = 1
      for nv in edge[v]:
          if nv == last:
              continue
          dfs(nv, v)
          dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
          dp[v][1] = dp[v][1] * dp[nv][0] % MOD


  dfs(1)
  print((dp[1][0] + dp[1][1])%MOD)
if __name__ == '__main__':
  main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
INF=float('inf')
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
d=[INF]*n
nbr=[[] for _ in range(n)]
used=[False]*m
for x in l:
    x[0]-=1
    x[1]-=1
#print(l)
for i in range(m):
    nbr[l[i][0]].append(i)
    nbr[l[i][1]].append(i)
#print(nbr)
def sol(i):
    if d[i]==INF:
        d[i]=0
    for x in nbr[i]:
        if used[x]:continue
        used[x]=True
        if l[x][0]==i:
            if d[l[x][1]]==INF:
                d[l[x][1]]=d[i]+l[x][2]
            elif d[l[x][1]]!=d[i]+l[x][2]:
                print('No')
                exit()
            sol(l[x][1])
        else:
            if d[l[x][0]]==INF:
                d[l[x][0]]=d[i]-l[x][2]
            elif d[l[x][0]]!=d[i]-l[x][2]:
                print('No')
                exit()
            sol(l[x][0])
for i in range(n):
    sol(i)
#print(d)
print('Yes')

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    INF=float('inf')
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    d=[INF]*n
    nbr=[[] for _ in range(n)]
    used=[False]*m
    for x in l:
        x[0]-=1
        x[1]-=1
    #print(l)
    for i in range(m):
        nbr[l[i][0]].append(i)
        nbr[l[i][1]].append(i)
    #print(nbr)
    def sol(i):
        for x in nbr[i]:
            if used[x]:continue
            used[x]=True
            i1=l[x][0]^l[x][1]^i
            dd=d[i]+l[x][2]*(2*(l[x][0]==i)-1)
            if d[i1]!=dd and d[i1]!=INF:
                print('No')
                exit()
            elif d[i1]==INF:
                d[i1]=dd
                sol(i1)
    for i in range(n):
        if d[i]==INF:
            d[i]=0
            sol(i)
    #print(d)
    print('Yes')
solve()
### BUGGY CODE ###

N = int(input())

l = []

ans = 1

s = input()
l.append(s)

for i in range(N-1):
    s = input()
    t = s in l
    if t == False:
        ans += 1
        l.append(s)

print(ans)







### FIXED CODE ###

N = int(input())

l = []

for i in range(N):
    l.append(input())

print(len(set(l)))
### BUGGY CODE ###

import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

ans=1
for a in A:
    ans*=a

if 10**18<ans:
    print -1
else:
    print ans


### FIXED CODE ###

import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

ans=1
for a in A:
    if a==0:
        ans*=a
    elif ans==-1:
        pass
    else:
        ans*=a
        if 10**18<ans:
            ans=-1

if 10**18<ans:
    print -1
else:
    print ans
### BUGGY CODE ###

import itertools
n,m,q = map(int, input().split())
abc = []
d = []
for _ in range(q):
    A,B,C,D = map(int, input().split())
    abc.append([A,B,C])
    d.append(D)

l = range(1,m+1)
point = 0
for v in itertools.combinations_with_replacement(l,n):
    p = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if [i+1,j+1, abs(v[j]-v[i])] in abc:
                p += d[abc.index([i+1,j+1, abs(v[j]-v[i])])]
    if point < p: point = p
print(point)

### FIXED CODE ###

import itertools
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

l = range(1,m+1)
point = 0
for v in itertools.combinations_with_replacement(l,n):
    p = 0
    for a,b,c,d in abcd:
        if v[b-1] - v[a-1] == c:
            p += d
    if p > point: point = p
print(point)
### BUGGY CODE ###

n = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
 
dp = [0] * (n+1)
AB = tuple(zip(A, B))
for i in range(n+1):
    for a, b in AB:
        if i - a >= 0:
            y = dp[i-a] + b - a
            if y > dp[i]:
                dp[i] = y
n += dp[n]
dp = [0] * (n+1)
BA = tuple(zip(B, A))
for i in range(n+1):
    for b, a in BA:
        if i - b >= 0:
            y = dp[i-b] + a - b
            if y > dp[i]:
                dp[i] = y 
print(n + dp[n])

### FIXED CODE ###

n = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
 
dp = [0] * (n+1)
AB = [] 
for a, b in zip(A, B):
    if b > a:
        AB.append((a, b))
for i in range(n+1):
    for a, b in AB:
        if i - a >= 0:
            y = dp[i-a] + b - a
            if y > dp[i]:
                dp[i] = y
n += dp[n]
dp = [0] * (n+1)
BA = []
for b, a in zip(B, A):
    if a > b:
        BA.append((b, a))
for i in range(n+1):
    for b, a in BA:
        if i - b >= 0:
            y = dp[i-b] + a - b
            if y > dp[i]:
                dp[i] = y 
print(n + dp[n])
### BUGGY CODE ###

N = int(input())
S = input()

resset = set()

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            temp = ''.join([S[i],S[j],S[k]])
            resset.add(temp)

print(len(resset))


### FIXED CODE ###

N = int(input())
S = input()

res = 0

for i in range(10):
    p1 = S.find(str(i))
    if p1 == -1:
        continue
    elif p1 > N-3:
        continue
    for j in range(10):
        p2 = S[p1+1:N].find(str(j))
        if p2 == -1:
            continue
        elif p2 > N-p1-3:
            continue
        for k in range(10):
            p3 = S[p1+p2+2:N].find(str(k))
            if p3 == -1:
                continue
            res += 1


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

N,K,Q = map(int,input().split())
human = [K for i in range(N)]
for i in range(Q):
     p = int(input())
     human = [human[j]-1 if j != p-1 else human[j] for j in range(N)]
for i in range(N):
    if human[i] <= 0:
        print("No")
    else:
        print("Yes")
    


### FIXED CODE ###

N,K,Q = map(int,input().split())
human_win = [0 for i in range(N)]
win = Q - K

for i in range(Q):
     human_win[int(input())-1] += 1

for i in range(N):
    if human_win[i] > win:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
 if i == 0:
  max_rieki = rieki[0]
 if rieki[i] > max_rieki:
  max_rieki = rieki[i]

print max_rieki

### FIXED CODE ###

n = input()
m = [0] * n
max_rieki = -1000000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

print max_rieki
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000000)
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


cnt = [0] * N
used = [0] * N
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1 
  cnt[p] += x

def dfs(u, pre, c):
  used[u] += 1
  if sum(used) == N:
    return
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

  return

dfs(0, -1, cnt[0])
print(*cnt)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)
### BUGGY CODE ###

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

s = 1
for i in range(N):
	s = s * A[i]

ans = 0
while s % 2 == 0:
	s = s // 2
	ans += 1
print(ans)

### FIXED CODE ###

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

s = 1
ans = 0
for a in A:	
	while a % 2 == 0:
		a = a // 2
		ans += 1
print(ans)
### BUGGY CODE ###

def main():
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  # M:カードの数字の最大値+1
  M = max(max(A),max(B))+1
  INF=float('inf')
  # dp[mask][a]:maskのカードが操作済で、そのうち右端のカードの数字がaであるときの操作回数の最小値
  dp = [[INF for _ in range(M)] for _ in range(1<<N)]
  dp[0][0] = 0
  
  for i in range(1<<N):
    # idx:操作済カードの枚数
    idx = 0
    for k in range(N):
      #k番目のカードが操作済みかどうか判定する。iでk番目にフラグがたってたら、操作済みとする。
      if (i>>k)&1 == 1:
        idx += 1
    for j in range(M):
      if dp[i][j] >= INF:
        continue
      for k in range(N):
        # k:右端の操作済カードの次に来るカード
        # kがすでに操作済の場合はcontinueする
        
        # kが何回操作されるかによってkの数字が表の数字になるか裏の数字になるかが決まる
        if abs(k-idx)%2 == 0:
          c = A[k]
        else:
          c = B[k]
  
        # kの数字広義単調増加にならない場合はcontinue
        if j > c:
          continue
        
        # t:kを右端の操作済カードの次に並べるための操作回数
        # それは、初期配置でkより左にあってまだ操作済でないカードの枚数と一致する
        t = 0
        for l in range(k):
          if (i>>l)&1 == 0:
            t += 1
        #print(i,k,idx,c,dp[i|(1<<k)][c],t)
        dp[i|(1<<k)][c] = min(dp[i|(1<<k)][c],dp[i][j]+t)
  
  ans = INF
  for i in range(M):
    ans = min(dp[(1<<N)-1][i],ans)
  print(ans if ans < INF else -1)

if __name__ == '__main__':
  main()

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
judge = False
ans = 10**9
for i in range(2**N):
  even = []
  odd = []
  x = 0
  tmp = True
  for j in range(N):
    if ((i>>j) & 1):
      if j%2==1:
        even.append([B[j],j])
      else:
        odd.append([B[j],j])
      
    else:
      if j%2==1:
        odd.append([A[j],j])
      else:
        even.append([A[j],j])
        
  if N%2==0:
    if len(even)!=len(odd):
      continue
      
  else:
    if (len(even)-1)!=len(odd):
      continue
      

  even = sorted(even,key = lambda x:x[0])
  odd = sorted(odd,key = lambda x:x[0])
  ind = [0]*N
  for k in range(N//2):
    o = odd[k]
    e = even[k]
    if o[0]<e[0]:
      tmp = False
      break
    
    if (k!=N//2-1)or(N%2==1):
      if o[0]>even[k+1][0]:
        tmp = False
        break
    
    ind[2*k]=e[1]
    ind[2*k+1]=o[1]

  if tmp:
    if N%2==1:
      ind[N-1]=even[-1][1]
      

    for k in range(N):
      y = ind[k]
      x+=abs(y-k)
      ind = [x+1 if (x<y)and(x>=k) else x for x in ind]
    ans = min(ans,x)
    judge = True
    
if judge:
  print(ans)
else:
  print(-1)
### BUGGY CODE ###

from collections import deque
d=deque()
for _ in range(int(input())):
  a=int(input())
  if a in d:
    try:
      d.remove(a)
    except ValueError:
      pass
  else:
    d.append(a)
print(len(d))

### 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 ###

from collections import Counter

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

cnt = Counter(A)

ans = 0
for i in range(len(cnt)):
    if cnt.most_common()[i][1] % 2 != 0:
        ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

cnt = Counter(A)

ans = 0
for i in cnt.values():
    if i % 2 != 0:
        ans += 1

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

import math
from functools import reduce

K = int(input())

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

print(ans)

### FIXED CODE ###

import math
from functools import reduce

K = int(input())

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

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

# C Sum of product of pairs

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

s = 0
for i in range(N-1):
  s += A[i] * sum(A[i+1:])
        
print(s % (10**9 + 7))

### FIXED CODE ###

# C Sum of product of pairs

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

s = 0
old = 0
for i in range(N-1):
  old += A[i]
  s += old * A[i+1]
        
print(s % (10**9 + 7))