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

N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(1, N + 1):
	w, v = WV[n - 1]
	for sumw in range(W + 1):
		dp[n][sumw] = max(dp[n][sumw], dp[n - 1][sumw])
		if sumw + w <= W:
			dp[n][sumw + w] = max(dp[n][sumw + w], dp[n - 1][sumw] + v)
"""
for x in dp:
	for y in x:
		print("{:4d}".format(y), end="")
	print()
"""
print(dp[-1][-1])


### FIXED CODE ###

def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	# while b:
	# 	a, b = b, a % b
	# return a

	if b:
		return gcd(b, a % b)
	else:
		return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

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

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
# li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	ans = li[0]
	for i in range(1,N):
		ans = gcd(ans, li[i])
	print(ans)
### BUGGY CODE ###

S=input()

comb=[]
for i in range(len(S)-3):
    for j in range(i+3,len(S)):
        if int(S[i:j+1])%2019==0:
            comb.append((i+1,j+1))

print(len(comb))

### FIXED CODE ###

S=input()
S=list(reversed(S))

m=2019
cnt=[0 for i in range(m)]

len_S=len(S)
x=1
tot=0
ans=0

for i in range(len(S)):
    cnt[tot]+=1
    tot+=(ord(S[i])-ord('0'))*x
    tot %= m
    ans+=cnt[tot]
    x=x*10%m

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

A,B,C,D = map(int,input().split())

ans = 0
for i in range(A,B+1):
    if i % C != 0 and i % D != 0:
        ans += 1

print(ans)

### FIXED CODE ###

import math
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

lcm = lcm(C,D)

u_b_ans = (B//C + B//D) - B//lcm
u_a_ans = ((A-1)//C + (A-1)//D) - (A-1)//lcm

print(B-A+1 - u_b_ans + u_a_ans)
### BUGGY CODE ###

def main():
    N = int(input())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))
    ans = 1
    for a in A_list :
        ans = ans * a
        if ans == 0 :
            break
    if ans > 10 ** 18 :
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))
    #print(A_list)
    A_list.sort()
    #print(A_list)
    ans = 1
    for a in A_list :
        ans = ans * a
        if ans == 0 :
            break
        elif ans > 10 ** 18 :
            ans = -1
            break

    print(ans)

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

from operator import itemgetter
from collections import Counter
import heapq

N, K = [int(v) for v in input().split()]
sushi = [tuple(int(v) for v in input().split()) for i in range(N)]

sushi = sorted(sushi, key=itemgetter(1), reverse=True)

ate_list = sushi[:K]

kind_counter = Counter([s[0] for s in ate_list])
kind_cnt = len(list(kind_counter))

kind_cnt_seq = kind_cnt ** 2
max_pt = sum([s[1] for s in ate_list]) + kind_cnt_seq

if K >= N:
    print(max_pt)
    exit()

# print(ate_list)

waiting_sushi = []
wait_kind = []
for s in sushi[K:]:
    if kind_counter[s[0]]:  # すでに食べてる種類
        continue

    if not s[0] in wait_kind:
        waiting_sushi.append(s)
        wait_kind.append(s[0])

# 食べた種類を増やしていくフェーズ
idx = K - 1

# print(waiting_sushi)

curr_pt = max_pt
for s in waiting_sushi:
    target = None
    for i in range(idx, -1, -1):
        # 1個しかないものは交換しない
        if kind_counter[ate_list[i][0]] > 1:
            target = ate_list[i]
            idx = i
            break

    if not target:
        break

    # 入れ替えして比較
    n_kind_cnt_seq = ((kind_cnt + 1) ** 2)
    curr_pt = curr_pt - target[1] + s[1] + n_kind_cnt_seq - kind_cnt_seq
    kind_cnt_seq = n_kind_cnt_seq

    max_pt = max(curr_pt, max_pt)
    kind_counter[target[0]] -= 1

    kind_cnt += 1
    idx -= 1

# print(kind_cnt)
print(max_pt)


### FIXED CODE ###

from operator import itemgetter
from collections import Counter

N, K = [int(v) for v in input().split()]
sushi = [tuple(int(v) for v in input().split()) for i in range(N)]

sushi = sorted(sushi, key=itemgetter(1), reverse=True)

#
# kind_counter = Counter([s[0] for s in ate_list])
# kind_cnt = len(list(kind_counter))

##
# すでにでてきたかどうかがわかれば良いので Counter を使う必要はない
# (数える必要ない)
##

kind = set()
can_converts = []  # 変更しても良いよリスト
max_pt = 0

for i in range(K):
    if sushi[i][0] in kind:
        can_converts.append(sushi[i])
    else:
        kind.add(sushi[i][0])
    max_pt += sushi[i][1]
max_pt += len(kind) ** 2

# 食べた種類を増やしていくフェーズ
curr_pt = max_pt

for s in sushi[K:]:
    if not can_converts: break
    if s[0] not in kind:
        target = can_converts.pop(-1)
        curr_pt = curr_pt - target[1] + s[1] - len(kind) ** 2 + (len(kind) + 1) ** 2
        max_pt = max(max_pt,curr_pt)

        kind.add(s[0])

print(max_pt)

# kind_cnt_seq = kind_cnt ** 2
# max_pt = sum([s[1] for s in ate_list]) + kind_cnt_seq
#
# if K >= N:
#     print(max_pt)
#     exit()
#
# waiting_sushi = []
# wait_kind = []
# for s in sushi[K:]:
#     if kind_counter[s[0]]:  # すでに食べてる種類
#         continue
#
#     if not s[0] in wait_kind:
#         waiting_sushi.append(s)
#         wait_kind.append(s[0])
#
# # 食べた種類を増やしていくフェーズ
# idx = K - 1
# curr_pt = max_pt
# for s in waiting_sushi:
#     target = None
#     for i in range(idx, -1, -1):
#         # 1個しかないものは交換しない
#         if kind_counter[ate_list[i][0]] > 1:
#             target = ate_list[i]
#             idx = i
#             break
#
#     if not target:
#         break
### BUGGY CODE ###

n = int(input())
alist = list(map(int,input().split(' ')))

from collections import defaultdict

adict = defaultdict(int)

resdict = {}

for a in alist:
    adict[a] += 1

for a in alist:
    if a in resdict:
        print(resdict[a])
        continue
    adict[a] -= 1
    temp = 0

    for k,v in adict.items():
        # print(k, v)
        if v >= 2:
            temp += v*(v-1)//2
    print(temp)
    resdict[a] = temp
    adict[a] += 1

### FIXED CODE ###

n = int(input())
alist = list(map(int,input().split(' ')))

from collections import defaultdict

resdict = {}

from collections import Counter

c = Counter(alist)

cdict = dict(c)

# cdict = dict((key, value) for (key, value) in old_cdict.items() if value >= 2)

# print(cdict)

maxi = 0

for k, v in cdict.items():
    maxi += v * (v - 1) // 2

for a in alist:
    num = cdict[a]
    if num in resdict:
        # print('used')
        print(resdict[num])
        continue
    # print('not used')
    if a in cdict:
        cdict[a] -= 1
        temp = 0
        for k,v in cdict.items():
            temp += v*(v-1)//2
        print(temp)
        resdict[num] = temp
        cdict[a] += 1
    else:
        print(maxi)
### BUGGY CODE ###

count = int(input())
zenbu = []

for x in range(count):
    keihin = str(input())
    flg = False
    
    for y in range(len(zenbu)):
        
        if zenbu[y] == keihin:
            flg = True
            break
        
    if flg == False:
        zenbu.append(keihin)

print(len(zenbu))

### FIXED CODE ###

count = int(input())
zenbu = set()
 
for x in range(count):
    keihin = input()
    zenbu.add(keihin)
print(len(zenbu))
### BUGGY CODE ###

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

if (B-A)%2==0:
    print((B-A)//2)
else:
    C=N+1-B
    D=N+1-A
    print(min(A + (B-A-1)//2,D + (D-C-1)//2))


### FIXED CODE ###

N=int(input())
print(N-1)
s=input()
if s=="Vacant":
    exit()
elif s=="Male":
    flag=1
else:
    flag=0
print(0)
s=input()
if s=="Vacant":
    exit()
elif s=="Male":
    flag=1
else:
    flag=0
st=0
end=N-1

while s!="Vacant":
    a=(end+st)//2
    print(a)
    s=input()
    if (a+flag*1)%2:
        if s=="Male":
            st=a
        else:
            end=a
    else:
        if s=="Female":
            st=a
        else:
            end=a
### BUGGY CODE ###

import math
import itertools

(d, g) = map(int, input().split(" "))

p = []
c = []

for i in range(d):
    (_p, _c) = map(int, input().split(" "))
    p.append(_p)
    c.append(_c)

ans = 114514
for order in itertools.permutations(range(d)):
    point = 0
    cnt = 0
    for i in order:
        if g - point <= 100 * (i + 1) * p[i]:
            cnt += math.ceil((g - point) / (100 * (i + 1)))
            break
        elif g - point <= 100 * (i + 1) * p[i] + c[i]:
            cnt += p[i]
            break
        else:
            point += 100 * (i + 1) * p[i] + c[i]
            cnt += p[i]         

    ans = min([ans, cnt])

print(ans)

### FIXED CODE ###

import math
import itertools

(d, g) = map(int, input().split(" "))

p = []
c = []

for i in range(d):
    (_p, _c) = map(int, input().split(" "))
    p.append(_p)
    c.append(_c)

ans = 114514
for order in itertools.permutations(range(d)):
    point = 0
    cnt = 0
    for i in order:
        if g - point <= 100 * (i + 1) * p[i]:
            cnt += math.ceil((g - point) / (100 * (i + 1)))
            break
        elif g - point <= 100 * (i + 1) * p[i] + c[i]:
            cnt += p[i]
            break
        else:
            point += 100 * (i + 1) * p[i] + c[i]
            cnt += p[i]         

    ans = min([ans, cnt])

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

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

points = [(i+1, y) for i, y in enumerate(A)]

diff_list = [y - x for x, y in points]
diff_list.sort()

max_b = diff_list[-1]
min_b = diff_list[0]

sadness_list = []
for b in range(min_b, max_b+1):
    sadness_list.append(sum([abs(y - (b + x)) for x, y in points]))

print(min(sadness_list))

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
def calc_sadness(points, b):
    return sum([abs(y - (b + x)) for x, y in points])

points = [(i+1, y) for i, y in enumerate(A)]

# y = x + b
# b = y - x
b_list = [y - x for x, y in points]
b_list.sort(reverse=True)

max_b = b_list[0]
min_b = b_list[-1]

best_ind = len(b_list)//2

minimum = calc_sadness(points, b_list[best_ind])

print(minimum)
### BUGGY CODE ###

N= int(input())
al=list(map(int,input().split()))
sss=0
for i in range(N):
    for j in range(i):
        sss+=al[j]*al[i]

print(sss%1000000007)

### FIXED CODE ###

N = int(input())
al = list(map(int,input().split()))
sss=0
pss=0
for i in range(1,N):
    pss+=al[i-1]
    sss+=al[i]*pss
print(sss%1000000007)
### BUGGY CODE ###

import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

def main():
    N, K = list(map(int, input().split()))
    A = list(input().split())

    D = collections.defaultdict(lambda: 0)

    for a in A:
        D[a] += 1

    selected = 0
    while selected != K and len(D) > 0:
        k, v = max(D.items(), key=lambda x:x[1])
        del D[k]

        selected += 1

    op = 0
    for v in D.values():
        op += v


    print(op)


main()


### FIXED CODE ###

import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

def main():
    N, K = list(map(int, input().split()))
    A = list(input().split())

    D = collections.defaultdict(lambda: 0)

    for a in A:
        D[a] += 1

    L = []
    for v in D.values():
        L.append(v)

    L.sort(reverse=True)

    i = 0
    S = 0
    U = min(K, len(L))
    while i < U:
        S += L[i]
        i += 1

    print(sum(L) - S)


main()
### BUGGY CODE ###

from collections import deque
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = deque()
C = deque()

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

for j in range(Q):
    rep = [i for i in A if i != B[j]]
    for _ in range(len(A) - len(rep)):
        rep.append(C[j])
    A = rep[::]

    print(sum(A))


### FIXED CODE ###

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

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

d = [0] * (10**5 + 7)
for a in A:
    d[a] += 1
sum_a = sum(A)
for j in range(Q):
    before = d[C[j]]
    d[C[j]] += d[B[j]]
    sum_a -= d[B[j]] * B[j]

    sum_a += (d[C[j]] - before) * C[j]
    d[B[j]] = 0
    print(sum_a)
### BUGGY CODE ###

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

def dfs(x, y, m):
    if y > N :
        return 0
    if mem[m][y][x] != INF:
        return mem[m][y][x]
    n = INF
    for j in range(2 if m > 0 else 1):
        for i, s in enumerate(st[y + 1 + j]):
            srip = max(0, st[y][x][1] + s[1])
            l = abs(st[y][x][0] - s[0])
            n = min(dfs(i, y + 1 + j, m - j) + srip * l, n)
    mem[m][y][x] = n
    return mem[m][y][x]

while True:
    N, M = map(int, input().split())
    if N == 0:
        break
    st = [[[-INF, -INF]] for i in range(N + 3)]
    for s in st[1:-2]:
        v = list(map(int, input().split()))
        del s[0]
        for i in range(1, len(v), 2):
            s.append([v[i], v[i + 1]])
    mem = [[[INF for i in range(N + 4)] for j in range(N + 1)] for k in range(M + 1)]
    print(dfs(0, 0, M))

### FIXED CODE ###

INF = 10000000000
dx = [0, 0, 1, -1]
dy = [-1, 1, 0, 0]
 
def dfs(x, y, m):
    if y > N :
        return 0
    if mem[x][y][m] != INF:
        return mem[x][y][m]
    n = INF
    for j in range(2 if m > 0 else 1):
        for i, s in enumerate(st[y + 1 + j]):
            srip = max(0, st[y][x][1] + s[1])
            l = abs(st[y][x][0] - s[0])
            n = min(dfs(i, y + 1 + j, m - j) + srip * l, n)
    mem[x][y][m] = n
    return mem[x][y][m]
 
while True:
    N, M = map(int, raw_input().split())
    if N == 0:
        break
    st = [[[-INF, -INF]] for i in range(N + 3)]
    for s in st[1:-2]:
        v = list(map(int, raw_input().split()))
        del s[0]
        for i in range(1, len(v), 2):
            s.append([v[i], v[i + 1]])
    mem = [[[INF for i in range(M + 1)] for j in range(N + 1)] for k in range(N + 4)]
    print(dfs(0, 0, M))
### BUGGY CODE ###

a, b, x = map(int, input().split())
cnt = 0
for i in range(a,b+1):
    if i%x == 0:
        cnt += 1
print(cnt)

### FIXED CODE ###

a, b, x = map(int, input().split())
cnt = 0
if (a%x == 0):
    cnt+=1
cnt += b//x - a//x
print(cnt)
### BUGGY CODE ###

K,S = map(int,input().split())
count = 0
for i in range(0,K+1):
    X = i
    for j in range(0,K+1):
        Y = j
        for k in range(0,K+1):
            Z = k
            ty = X + Y + Z
            if ( ty == S):
                count += 1
print(count)

### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if (0 <= z < K + 1):
            count += 1
print(count)
### BUGGY CODE ###

s = input()
q = int(input())
li=[list(map(str,input().split())) for _ in range(q)]

que = []

for i in range(q):
    que = li[i]
    if que[0] == "1":
        s = s[::-1]
    else:
        f = que[1]
        c = que[2]
        if f == "1":
            s = c + s
        else:
            s = s + c

print(s)

### FIXED CODE ###

s = input()
q = int(input())
li=[list(map(str,input().split())) for _ in range(q)]

moji = "0"
frag = True

for i in range(q):
    que = li[i]
    if que[0] == "1":
        if frag:
            frag = False
        else:
            frag = True
    else:
        f = que[1]
        c = que[2]
        if frag:
            if f == "1":
                moji = c+moji
            else:
                moji = moji+c
        else:
            if f == "1":
                moji = moji+c
            else:
                moji = c+moji


if frag:
    print(moji.replace("0",s))
else:
    moji = moji[::-1]
    print(moji.replace("0",s[::-1]))
### BUGGY CODE ###

import math

from itertools import product
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


a = input()
a = int(a)
count = 0
l = range(1, a + 1)
m = range(1, a + 1)
n = range(1, a + 1)

for x, y, z in product(l, m, n):
            count +=  gcd(x, y, z)

print(count)

### FIXED CODE ###

import math


a = input()
a = int(a)
count = 0
for l in range(1, a + 1):
    for m in range(1, a + 1):
        x = math.gcd(l, m)
        for n in range(1, a + 1):
            count += math.gcd(x,n)

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

n=int(input())
x=list(int(input()) for _ in range(n))

import numpy as np

y=np.array(x)
z=np.ones(n)

for i in range(n):
	z=np.ones(n)
	z[i]=0
	print(int(max(y*z)))

### FIXED CODE ###

n=int(input())
x=list(int(input()) for _ in range(n))

import numpy as np

mi=np.argmax(x)

y=np.array(x)

for i in range(n):
	if i!=mi:
		print(x[mi])
	else:
		z=np.ones(n)
		z[i]=0
		print(int(max(y*z)))
### BUGGY CODE ###

primes = [[True]*100000][0]
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [[False]*100000][0]

for i in range(3, 100000, 2):
  if primes[i] == False:
    continue
  if primes[(i+1)//2] == True:
    c[i] = True

q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(sum(c[:ran[i][1]+1])-sum(c[:ran[i][0]]))


### FIXED CODE ###

primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])
### BUGGY CODE ###

N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
m = 0

for n in range(N):
    A[n] = int(A[n])
    B[n] = int(B[n])
    C[n] = int(C[n])

for i in range(N):
    for j in range(N):
        if A[i] >= B[j]:
            continue
        for k in range(N):
            if B[j] < C[k]:
                m =  m + 1

print(m)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
B.sort()
C.sort()
C.reverse()
 
ans = 0
ai = 0
ci = N-1
for b in B:
    while ai < N and A[ai] < b:
        ai += 1
    while ci >= 0 and C[ci] <= b:
        ci -= 1
    ans += ai * (ci+1)
 
print(ans)
### BUGGY CODE ###

X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
for i in r:
    p_min = p[len(p) - 1]
    q_min = q[len(q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        p.pop()
        p = [i] + p
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        q.pop()
        q = [i] + q
 
print(sum(p) + sum(q))

### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
colored_p = []
colored_q = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else colored_p[len(colored_p) - 1]
    q_min = q[len(q) - 1] if len(q) > 0 else colored_q[len(colored_q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored_p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored_q.append(i)
 
print(sum(p) + sum(q) + sum(colored_p) + sum(colored_q))
### BUGGY CODE ###

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

    r = list(range(N - 2, -1, -1))
    result = 0
    for b in range(60):
        t = 0
        bs = (A[N - 1] >> b) & 1
        for i in r:
            a = (A[i] >> b) & 1
            if a == 0:
                t += bs
            else:
                t += (N - (i + 1)) - bs
            bs += a
        result = (result + t * (1 << b)) % 1000000007
    print(result)
main()


### FIXED CODE ###

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

    r = list(range(N - 2, -1, -1))
    result = 0
    for b in range(60):
        t = 0
        bs = (A[N - 1] >> b) & 1
        for i in r:
            if (A[i] >> b) & 1 == 0:
                t += bs
            else:
                t += (N - (i + 1)) - bs
                bs += 1
        result = (result + t * (1 << b)) % 1000000007
    print(result)
main()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(1,N+1):
  for j in range(N):
    if i == A[j]:
      B.append(str(j+1))
print(' '.join(B))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = [0] * N
for i, a in enumerate(A):
  ans[a-1] = i+1
print(*ans)
### BUGGY CODE ###

import sys

def judge(string):
    mem = ""
    for char in string:
        if mem == char:
            return False
        mem = char

    return True


def main():
    sinputl = sys.stdin.readline

    input = sinputl().strip()
    length = len(input)
    input = int(input, base=2)

    paint = [length]

    for i in range(2 ** length):
        status = input ^ i
        if judge(bin(status)[2:].zfill(length)):
            paint.append(bin(i).count('1'))

        
    print(min(paint))


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

def main():
    sinputl = sys.stdin.readline

    input = sinputl().strip()
    length = len(input)
    string1 = "10" * (length // 2) + "1" * (length % 2)
    string2 = "01" * (length // 2) + "0" * (length % 2)
    count1 = 0
    count2 = 0

    for i in range(length):
        if input[i] != string1[i]:
            count1 += 1

    for i in range(length):
        if input[i] != string2[i]:
            count2 += 1

    print(min(count1, count2))


if __name__ == "__main__":
    main()