jiahuimbzuai/CoQuIR huggingface dataset:
//  [javascript]
function twoMax(arr) {
    var first = 0;
    var firstKey = -1
    var second = 0;
    var secondKey = -1;
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] >= first) {
            second = first;
            secondKey = firstKey;
            first = arr[i];
            firstKey = i;
        } else if (arr[i] >= second) {
            second = arr[i];
            secondKey = i;
        }
    }
    return [first, firstKey, second, secondKey];
}
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var V = input[1].split(" ").map(x => parseInt(x, 10));
    var freqEven = new Array(100001).fill(0);
    var freqOdd = new Array(100001).fill(0);
    for (var i = 0; i < n; i++) {
        if (i % 2 == 0) {
            freqEven[V[i]]++;
        } else {
            freqOdd[V[i]]++;
        }
    }
    var evenTwoMax = twoMax(freqEven);
    var evenFirst = evenTwoMax[0];
    var evenFirstKey = evenTwoMax[1]; 
    var evenSecond = evenTwoMax[2];
    var oddTwoMax = twoMax(freqOdd);
    var oddFirst = oddTwoMax[0];
    var oddFirstKey = oddTwoMax[1];
    var oddSecond = oddTwoMax[2];
    var minus = 0;
    if (evenFirstKey == oddFirstKey) {
        minus = Math.max(evenFirst+oddSecond, oddFirst + evenSecond);
    } else {
        minus = evenFirst + oddFirst;
    }
    console.log(n-minus);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  input = input.split("\n");
  n = parseInt(input[0]);
  tmp=input[1].split(" ");
  v=new Array(n);
  var countse = {};
  var countso = {};
  var maxe1 =0;
  var maxe2 =0;
  var maxenum=0;
  var maxo1 =0;
  var maxo2 =0;
  var maxonum=1;
  var ans =0;
  for(i=0;i<n;i++){
    v[i]=parseInt(tmp[i]);
    if(i%2==0){
      var num = v[i];
      countse[num]=countse[num] ? countse[num] +1 :1;
      if(maxe1!=0&&v[maxenum]!=v[i]&&countse[num]>maxe2){
        maxe2=countse[num];
      }
      if(countse[num]>maxe1){
        if(v[maxenum]!=v[i]){
          maxe2=maxe1;
        }
        maxe1=countse[num];
        maxenum=i;
      }
    }else{
      var num = v[i];
      countso[num]=countso[num] ? countso[num] +1: 1;
      if(maxo1!=0&&v[maxonum]!=v[i]&&countso[num]>maxo2){
        maxo2=countso[num];
      }
      if(countso[num]>maxo1){
        if(v[maxonum]!=v[i]){
          maxo2=maxo1;
        }
        maxo1=countso[num];
        maxonum=i
      }
    }
  }

  if(v[maxenum]!=v[maxonum]){
    ans=n-maxe1-maxo1;
  }else{
    ans=Math.min(n-maxe1-maxo2,n-maxe2-maxo1);
  }


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
(function(input) {
  'use strict';
  const INPUT = input.split("\n")
  for(let i = 0; i<INPUT.length; i=i+2){
    if(!INPUT[i] || !INPUT[i+1]) continue
    if (INPUT[i] === 2) {
      console.log('0')
      continue
    }
    const length = INPUT[i]
    const line = INPUT[i+1].split(" ")
    let Max = 0
    let MaxNumFirst = ''
    let SecmaxNumFirst = ''
    let countHashFirst = {}
    for(let j=0; j< length; j=j+2){
      countHashFirst[line[j]]
      ? countHashFirst[line[j]]++
      : countHashFirst[line[j]]=1
      if(countHashFirst[line[j]] >= Max){
        Max = countHashFirst[line[j]]
        if (MaxNumFirst != line[j]) SecmaxNumFirst = MaxNumFirst
        MaxNumFirst = line[j]
      }
    }

    Max = 0
    let MaxNumSecond = ''
    let SecmaxNumSecond = ''
    let countHashSecond = {}
    for(let j=1; j< length; j=j+2){
      countHashSecond[line[j]]
      ? countHashSecond[line[j]]++
      : countHashSecond[line[j]]=1
      if(countHashSecond[line[j]] >= Max){
        Max = countHashSecond[line[j]]
        if (MaxNumSecond != line[j])SecmaxNumSecond = MaxNumSecond
        MaxNumSecond = line[j]
      }
    }

    if(MaxNumFirst==MaxNumSecond) {
      let resA = 0
      let resB = 0
      for(let j=0; j< length; j=j+2){
        if(SecmaxNumFirst != line[j]) resA++
        if(MaxNumSecond != line[j+1]) resA++
      }
      for(let j=0; j< length; j=j+2){
        if(SecmaxNumSecond != line[j+1]) resB++
        if(MaxNumFirst != line[j] ) resB++
      }
      console.log(resA > resB ? resB : resA)
    } else {
      let res = 0
      for(let j=0; j< length; j=j+2){
        if(MaxNumFirst != line[j]) res++
        if(MaxNumSecond != line[j+1]) res++
      }
      console.log(res)
    }
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')

N = inp.shift() * 1
inp = inp.shift().split(' ')
a = []
b = []
ao = {}
bo = {}
for (i=0; i<N; i++) {
    if (i % 2) {
        bo[inp[i]] = (bo[inp[i]] || 0) + 1
    } else {
        ao[inp[i]] = (bo[inp[i]] || 0) + 1
    }
}
as = 0
bs = 0
for (k in ao) {
    a.push({k: k, n: ao[k]})
    as += ao[k]
}
for (k in bo) {
    b.push({k: k, n: bo[k]})
    bs += bo[k]
}
a.sort((a, b) => b.n - a.n)
b.sort((a, b) => b.n - a.n)

min = Infinity
if (a[0].k == b[0].k) {
    if (a[1] && b[1]) {
        if (a[0].n < b[0].n) {
            bs -= b[0].n
            as -= a[1].n
        } else {
            bs -= b[1].n
            as -= a[0].n
        }
    } else {
        if (!a[1] && b[1]) {
            bs -= b[1].n
            as -= a[0].n
        } else if (a[1] && !b[1]) {
            bs -= b[0].n
            as -= a[1].n
        } else {
            if (a[0].n < b[0].n) {
                bs = 0
            } else {
                as = 0
            }
        }
    }
} else {
    as -= a[0].n
    bs -= b[0].n
}

console.log(as + bs)
//  [javascript]
'use strict';
const main = input => {
  const n = parseInt(input[0]), v = input[1].split(' ').map(val => parseInt(val));
  let even = [], odd = [];
  for(let i=0; i<n; i++) {
    if(i%2) odd.push(v[i]);
    else even.push(v[i]);
  }

  let oddmode = (new Array(100000)).fill(0);  
  odd.map(val => oddmode[val]++);
  let OmaxId = oddmode.indexOf(Math.max.apply(null, oddmode));
  let Omax = oddmode[OmaxId];
  oddmode[OmaxId] = 0;
  let Osec = Math.max.apply(null, oddmode);
  
  let evenmode = (new Array(100000)).fill(0);
  even.map(val => evenmode[val]++);
  let EmaxId = evenmode.indexOf(Math.max.apply(null, evenmode));
  let Emax = evenmode[EmaxId];
  evenmode[EmaxId] = 0;
  let Esec = Math.max.apply(null, evenmode);
  
  if (EmaxId != OmaxId) {
    console.log(n-Emax-Omax);    
    return;
  }
  if (Esec==0&&Osec==0) {
    console.log(n/2);    
    return;
  }
  if (Esec==0) {
    console.log(n-Emax-Osec);
    
    return;
  }
  if (Osec==0) {
    console.log(n-Esec-Omax);
    
    return;
  }
  console.log(Math.min(n-Emax-Osec, n-Esec-Omax));
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));
//  [javascript]
'use strict';
const main = input => {
  const n = parseInt(input[0]), v = input[1].split(' ').map(val => parseInt(val));
  // console.log(n, v);
  let even = [], odd = [];
  for(let i=0; i<n; i++) {
    if(i%2) odd.push(v[i]);
    else even.push(v[i]);
  }
  // console.log(even, odd);

  let oddmode = (new Array(100000)).fill(0);
  odd.map(val => oddmode[val]++);
  let Omax = Math.max.apply(null, oddmode);
  let OmaxId = oddmode.indexOf(Math.max.apply(null, oddmode));
  oddmode[OmaxId] = 0;
  let Osec = Math.max.apply(null, oddmode);
  let OsecId = oddmode.indexOf(Math.max.apply(null, oddmode));
  
  let evenmode = (new Array(100000)).fill(0);
  even.map(val => evenmode[val]++);
  let Emax = Math.max.apply(null, evenmode);
  let EmaxId = evenmode.indexOf(Math.max.apply(null, evenmode));
  evenmode[EmaxId] = 0;
  let Esec = Math.max.apply(null, evenmode);
  let EsecId = evenmode.indexOf(Math.max.apply(null, evenmode));
  
  if (EmaxId != OmaxId) {
    console.log(n-Emax-Omax);
    return;
  }
  if (Esec==0&&Osec==0) {
    console.log(n/2);
    return;
  }
  if (Esec==0) {
    console.log(n-Emax-Osec);
    return;
  }
  if (Osec==0) {
    console.log(n-Esec-Omax);
    return;
  }
  console.log(Math.min(n-Emax-Osec, n-Esec-Omax));
  
  // console.log(even, odd);
  // console.log(Emax, Esec, Omax, Osec);
  

  // if (OmaxId == EmaxId) {
  //   if (odd.length-Omax == even.length-Emax) {
  //     if (odd.length-Osec > even.length-Esec) {
  //       console.log(n-Esec-Omax);
  //     } else {
  //       console.log(n-Osec-Emax);
  //     }
  //   } else if (odd.length-Omax > even.length-Emax) {
  //     console.log(n-Omax-Esec);
  //   } else {
  //     console.log(n-Emax-Osec);
      
  //   }
  // } else {
  //   console.log(n-Omax-Emax);
  // }
  // // console.log(even.length, odd.length);
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));
//  [go]
package main

import (
	"fmt"
	"strconv"
	"os"
	"bufio"
	"strings"
)

// template start
var sc = bufio.NewScanner(os.Stdin)


func input2int() int{
	sc.Scan()
	num , _ := strconv.Atoi(sc.Text())
	return num
}

func input2intarr(n int) []int{
	sc.Scan()
	in := strings.Split(sc.Text(), " ")
	out := make([]int, n)
	for i:=0; i<n; i++{
		out[i], _ = strconv.Atoi(in[i])
	}
	return out
}
// template end

func main(){
	var buf = make([]byte, 10000)
	sc.Buffer(buf, 1000000)
	var n = input2int()
	var arr = input2intarr(n)
	var even = make(map[int]int, n/2)
	var odd = make(map[int]int, n/2)
	for i:=0; i<n; i++{
		if i%2 == 0{
			even[arr[i]]++
		} else {
			odd[arr[i]]++
		}
	}
	var e_max, o_max int
	var e_k, o_k int
	for k, v := range(even){
		if v > e_max{
			e_k, e_max = k, v
		}
	}
	for k, v := range(odd){
		if v > o_max{
			o_k, o_max = k, v
		}
	}
	if e_k == o_k{
		if e_max == o_max{
			var first, second int
			first = e_max
			o_max = 0
			odd[o_k] = 0
			for _, v := range(odd){
				if v > o_max{
					o_max =  v
				}
			}
			e_max = 0
			even[e_k] = 0
			for _, v := range(even){
				if v > e_max{
					e_max =  v
				}
			}
			if e_max >= o_max{
				second = e_max
			}else if o_max > e_max{
				second = o_max
			}
			e_max, o_max = first, second
		} else if e_max > o_max{
			o_max = 0
			odd[o_k] = 0
			for _, v := range(odd){
				if v > o_max{
					o_max =  v
				}
			}
		} else {
			e_max = 0
			even[e_k] = 0
			for _, v := range(even){
				if v > e_max{
					e_max =  v
				}
			}
		}
	}
	fmt.Println(n - (e_max + o_max))
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	var n int
	fmt.Scan(&n)

	om := make(map[int]int, n/2)
	em := make(map[int]int, n/2)
	for i := 0; i < n/2; i++ {
		xo := scanInt()
		om[xo]++
		xe := scanInt()
		em[xe]++
	}

	type entry struct{ k, v int }
	ol := make([]entry, len(om))
	index := 0
	for k, v := range om {
		ol[index].k, ol[index].v = k, v
		index++
	}
	sort.Slice(ol, func(i, j int) bool { return ol[i].v > ol[j].v })

	el := make([]entry, len(em))
	index = 0
	for k, v := range em {
		el[index].k, el[index].v = k, v
		index++
	}
	sort.Slice(el, func(i, j int) bool { return el[i].v > el[j].v })

	if ol[0].k != el[0].k {
		fmt.Println(n - ol[0].v - el[0].v)
		return
	}

	if len(ol) == 1 {
		ol = append(ol, entry{-1, 0})
	}
	if len(el) == 1 {
		el = append(el, entry{-1, 0})
	}
	if v1, v2 := n-ol[0].v-el[1].v, n-ol[1].v-el[0].v; v1 < v2 {
		fmt.Println(v1)
	} else {
		fmt.Println(v2)
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

type pair struct {
	key int
	val int
}
type pairlist []pair

func (p pairlist) Len() int           { return len(p) }
func (p pairlist) Less(i, j int) bool { return p[i].val > p[j].val }
func (p pairlist) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func sortMapByValue(m map[int]int) pairlist {
	pl := make(pairlist, len(m))
	i := 0
	for k, v := range m {
		pl[i] = pair{k, v}
		i++
	}
	sort.Sort(pl)
	return pl
}

func f(a []int) (pair, pair) {
	if len(a) == 0 {
		panic("hoge")
	}

	m := make(map[int]int)
	for _, aa := range a {
		m[aa]++
	}
	sorted := sortMapByValue(m)

	var x, y pair
	if len(sorted) == 1 {
		x, y = sorted[0], pair{-1, 0}
	} else {
		x, y = sorted[0], sorted[1]
	}
	return x, y
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	vo := make([]int, 0, n/2)
	ve := make([]int, 0, n/2)
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			vo = append(vo, ri())
		} else {
			ve = append(ve, ri())
		}
	}
	odd_1, odd_2 := f(vo)
	evn_1, evn_2 := f(ve)
	cost := -1
	if odd_1.key != evn_1.key {
		cost = len(vo) - odd_1.val + len(ve) - evn_1.val
	} else {
		tmp1 := len(vo) - odd_1.val + len(ve) - evn_2.val
		tmp2 := len(vo) - odd_2.val + len(ve) - evn_1.val
		cost = smaller(tmp1, tmp2)
	}
	fmt.Println(cost)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func min(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m > v {
			m = v
		}
	}
	return m
}

func max(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m < v {
			m = v
		}
	}
	return m
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - /\/\/\/
	var n int
	fmt.Scan(&n)

	sc.Split(bufio.ScanWords)
	v := make([]int, n)
	temp1 := make(map[int]int, n)
	temp2 := make(map[int]int, n)

	var count1, count2 int
	for i := 0; i < n; i++ {
		v[i] = nextInt()
		if i%2 == 0 {
			temp1[v[i]]++
			count1++
		} else {
			temp2[v[i]]++
			count2++
		}
	}

	//fmt.Println(temp1, count1)
	//fmt.Println(temp2, count2)

	sortTemp1 := make([]int, 0)
	for _, v := range temp1 {
		sortTemp1 = append(sortTemp1, v)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(sortTemp1)))

	var max1Num1, max2Num1 int
	for i, v := range temp1 {
		if v == sortTemp1[0] {
			max1Num1 = i
		} else if v == sortTemp1[1] {
			max2Num1 = i
		}
	}

	sortTemp2 := make([]int, 0)
	for _, v := range temp2 {
		sortTemp2 = append(sortTemp2, v)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(sortTemp2)))

	//fmt.Println(sortTemp2)
	var max1Num2, max2Num2 int
	for i, v := range temp2 {
		if v == sortTemp2[0] {
			max1Num2 = i
		} else if v == sortTemp1[1] {
			max2Num2 = i
		}
	}

	//fmt.Println(temp1[max1Num1], temp2[max2Num1])
	if max1Num1 == max1Num2 {
		fmt.Println(min(count1-temp1[max1Num1]+count2-temp2[max2Num2], count1-temp1[max2Num1]+count2-temp2[max1Num2]))
		//fmt.Println("Test1")
	} else {
		fmt.Println(count1 - temp1[max1Num1] + count2 - temp2[max1Num2])
		//fmt.Println("Test2")
	}
}
//  [ruby]
INF = 10 ** 6
n = gets.chomp.to_i
nums = gets.chomp.split(" ").map(&:to_i)
odds = Array.new(10 ** 5 + 1, 0)
evens = Array.new(10 ** 5 + 1, 0)
nums.each_with_index do |num, index|
  if index.even?
    odds[num] += 1
  else
    evens[num] += 1
  end
end

odds_candidates = []
evens_candidates = []

2.times do
  odds_max = odds.index(odds.max)
  if odds[odds_max] == -1
    break
  else
    odds_candidates << [odds_max, n / 2 - odds[odds_max]]
    odds[odds_max] = -1
  end

  evens_max = evens.index(evens.max)
  if evens[evens_max] == -1
    break
  else
    evens_candidates << [evens_max, n / 2 - evens[evens_max]]
    evens[evens_max] = -1
  end
end

odds_candidates << [INF, n / 2]
evens_candidates << [INF, n / 2]

mins = []

odds_candidates.each do |odds_candidate|
  evens_candidates.each do |evens_candidate|
    if odds_candidate[0] == evens_candidate[0]
      next
    else
      mins << odds_candidate[1] + evens_candidate[1]
    end
  end
end

puts mins.min
//  [ruby]
nu = gets.to_i
array = gets.chomp.split(' ').map(&:to_i)
count1 = []
count2 = []
(0..nu - 1).each do |i|
  if i.even?
    count1.push(array[i])
  else
    count2.push(array[i])
  end
end
count3 = Array.new(10**5 + 1, 0)
count4 = Array.new(10**5 + 1, 0)

(0..count1.length - 1).each do |i|
  count3[count1[i]] += 1
end
(0..count1.length - 1).each do |i|
  count4[count2[i]] += 1
end

check1 = [0, 0]
check2 = [0, 0]
check3 = [0, 0]
check4 = [0, 0]
(1..10**5).each do |i|
  if check1[1] < count3[i]
    check1[1] = count3[i]
    check1[0] = i
  end
  if check2[1] < count4[i]
    check2[1] = count4[i]
    check2[0] = i
  end
end
(1..10**5).each do |i|
  if check3[1] < count3[i] && i != check1[0]
    check3[1] = count3[i]
    check3[0] = i
  end
  if check4[1] < count4[i] && i != check2[0]
    check4[1] = count4[i]
    check4[0] = i
  end
end

if check1[0] != check2[0]
  puts (count1.length - check1[1]) + (count2.length - check2[1])
  exit
end

if (check1[1] + check4[1]) > (check2[1] + check3[1])
  puts (count1.length - check1[1]) + (count2.length - check4[1])
else
  puts (count1.length - check3[1]) + (count2.length - check2[1])
end
//  [ruby]
n=gets.to_i
v=gets.split.map(&:to_i)
he=[0]*(10**5+1)
ho=[0]*(10**5+1)
n.times do |i|
  if i.even?
    he[v[i]]+=1
  else
    ho[v[i]]+=1
  end
end
hemv = he.max
homv = ho.max
hemk = he.index(he.max)
homk = ho.index(ho.max)
if hemk == homk
  he[hemk]=0
  ho[homk]=0
  if he==[0]*(10**5+1)
    hhemv=0
  else
    hhemv = he.max
  end
  if ho==[0]*(10**5+1)
    hhomv=0
  else
    hhomv = ho.max
  end
  puts n-[hemv+hhomv,homv+hhemv].max
else
  puts n-hemv-homv
end
//  [ruby]
def hahs_sort_desc(hash)
  hash.sort {|a,b| a[1]<=>b[1]}.reverse
end

def max_key(hash)
  hash = hahs_sort_desc(hash)
  hash[0][0]
end

def func(hash, exclude_key = nil)
  res = 0
  if exclude_key
    # 2つ目の計算
    keys = hash.keys
    max_key = max_key(hash)

    if max_key == exclude_key
      if keys.size == 1
        res = hash.first[1]
      else
        hash = hahs_sort_desc(hash)
        target_key = hash[1][0]
        hash.each{|k,v| res += v if k != target_key}
      end
    else
      if keys.size != 1
        hash = hahs_sort_desc(hash)
        hash[1..-1].each{|k,v| res += v}
      end
    end
  else
    if hash.keys.size != 1
      hash = hahs_sort_desc(hash)
      hash[1..-1].each{|k,v| res += v}
    end
  end
  res
end

_ = gets.to_i
a = []
b = []
x = Hash.new(0)
y = Hash.new(0)
gets.chomp.split.each_with_index do |s, i|
  s = s.to_i
  if i.even?
    a << s
    x[s] += 1
  else
    b << s
    y[s] += 1
  end
end

puts func(x) + func(y, max_key(x))
//  [ruby]
def hahs_sort_desc(hash)
  hash.sort {|a,b| a[1]<=>b[1]}.reverse
end

def max_key(hash)
  hash = hahs_sort_desc(hash)
  hash[0][0]
end

def func(hash, exclude_key = nil)
  res = 0
  if exclude_key
    # 2つ目の計算
    keys = hash.keys
    max_key = max_key(hash)

    if max_key == exclude_key
      if keys.size == 1
        res = hash.first[1]
      else
        hash = hahs_sort_desc(hash)
        target_key = hash[1][0]
        hash.each{|k,v| res += v if k != target_key}
      end
    else
      hash[1..-1].each{|k,v| res += v}
    end
  else
    if hash.keys.size != 1
      hash = hahs_sort_desc(hash)
      hash[1..-1].each{|k,v| res += v}
    end
  end
  res
end

_ = gets.to_i
a = []
b = []
x = Hash.new(0)
y = Hash.new(0)
gets.chomp.split.each_with_index do |s, i|
  s = s.to_i
  if i.even?
    a << s
    x[s] += 1
  else
    b << s
    y[s] += 1
  end
end

puts func(x) + func(y, max_key(x))
//  [ruby]
def max_key(hash)
  hash = hash.sort {|a,b| a[1]<=>b[1]}.reverse
  hash[0][0]
end

def func(hash, exclude_key = nil)
  res = 0
  if hash.keys.size != 1
    hash = hash.sort {|a,b| a[1]<=>b[1]}.reverse
    if exclude_key
      hash.each{|k,v| res += v if k != exclude_key}
    else
      hash[1..-1].each{|k,v| res += v}
    end
  elsif exclude_key
    res = hash.first[1]
  end
  res
end

_ = gets.to_i
a = []
b = []
x = Hash.new(0)
y = Hash.new(0)
gets.chomp.split.each_with_index do |s, i|
  s = s.to_i
  if i.even?
    a << s
    x[s] += 1
  else
    b << s
    y[s] += 1
  end
end

if a == b
  puts func(x) + func(y, max_key(x))
else
  puts func(x) + func(y)
end
//  [rust]
fn main() {
    let mut buf: String = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse::<usize>().unwrap();
    let mut v1: Vec<usize> = vec![0; 100001];
    let mut v2: Vec<usize> = vec![0; 100001];
    let mut buf: String = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut itr = buf.split_whitespace();
    while let Some(i) = itr.next() {
        v1[i.parse::<usize>().unwrap()] += 1;
        if let Some(i) = itr.next() {
            v2[i.parse::<usize>().unwrap()] += 1;
        }
    }
    let (mut m11,mut m12,mut m21,mut m22,mut m31,mut m32): (usize,usize,usize,usize,usize,usize) = (0,0,0,0,0,0);
    for x in 0..100001 {
        if v1[x] > m12 {
            if v1[x] > m11 {
                m12 = m11;
                m11 = v1[x];
                m31 = x;
            } else {
                m12 = v1[x];
            }
        }
        if v2[x] > m22 {
            if v2[x] > m21 {
                m22 = m21;
                m21 = v2[x];
                m32 = x;
            } else {
                m22 = v2[x];
            }
        }
    }
    println!("{}", if m31 != m32 {n-m11-m21} else {std::cmp::min(n-m11-m22,n-m12-m21)});
}
//  [rust]
// input macro
// ref: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[allow(unused_mut)]
fn main() {
    input!(
        n: usize,
        v: [usize; n],
    );

    let mx = 10_usize.pow(5) + 1;
    let mut odd: Vec<usize> = vec![0; mx];
    let mut even: Vec<usize> = vec![0; mx];

    for (i, &vi) in v.iter().enumerate() {
        if i%2 == 0 {
            odd[vi] += 1;
        }
        else {
            even[vi] += 1;
        }
    }

    let mut oddfirst = (0,0);
    let mut oddsecond = (0,0);
    for (oi, &oddi) in odd.iter().enumerate() {
        if oddi > oddfirst.1 {
            oddsecond = oddfirst.clone();
            oddfirst = (oi, oddi);
        }
        else if oddi > oddsecond.1 {
            oddsecond = (oi, oddi);
        }
    }

    let mut evenfirst = (0,0);
    let mut evensecond = (0,0);
    for (ei, &eveni) in even.iter().enumerate() {
        if eveni > evenfirst.1 {
            evensecond = evenfirst.clone();
            evenfirst = (ei, eveni);
        }
        else if eveni > evensecond.1 {
            evensecond = (ei, eveni);
        }
    }

    if oddfirst.0 == evenfirst.0 {
        if oddsecond.1 > evensecond.1 {
            println!("{}", n - evenfirst.1 - oddsecond.1);
        }
        else {
            println!("{}", n - oddfirst.1 - evensecond.1);
        }
    }
    else {
        println!("{}", n - oddfirst.1 - evenfirst.1);
    }


}
//  [rust]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let v = get!([usize]);
    let mut even = HashMap::with_capacity(n / 2);
    let mut odd = HashMap::with_capacity(n / 2);
    for (i, x) in v.iter().enumerate() {
        if i % 2 == 0 {
            let counter = even.entry(x).or_insert(0);
            *counter += 1;
        } else {
            let counter = odd.entry(x).or_insert(0);
            *counter += 1;
        }
    }
    let mut e_max_val = 0;
    let mut e_second_val = 0;
    let mut key_of_e_max_val = 0;
    for (key, val) in even.iter() {
        if e_max_val <= *val {
            key_of_e_max_val = **key;
            e_second_val = e_max_val;
            e_max_val = *val;
        } else if e_second_val <= *val {
            e_second_val = *val;
        }
    }
    let mut o_max_val = 0;
    let mut o_second_val = 0;
    let mut key_of_o_max_val = 0;
    for (key, val) in odd.iter() {
        if o_max_val <= *val {
            key_of_o_max_val = **key;
            o_second_val = o_max_val;
            o_max_val = *val;
        } else if o_second_val <= *val {
            o_second_val = *val;
        }
    }
    //eprintln!(
    //    "key_of_e_max_val: {}, e_max_val: {}, e_second_val: {}",
    //    key_of_e_max_val, e_max_val, e_second_val
    //);
    //eprintln!(
    //    "key_of_o_max_val: {}, o_max_val: {}, o_second_val: {}",
    //    key_of_o_max_val, o_max_val, o_second_val
    //);
    if key_of_e_max_val != key_of_o_max_val {
        println!("{}", n - e_max_val - o_max_val);
    } else {
        println!(
            "{}",
            std::cmp::min(n - e_max_val - o_second_val, n - e_second_val - o_max_val)
        );
    }
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

fn main() {
    input! {
    n: usize,
    v: [usize; n]
    }
    let mut ec = vec![0; 100005];
    let mut oc = vec![0; 100005];
    for i in 0..n {
        if i % 2 == 0 {
            ec[v[i]] += 1;
        } else {
            oc[v[i]] += 1;
        }
    }
    let (mut em, mut om) = (0, 0);
    let (mut sem, mut som) = (0, 0);
    for i in 0..100005 {
        if ec[em] <= ec[i] {
            sem = em;
            em = i;
        }
        if oc[om] <= oc[i] {
            som = om;
            om = i;
        }
    }
    let ans = ec.iter().sum::<usize>() + oc.iter().sum::<usize>()
        - if em == om || em == som || om == sem {
        max(ec[em] + oc[som], ec[sem] + oc[om])
    } else {
        ec[em] + oc[om]
    };
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

fn main() {
    input! {
    n: usize,
    v: [usize; n]
    }
    let mut ec = vec![0; 100005];
    let mut oc = vec![0; 100005];
    for i in 0..n {
        if i % 2 == 0 {
            ec[v[i]] += 1;
        } else {
            oc[v[i]] += 1;
        }
    }
    let (mut em, mut om) = (0, 0);
    let (mut sem, mut som) = (0, 0);
    for i in 0..100005 {
        if ec[em] <= ec[i] {
            sem = em;
            em = i;
        }
        if oc[om] <= oc[i] {
            som = om;
            om = i;
        }
    }
    let ans = ec.iter().sum::<usize>() + oc.iter().sum::<usize>()
        - if em == om {
        max(ec[em] + oc[som], ec[sem] + oc[om])
    } else {
        ec[em] + oc[om]
    };
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    n: usize,
    v: [usize; n]
    }
    let mut ec = vec![0; 100005];
    let mut oc = vec![0; 100005];
    for i in 0..n {
        if i % 2 == 0 {
            ec[v[i]] += 1;
        } else {
            oc[v[i]] += 1;
        }
    }
    let (mut em, mut om) = (0, 0);
    let (mut sem, mut som) = (0, 0);
    for i in 0..100005 {
        if ec[em] <= ec[i] {
            sem = em;
            em = i;
        }
        if oc[om] <= oc[i] {
            som = om;
            om = i;
        }
    }
    let ans = ec.iter().sum::<usize>() + oc.iter().sum::<usize>()
        - if em == om {
        if ec[em] > oc[om] {
            ec[em] + oc[som]
        } else {
            ec[sem]+ oc[om]
        }
    } else {
        ec[em] + oc[om]
    };
    println!("{}", ans);
}
//  [swift]
let n = Int(readLine()!)!
let v = readLine()!.characters.split(" ").map{Int(String($0))!}
var num = (0..<2).map{_ in (0..<100000).map{_ in 0}}
for (i, vi) in v.enumerate() {
    num[i%2][vi-1] += 1
}
var first = [0, 0]
var second = [0, 0]
for i in 0..<100000 {
    for j in 0..<2 {
        if num[j][i] > first[j] {
            (first[j], second[j]) = (num[j][i], first[j])
        } else if num[j][i] > second[j] {
            second[j] = num[j][i]
        }
    }
}
if num[0].indexOf(first[0]) != num[1].indexOf(first[1]) {
    print(n - (first[0]+first[1]))
} else {
    print(n - max(first[0]+second[1], second[0]+first[1]))
}
//  [swift]
let n = Int(readLine()!)!
let v = readLine()!.characters.split(" ").map{Int(String($0))!}
var num = (0..<2).map{_ in (0..<100000).map{_ in 0}}
for (i, vi) in v.enumerate() {
    num[i%2][vi-1] += 1
}
let sortedNum = num.map{$0.sort(>)}
let maxNum = (0..<2).map{sortedNum[$0][0]}
if num[0].indexOf(maxNum[0]) != num[1].indexOf(maxNum[1]) {
    print(n - (maxNum[0] + maxNum[1]))
} else {
    print(n - max(maxNum[0]+sortedNum[1][1], sortedNum[0][1]+maxNum[1]))
}
//  [swift]
let n = Int(readLine()!)!
let v = readLine()!.characters.split(" ").map{Int(String($0))!}
var num = (0..<2).map{_ in (0..<100000).map{_ in 0}}
for (i, vi) in v.enumerate() {
    num[i%2][vi-1] += 1
}
let sortedNum = num.map{$0.filter{$0>0}.sort(>)}
let maxNum = (0..<2).map{sortedNum[$0][0]}
if num[0].indexOf(maxNum[0]) != num[1].indexOf(maxNum[1]) {
    print(n - (maxNum[0] + maxNum[1]))
} else {
    print(n - max(maxNum[0]+sortedNum[1][1], sortedNum[0][1]+maxNum[1]))
}
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const n = Number(stdin.split('\n')[0])

const v = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const getHighFreqSeq = _ => {
  let euniqsObj = {}
  let euniqs = []
  let eseqs = []
  let emax = 0
  let emaxi = 0

  let ouniqsObj = {}
  let ouniqs = []
  let oseqs = []
  let omax = 0
  let omaxi = 0
  
  for (let i = 0; i < v.length; i++) {
    if (i % 2 === 0) {
      const euniqIdx = euniqsObj[v[i]]
      if (euniqIdx === undefined) {
        euniqs.push(v[i])
        euniqsObj[v[i]] = euniqs.length-1
        eseqs.push(1)
      } else {
        eseqs[euniqIdx]++
        if (eseqs[euniqIdx] > emax) {
          emax = eseqs[euniqIdx]
          emaxi = euniqIdx
        }
      }
    } else {
      const ouniqIdx = ouniqsObj[v[i]]
      if (ouniqIdx === undefined) {
        ouniqs.push(v[i])
        ouniqsObj[v[i]] = ouniqs.length-1
        oseqs.push(1)
      } else {
        oseqs[ouniqIdx]++
        if (oseqs[ouniqIdx] > omax) {
          omax = oseqs[ouniqIdx]
          omaxi = ouniqIdx
        }
      }
    }
  }

  return {
    e: {
      max: emax,
      maxi: emaxi,
      seqs: eseqs,
      uniqs: euniqs,
    },

    o: {
      max: omax,
      maxi: omaxi,
      seqs: oseqs,
      uniqs: ouniqs,
    },
  }
}

const res = _ => {
  const { e, o } = getHighFreqSeq()

  const eMIdx = e.maxi
  const oMIdx = o.maxi
  const eMaxFreq = e.uniqs[eMIdx]
  const oMaxFreq = o.uniqs[oMIdx]

  e.seqs.sort((a, b) => b - a)
  o.seqs.sort((a, b) => b - a)

  let esum = 0
  let esum2 = 0
  let osum = 0
  let osum2 = 0

  for (let i = 0; ; i++) {
    if (i !== 0 && e.seqs.length > i) {
      esum += e.seqs[i]
    }
    if (i !== 1 && e.seqs.length > i) {
      esum2 += e.seqs[i]
    }

    if (i !== 0 && o.seqs.length > i) {
      osum += o.seqs[i]
    }
    if (i !== 1 && o.seqs.length > i) {
      osum2 += o.seqs[i]
    }

    if (e.seqs.length <= i && o.seqs.length <= i) {
      break
    }
  }

  if (eMaxFreq === oMaxFreq) {
    return Math.min(esum + osum2, esum2 + osum)
  } else {
    return esum + osum
  }
}

console.log(res())
//  [typescript]
const p = (...args) => {
  process.env.NODE_ENV === "test" ? console.log(...args) : ""
}

const tupple = (obj, mark) => {
  return Object.keys(obj).map((key) => {
    const value = obj[key]
    return {
      key,
      value,
      mark
    }
  })
  // .sort((a, b) => b.value - a.value)
}

const calc = (n, a, b) => {
  if (a[0].key !== b[0].key) {
    return n - a[0].value - b[0].value
  }
  if (b.length > 1) {
    return n - a[0].value - b[1].value
  }
  return n - a[0].value
}
const solve = (input) => {
  let [n, rest] = input.split("\n")

  // let odd = []
  let oddNum = {}
  // let even = []
  let evenNum = {}
  const vs = rest.split(" ").map(Number)
  n = vs.length
  vs.forEach((v, i) => {
    if (i % 2 == 0) {
      // even.push(v)
      evenNum[v] = (evenNum[v] || 0) + 1
    } else {
      // odd.push(v)
      oddNum[v] = (oddNum[v] || 0) + 1
    }
  })
  const odd2 = tupple(oddNum).sort((a, b) => b.value - a.value)
  const even2 = tupple(evenNum).sort((a, b) => b.value - a.value)
  return Math.min(calc(n, odd2, even2), calc(n, even2, odd2))
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}
//  [typescript]
export default solve;

// =================================================
// ABC110C
// =================================================

// main
function main(lines) {
  console.log(solve(lines));
}

// interface
type Tuple = { value: number; count: number };

// solver
function solve(lines: string[]): string {
  const { N, evens, odds } = parseLines(lines);

  const evenTuples = getDescSortedTuplesByExistsNumberCount(evens);
  const oddTuples = getDescSortedTuplesByExistsNumberCount(odds);
  const steps: number[] = [];
  for (let i = 0; i < 2; i++) {
    for (let j = 0; j < 2; j++) {
      const evenTuple = evenTuples[i];
      const oddTuple = oddTuples[j];
      if (evenTuple && oddTuple && evenTuple.value === oddTuple.value) {
        steps.push(N - (evenTuple ? evenTuple.count : 0));
      } else {
        steps.push(N - (evenTuple ? evenTuple.count : 0) - (oddTuple ? oddTuple.count : 0));
      }
    }
  }
  return Math.min(...steps).toString();
}

// helpers
function getDescSortedTuplesByExistsNumberCount(nums: number[]): Tuple[] {
  const numsCountMap: Record<number, number> = nums.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const sortedTuples: Tuple[] = Object.keys(numsCountMap)
    .map(key => ({ value: +key, count: numsCountMap[key] }))
    .sort((x, y) => y.count - x.count);
  return sortedTuples;
}

function parseLines(lines: string[]) {
  const N = +lines[0];
  const nums = lines[1].split(' ').map(s => +s);
  const evens = nums.filter((v, i) => i % 2 === 0);
  const odds = nums.filter((v, i) => i % 2 !== 0);
  const obj = { N, nums, evens, odds };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

// reader
if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume().setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}
//  [typescript]
export default solve;

// =================================================
// ABC110C
// =================================================

// main
function main(lines) {
  console.log(solve(lines));
}

// interface
type Pair = { value: number; count: number; even: boolean };

// solver
function solve(lines: string[]): string {
  const { N, evens, odds } = parseLines(lines);

  const evenNumsCountMap: Record<number, number> = evens.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const oddNumsCountMap: Record<number, number> = odds.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const evenTuples = Object.entries(evenNumsCountMap).map(v => ({ value: +v[0], count: v[1], even: true }));
  const oddTuples = Object.entries(oddNumsCountMap).map(v => ({ value: +v[0], count: v[1], even: false }));

  let even: Pair | null = null;
  let odd: Pair | null = null;
  const mixedTuples = evenTuples.concat(oddTuples).sort((x, y) => y.count - x.count);
  debug({ evenTuples, oddTuples, mixedTuples });
  loop: for (let i = 0; i < mixedTuples.length; i++) {
    if (mixedTuples[i].even && !even) {
      if (odd && mixedTuples[i].value !== odd.value) {
        even = mixedTuples[i];
      } else if (!odd) {
        even = mixedTuples[i];
      }
    } else if (!mixedTuples[i].even && !odd) {
      if (even && mixedTuples[i].value !== even.value) {
        odd = mixedTuples[i];
      } else if (!even) {
        odd = mixedTuples[i];
      }
    }
    if (even && odd) break loop;
  }
  debug({ even, odd });
  return (N / 2 - (even ? even.count : 0) + N / 2 - (odd ? odd.count : 0)).toString();
}

// helpers
function parseLines(lines: string[]) {
  const N = +lines[0];
  const nums = lines[1].split(' ').map(s => +s);
  const evens = nums.filter((v, i) => i % 2 === 0);
  const odds = nums.filter((v, i) => i % 2 !== 0);
  const obj = { N, nums, evens, odds };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

// reader
if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume().setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}

// polyfills
if (!Object.entries) {
  Object.entries = function(obj) {
    var ownProps = Object.keys(obj),
      i = ownProps.length,
      resArray = new Array(i); // preallocate the Array
    while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];
    return resArray;
  };
}
//  [typescript]
export default solve;

// =================================================
// ABC110C
// =================================================

// main
function main(lines) {
  console.log(solve(lines));
}

// solver
function solve(lines: string[]): string {
  const { evens, odds } = parseLines(lines);

  const evenNumsMap: Record<number, number> = evens.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const oddNumsMap: Record<number, number> = odds.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const evenMaxs = Object.entries(evenNumsMap).map(v => [+v[0], v[1], 0]);
  const oddMaxs = Object.entries(oddNumsMap).map(v => [+v[0], v[1], 1]);

  let even = [];
  let odd = [];
  const mixed = evenMaxs.concat(oddMaxs).sort((x, y) => y[1] - x[1]);
  debug({ evenMaxs, oddMaxs, mixed });
  loop: for (let i = 0; i < mixed.length; i++) {
    if (mixed[i][2] === 0 && even.length === 0) {
      if (odd.length !== 0 && mixed[i][0] !== odd[0]) {
        even = mixed[i];
      } else if (odd.length === 0) {
        even = mixed[i];
      }
    } else if (mixed[i][2] === 1 && odd.length === 0) {
      if (even.length !== 0 && mixed[i][0] !== even[0]) {
        odd = mixed[i];
      } else if (even.length === 0) {
        odd = mixed[i];
      }
    }
    if (even.length !== 0 && odd.length !== 0) break loop;
  }
  debug({ even, odd });
  return (evens.length - (even[1] || 0) + odds.length - (odd[1] || 0)).toString();
}

// helpers
function parseLines(lines: string[]) {
  const N = +lines[0];
  const nums = lines[1].split(' ').map(s => +s);
  const evens = nums.filter((v, i) => i % 2 === 0);
  const odds = nums.filter((v, i) => i % 2 !== 0);
  const obj = { N, nums, evens, odds };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

// reader
if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume().setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}

// polyfills
if (!Object.entries) {
  Object.entries = function(obj) {
    var ownProps = Object.keys(obj),
      i = ownProps.length,
      resArray = new Array(i); // preallocate the Array
    while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];
    return resArray;
  };
}
//  [typescript]
export default solve;

// =================================================
// ABC110C
// =================================================

// main
function main(lines) {
  console.log(solve(lines));
}

// solver
function solve(lines: string[]): string {
  const { evens, odds } = parseLines(lines);

  const evenNumsMap: Record<number, number> = evens.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const oddNumsMap: Record<number, number> = odds.reduce((acc, v) => {
    !acc[v] ? (acc[v] = 1) : acc[v]++;
    return acc;
  }, {});
  const evenMaxs = Object.entries(evenNumsMap).map(v => [+v[0], v[1], 0]);
  const oddMaxs = Object.entries(oddNumsMap).map(v => [+v[0], v[1], 1]);

  let even = [];
  let odd = [];
  const mixed = evenMaxs.concat(oddMaxs).sort((x, y) => y[1] - x[1]);
  debug({ evenMaxs, oddMaxs, mixed });
  loop: for (let i = 0; i < mixed.length; i++) {
    if (mixed[i][2] === 0 && even.length === 0) {
      if (odd.length !== 0 && mixed[i][0] !== odd[0]) {
        even = mixed[i];
      } else if (odd.length === 0) {
        even = mixed[i];
      }
    } else if (mixed[i][2] === 1 && odd.length === 0) {
      if (even.length !== 0 && mixed[i][0] !== even[0]) {
        odd = mixed[i];
      } else if (even.length === 0) {
        odd = mixed[i];
      }
    }
    if (even.length !== 0 && odd.length !== 0) break loop;
  }
  debug({ even, odd });
  return (evens.length - (even[1] || 0) + odds.length - (odd[1] || 0)).toString();
}

// helpers
function parseLines(lines: string[]) {
  const N = +lines[0];
  const nums = lines[1].split(' ').map(s => +s);
  const evens = nums.filter((v, i) => i % 2 === 0);
  const odds = nums.filter((v, i) => i % 2 !== 0);
  const obj = { N, nums, evens, odds };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

// reader
if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume().setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}
//  [python]
n,d=map(int,input().split())
print(-(-n//(d*2+1)))
//  [python]
n,d=map(int,input().split())
c=n//(2*d+1)
if n%(2*d+1)==0:print(c)
else:print(c+1)
//  [python]
import math

# スペース区切り整数の入力
N, D = map(int, input().split())
# 最小の監視員数の出力
print("{}".format(math.ceil(N / (2 * D + 1))))
//  [python]
a,b = map(int,input().split())
ans = a//(b+1)
if ans == a/(b+1):
  print(ans)
else:
  print(ans + 1)
//  [python]
n, d = map(int, input().split())
c = 0
while n > d:
    d = d*2 + 1
    c += 1
if c == 0:
    print(1)
else:
    print(c)
//  [python]
import math
x,y =map(int,input().split())
print(math.ceil(x/((y*y)+1)))
//  [java]
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力受取
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String line1 = input.readLine();

        String[] arr = line1.split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        // 1人が見れる本数
        int a = D * 2 + 1;
        // N本を見るために必要な監視員
        int b = N / a;
        if(N % a > 0) b++;

        System.out.println(b);
    }
}
//  [java]
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int d = saori.saori_hayami();
		boolean flg = true;
		int num = 0;
		int ans = 0;
		while(flg){
			if(num >= n){
				flg = false;
				break;
			}
			num += 1;
			num +=  2*d;
			ans++;
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}
//  [java]
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don�t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int D = Integer.parseInt(st.nextToken());
         int boof = 2*D+1;
         int res = N/boof;
         if(N%boof > 0)
            res++;
         System.out.println(res);
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }
//  [java]
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int d = sc.nextInt() + 1;
    int ans = 1;

    while (true) {
      d *= 2;
      if (d <= n) {
        ans++;
      } else {
        break;
      }
    }

    System.out.println(ans);

  }
}