open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let abs v = abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) let min_int,max_int = min_int,max_int end
module MyInt64 = struct
	let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (+) p q = Int64.add p q let (-) p q = Int64.sub p q let ( * ) p q = Int64.mul p q let (/) p q = Int64.div p q let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v let labs p = if p < 0L then -1L*p else p let (~|) p = Int64.to_int p let (~~|) p = Int64.of_int p let input_i64_array n = Array.init (~| n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let print_i64_endline n = n |> Int64.to_string |> print_endline let (mod) m n = m - (m/n) * n let (%) = (mod) let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n) let lcm m n = (m*n) / gcd m n let rep from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod ~~| !i with | `Break -> f := false | _ -> i := !i +$ 1; done let repb from_ to_ fbod = let i,f = ref ~|from_,ref true in while !i <= ~|to_ && !f do match fbod (~~| !i) with | `Break -> f := false | _ -> i := !i +$ 1 done; !f let repm from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod !m (~~| !i) with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; !m let repmb from_ to_ m_init fbod = let i,f,m = ref ~|from_,ref true,ref m_init in while !i <= ~|to_ && !f do match fbod (~~| !i) !m with | `Break -> f := false | `Break_m m' -> (f := false; m := m') | `Ok m' -> (i := !i +$ 1; m := m') done; (!m,!f) let string_of_list ?(separator=" ") f ls = let rec f0 a s = match a with | [] -> s | [h] -> s ^ (f h) ^ separator | h::t -> f0 t (s ^ (f h) ^ separator) in f0 ls "" let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) [] let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
	let (@@@) = (@) let (@) a i = a.(~|i) let (<@) a (i,v) = a.(~|i) <- v
	let ceildiv m n = (m+n-1L) / n
	let abs v = Int64.abs v let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) = let open Int64 in (logand),(logor),(logxor),lognot,(fun u v -> shift_left u (~|v)),(fun u v -> shift_right u (~|v)),(fun u v -> shift_right_logical u (~|v)) let min_int,max_int = Int64.min_int,Int64.max_int let get_string _ = scanf " %s" (fun v -> v)
	let i32,i64 = Int64.to_int,Int64.of_int let alen a = i64 @@ Array.length a
	let dump_array a = a |> Array.to_list |> string_of_list Int64.to_string |> print_endline let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y) let repi from_ to_ fbod = let i,f = ref from_,ref true in while !i <= to_ && !f do match fbod !i with | `Break -> f := false | _ -> i := !i +$ 1 done
end open MyInt64
let llen l = i64 @@ List.length l
(* module IMap = Map.Make (struct
	type t = int64
	let compare i j = 
end) *)
module IMap = Map.Make (Int64)
let find k m = try IMap.find k m with | Not_found -> 0L

let f = List.fold_left (fun (k,u) (j,v) -> 
		if u < v then (j,v) else (k,u)
) (-1L,Int64.min_int)

let d l = string_of_list (fun (k,v) -> sprintf "(%Ld,%Ld)" k v) l |> print_endline

let () =
	let n = get_i64 0 in let a = input_i64_array n in
	let a0 = (Array.init (i32 n) (fun i -> a.(i))) in
	Array.sort compare a0;
	if a0.(0) = a0.(i32 n -$ 1) then (
		printf "%Ld\n" (n/2L)
	) else (
		let (o,e,_) = Array.fold_left (fun (o,e,i) v ->
			(* printf "%Ld %Ld\n" i v; *)
			if i mod 2L = 0L then (o,IMap.add v (find v e + 1L) e,i+1L)
			else (IMap.add v (find v o + 1L) o,e,i+1L)
		) (IMap.empty, IMap.empty, 0L) a
		in
		let (o2,e2) = IMap.bindings o,IMap.bindings e in
		(* List.iter (fun (u,v) -> printf "(%Ld,%Ld);" u v) o2;
		print_endline "";
		List.iter (fun (u,v) -> printf "(%Ld,%Ld);" u v) e2;
		print_endline "";
		let ((k,p),(j,q)) = f o2, f e2
		in
		if k = j then (
			printf "%Ld\n" (n - (max p q))

		) else (
			printf "%Ld %Ld %Ld %Ld\n" (n / 2L) p ((n+1L)/2L) q;
			printf "%Ld\n" (n - p - q)
		) *)
		let (o2,e2) =
			List.sort (fun (k,u) (j,v) -> -compare u v) o2,
			List.sort (fun (k,u) (j,v) -> -compare u v) e2
		in
		(* d o2;
		d e2; *)
		let (o2,e2) = Array.of_list o2,Array.of_list e2 in
		let ((k,p),(j,q)) = o2.(0),e2.(0) in
		(* printf "%Ld %Ld %Ld %Ld\n" k p j q; *)
		if k = j then (
			if snd o2.(1) > snd e2.(1) then (
				printf "%Ld\n" (n - (snd o2.(1)) - q)
			) else (
				printf "%Ld\n" (n - (snd e2.(1)) - p)
			)
		) else (
			printf "%Ld\n" (n - p - q)
		)
	)









Measured memory_bytes: 24832