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

import copy
N = int(input())
numList = list(map(int, input().split()))
medIndex = int((N-1)/2)

for i in range(0,N):
	numListCopy = copy.deepcopy(numList)
	numListCopy.pop(i)
	numListCopy = sorted(numListCopy)
	print(numListCopy[medIndex])

### FIXED CODE ###

import copy
N = int(input())
numList = list(map(int, input().split()))
numListCopy = copy.deepcopy(numList)
numList = sorted(numList)
medIndex = int((N)/2)
med1 = numList[medIndex-1]
med2 = numList[medIndex]


for i in range(0,N):
	if numListCopy[i] <= med1:
		print(med2)
	elif med2 <= numListCopy[i]:
		print(med1)
### BUGGY CODE ###

s = input()+"0"
m = dict()
for i in range(len(s)):
    mod = int(s[i:])%2019
    if mod in m.keys():
        m[mod] += 1
    else:
        m[mod] = 1

def c2(n):
    return n*(n-1)//2

print(sum([c2(i) for i in m.values()]))

### FIXED CODE ###

s = input()[::-1]
m = [0]*2019
m[0] = 1
d = 1
t = 0
for i in s:
    t += int(i)*d
    t %= 2019
    m[t] += 1
    d = (d*10)%2019


def c2(n):
    return n*(n-1)//2
print(sum([c2(i) for i in m]))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from heapq import heappop, heappush
INF = 10**9

n, m = map(int, input().split())
pqc = []

seen = set()
for i in range(n):
    seen.add((i, 0))
for _ in range(m):
    p, q, c = map(int, input().split())
    p -= 1; q -= 1
    pqc.append((p, q, c))
    seen.add((p, c))
    seen.add((q, c))
comp = dict()
for i, node in enumerate(seen):
    comp[node] = i

edge = [[] for _ in range(len(comp))]
for key in comp.keys():
    v, c = key
    if c != 0:
        frm = comp[(v, c)]
        too = comp[(v, 0)]
        edge[frm].append((too, 0))
        edge[too].append((frm, 1))

for p, q, c in pqc:
    frm = comp[(p, c)]
    too = comp[(q, c)]
    edge[frm].append((too, 0))
    edge[too].append((frm, 0))

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heappush(self.q, (self.dist[dest], dest))
        return self.dist

DIJK = Dijkstra(edge)
DIJK.calc(comp[(0, 0)])
ans = DIJK.dist[comp[(n-1, 0)]]
if ans == INF:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
INF = 10**9

n, m = map(int, input().split())
pqc = []

seen = set()
for i in range(n):
    seen.add((i, 0))
for _ in range(m):
    p, q, c = map(int, input().split())
    p -= 1; q -= 1
    pqc.append((p, q, c))
    seen.add((p, c))
    seen.add((q, c))
comp = dict()
for i, node in enumerate(seen):
    comp[node] = i

edge = [[] for _ in range(len(comp))]
for key in comp.keys():
    v, c = key
    if c != 0:
        frm = comp[(v, c)]
        too = comp[(v, 0)]
        edge[frm].append((too, 0))
        edge[too].append((frm, 1))

for p, q, c in pqc:
    frm = comp[(p, c)]
    too = comp[(q, c)]
    edge[frm].append((too, 0))
    edge[too].append((frm, 0))

class BFS:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = deque()

    def calc(self, start):
        self.dist[start] = 0
        self.q.append((0, start))
        while len(self.q) != 0:
            prov_cost, src = self.q.popleft()
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    if cost == 1:
                        self.q.append((self.dist[dest], dest))
                    else:
                        self.q.appendleft((self.dist[dest], dest))
        return self.dist

bfs = BFS(edge)
bfs.calc(comp[(0, 0)])
ans = bfs.dist[comp[(n-1, 0)]]
if ans == INF:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import sys

def main():

	input = sys.stdin.readline

	N = int(input().strip())
	P = list(map(int,input().strip().split()))

	pp = []
	for i, val in enumerate(P):
		pp.append([i,val])
	pp.sort(key=lambda x:x[1],reverse=True)

	x = 0
	largeind = [-1,-1,N,N]
	for i in range(N):
		target = pp[i][0]
		L1ind, L2ind = -1, -1
		R1ind, R2ind = N, N

		larger = len(largeind)
		smaller = -1
		while larger-smaller!=1:
			medium = int((larger+smaller)/2)
			if largeind[medium]>target:
				larger = medium
			else:
				smaller = medium
		largeind.insert(larger,target)

		L1ind = largeind[larger-1]
		L2ind = largeind[larger-2]
		R1ind = largeind[larger+1]
		R2ind = largeind[larger+2]

		x += ((L1ind-L2ind)*(R1ind-target) + (target-L1ind)*(R2ind-R1ind))*pp[i][1]

	print(x)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

def main():

	input = sys.stdin.readline

	N = int(input().strip())
	P = list(map(int,input().strip().split()))

	RR = [i+1 for i in range(N)]
	LL = [i-1 for i in range(N)]
	ips = [0]*(N)
	for i, val in enumerate(P):
		ips[val-1] = i
	P.sort()

	x = 0
	for i in range(N):
		target = ips[P[i]-1]
		R1ind = RR[target]
		R2ind = RR[ min(R1ind,N-1) ]
		L1ind = LL[target]
		L2ind = LL[ max(L1ind,0) ]

		x += ((L1ind-L2ind)*(R1ind-target) + (target-L1ind)*(R2ind-R1ind))*P[i]

		if L1ind!=-1:
			RR[L1ind] = R1ind
		if R1ind!=N:
			LL[R1ind] = L1ind

	print(x)

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

import numpy as np
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in a:
    x = np.ones(n)
    x *= i
    x %= a
    if np.count_nonzero(x==0) == 1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
m = max(a)
y = [0] * (m + 1)
for i in a:
    x = i
    while x <= m:
        y[x] += 1
        x += i
ans = 0
for j in a:
    if y[j] == 1:
        ans += 1

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

import copy
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  copy_a = copy.copy(a)
  tmp = copy_a.pop(i)
  print(max(copy_a))

### FIXED CODE ###

import copy
n = int(input())
a = [int(input()) for i in range(n)]
sorted_a = sorted(a, reverse=True)
n1 = sorted_a[0]
n2 = sorted_a[1]
if(n1 == n2):
  for i in range(n):
    print(n1)
else:
  for i in range(n):
    if a[i] == n1:
      print(n2)
    else:
      print(n1)
### BUGGY CODE ###

import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

input = sys.stdin.buffer.readline
int1 = lambda x: int(x) - 1
N, M = map(int, input().split())

if M == 0:
    print(-1)
    exit()

UV = np.array([tuple(map(int1, input().split())) for _ in range(M)]) * 3
frm = UV[:, 0].repeat(3) + np.tile(np.arange(3), M)
to = UV[:, 1].repeat(3) + np.tile((np.arange(3) + 1) % 3, M)

S, T = map(int1, input().split())
matr = csr_matrix((np.ones(3 * M, dtype=int), (frm, to)), shape=(3 * N, 3 * N))
way = dijkstra(matr, indices=3 * S)

print(-1 if np.isinf(res := way[3 * T]) else int(res) // 3)


### FIXED CODE ###

import sys
from collections import deque

input = sys.stdin.buffer.readline
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
G = [[] for _ in range(3 * N)]
for _ in range(M):
    u, v = map(int1, input().split())
    G[u * 3].append(v * 3 + 1)
    G[u * 3 + 1].append(v * 3 + 2)
    G[u * 3 + 2].append(v * 3)

S, T = map(int1, input().split())
S *= 3
T *= 3

# bfs
d = deque([S])
distance = [0] * (3 * N)
while d:
    v = d.popleft()
    dist_v = distance[v]
    if v == T:
        print(dist_v // 3)
        exit()
    for x in G[v]:
        if not distance[x]:
            d.append(x)
            distance[x] = dist_v + 1
print(-1)
### BUGGY CODE ###

from sys import stdin
a,b,k = [int(_) for _ in stdin.readline().rstrip().split()]
nums = [_ for _ in range(a,b+1)]
ans = nums[:k]+nums[-k:]
if len(nums) < k*2:
    ans = list(set(ans))
    ans.sort()
for i in ans:
    print(i)

### FIXED CODE ###

from sys import stdin
a,b,k = [int(_) for _ in stdin.readline().rstrip().split()]
for i in range(a, min(b,a+k-1)+1):
    print(i)
for i in range(max(a+k,b-k+1), b+1):
    print(i)
### BUGGY CODE ###

mod = 998244353

class mod_combination:
    def __init__(self, N):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.invmod = [1] * (N + 1)
        self.invmod[N] = pow(self.fac[N], mod - 2, mod)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % mod
        
    def calc(self, n, k): # nCk
        return self.fac[n] * self.invmod[k] % mod * self.invmod[n - k] % mod


n, m, k = map(int, input().split())
C = mod_combination(n)
ans = 0
color = m
for x in reversed(range(n)):
    if x <= k:
        ans += C.calc(n - 1, n - x - 1) * color % mod
        ans %= mod
    color *= m - 1
print(ans)


### FIXED CODE ###

mod = 998244353

class mod_combination:
    def __init__(self, N):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.invmod = [1] * (N + 1)
        self.invmod[N] = pow(self.fac[N], mod - 2, mod)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % mod
        
    def calc(self, n, k): # nCk
        return self.fac[n] * self.invmod[k] % mod * self.invmod[n - k] % mod


n, m, k = map(int, input().split())
C = mod_combination(n)
ans = 0
for x in range(k + 1):
    ans = (ans + C.calc(n - 1, n - x - 1) * m * pow(m - 1, n - x - 1, mod) % mod) % mod
print(ans)
### BUGGY CODE ###

import numpy as np

N, Q = map(int, input().split())
ans = np.zeros((N+1), dtype=np.int)
graph = {i:[None, []] for i in range(1, N+1)}
nums = [False] * (N)
visited = [False] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    graph[b][0] = a
    graph[a][1].append(b)
    nums[a] = True
        
q = [idx+1 for idx, _ in enumerate(nums) if not _]

while q:
    n = q.pop(0)
    visited[n] = True

    par, child = graph[n]
    if not par is None and not visited[par]:
        graph[par][1].extend(child)
        q.append(par)
        
for i in range(Q):
    p, x = map(int, input().split())
    ans[p] += x
    
for i in range(1, N+1):
    ans[graph[i][1]] += ans[i]
    print(ans[i])

### FIXED CODE ###

from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

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

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


for i in range(n):
  b = a[:]
  b.pop(i)
  r = 0
  for j in range(n):
    c = b.count(j)
    if c > 1:
      r += c * (c-1) / 2
    else:
      pass
  print(int(r))

### FIXED CODE ###

from collections import Counter
import math

def combinations_count(n):
    return (n * (n - 1)) // 2

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

combs = {}
dic = Counter(A)
for k, v in dic.items():
    combs[k] = combinations_count(v)
ans = sum(combs.values())

for i in range(N):
    a = A[i]
    ans_i = ans
    if combs[a] < 2:
        ans_i -= combs[a]
        print(ans_i)
    else:
        ans_i -= dic[a] - 1
        print(ans_i)
### BUGGY CODE ###

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

def Comb(n):
    gyakugen = [1]*(n+1)
    fac = [1]*(n+1)

    for i in range(1,n+1):
        fac[i] = (fac[i-1]*i)%mod

    gyakugen[n] = pow(fac[n],mod-2,mod)

    for i in range(n,0,-1):
        gyakugen[i-1] = gyakugen[i]*i

    com = [1]*(n+1)

    for i in range(1,n+1):
        com[i] = (fac[n]*gyakugen[i]*gyakugen[n-i])%mod

    return com

N = int(input())
aa = inpl_int()

i = 1
dd = defaultdict(int)
for i,a in enumerate(aa):
	if dd[a] == 0:
		dd[a] = i+1
	else:
		X1 = dd[a]-1
		X2 = i

L,R = X1,N-X2
ALL = 1


ALL = Comb(N+1)
daburi = Comb(L+R)


for i in range(1,N+2):
	if L+R+1 >= i:
		print(ALL[i]-daburi[i-1])
	else:
		print(ALL[i])


### FIXED CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

def Comb(n):
    gyakugen = [1]*(n+1)
    fac = [1]*(n+1)

    for i in range(1,n+1):
        fac[i] = (fac[i-1]*i)%mod

    gyakugen[n] = pow(fac[n],mod-2,mod)

    for i in range(n,0,-1):
        gyakugen[i-1] = (gyakugen[i]*i)%mod

    com = [1]*(n+1)

    for i in range(1,n+1):
        com[i] = (fac[n]*gyakugen[i]*gyakugen[n-i])%mod

    return com

N = int(input())
aa = inpl_int()

i = 1
dd = defaultdict(int)
for i,a in enumerate(aa):
	if dd[a] == 0:
		dd[a] = i+1
	else:
		X1 = dd[a]-1
		X2 = i

L,R = X1,N-X2
ALL = 1

ALL = Comb(N+1)
daburi = Comb(L+R)

for i in range(1,N+2):
	if L+R+1 >= i:
		print((ALL[i]-daburi[i-1])%mod)
	else:
		print(ALL[i]%mod)
### BUGGY CODE ###

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

for x in range(0,K+1):
    for y in range(0,K+1):
        for z in range(0,K+1):
            if ((x + y + z )== S):
                cnt += 1
                if((x + y + z )>S):
                    break

print(cnt)

### FIXED CODE ###

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

for x in range(0,K+1):
    for y in range(0,K+1):
        if(0 <= S - x - y and S - x - y <= K):
            cnt += 1

print(cnt)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト

    next_A = [0 for _ in range(N)]

    for k in range(min(K, 41)):
        if sum(A) == N**2:
            break
        for i in range(N):
            for j in range(i-A[i], i+A[i]+1):
                if j >= 0 and j < N:
                    next_A[j] += 1
        A = next_A
        next_A = [0 for _ in range(N)]

    for i in A:
        print(i, end=" ")

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト
    B = [0] * N

    for j in range(min(K, 41)):
        for i in range(N):
            l = max(0, i-A[i])
            r = min(N-1, i+A[i])
            B[l] += 1
            if r+1 < N: B[r+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
        B = [0] * N

    for i in A:
        print(i, end=" ")

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

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

#print(N,A)

for i in range(N):
  d = {}
  for j,a in enumerate(A):
    if j != i:
      d[a] = d.get(a, 0) + 1
  sum = 0
  for v in d.values():
    sum += int(v*(v-1)/2)
  print(sum)


### FIXED CODE ###

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

d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
sum = sum([v*(v-1)/2 for v in d.values()]) 

for i in range(N):
  print(int(sum-d[A[i]]+1))
### BUGGY CODE ###

from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(input())

def ggcd(*numbers):
    return reduce(gcd, numbers)

sum=0

for x in range(1,a+1):
    for y in range(1,a+1):
        if x == 1 and y==1 : sum+=(1*a);continue
        for z in range(1,a+1):
            if x==y==z:
                sum+=x
            else:
                if(x == y or y==z):
                    sum += gcd(x, z)
                elif(x==z):
                    sum += gcd(x, y)
                else:
                    sum += ggcd(x, y,z)
                    

print(sum)


### FIXED CODE ###

from math import gcd
from functools import reduce
# import itertools
from collections import defaultdict

a=int(input())

sum=0


for x in range(1,a+1):
    for y in range(1,a+1):
        for z in range(1,a+1):
            sum+=gcd(gcd(x,y),z)


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

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()
BC = [LIST() for _ in range(M)]

for B, C in BC:
	for i in range(B):
		A.append(C)

A.sort(reverse=True)
print(sum(A[0:N]))


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()
BC = [LIST() for _ in range(M)]
A.sort(reverse=True)
BC.sort(key=lambda x:-x[1])
# print(A)
# print(BC)
count = 0
ans = 0
while count < N:
	if BC and A[0] < BC[0][1]:  # BCからとる
		if BC[0][0] + count > N:
			ans += BC[0][1] * (N-count)
			count = N
		else:
			count += BC[0][0]
			ans += BC[0][1] * BC[0][0]
		# print(count, ans)
		BC.pop(0)
	else:
		count += 1
		ans += A.pop(0)
		# print(count, ans)
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import heapq
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
heapq.heapify(clst)
res=0
q=2**(n-1)+(n-1)*2**(n-2)
for i in range(n):
  h=heapq.heappop(clst)
  res+=h*q
  q-=2**(n-2)
print(2**n*res % mod)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
mod=10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(clst[0]*2%mod)
  quit()
clst.sort(reverse=True)
res=sum(i*item for i, item in enumerate(clst,2))
print((4**(n-1)*res)%mod)
### BUGGY CODE ###

def weight( n, lst ):
    l = len(lst)
    wei = 0
    for i in range(N):
        if n % 2 == 1:
            wei += lst[l-i-1] 
        n  = n // 2
    return wei

N = int(input())
Vlist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

maxval = 0
for i in range(2 ** N):
    vsum = weight(i,Vlist)
    csum = weight(i,Clist)
    gain = vsum - csum
    if i == 0:
        maxval = gain
    else:
        if maxval < gain:
            maxval = gain

print(maxval)

### FIXED CODE ###

N = int(input())
Vlist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
sum1 = 0
for i in range(N):
    x = Vlist[i]
    c = Clist[i]
    if x - c > 0:
        sum1 += (x-c)
print(sum1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N = map(int,input().split())
    a = list(map(int,input().split()))
    MOD = 10**9+7
    M = max(a)
    l = M.bit_length()
    bit = [[0,0] for _ in range(l)]

    for num in a:
        for i in range(l):
            re = num%2
            bit[i][re] += 1
            num //= 2

    ans = 0
    for i in range(l):
        x = (bit[i][0]*bit[i][1])*(1<<i)
        ans += (x%MOD)
    
    print(ans%MOD)    
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N = int(input())
    a = np.array(list(map(int,input().split())),dtype = int)
    MOD = 10**9+7
    ans = 0
    for n in range(60):
        bit = (a>>n)&1
        nonzero = np.count_nonzero(bit)
        zero = N-nonzero
        count = nonzero*zero
        for _ in range(n):
            count *= 2
            count %= MOD
        ans += count
        ans %= MOD
    
    print(ans)

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

import itertools
n,m = map(int,input().split())
zahyou_list = [i for i in map(int,input().split())]
zahyou_list.sort()
#print(zahyou_list)
kaisa_list = []
#print(sum(kaisa_list))

for i in range(len(zahyou_list)-1):
    kaisa_list.append(zahyou_list[i+1] - zahyou_list[i])
mini = sum(kaisa_list)
#print(kaisa_list)
if n >= m:
    print(0)
else:
    for v in itertools.combinations(kaisa_list,n-1):
        #print(mini)
        #print(sum(kaisa_list)-sum(v))
        mini = min(mini,sum(kaisa_list)-sum(v))
    print(mini)
"""
階差のリストのうちn-1個要素を減らして合計値の最小値で求める
"""


### FIXED CODE ###

import itertools
n,m = map(int,input().split())
zahyou_list = [i for i in map(int,input().split())]
zahyou_list.sort()
#print(zahyou_list)
kaisa_list = []

#print(sum(kaisa_list))

for i in range(len(zahyou_list)-1):
    kaisa_list.append(zahyou_list[i+1] - zahyou_list[i])
mini = sum(kaisa_list)
kaisa_list.sort()
#print(kaisa_list)
if n >= m:
    print(0)
elif n == 1:
    print(sum(kaisa_list))
else:
    print(sum(kaisa_list[:-(n-1)]))
### BUGGY CODE ###

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a
cost = sum(s_cost)
for k in range(1,N):
    s_cost = [min(s_cost[x],a[y]) for (x,y) in zip( list(range(N)), list(range(N-k,N))+list(range(N-k)) )]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break
print(cost)


### FIXED CODE ###

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)