Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline

def main():
    def calc(n, mod):
        f = 1
        for m in range(1, n + 1):
            f *= m
            f %= mod
        fn = f
        inv = pow(f, mod - 2, mod)
        invs = [1] * (n + 1)
        invs[n] = inv
        for m in range(n, 1, -1):
            inv *= m
            inv %= mod
            invs[m - 1] = inv 
        return fn, invs

    mod = 10**9+7
    n,a,b=map(int,input().split())
    ans=0
    fn,invs=calc(n,mod)
    for i in range(1,n+1):
        if i==a or i==b:
            continue
        else:
            ans+=(invs[i]*invs[n-i])%mod
    print((fn*ans)%mod)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n,r=map(int,input().split())
    if n>=10:
        print(r)
    else:
        print(int(100*(10-n)+r))


if __name__ == '__main__':
    main()
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
field = []
H, W = 0, 0

def solver(x, y, symbol):
  global field, H, W
  if x < 0 or y < 0 or x >= H or y >= W:
    return
  for dx, dy in dxy:
    if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W:
      continue
    if field[x+dx][y+dy] == symbol:
      field[x+dx][y+dy] = '.'
      solver(x+dx, y+dy, symbol)

while True:
  H, W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  field = [list(raw_input()) for i in range(H)]

  ans = 0
  for x in xrange(H):
    for y in xrange(W):
      if field[x][y] != '.':
        solver(x, y, field[x][y])
        ans += 1
  print ans

### FIXED CODE ###

import Queue

dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
field = []
H, W = 0, 0
q = Queue.Queue()

def solver(x, y, symbol):
  global q, field, H, W
  while True:
    if x < 0 or y < 0 or x >= H or y >= W:
      continue
    for dx, dy in dxy:
      if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W:
        continue
      if field[x+dx][y+dy] == symbol:
        field[x+dx][y+dy] = '.'
        q.put([x+dx, y+dy])
    if q.empty():
      return
    x, y = q.get()

while True:
  H, W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  field = [list(raw_input()) for i in range(H)]

  ans = 0
  for x in xrange(H):
    for y in xrange(W):
      if field[x][y] != '.':
        solver(x, y, field[x][y])
        ans += 1
  print ans
from collections import deque
n,m = map(int, input().split())

rel = [[] for _ in range(n)]
for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1)

ans = [-1]*n
def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return

cnt = 0
for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1

print(cnt)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
n,m = map(int, input().split())

rel = [[] for _ in range(n)]
for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1)

ans = [-1]*n
def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return

cnt = 0
for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1

print(cnt)
# 二次元累積和
# A[i1, j1] から A[i2, j2] までの長方形の積算値は
# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)

### FIXED CODE ###

A,B=map(int,input().split())
print((A-1)*(B-1))
# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (len(s) + 1)
idx = 1
while idx <= len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])


### FIXED CODE ###

n, m = map(int, input().split())
s = input()
imos = [0 for _ in range(n)]
for i in range(1, n):
    if s[i-1] == "A" and s[i] == "C":
        imos[i] = imos[i-1]+1
    else:
        imos[i] = imos[i - 1]
for _ in range(m):
    l, r = map(int, input().split())
    if l > 1:
        print(imos[r-1]-imos[l-1])
    else:
        print(imos[r-1])
_ = input()
*a,=input().split()
flag = True
for i in a:
  if i%2 == 0:
    if i%3 != 0:
      if i%5 != 0:
        flag = False
        break
if flag:
  print("APPROVED")
else:
  print("DENIED")

### FIXED CODE ###

_ = input()
a=map(int,input().split())
flag = True
for i in a:
  if i%2 == 0:
    if i%3 != 0:
      if i%5 != 0:
        flag = False
        break
if flag:
  print("APPROVED")
else:
  print("DENIED")
import numpy as np
import sympy as sp
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = [True] * n
for i, num in enumerate(a):
    div = sp.divisors(num)
    for d in div:
        if d == num:
            if a.count(d)>1:
                flag[i] = False
            continue
        if d in a:
            flag[i] = False
print(np.count_nonzero(flag))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = [True] * (a[-1]*3)
for i, num in enumerate(a):
    if a[(i-1)%n]==num or a[(i+1)%n]==num:
        if i-1>=0 or i+1<n:
            flag[num] = False
    for j in range(2, a[-1]//num+2):
        flag[j*num] = False
counter = 0
for i in a:
    if flag[i]:
        counter += 1
print(counter)
A, B, C=map(int(input().split()))
if A+B==C or A+C==B or B+C==A:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

abc = list(map(int, input().split()))
abc.sort(reverse = True)
if abc[0] == abc[1] + abc[2]:
    print("Yes")
else:
    print("No")
S = input()

def kaibun(string):
    count = 0
    strli = list(string)
    for i in range(len(string)/2):
        if strli[i] == strli [-i-1]:
            continue
        else:
            count += 1
    return count

print(kaibun(S))

### FIXED CODE ###

S = input()

def kaibun(string):
    count = 0
    strli = list(string)
    for i in range(len(string)//2):
        if strli[i] == strli [-i-1]:
            continue
        else:
            count += 1
    return count

print(kaibun(S))
N,x,MOD = map(int, input().split())
s = x
t_s = 0
for i in range(2,MOD + 1):
  x = (x*x)%MOD
  s += x
  if i == N:
    break
res = N - i
init = x
t_s = x
cnt = 1
for i in range(MOD):
  x = (x*x)%MOD
  if x == init:
    break
  cnt += 1
  t_s += x
bai = res // cnt
res = res %  cnt
s += t_s * bai
if res > 0:
  for i in range(res):
    x = (x*x)%MOD
    s += x
print(s)

### FIXED CODE ###

N,x,MOD = map(int, input().split())
s = x
flag = False
sflag = False
if N == 1:
  flag = True
  sflag = True
  print(s)
for i in range(1,MOD):
  x = (x*x) % MOD
  s += x
  if N == (i+1):
    flag = True
    break
if flag == True:
  if sflag == False:
    print(s)
else:
  t_s = 0
  cnt = 0
  init = x
  for i in range(MOD):
    x = (x*x) % MOD
    t_s += x
    cnt += 1
    if x == init:
      break
  bi = (N-MOD)//cnt
  res = (N-MOD)%cnt
  s += t_s * bi
  for i in range(res):
    x = (x*x) % MOD
    s += x
  print(s)
n=int(input())
l=list(map(int,input().split()))
sum=1#個数
if l[0]==l[1]:
  sum=0
l.sort()
for j in range(1,n):
  i=1
  for m in range(0,j):
    if l[j]%l[m]==0:
      i=0
      break
  sum+=i
    
print(sum)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in a:
  dp[i]+=1
for i in range(1,10**6+1):
  if dp[i]:
    for  j in range(2*i,10**6+1,i):
      dp[j]=0
print(dp.count(1))
N, M = int(input().split())

ans = 0

for i in range(1, 1000000):
    p = ((1/2)**M)*(1-(1/2)**M)**(i-1)
    ans += (100*(N-M) + 1900*M)*i*p

print(int(ans))

### FIXED CODE ###

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

ans = 0

for i in range(1, 100000):
    p = ((1/2)**M)*(1-(1/2)**M)**(i-1)
    ans += (100*(N-M) + 1900*M)*i*p

print(round(ans))
from collections import  *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n=int(input())
c=1
x=100
while 1:
    x=x*(1.01)
    x=int(x)
    if x==n:
        break
    c+=1
print(c)

### FIXED CODE ###

n=int(input())
c=1
x=100
while x<n:
    x=x*(1.01)
    x=int(x)
    c+=1
print(c-1)
class Node:
    def __init__(self, index, parent_index):
        self.index = index
        self.parent_index = parent_index
        self.children = []
        self.value = 0

    def add_value(self, value):
        if self.index > 0:
            self.value += value
            for child in self.children:
                child.add_value(value)


class Tree:
    def __init__(self):
        self.node_indices = {}
        self.nodes = []

        self.add_node(1, 0)

    def add_node(self, index, parent_index):
        node = Node(index, parent_index)
        self.node_indices[index] = len(self.nodes)
        self.nodes.append(node)

        if index > 1:
            parent_node = self.nodes[self.node_indices[parent_index]]
            parent_node.children.append(node)

    def add_value(self, index, value):
        node = self.nodes[self.node_indices[index]]
        node.add_value(value)


def main():
    n, q = map(int, input().split())

    tree = Tree()
    for _ in range(n - 1):
        parent_index, child_index = map(int, input().split())
        tree.add_node(child_index, parent_index)

    for _ in range(q):
        index, value = map(int, input().split())
        tree.add_value(index, value)

    res = []
    for index in range(1, n + 1):
        node = tree.nodes[tree.node_indices[index]]
        res.append(node.value)
    print(' '.join(map(str, res)))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])
n = int(input())
s = input()*n

ms = n
for i in range(n):
	c = s[0:i].count('W')
	c += s[i+1:n].count('E')
	print(s[0:i], s[i+1:n], c)
	if(ms >= c):
		ms = c
	else:
		break

print(ms)

### FIXED CODE ###

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

ms = n
a = 0
b = s.count('E')
for i in range(n):
	if(i != 0 and s[i-1] == 'W'):
		a += 1
	if(s[i] == 'E'):
		b -= 1
	# print(s[0:i], s[i+1:n], s[0:i].count('W'), s[i+1:n].count('E'), a, b)
	# c = s[0:i].count('W')
	# c += s[i+1:n].count('E')
	c = a + b
	if(ms > c):
		ms = c

print(ms)
"""Shift Only
【問題概要】
黒板に N 個の正の整数 A1,…,AN が書かれています。
すぬけ君は，黒板に書かれている整数がすべて偶数であるとき，次の操作を行うことができます。

黒板に書かれている整数すべてを，2 で割ったものに置き換える。
すぬけ君は最大で何回操作を行うことができるかを求めてください。

【制約】

1≤N≤2001≤N≤200
1≤Ai≤1091≤Ai≤109
【数値例】
1)
　N=3
　A=(16,12,24)
"""
N = int(input())
A = list(map(int, input().split(',')))

is_all_odd = True
counter = 0
while True:
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            is_all_odd = False
    if is_all_odd:
        counter += 1
    else:
        break
print(counter)


### FIXED CODE ###

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

is_all_even = True
counter = 0
while True:
    for i, v in enumerate(A):
        if v % 2 == 0:
            A[i] = A[i] // 2
        else:
            is_all_even = False
    if is_all_even:
        counter += 1
    else:
        break
print(counter)
from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    back = ''
    tmp = ''
    pos = 0
    for i in range(len(s))[::-1]:
        if i==25:
            back += s[i]
            tmp = s[i]
        elif s[i]>tmp:
            back += s[i]
            tmp = s[i]
        else:
            pos = i
            break

    res = s[:pos]
    l = []
    for b in back:
        if b > w:
            l.append(b)
    print(res + min(l))

### FIXED CODE ###

from string import ascii_lowercase
s = input()

if s == ascii_lowercase[::-1]:
    print(-1)
elif len(s)!=len(ascii_lowercase):
    s1 = set(list(s))
    s2 = set(list(ascii_lowercase))
    w = min(s2-s1)
    print(s+w)
else:
    back = ''
    tmp = ''
    pos = 0
    for i in range(len(s))[::-1]:
        if i==25:
            back += s[i]
            tmp = s[i]
        elif s[i]>tmp:
            back += s[i]
            tmp = s[i]
        else:
            pos = i
            break
    
    res = s[:pos]
    w = s[pos]
    l = []
    for b in back:
        if b > w:
            l.append(b)
    print(res + min(l))
nums = [int(input()) for _ in range(5)]


def orders(nums):
  r = [10 - (num % 10) for num in nums if (num % 10)]
  return sum(nums) + sum(r) - max(r)

print(orders(nums))

### FIXED CODE ###

nums = [int(input()) for _ in range(5)]


def orders(nums):
  r = [10 - (num % 10) for num in nums if (num % 10)]
  if r:
  	return sum(nums) + sum(r) - max(r)
  return sum(nums)

print(orders(nums))
#include <iostream>
using namespace std;

double func(double a) {
    double b = a;
    for(int i = 0; i < 1000; i++) {
        b = (b * b + a) / (2 * b);
    }
    return b;
}

int main(void){
    int l, i=0, g[10];
    while(cin>>l){
        g[i] = l;
        i++;
    }
  float a,b,c=0;
  
  a = func(g[0]);
  b = func(g[1]);
  c = func(g[2]);
  printf("%f,%f,%f\n",a,b,c);
  
  if(a+b < c){
    printf("Yes");
  }
    else{
    printf("No");
    }
  
  return 0;
}



### FIXED CODE ###

s = input().split()

d = [int(s) for s in s]
a = d[0]
b = d[1]
c = d[2]

if(c-a-b > 0 and 4*a*b < (c-a-b)**2):
  print("Yes")
else:
  print("No")
N = int(intput())
print(N ** 3)

### FIXED CODE ###

N = int(input())
a = N**3
print(a)
print(-min(int(input())-abs(int(input())-int(input())),0))

### FIXED CODE ###

w,a,b = map(int,input().split())
print(max(max(a,b)-min(a,b)-w,0))
s=input()
day=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
  if s=day[i]:
    print(7-i)

### FIXED CODE ###

s=input()
day=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
  if s==day[i]:
    print(7-i)
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

maxd = 0
ans = None

A, B, C, D, E, F = reads()
for i, j, k in product(range(31), range(31), range(3001)):
  water100 = A * i + B * j
  if C * k > water100 * E or water100 == 0:
    continue
  l = (water100 * E - C * k) // D
  sugar = C * k + D * l
  mass = water100 * 100 + sugar
  density = sugar / mass
  if mass <= F and maxd < density:
    maxd = density
    ans = (mass, sugar)

print(ans[0], ans[1])



### FIXED CODE ###

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

maxd = -1
ans = None

A, B, C, D, E, F = reads()
for i, j, k in product(range(31), range(31), range(3001)):
  water100 = A * i + B * j
  if C * k > water100 * E or C * k > F - water100 * 100 or water100 == 0:
    continue
  l = min(water100 * E - C * k, F - water100 * 100 - C * k) // D
  sugar = C * k + D * l
  mass = water100 * 100 + sugar
  density = sugar / mass
  if mass <= F and maxd < density:
    maxd = density
    ans = (mass, sugar)

print(ans[0], ans[1])
import sys
input = sys.stdin.readline

s = str(input())
Q = int(input())

for _ in range(Q):
	qu = input()
	if qu == '1':
		s = s[::-1]
	else:
		_, fi, ci = qu.split()
		if fi == '1':
			s = ci + s
		if fi == '2':
			s += ci
print(s)

### FIXED CODE ###

from collections import deque
import sys

def main():
    s = sys.stdin.readline().strip()
    qn = int(sys.stdin.readline().strip())
    qs = [input().split() for _ in range(qn)]

    s = deque(s)
    r = 1
    for q in qs:
        if len(q) == 1:
            r = r * -1

        else:
            if q[1] == '1':
                if r == 1:
                    s.appendleft(q[2])
                else:
                    s.append(q[2])
            else:
                if r == 1:
                    s.append(q[2])
                else:
                    s.appendleft(q[2])

    if r == 1:
        print(''.join(s))
    else:
        s.reverse()
        print(''.join(s))

if __name__ == "__main__":
    main()
import numpy as np
N = int(input())
a = [int(_) for _ in input().split()]
a = np.array(a)
a = np.sort(a)
min = 0
max = 0
m = 0

for i in range(8):
    set_1 = set(np.where(i*400<=a)[0])
    set_2 = set(np.where(a<(i+1)*400)[0])
    match = list(set_1 & set_2)
    if len(match)>0:
        min+=1
if min=0:
    min=1
    if N>8:
	max = 8
    else:
	max = N
else:
    if len(np.where(a>=3200)[0])==0:
        max = min
    else:
        max = min + len(np.where(a>=3200)[0])
    	if max>8:
            max = 8
print (min, max)

### FIXED CODE ###

import numpy as np
N = int(input())
a = [int(_) for _ in input().split()]
a = np.array(a)
a = np.sort(a)
min = 0
max = 100

for i in range(8):
    set_1 = set(np.where(i*400<=a)[0])
    set_2 = set(np.where(a<(i+1)*400)[0])
    match = list(set_1 & set_2)
    if len(match)>0:
        min+=1
if min==0:
    min=1
    max = N
else:
    if len(np.where(a>=3200)[0])==0:
        max = min
    else:
        max = min + len(np.where(a>=3200)[0])
print (min, max)
def sol():
    N = int(input())
    S = int(input())

    if N == S:
        print(N + 1)
        return

    def digitSum(n, b):
        if b < 0:
            return -1
        if n < b:
            return n
        return digitSum(n // b, b) + n % b

    for b in range(2, int(N**0.5 + 10)):
        if digitSum(N, b) == S:
            print(b)
            return

    for p in range(1, int(N**0.5 + 10)):
        b = (N - S) // p + 1
        if digitSum(N, int(b)) == S:
            print(int(b))
            return
    print('-1')
sol()

### FIXED CODE ###

def sol():
    N = int(input())
    S = int(input())

    if N == S:
        print(N + 1)
        return

    def digitSum(n, b):
        if b < 2:
            return -1
        if n < b:
            return n
        return digitSum(n // b, b) + n % b

    for b in range(2, int(N**0.5) + 1):
        if digitSum(N, b) == S:
            print(b)
            return

    for p in range(int(N**0.5), 0, -1):
        b = (N - S) // p + 1
        if digitSum(N, b) == S:
            print(b)
            return
    print('-1')

sol()
import copy
n, m = map(int, input().split())
s = [int(x) for x in input().split()]
s2 = copy.deepcopy(s)
for _ in range(m):
    a, b = map(int, input().split())

    a1=s[a-1]
    b1=s[b-1]
    if a1<b1:
        p=(a1 in s2)
        if p == False:
            f=1
        else:
            s2.remove(a1)
    elif a1>b1:
        p=(a1 in s2)
        if p == False:
            f=1
        else:
            s2.remove(b1)
print(len(s2))

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
D = dict()
for i in range(1, n+1):
    D[i] = h[i-1]
L = [1 for i in range(n)]
for _ in range(m):
    a, b =map(int, input().split())
    if D[a] > D[b]:
        L[b-1] = 0
    elif D[a] == D[b]:
        L[a-1] = 0
        L[b-1] = 0
    else:
        L[a-1] = 0
ans = 0
for e in L:
    ans += e
print(ans)
n, x = map(int, input().split())
l = [input() for i in range(n)]
l.sort()
count, total = 0
while total < x:
    total += int(l[i])
    count += 1
print(count)

### FIXED CODE ###

n, x = map(int, input().split())
l = [int(input()) for i in range(n)]
l.sort()
print((x - sum(l)) // l[0] + n)
from numpy import *
N,K = map(int,input().split())
A = array(sorted(list(map(int,input().split()))))
nega = A[A<0]
zera = A[A==0]
posa = A[0<A]

def cnt(x):
  y = 0
  if x>=0:
    y+=n*len(zera)
  y+=searchsorted(A,x//posa,side="right").sum()
  y+=N*len(nega)-searchsorted(A,-(-x//nega)).sum() 
  y-=len(A[A*A<=x])
  return y//2

r = 10**18
l = -r-1

while r-l>1:
  c=(r+l)//2
  if K<=cnt(c):
    r=c
  else:
    l=c

print(r)

### FIXED CODE ###

from numpy import *
N,K = map(int,input().split())
A = array(sorted(list(map(int,input().split()))))
nega = A[A<0]
zera = A[A==0]
posa = A[0<A]

def cnt(x):
  y = 0
  if x>=0:
    y+=N*len(zera)
  y+=searchsorted(A,x//posa,side="right").sum()
  y+=N*len(nega)-searchsorted(A,-(-x//nega)).sum() 
  y-=len(A[A*A<=x])
  return y//2

r = 10**18
l = -r-1

while r-l>1:
  c=(r+l)//2
  if K<=cnt(c):
    r=c
  else:
    l=c

print(r)
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(max(H)- min(H))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
        A = sorted(A,reverse = False) 
print(sum(A[:-N+1]))

### FIXED CODE ###

N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
    A = sorted(A,reverse = False) 
    print(sum(A[:-N+1]))
import sys 
S = input()
A = []
for i,s in enumerate(S):
    if s != 'x':  A.append(i)
for i in range(len(A)//2):
    if S[A[i]] != S[A[-i-1]]:
        print(-1)
        sys.exit()
ans = abs((len(S)-1-A[-1])-A[0])
for i in range(len(A)//2):
    cnt = abs(A[i+1]-A[i] - (A[-1-i]-A[-2-i]))
    ans += cnt
print(ans)


### FIXED CODE ###

import sys 
S = input()
A = []
for i,s in enumerate(S):
    if s != 'x':  A.append(i)
if not A:
    print(0)
    sys.exit()
for i in range(len(A)//2):
    if S[A[i]] != S[A[-i-1]]:
        print(-1)
        sys.exit()
ans = abs((len(S)-1-A[-1])-A[0])
for i in range(len(A)//2):
    cnt = abs(A[i+1]-A[i] - (A[-1-i]-A[-2-i]))
    ans += cnt
print(ans)
import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
from math import sqrt
n=int(input())
v=map(int,input().split())

a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=n/2
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)


### FIXED CODE ###

import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
from math import sqrt
n=int(input())
v=list(map(int,input().split()))

a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=int(n/2)
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)