Harryxun/stf_run huggingface dataset:
# 足場iにたどり着く最初コストを返す
def rec(i):
    # ベースケースをセット
    if i == 0:
        return 0
    
    # i-1から遷移する場合
    cost = rec(i-1) + abs(H[i] - H[i-1])
    
    if i > 1:
        # i-2から遷移する場合
        cost = min(cost, rec(i-2) + abs(H[i] - H[i-2]))
    
    return cost

# 入力
N = int(input())
H = [int(i) for i in input().split()]

print(rec(N-1))

### FIXED CODE ###

# 最小値に置き換える関数
def chmin(a, b):
    if a > b:
        a = b
        return True
    
    return False

# 入力
N = int(input())
H = [int(i) for i in input().split()]

# dpテーブルの生成
dp = [float("inf") for i in range(N)]
# 初期条件のセット(足場1)
dp[0] = 0

# N番目の足場までのループ
# i = 1のときはi-2がないことに注意
for i in range(N):
    # ノードi-1からの遷移を計算
    dp[i] = min(dp[i], dp[i-1]+abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(H[i] - H[i-2]))

# dpテーブルの末尾が答え
print(dp[N-1])
a,b= int(input().split())

if(a==1):
  a= 14

if(b==1):
  b= 14

if(a-b>0):
  print("Alice")
elif(a-b< 0):
  print("Bob")
else:
  print("Draw")
  

### FIXED CODE ###

a,b= input().split()

int(a)
int(b)

if(a=='1'):
  a= 14

if(b=='1'):
  b= 14

if(int(a)-int(b)>0):
  print("Alice")
elif(int(a)-int(b)< 0):
  print("Bob")
else:
  print("Draw")
letters = eval(input("Enter: "))
for i in letters:
  if i[2]==i[3] and i[4]==i[5]:
    print("Yes")
  elif letters=="coffee-like":
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

l = input()
print("Yes" if (l[2]==l[3] and l[4]==l[5]) else "No")
N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]

point = 0
if K < N:
  while i < K:
    point = T_list[point]
    i += 1  

else:
  syuuki = 0
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1

  second_point = point
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)

### FIXED CODE ###

N, K = map(int, input().split())
T_list = list(map(int, input().split()))
T_list = [T_list[i]-1 for i in range(N)]
point = 0
syuuki = 0

if K < N:
  i = 0
  while i < K:
    point = T_list[point]
    i += 1  

else:
  i = 0
  while i < N:
    point = T_list[point]
    if point == 0:
      syuuki = i+1
      break
    i += 1
  second_point = point
  
  if syuuki != 0:
    L = K % syuuki

  else:
    j = 0
    while j < N:
      point = T_list[point]
      if point == second_point:
        syuuki = j+1
        break
      j += 1
    L = (K-i) % syuuki

  k = 0
  while k < L:
    point = T_list[point]
    k += 1
  
print(point+1)
L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		m = min(l)
		L.remove(l)
		for i in range(len(l)):
			l[i] = l[i] - m
		count += m
		l = list(map(str , l))
		l = " ".join(l)
		l = (l.split("0 "))
		for a in l:
			L.append(list(map( int, (a.split()))))
		while [] in L:
			L.remove([])

print(count)

### FIXED CODE ###

N = int(input())

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

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
print(count)
n = input()
if 7 in n:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = input()
if n.count("7") == 0:
    print("No")
else:
    print("Yes")
a,n=map(int,input().split())

amari=n%500

if amari=<a:
    print('Yes')

else:
    print('No')


### FIXED CODE ###

n=int(input())
a=int(input())

amari=int(n%500)

if amari<=a:
    print('Yes')

else:
    print('No')
# -*- coding: utf-8 -*-

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

ans = "NO"
for i in range(B+1)):
    res = A * i % B
    if res == C:
        ans = "YES"
        break

print(ans)

### FIXED CODE ###

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

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

mod = []
for i in range(max(B,C)):
    res = A * i % B
    if res == C:
        ans = "YES"
        break
    if res in mod:
        ans = "NO"
        break
    mod.append(res)

print(ans)
input()
l=sorted(map(int,input().split()))[::-1]
pritn(sum(l[::2])-sum(l[1::2]))

### FIXED CODE ###

input()
l=sorted(map(int,input().split()))[::-1]
print(sum(l[::2])-sum(l[1::2]))
n = int(input())
l = list(map(int,input().split()))
ans = 0
g = set(l)
m = list(g)
m.sort()
for i in range(n):
  judge = 0
  for j in range(i+1,n):
    for k in range(j+1,n):
      if(m[i]<m[j]+m[k]):
        ans += 1
      else:
        break
    if(judge==0):
      break
print(ans)


### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
ans = 0
l.sort(reverse=True)
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if(l[i]!=l[j])and(l[j]!=l[k])and(l[i]!=l[k])and(l[i]<l[j]+l[k]):
        ans += 1
print(ans)
a=input()
b=input()
m=int(a)+int(b)
if int(m)<10:
	print(int(m))
else:
	print("error")

### FIXED CODE ###

# coding: utf-8
a,b=input().split()
m=int(a)+int(b)
if m<10:
  print(int(m))
else:
  print("error")
from itertools import accumulate as ac
def isok(arg):
    x = 0
    for i in a:
        if arg - i >= 0:
            x += cs[arg-i]
        else:
            x += n
    if x >= m:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,m = map(int,input().split())
a = list(map(int,input().split()))
cs = [0]*(10**5+1)
for i in a:
    cs[i] += 1
for i in range(10**5):
    cs[10**5-i-1] += cs[10**5-i]
h = bisect(10**5*2,0)
count = 0
ans = 0
for i in a:
    num = max(0,h-i+1)
    ans += 2*i*cs[num]
    count += cs[num]
ans += (m-count)*h
print(ans)

### FIXED CODE ###

def isok(arg):
    x = 0
    for i in a:
        if arg - i >= 0:
            if arg-i <= 10**5:
                x += cs[arg-i]
        else:
            x += n
    if x >= m:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,m = map(int,input().split())
a = list(map(int,input().split()))
cs = [0]*(10**5+1)
for i in a:
    cs[i] += 1
for i in range(10**5):
    cs[10**5-i-1] += cs[10**5-i]
h = bisect(10**5*2+1,0)
count = 0
ans = 0
for i in a:
    num = max(0,h-i)
    if num <= 10**5:
        ans += 2*i*cs[num]
        count += cs[num]
ans -= (count-m)*h
print(ans)
while True:
    a,o,b=map(input().split())
    int(a,b)
    if o==?:break
    else:
        if o==/:o=//
    print(a,o,b)

### FIXED CODE ###

while True:
    a=input()
    if '?' in a:break
    print(int(eval(a)))
s = "".join(sorted(list(input())))
t = "".join(sorte(list(input()),reverse = True))

is s < t:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = ''.join(sorted(list(input())))
t = ''.join(sorted(list(input()), reverse=True))

if s < t:
    print('Yes')
else:
    print('No')
A,B,C = map(int(input()))

if A + B >= C:
    print('Yes')
else:
    print('No')
    

### FIXED CODE ###

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

if A + B >= C:
    print('Yes')
else:
    print('No')
import sys
input = sys.stdin.readline

n = int(input())

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

a.sort()
cnt = 0

for i in range(n):
    for j in range(i+1):
        if i==0 and a[i] == a[i+1]:
            cnt += 1
            break
        if a[i]%a[j]==0 and i!=j:
            cnt += 1
            break

print(n-cnt)

### FIXED CODE ###

n = int(input())

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

c = [0] * (10**6+1)
for i in a:
    c[i] += 1

uni = []
a = list(set(a))

for i in a:
    if c[i] == 1:
        uni.append(i)

b = [0 for _ in range(10**6+1)]

for i in a:
    for j in range(i*2, 10**6+1, i):
        b[j] = 1

cnt = 0
for i in uni:
    if b[i] == 0:
        cnt += 1

print(cnt)
def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*n]
    for a,b in ab:
        while a!=b:
            a,b=min(a,b),max(a,b)
            b=(b+1)//3
        print(a)
    
    
main()

### FIXED CODE ###

def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    if n==1:
        for a,b in ab:
            print(min(a,b))
        return
    for a,b in ab:
        while a!=b:
            a,b=min(a,b),max(a,b)
            b=(b+n-2)//n
        print(a)
    
main()
A = int(input())
B = int(input())
print(int((A-1)*(B-1)))

### FIXED CODE ###

A,B=map(int,input().split())
print((A-1)*(B-1))
import numpy as np
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

num_str = input()

num_list = [int(num_str[i]) for i in range(len(num_str))]

num_sum = sum(num_list)

if num_sum%9 == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import numpy as np
import sys
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
 
num_str = input()

num_sum = 0
for i in range(len(num_str)):
  num_sum+=int(num_str[i])
 
if num_sum%9 == 0:
  print("Yes")
else:
  print("No")
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, x, y = map(int, input().split())
    tree = [None]*n

    for i in range(1, n):
        for j in range(i+1, n+1):
            # if i <= x and j >= y:
            #     tree[i - 1][j - 1] = j-i-(y - x - 1)
            # elif i <= x and j < y:
            #     tree[i - 1][j - 1] = x - i + min(y - j + 1, j - x)
            # elif i > x and j >= y:
            #     tree[i - 1][j - 1] = j - y + min(i-x+1, y-i)
            # else:
            #     tree[i - 1][j - 1] = j-i
            tree[i - 1].append = min(j-i, abs(x-i) +
                                     1+abs(j-y), abs(y-i)+1+abs(j-x))

    for k in range(1, n):
        ans = 0
        for i in range(n):
            ans += tree[i].count(k)
        print(ans)


### FIXED CODE ###

from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, x, y = LI()
    d = [0]*n
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            d[min(j - i, abs(x - i) + 1 + abs(j - y),
                  abs(y - i) + 1 + abs(j - x)) - 1] += 1
    for k in range(n-1):
        print(d[k])


if __name__ == "__main__":
    main()
n = int(input())
s = input()

print(s)
s = list(s)

print(s)

l1 = 'abcdefghijklmnopqrstuvwxyz'
l1 = list(l1)

l2 = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
l2 = list(l2)

print(l1)

s1 = [0]*len(s)
s2 = [0]*len(s)

for i in range(len(s)):
	s1[i] = l1.index(s[i])

for i in range(len(s)):
	s2[i] = l2[s1[i]+n] 

#リスト１つずつくっつけて文字列にする
ans = ''
for i in range(len(s2)):
	ans = ans + s2[i]

print(ans)


### FIXED CODE ###

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

s = list(s)

l1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l1 = list(l1)

l2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
l2 = list(l2)

s1 = [0]*len(s)
s2 = [0]*len(s)

for i in range(len(s)):
	s1[i] = l1.index(s[i])

for i in range(len(s)):
	s2[i] = l2[s1[i]+n] 

#リスト１つずつくっつけて文字列にする
ans = ''
for i in range(len(s2)):
	ans = ans + s2[i]

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

Ball = ''

while len(Ball) < N:
    Ball += "B" * A + "R" * B

print(Ball[:N].count("B"))


### FIXED CODE ###

N, A, B = map(int, input().split())
num = N // (A + B) + 1
zan = num * (A + B) - N

if zan <= B:
    print(num * A)
else:
    print(num * A + B - zan)
n,k = map(int,input().split())

x = list(map(int,input().split()))
#x = [ abs(int(i))  for i in input().split()]
x.append(0)
x.sort()

min = 10**8

zeroIdx = x.index(0)

# plus
if zeroIdx + k < len(x) :
    min = x[zeroIdx + k] 

# minus 
if zeroIdx - k >= 0 :
    tmp = abs(x[zeroIdx + k])
    if tmp < min :
        min = tmp

# plus/minus
plsIdx = k+1
misIdx = k-1
while True:
    p = 0
    m = 0
    if plsIdx + 1 <  len(x):
        p = abs(x[plsIdx])

    if misIdx - 1 >= len(x):
        m = abs(x[plsIdx])
    
    if p == 0 :
        misIdx -= 1
    elif m == 0 :
        plsIdx += 1
    elif p < m :
        plsIdx += 1
    else: 
        misIdx -= 1

    if plsIdx - misIdx >= k :
        if abs(x[plsIdx]) > abs(x[misIdx]) :
            tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)
        else:
            tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])
        break

if tmp < min :
    min = tmp
print(min)

### FIXED CODE ###

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

x.append(0)
x.sort()

#print(x)

min = 10**10

zeroIdx = x.index(0)

for i in range(zeroIdx-k,zeroIdx+1):
    if i < 0 : 
        continue
    elif len(x) <= i + k :
        break

    plsIdx = i + k 
    misIdx = i

    #print(misIdx,plsIdx,x[misIdx],x[plsIdx])

    if abs(x[plsIdx]) > abs(x[misIdx]) :
        tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)
    else:
        tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])

    if tmp < min :
        min = tmp

print(min)
def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k-1):
    a+=a

 
 
print(count_inversion(a)%100000007)

### FIXED CODE ###

m,d=map(int,input().split())
count=0

for i in range(1,m+1):
    for j in range(22,d+1):
        d1,d2=map(int,str(j))
        if i==(d1*d2) and d2>=2:
            count+=1
            
print(count)
N,Y = map(int, input().split())
for i in range(N + 1):
    for l in range(N - i + 1):
            if 10000*i + 5000*l + 1000*(N - i - l) == Y:
                print(i ,l ,(N - i - l))
                exit()

print(-1 ,-1 ,-1)


### FIXED CODE ###

s = str(input())
l = s.replace("2017", "2018")
print(l)
A, B = int(input())
print(A*B)

### FIXED CODE ###

A, B = (int(x) for x in input().split())
print(A*B)
from statistics import mode
n = int(input())
vlist = list(map(int, input().split()))


a = vlist[::2]
b = vlist[1::2]

freq_a = mode(a)
freq_b = mode(b)


x = len(a) - freq_a
y = len(b) - freq_b

print(a)
print(b)
print(freq_a)
print(freq_b)

if len(set(vlist)) == 1:
    print(min(len(a), len(b)))
else:
    print(x+y)


### FIXED CODE ###

from collections import Counter

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

# most_commonを使うためにリストをCounterオブジェクトに渡す
Counter_evens = Counter(vlist[::2])
Counter_odds = Counter(vlist[1::2])


# even_indexes
top2_even = Counter_evens.most_common(2)  # [(一番多い要素,その出現回数),(2番目に多い要素,その出現回数)]

E_most_common = top2_even[0][0]
Emnum = top2_even[0][1]

if len(top2_even) == 2:
    E_2nd_common = top2_even[1][0]
    E2num = top2_even[1][1]
else:
    E_2nd_common = 'foo'
    E2num = 0

# odd_indexes
top2_odd = Counter_odds.most_common(2)

O_most_common = top2_odd[0][0]
Omnum = top2_odd[0][1]

if len(top2_odd) == 2:
    O_2nd_common = top2_odd[1][0]
    O2num = top2_odd[1][1]
else:
    O_2nd_common = 'foo'
    O2num = 0


if E_most_common == O_most_common:  # most commonどうしが衝突してしまっている。
    # もし偶数番目・奇数番目をどちらもmost commonに書き換えると、3つ目の条件「数列は1種類の数ではだめ」が満たされない。
    # なので奇数番目・偶数番目のどちらかは2番目に多いやつに書き換える必要がある

    # 偶数番目をmost commonに、oddsを2nd commonにそろえる場合に書き換えないといけない要素の数
    x = len(vlist[::2]) - Emnum + len(vlist[1::2]) - O2num
    # 逆の場合
    y = len(vlist[::2]) - E2num + len(vlist[1::2]) - Omnum

    print(min(x, y))
else:
    # most common は衝突していない、つまり異なる数。よって3つ目の条件「数列は1種類の数ではだめ」は満たされている。
    # 両方とも most commonに書き換えてOK
    print(len(vlist[::2]) - Emnum + len(vlist[1::2]) - Omnum)
import numpy as np
from math import gcd

def LGcd(l):
    a = l[0]
    for i in range(1,len(l)):
        a = gcd(a,l[i])
    return a
N, X = map(int,input().split())
k = np.array(input().split())
k = k.astype(np.int64)
k -= X
if N == 1:
    print(str(abs(k[0])))
else:
    print(str(LGcd(k)))

### FIXED CODE ###

# 正の数を受け取るように定義
def gcd(a,b):
    if b == 0:
        return a 
    return gcd(b,a % b)

N, X = map(int,input().split())
k = [abs(int(x) - X) for x in input().split()] # リスト内包表記で入力の受け取り
a = k[0]
for i in range(1,N):
    a = gcd(a,k[i])
print(str(a))
import sys

sys.setrecursionlimit(10**8)

def find(x,table):	#xの根を返す	
	if table[x] == x:
		return x
	else:
		table[x] = find(table[x],table)	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,table,rank):	#xとyを繋げる
	x = find(x,table)	
	y = find(y,table)
	
	if x == y:
		return
	
	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y,table):
	if find(x,table) == find(y,table):
		return True
	else:
		return False

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

table = [i for i in range(N+1)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N+1)]	#木の長さ

for i in range(0,M):
	a,b = map(int, input().split())
	union(a,b,table,rank)
	
ans = 0

for i in range(1,N+1):
	if check(i,P_li[i-1],table):
		ans += 1

print (ans)


### FIXED CODE ###

import sys
import itertools
from collections import defaultdict

sys.setrecursionlimit(10**8)

def find(x,table):	#xの根を返す	
	if table[x] == x:
		return x
	else:
		table[x] = find(table[x],table)	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def union(x,y,table,rank):	#xとyを繋げる
	x = find(x,table)	
	y = find(y,table)
	
	if x == y:
		return
	
	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def check(x,y,table):
	if find(x,table) == find(y,table):
		return True
	else:
		return False

N,K,L = map(int,input().split())

table_car = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank_car  = [1 for i in range(N)]	#木の長さ
table_tr  = [i for i in range(N)] 
rank_tr   = [1 for i in range(N)]

for i in range(0,K):
	a,b = map(int, input().split())
	union(a-1,b-1,table_car,rank_car)
	
for i in range(0,L):
	a,b = map(int, input().split())
	union(a-1,b-1,table_tr,rank_tr)
	
ar = [(find(i,table_car),find(i,table_tr)) for i in range(N)]
dd = defaultdict(int)
for s in ar:
    dd[s] += 1
	
ans =[]
for i in range(N):
    ans.append(dd[ar[i]])
	
print(' '.join(map(str, ans)))
k, s = [int(x) for x in input().split()]
k += 1

count = 0

for x in range(k):
    for y in range(k):
        for z in range(k):
            if x + y + z == s:
                count += 1

print(count)


### FIXED CODE ###

s = input()
print(s.replace(",", " "))
R,G = map(int,input().split())
print(2*G-R)

### FIXED CODE ###

R = int(input())
G = int(input())
print(2*G-R)
import math,bisect
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
    print(sum(A))
else:
    A = sorted(A)
    ind = bisect.bisect_right(A,K)
    A = A[:ind]
    n2 = math.floor(math.log2(K))+1
    cnt = 0
    k = n2-1
    while k>=0:
        B = [(A[i]//(2**k))%2 for i in range(N)]
        b = sum(B)
        cnt += 2**k*max(b,N-b)
        k -= 1
    print(cnt)

### FIXED CODE ###

import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
a1 = max(A)
n = int(math.log2(max(a1,K)))+1
B = [0 for _ in range(n)]
for i in range(N):
    a = bin(A[i])[2:]
    for j in range(len(a)):
        if a[len(a)-1-j]=="1":
            B[j] += 1
x = bin(K)[2:]
y = ""
flag = 0
for i in range(len(x)):
    if flag==0:
        if x[i]=="0":
            y += x[i]
        else:
            if B[len(x)-1-i]<=N//2:
                y += x[i]
            else:
                y += "0"
                flag = 1
    else:
        if B[len(x)-1-i]<=N//2:
            y += "1"
        else:
            y += "0"
y = int(y,2)
cnt = 0
for i in range(N):
    cnt += y^A[i]
print(cnt)
n, m = map(int, input().split())
l = []
for i in range(m+1):
  l.append([])
types = set()
combo = []
for i in range(m):
  f, t = map(int, input().split())
  if not t in l[f]:
    l[f].append(t)
  
  if not f in l[t]:
    l[t].append(f)

def dfs(path, now):
  if len(set(path)) == n and not path in combo:
    combo.append(path)
    return

  for i in l[now]:
    if not i in path:
      temp = path[:]
      temp.append(i)
      dfs(temp, i)

  return

dfs([1], 1)
print(len(combo))

### FIXED CODE ###

n, m = map(int, input().split())
l = []
combo = []
for i in range(max(n, m)+1):
  l.append([])
  
def dfs(path, now):
  if len(set(path)) == n and not path in combo:
    combo.append(path)
    return

  for i in l[now]:
    if not i in path:
      temp = path[:]
      temp.append(i)
      dfs(temp, i)

  return

if m == 0:
  print(0)
else:

  for i in range(m):
    f, t = map(int, input().split())
    if not t in l[f]:
      l[f].append(t)
    
    if not f in l[t]:
      l[t].append(f)

  dfs([1], 1)
  print(len(combo))
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic[b]
    if x == None:
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b- c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)

### FIXED CODE ###

import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic.get(b)
    if x == None:
        l.append(sum)
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b - c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
fibo = [1,1]
r = [a[0]-1]

for i in range(m-1):
    r.append((a[i+1]-a[i])-2)
    if a[i+1] - a[i] == 1:
        print(0)
        exit()
else:
    r.append(n-a[-1]-1)

    for i in range(max(r)+2):
        fibo.append((fibo[-1]+fibo[-2])%1000000007)

    ans = 1

    for i in range(len(r)):
        ans = (fibo[r[i]] * ans)%1000000007

    print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
fibo = [1,1]
ans = 1

for i in range(n):
            fibo.append((fibo[-1]+fibo[-2])%1000000007)

if m:
    r = [a[0]-1]

    for i in range(m-1):
        r.append((a[i+1]-a[i])-2)
        if a[i+1]-a[i] == 1:
            print(0)
            exit()

    else:
        r.append(n-a[-1]-1)

        for i in range(len(r)):
            ans = (fibo[r[i]] * ans)%1000000007

        print(ans)
else:
    print(fibo[n])
import sys
N = int(input())
D = list(map(int,input().split()))
ans=0

if D.count(0)==0 :
    print(ans)
    sys.exit()
else:
    ans=1

for i in range(2,99999):
    mae=D.count(i-1)
    ato=D.count(i)

    if ato>0:
        ans *= mae**ato
    elif ato==0 and i<max(D):
        ans=0
    else:
        break

print(ans%998244353)

### FIXED CODE ###

N = int(input())
ans=0
if N%2==0:
    ans=N/2-1
elif N!=1:
    ans=N/2
print(int(ans))