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

def powmod(a,b,m):
	ans=1
	while(b):
		if b%2:
			ans*=a
			ans%=m
			b//=2
		a*=a
		a%=m
	return ans

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
mod=10**9+7
fact = [1]*100005
inv = [0]*100005
for i in range(2,100003):
	fact[i] = (fact[i-1]*i)%mod
for i in range(1,100003):
	inv[i] = powmod(fact[i],mod-2,mod)

#n!//k!(n-k)!
def nCk(n,k):
	return fact[n]*inv[k]%mod*inv[n-k]%mod

ans = 0

for i in range(n-3):
	ans += (a[i]-a[n-1-i])*nCk(n-1-i,k-1)
	ans%=mod
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
mod=10**9+7
fact = [1]*100005
inv = [1]*100005
for i in range(2,100003):
	fact[i] = (fact[i-1]*i)%mod
for i in range(1,100003):
	inv[i] = pow(fact[i],mod-2,mod)

#n!//k!(n-k)!
def nCk(n,k):
	return fact[n]*inv[k]%mod*inv[n-k]%mod

ans = 0

for i in range(n-k+1):
	ans += (a[i]-a[n-1-i])*nCk(n-1-i,k-1)
	ans%=mod
print(ans)
### BUGGY CODE ###

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

for i in range(N):
    print(max( A[:i]+A[i+1:]))

### FIXED CODE ###

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

# 入力された数列を降順でソート
sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    # 最大値が2個発生するならば、そのときはすべての行で最大値が表示される
    for i in range(N):
        print(sortA[0])
else:
    # 最大値が1個しかない場合、最大値の存在する位置では最大から2番めの値が表示されるが、それ以外では最大値が表示される
    maxP = A.index(sortA[0])
    for i in range(maxP):
        print(sortA[0])
    print(sortA[1])
    for i in range(maxP+1, N):
        print(sortA[0])
### BUGGY CODE ###

import sys
n, W = map(int, input().split())

weight = [0]*n
value = [0]*n
for i in range(n):
  weight[i], value[i] = map(int, input().split())

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

for i in range(n):
  sum_w = 0
  while sum_w <= W:
    if sum_w >= weight[i]:
      dp[i+1][sum_w] = max(dp[i][sum_w - weight[i]] + value[i],
                          dp[i][sum_w])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]
    sum_w += 1
print(dp[n][W])    

### FIXED CODE ###

import sys
input = sys.stdin.readline

weight = [0]*110
value = [0]*110
dp = [[0]*100010 for i in range(110)]

N, W = map(int, input().split())
for i in range(N):
  weight[i], value[i] = map(int, input().split())

# dp roop
for i in range(N):
  sum_w = 0
  while sum_w <= W:
    if sum_w >= weight[i]:
      dp[i+1][sum_w] = max(dp[i][sum_w - weight[i]] + value[i], dp[i][sum_w])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]
    sum_w += 1
print(dp[N][W])
### BUGGY CODE ###

# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


for i in range(N-1):
    C[i+1], S[i+1], F[i+1] = (int(i) for i in input().split())

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            # print("i =", i)
            for j in range(10000000):
                if t <= S[i] + j * F[i]:
                    t = S[i] + j * F[i]
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)


### FIXED CODE ###

# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


for i in range(N-1):
    C[i+1], S[i+1], F[i+1] = (int(i) for i in input().split())

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            # print("i =", i)
            # print("S[", i, "] =", S[i])
            if t < S[i]:
                t = S[i]
            for j in range(F[i]):
                if (t + j) % F[i] == 0:
                    t = t + j
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)
### BUGGY CODE ###

n=int(input())
s=str(input())
s=list(s)
import collections
c=collections.Counter(s)
values, counts = zip(*c.most_common())
temp=list(counts)
l=len(temp)
ans=0
for i in range(2**l):
  t=[]
  for j in range(l):
    if ((i >> j) & 1):
      t.append(temp[j])
  tt=1
  for j in range(len(t)):
    tt=(tt*t[j])%(10**9+7)
  ans=ans+tt
print((ans-1)%(10**9+7))

### FIXED CODE ###

n=int(input())
s=str(input())
s=list(s)
import collections
c=collections.Counter(s)
values, counts = zip(*c.most_common())
temp=list(counts)
l=len(temp)
ans=1
for i in range(l):
  ans=ans*(temp[i]+1)
print((ans-1)%(10**9+7))
### BUGGY CODE ###

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

ans = []
cnt = 0
kcn = 0
for i,x in enumerate(s[::-1]):
    i = n - i - 1
    if cnt:
        cnt -= 1
    elif x == 'o' and kcn < k:
        cnt += c
        kcn += 1
        ans.append(i)
cnt = 0
j = len(ans) - 1
kcn = 0
for i,x in enumerate(s):
    if cnt:
        cnt -= 1
    elif x == 'o' and kcn < k:
        cnt += c
        kcn += 1
        # while 0<=j and ans[j] <= i:
        #     if ans[j] == i:
        #         print(i+1)
        #     j -= 1
        if i in ans:
            print(i+1)


### FIXED CODE ###

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

ans = []
cnt = 0
kcn = 0
for i,x in enumerate(s[::-1]):
    i = n - i - 1
    if cnt:
        cnt -= 1
    elif x == 'o' and kcn < k:
        cnt += c
        kcn += 1
        ans.append(i)

cnt = 0
j = len(ans) - 1
kcn = 0
for i,x in enumerate(s):
    if cnt:
        cnt -= 1
    elif x == 'o' and kcn < k:
        cnt += c
        kcn += 1
        if ans[j] == i:
            print(i+1)
        j -= 1
### BUGGY CODE ###

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

BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
cards = A[:]
cards  =sorted(cards)

opes = BC[:]


import bisect
for b, c in opes:
    for _ in range(b):
        if cards[0] > c:
            break
        else:
            cards.pop(0)
            bisect.insort(cards, c)
            
ans = sum(cards)
#print(cards)
print(ans)
            


### FIXED CODE ###

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

BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
cards = A[:]
opes = BC[:]

cards_dict = {}

for c in cards:
    if c in cards_dict:
        cards_dict[c] += 1
    else:
        cards_dict[c] = 1

for b, c in opes:
    if c in cards_dict:
        cards_dict[c] += b
    else:
        cards_dict[c] = b
        
cards_dict = sorted(cards_dict.items(), reverse=True)
#print(cards_dict)

num = 0
ans = 0
for k, v in cards_dict:
    if num + v > N:
        ans += k * (N-num)
        num = N
    else:
        ans +=  k * v
        num += v
    if num == N:
        break
        
print(ans)
### BUGGY CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))

memo = {}


def step(now):
    if now in a:
        return 0
    # print(now)
    if now == n:
        return 1
    if now > n:
        return 0
    if now in memo.keys():
        return memo[now]
    memo[now] = step(now+1)+step(now+2)
    return memo[now]


print(step(0) % 1000000007)
# print(memo)

### FIXED CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))
a=set(a)

memo = [0]*(n+1)
memo[0]=1
if not(1 in a):
    memo[1]=1

for i in range(2,n+1):
    #print(i)
    if i in a:
        continue
    #print(memo[i-1],memo[i-2])
    memo[i]=memo[i-2]+memo[i-1]
            

#print(memo)
print(memo[n]% 1000000007)
### BUGGY CODE ###

from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, C = map(int, input().split())

posDist = []
posVal = []
for _ in range(N):
    d, v = list(map(int, input().split()))
    posDist.append(d)
    posVal.append(v)

negDist = []
negVal = []
for d, v in zip(reversed(posDist), reversed(posVal)):
    negDist.append(C-d)
    negVal.append(v)


posDist = [0]+posDist
negDist = [0]+negDist

posVal = [0]+list(accumulate(posVal))
negVal = [0]+list(accumulate(negVal))
# print(posDist)
# print(negDist)
# print(posVal)
# print(negVal)
for i, d in enumerate(posDist):
    posVal[i] -= d
for i, d in enumerate(negDist):
    negVal[i] -= d
ans = 0
# print("after")
# print(posVal)
# print(negVal)
for l in range(N+1):
    if negVal[l] < 0:
        continue
    for r in range(N-l+1):
        tmp = posVal[r]+negVal[l]-min(posDist[r], negDist[l])
        #print("l,r->", l, r, tmp)
        ans = max(tmp, ans)
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, C = map(int, input().split())
sushis = [list(map(int, input().split())) for _ in range(N)]

# Aを時計回り,Bを反時計回りとする
# O->Aと0->A->Oのコストを計算
valA = []
valArev = []
sumV = 0
tmpMax = -float('inf')

for d, v in sushis:
    sumV += v
    valArev.append(sumV-2*d)
    tmpMax = max(tmpMax, sumV-d)
    valA.append(tmpMax)

valB = []
valBrev = []
sumV = 0
tmpMax = -float('inf')
for d, v in reversed(sushis):
    sumV += v
    revD = C-d
    valBrev.append(sumV-2*revD)
    tmpMax = max(tmpMax, sumV-revD)
    valB.append(tmpMax)


# 折り返しなしの場合の値
ans = max(valA+valB+[0])
# O->A->O->B
for i in range(N-1):
    ans = max(ans, valArev[i]+valB[N-i-2])

# O->B->O->A
for i in range(N-1):
    ans = max(ans, valBrev[i]+valA[N-i-2])
print(ans)
### BUGGY CODE ###

N = int(input())

ans = 0

for m in range(1, N+1):
    if N//m == N % m:
        ans += m

print(ans)


### FIXED CODE ###

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


N = int(input())

divisors = gen_divisors(N)
divisors.remove(1)
ans = 0
for d in divisors:
    m = d-1
    if N//m == N%m:
        ans += m

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

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

MOD = 10 ** 9 + 7


def prime_counter(n):
    ret = []
    for i in range(2, int(n / 2) + 2):
        count = 0
        while n % i == 0:
            n /= i
            count += 1
        if 0 < count:
            ret.append(count)
        if n == 1:
            break
    if 1 < n:
        ret.append(1)
    return ret


def comb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    elif r == 1:
        return n
    return (n % MOD) * pow(r, MOD - 2, MOD) * comb(n - 1, r - 1) % MOD


factnum = prime_counter(M)
ans = 1

for i, p in enumerate(factnum):
    ans *= comb(p + N - 1, p)

ans %= MOD
print(ans)


### FIXED CODE ###

MOD = 10 ** 9 + 7

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

f = []
p = 2
while p * p <= M:
    if M % p != 0:
        p += 1
        continue
    c = 0
    while M % p == 0:
        c += 1
        M //= p
    f.append(c)
    p += 1
if M != 1:
    f.append(1)

ans = 1
for i in f:
    c = 1
    for j in range(i):
        c = c * (N + j) // (j + 1)
    ans = ans * c % MOD
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n,2):
    if a.count(i+1)!=2:
        print(0)
        exit()
else:
  if a.count(0)!=1:
    print(0)
    exit()
  else:
    for i in range(2,n,2):
      if a.count(i)!=2:
        print(0)
        exit()
  
print(2**(n//2))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
  for i in range(0,n,2):
    if a[i]!=i+1 or a[i+1]!=i+1:
        print(0)
        exit()
else:
  if a[0]!=0:
    print(0)
    exit()
  for i in range(2,n,2):
    if a[i-1]!=i or a[i]!=i:
      print(0)
      exit()
      
print((2**(n//2))%(10**9+7))
### BUGGY CODE ###

n,a=open(0);print(*sorted(range(1,int(n)+1),key=lambda x:int(a.split()[x-1])))

### FIXED CODE ###

n,a=open(0)
n=int(n)
b=[0]*int(n)
for i,t in enumerate(a.split()):b[int(t)-1]=i+1
print(*b)
### BUGGY CODE ###

N,M = list(map(int,input().split()))
atob = []
btoz = []
for _ in range(M):
    a, b = list(map(int,input().split()))
    if a == 1:
        if b in btoz:
            print('POSSIBLE')
            break
        atob.append(b)
    elif b == N:
        if a in atob:
            print('POSSIBLE')
            break
        btoz.append(a)
else:print('IMPOSSIBLE')

### FIXED CODE ###

N,M = list(map(int,input().split()))
atob = [0] * N
btoz = [0] * N
for _ in range(M):
    a, b = list(map(int,input().split()))
    if a == 1:atob[b-1] = 1
    elif a == N:btoz[b-1] = 1
    if b == 1:atob[a-1] = 1
    elif b == N:btoz[a-1] = 1

for i in range(N):
    if atob[i]*btoz[i] == 1:
        print('POSSIBLE')
        break
else:print('IMPOSSIBLE')
### BUGGY CODE ###

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

def three_change(i):
    a[i], a[i + 2] = a[i + 2], a[i]

def two_change(i):
    a[i],a[i + 1] = a[i + 1], a[i]

sorted_a = a[:]
sorted_a = sorted(sorted_a)


tar_ind = n - 1
count = 0
while (tar_ind >= 0):
    target = sorted_a[tar_ind]
    if(target != a[tar_ind]):
        cur_ind = a.index(target)
        tmp = tar_ind - cur_ind
        m2 = tmp // 2
        m1 = tmp % 2
        count += m1
        for i in range(m2):
            three_change(cur_ind)
            cur_ind += 2
        for i in range(m1):
            two_change(cur_ind)
            cur_ind += 1
    tar_ind -= 1

print(count)


### FIXED CODE ###

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

even_num = set([a[i] for i in range(0,n) if i % 2 == 0])

a = sorted(a)

odd_num = set([a[i] for i in range(0, n) if i % 2 == 1])

count = len(even_num & odd_num)
print(count)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter, defaultdict
c = Counter(a)
n1, n2, n3 = c[1], c[2], c[3]
n0 = c[0]
def glist(*l, fill=None):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [glist(*ll) for _ in range(l[0])]
dp = glist(301, 301, 301)
dp[0][0][0] = 0
def sub(i1,i2,i3):
    if dp[i1][i2][i3] is not None:
        return dp[i1][i2][i3]
    ans = n
    if i1>0:
        ans += i1 * sub(i1-1,i2,i3)
    if i2>0:
        ans += i2 * sub(i1+1,i2-1,i3)
    if i3>0:
        ans += i3 * sub(i1,i2+1,i3-1)
    ans = ans/(i1+i2+i3)
    dp[i1][i2][i3] = ans
    return ans
print(sub(n1,n2,n3))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter, defaultdict
c = Counter(a)
n1, n2, n3 = c[1], c[2], c[3]
n0 = c[0]
def glist(*l, fill=None):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [glist(*ll) for _ in range(l[0])]

count = 0
S = sum(a)
sub = glist(n1+n2+n3+1,n2+n3+1,n3+1)
sub[0][0][0] = 0
#     for i1 in range(min(n+1, s+1)):
#         for i2 in range(min(n+1, (s-i1)//2+1)):
for i3 in range(n3+1):
    for i2 in range(n2+n3+1-i3):
        for i1 in range(n1+n2+n3 - (i2+i3) + 1):
            if i1==i2==i3==0 or i1+i2+i3>n:
                continue
#             print(i1,i2,i3)
            ans = n
            p = 0
            if i1>0:
                ans += i1 * sub[i1-1][i2][i3]
                p += i1
            if i2>0:
                ans += i2 * sub[i1+1][i2-1][i3]
                p += i2
            if i3>0:
                ans += i3 * sub[i1][i2+1][i3-1]
                p += i3
            ans = ans/p
            sub[i1][i2][i3] = ans
print(sub[n1][n2][n3])
### BUGGY CODE ###

s = input()

n = len(s)
mod = [int(s[n-i-1:]) % 2019 for i in range(n)]
mod.insert(0, 0)

cnt = 0
for i in range(n-3):
    for I in range(i+4,n+1):
        if mod[i] == mod[I]:
            cnt += 1

print(cnt)

### FIXED CODE ###

s = input()

MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i * (i - 1) // 2 for i in d))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
alist = tuple(map(int,input().split()))
anslist = tuple(alist[i]^alist[j] for i in range(n) for j in range(i+1,n))
s = sum(anslist)
if s < 10**9+7:
  print(s)
else:
  print(s%(10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

ans  = 0
for b in range(60+1):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b,mod))%mod


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

import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    for i in range(n):
        if b[i] >= max(a):
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    while True:
        h -= max(a)
        ans += 1
        if h <= 0:
            print(ans)
            exit()
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    b.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0
 
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

n=int(input())
s=input()
a=[[int(i) for i in s.split()]]
b=[[int(i) for i in s.split()]]

ans=n
for i in range(n-1):
	a1=[]
	b1=[]
	for j in range(n-i-1):
		a1.append(a[i][j]^a[0][i+j+1])
		b1.append(b[i][j]+b[0][i+j+1])
		if a1[j]==b1[j]:
			ans+=1
	a.append(a1)
	b.append(b1)
print(ans)


### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]

ans=0
b=0
j=0
for i in range(n):
	while j<n and b^a[j]==b+a[j]:
		b^=a[j]
		j=j+1
	ans += j-i
	b^=a[i]
print(ans)
### BUGGY CODE ###

from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
    s = "".join([c,s])
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

### FIXED CODE ###

from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()
### BUGGY CODE ###

def solve():
    h, k = read()
    result = think(h, k)
    write(result)


def read():
    n, k = read_int(2)
    return read_int(n), k


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h, k):
    cost = [0 for x in range(len(h))]
    # element of h <= 10 ** 4, elements <= 10 ** 5, +1 in case
    initial_value_of_cost = 10 ** (4 + 5) + 1
    n = len(h)
    for dst in range(1, n):
        minimum_cost = initial_value_of_cost
        for src in range(max(0, dst - k), dst):
            minimum_cost = min(minimum_cost, cost[src] + abs(h[src] - h[dst]))
        cost[dst] = minimum_cost
    return cost[n - 1]


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    h, k = read()
    result = think(h, k)
    write(result)


def read():
    n, k = read_int(2)
    return read_int(n), k


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h, k):
    cost = [0 for x in range(len(h))]
    for dst in range(1, len(h)):
        start_point = max(0, dst - k)
        cost[dst] = min([cost[src] + abs(h[src] - h[dst]) for src in range(start_point, dst)])
    return cost[len(h) - 1]


def write(result):
    print(result)


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

n = int(input())
x = [int(i) for i in input().split()]
for i in range(n):
    y = x[:i]+x[i+1:]
    y_new = sorted(y)
    print(y_new[n//2-1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
x_new = sorted(x)
med1 = x_new[n//2]
med2 =x_new[n//2-1]
for i in range(n):
    if x[i] < med1:
        print(med1)
    else:
        print(med2)
### BUGGY CODE ###

mod = 1000000007
n,m = map(int, input().split(" "))
a = [int(input()) for i in range(m)]
ans = [0]*(n+1)
ans[0] = 1
for j in range(1,n+1):
  if j in a:
    ans[j] = 0
  else:
    ans[j] = ans[j-1] + ans[j-2]
    ans[j] = ans[j]%mod
print(ans[-1])
      

### FIXED CODE ###

mod = 1000000007
n,m = map(int, input().split(" "))
a = set([int(input()) for i in range(m)])
ans = [0]*(n+1)
ans[0] = 1
for j in range(1,n+1):
  if j in a:
    ans[j] = 0
  else:
    ans[j] = (ans[j-1] + ans[j-2])%mod
print(ans[-1])
### BUGGY CODE ###

n,q=map(int,input().split())
hoge=input()

for i in range(q):
  a,b=map(int,input().split())
  huga=hoge[a-1:b]
  print(huga.count("AC"))

### FIXED CODE ###

n,q=map(int,input().split())
hoge=input()
huga=[0]
for i in range(n-1):
  flag=0
  if(hoge[i]=="A" and hoge[i+1]=="C"):
    flag=1
  huga.append(huga[-1]+flag)

for i in range(q):
  a,b=map(int,input().split())
  print(huga[b-1]-huga[a-1])
### BUGGY CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        try:
            w = (N * h * n) / (4 * (h * n) - (N * n) - (N * h))
        except:
            continue
        if w.is_integer() and 0 < w and w < 3501:
            if 4 * (h * n * w) == N * ((n * w) + (h * w) + (h * n)):
                ans = [h, n, int(w)]
                exit(print(' '.join(map(str, ans))))

### FIXED CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        try:
            w = (N * h * n) / (4 * (h * n) - (N * n) - (N * h))
        except:
            continue
        if w.is_integer() and w > 0:
            if 4 * (h * n * w) == N * ((n * w) + (h * w) + (h * n)):
                ans = [h, n, int(w)]
                exit(print(' '.join(map(str, ans))))
### BUGGY CODE ###

MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)


### FIXED CODE ###

MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(60):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)