let read () = Scanf.scanf "%d " (fun n -> n)

let list_init n =
    let rec loop i list =
        if i < n
        then
            let element = read () in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = read () in
    let k = read () in
    let list = list_init n in
    (n, k, list)

let get_sums list =
    let rec loop list sum sum_list =
        match list with
            | (head :: tail) ->
                let sum = head + sum in
                loop tail sum (sum :: sum_list)
            | [] -> List.rev sum_list
    in loop list 0 [0]

let solve (n, k, list) =
    let fence = get_sums list in
    let arr = Array.of_list fence in
    let rec loop i j min =
        if i + k <= n
        then
            let diff = arr.(i + k) - arr.(i) in
            if diff < min
            then
                loop (i + 1) i diff
            else
                loop (i + 1) j min
        else
            j + 1
    in loop 0 (n + 1) 1000000000

let print result = Printf.printf "%d\n" result

let () = print (solve (input ()))

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)

let () =
	let n = read_int ()
	and m = read_int ()
	and wyn = ref 100000000
	and indeks = ref 1 in

	let tab = Array.init n read_int
	and pref = Array.make (n + 1) 0 in

	for i = 1 to n do
		pref.(i) <- pref.(i - 1) + tab.(i - 1);
	done;

	for i = 1 to n - m + 1 do
		let roznica = pref.(i + m - 1) - pref.(i - 1) in
		if roznica < !wyn then begin
			wyn := roznica;
			indeks := i;
		end;
	done;

	printf "%d\n" !indeks;;

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)

let () =
	let n = read_int ()
	and m = read_int ()
	and wyn = ref 100000000
	and indeks = ref 1 in

	let tab = Array.init n read_int
	and pref = Array.make (n + 1) 0 in

	for i = 1 to n do
		pref.(i) <- pref.(i - 1) + tab.(i - 1);
	done;

	for i = 1 to n - m + 1 do
		let roznica = pref.(i + m - 1) - pref.(i) in
		if roznica < !wyn then begin
			wyn := roznica;
			indeks := i;
		end;
	done;

	printf "%d\n" !indeks;;

let read () = Scanf.scanf "%d " (fun n -> n)

let list_init n =
    let rec loop i list =
        if i < n
        then
            let element = read () in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = read () in
    let k = read () in
    let list = list_init n in
    (n, k, list)

let get_sums list =
    let rec loop list sum sum_list =
        match list with
            | (head :: tail) ->
                let sum = head + sum in
                loop tail sum (sum :: sum_list)
            | [] -> List.rev sum_list
    in loop list 0 [0]

let solve (n, k, list) =
    let fence = get_sums list in
    let arr = Array.of_list fence in
    let rec loop i j min =
        if i + k < n
        then
            let diff = arr.(i + k) - arr.(i) in
            if diff < min
            then
                loop (i + 1) i diff
            else
                loop (i + 1) j min
        else
            j + 1
    in loop 0 (n + 1) 1500001

let print result = Printf.printf "%d\n" result

let () = print (solve (input ()))

let read () = Scanf.scanf "%d " (fun n -> n)

let list_init n =
    let rec loop i list =
        if i < n
        then
            let element = read () in
            loop (i + 1) (element :: list)
        else
            List.rev list
    in loop 0 []

let input () =
    let n = read () in
    let k = read () in
    let list = list_init n in
    (n, k, list)

let get_sums list =
    let rec loop list sum sum_list =
        match list with
            | (head :: tail) ->
                let sum = head + sum in
                loop tail sum (sum :: sum_list)
            | [] -> List.rev sum_list
    in loop list 0 [0]

let solve (n, k, list) =
    let fence = get_sums list in
    let arr = Array.of_list fence in
    let rec loop i j min =
        if i + k <= n
        then
            let diff = arr.(i + k) - arr.(i) in
            if diff < min
            then
                loop (i + 1) i diff
            else
                loop (i + 1) j min
        else
            j + 1
    in loop 0 (n + 1) 1500001

let print result = Printf.printf "%d\n" result

let () = print (solve (input ()))


(* Mish test sort - worked *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let rec is_sq a n =
    (* let _ = begin print_int a; print_string "\n" end in *)
		if n < 0 then false
		else if n==0 || n==1 then true
    else if a*a == n then true
    else if a*a>n then false
    else
      let da = (n - a*a)/(3*a) in
      let da = if da > a then a else da in
      let da = if da < 1 then 1 else da in
      let a1 = a+da in
      is_sq a1 n;;

let rec max_list mx l = match l with
	| [] -> mx
	| h :: t ->
		let nmx = max mx h in
		max_list nmx t;;

let main() =
	let n = gr() in
	let l = readlist (n) [] in
	let lnsq = List.filter (fun x -> (not (is_sq 1 x))) l in
	let ans = max_list (-100011122) lnsq in
	begin
		print_int ans;
		print_string "\n"
	end;;

main();;

let get_int () = Scanf.scanf " %d" (fun i -> i)
let get_float () = Scanf.scanf " %f" (fun i -> i)

let is_sqrt x =
  let r = int_of_float @@ sqrt (float_of_int x) in
  r * r = x

let get_array n =
  let rec aux acc k =
    if k = 0 then acc
    else aux (get_int () :: acc) (k - 1)
  in aux [] n

let main () =
  let n = get_int () in
  let rec aux m k =
    if k = 0 then m
    else
      let x = get_int () in
      if not (is_sqrt x) && x > m then aux x (k - 1)
      else aux m (k - 1)
  in
  let ans = aux (-1_000_000) n in
  Printf.printf "%d" ans

let () = main ()

let get_int () = Scanf.scanf " %d" (fun i -> i)
let get_float () = Scanf.scanf " %f" (fun i -> i)

let is_sqrt x =
  let r = int_of_float @@ sqrt (float_of_int x) in
  r * r = x

let get_array n =
  let rec aux acc k =
    if k = 0 then acc
    else aux (get_int () :: acc) (k - 1)
  in aux [] n

let main () =
  let n = get_int () in
  let rec aux m k =
    if k = 0 then m
    else
      let x = get_int () in
      if not (is_sqrt x) && x > m then aux x (k - 1)
      else aux m (k - 1)
  in
  let ans = aux 0 n in
  Printf.printf "%d" ans

let () = main ()


type repost = Leaf of string
            | Node of repost list

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg,rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
    beg :: (split num rest)

let rec returnStringList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0) then
    (String.lowercase one) :: (returnStringList t "")
    else returnStringList t (one^h)
  | _ -> (String.lowercase one) :: []

let splitToList line =
  let lineList = split 1 line in
  returnStringList lineList ""

let rec makePairList strList =
  match strList with
  | (a :: b :: c::[]) :: t -> (c,a) :: (makePairList t)
  | _ -> []

let makeNode pairList st =
  let rec nodePair pList str =
    match pList with
    | (a,b) :: t ->
      if (compare a str) == 0 then
        Node (Leaf(b) :: nodePair pairList b) :: nodePair t str
      else nodePair t str
    | _ -> [] in
  Node(Leaf(st) :: nodePair pairList st) :: []

let rec countNode repost num=
  match repost with
  | Node(h :: t) :: tail ->
    let n = countNode t (num+1) in
    let m = countNode tail num in
    if (n > m) then n else m
  | _ -> num

let printLeaf leaf =
  match leaf with
  | Leaf(a) -> print_string "[Leaf : "; print_string a; print_string " ]"
  | _ -> print_string " "

let rec printList strList =
  match strList with
  | h :: t ->
    print_string h;print_string " ";printList t
  | _ -> print_string "\n"
let rec printPairList pairList =
  match pairList with
  | (a,b) :: t ->
    print_string a; print_string " "; print_string b; print_string "\n";
    printPairList t
  | _ -> print_string"\n"

let rec printRepost repost =
  match repost with
  | Node (h :: t) :: tail ->
    print_string "[Node : ";printLeaf h; printRepost t; print_string " ]";
    printRepost tail
  | _ -> print_string " "

let n = read_int()

let rec strList num =
  if (num > 0) then
    let line = read_line() in
    let lineList = splitToList line in
    lineList :: (strList (num-1))
  else []
let pairList = makePairList (strList n)

let repost = makeNode pairList "polycarp"
let _ = print_int (countNode repost 0)

type graph = Leaf of string | Node of graph list ;;
let tl = read_int() ;;
let rec genList num =
        if (num > 0) then
                let line = read_line() in
                let edge = Str.split (Str.regexp " ") (String.lowercase line) in
                ((List.nth edge 2), (List.nth edge 0)) :: (genList (num-1))
        else []

let to_graph list_in str1 =
        let rec gen_pair list_in2 str2 =
                match list_in2 with
                | (a,b) :: t ->
                                if (compare a str2) == 0 then
                                        Node (Leaf(b) :: gen_pair list_in2 b) :: gen_pair t str2
                                else gen_pair t str2
                | _ -> [] in
        Node(Leaf(str1) :: gen_pair list_in str1) :: []

let rec count_node graph n =
        match graph with
        | Node(h :: t) :: tail ->
                        max (count_node t (n+1)) (count_node tail n)
        | _ -> n
let myList = genList tl ;;
let graphRep = to_graph myList "polycarp" ;;
print_int(count_node graphRep 0)


let read_int () = Scanf.scanf " %d " (fun x -> x)
let read_string () = Scanf.scanf " %s " (fun x -> x)

let ( $ ) f x = f x

let main () =
  let n = ref (read_int ()) in
  let l = ref (-123456789) in
  let r = ref 123456789 in
  let a, b = ref 0, ref 0 in
  for i = 1 to !n do
    a := read_int();
    b := read_int();
    if !b = 1 then
      l := max !l 1900
    else
      r := min !r 1899;
    l := (!l + !a);
    r := (!r + !a);
  done;
  if !l > !r then Printf.printf "Impossible"
  else if !r > 100000000 then Printf.printf "Infinity"
  else Printf.printf "%d" !r

let () = main ()

open Printf
open Scanf

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))

let () =
  let n = read_int () in

  let inf = 1_000_000_000 in

  let (++) a b = if abs a = inf then a else a+b in

  let rec loop i (lo,hi) = if i=n then (lo,hi) else
      let (c,div) = read_pair() in
      let hi = if div = 2 then min hi 1899 else hi in
      let lo = if div = 1 then max lo 1900 else lo in
      let lo = lo ++ c in
      let hi = hi ++ c in
      if lo > hi then (lo,hi)
      else loop (i+1) (lo,hi)
  in

  let (lo,hi) = loop 0 (-inf,inf) in

  if lo > hi then printf "Impossible\n"
  else if hi = inf then printf "Infinity\n"
  else printf "%d\n" hi

let read_int () = Scanf.scanf " %d " (fun x -> x)
let read_string () = Scanf.scanf " %s " (fun x -> x)

let ( $ ) f x = f x

let main () =
  let n = ref (read_int ()) in
  let l = ref (-min_int) in
  let r = ref max_int in
  let a, b = ref 0, ref 0 in
  for i = 1 to !n do
    a := read_int();
    b := read_int();
    if !b = 1 then
      l := max !l 1900
    else
      r := min !r 1899;
    l := (!l + !a);
    r := (!r + !a);
  done;
  if !l > !r then Printf.printf "Impossible"
  else if !r > 100000000 then Printf.printf "Infinity"
  else Printf.printf "%d" !r

let () = main ()


let hasMax l r a = r-l+1 >= a || (r mod a < l mod a) ;;

let searchMax r a = let toto = r/a in if r mod a = a-1 then (toto + a-1) else toto-1 + a -1;;

let n = int_of_string(input_line stdin) in
for i = 0 to n-1 do
  let l,r,a = Scanf.sscanf(input_line stdin)" %d  %d  %d"(fun l r a->l,r,a) in
  let toto = if hasMax l r a then searchMax r a else (r/a + r mod a) in
  print_endline (string_of_int toto)
done;
;;

(* Codeforces 1638 A Reverse train done *)

(* you can use either gr or rdln but not both, several gr() - inverted order *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

(* reading list *)
let rec readlist n acc = match n with
	| 0 -> List.rev acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printlists ls = List.iter (fun s -> (print_string s; print_string " ")) ls;;
let list_to_s li = String.concat " " (List.map string_of_int li);;

let do_one () =
    let a,r,l = gr(), gr(), gr() in
    (* let _ = Printf.printf "l,r,a = %d %d %d\n" l r a in *)
    let dl = l / a in
    let dr = r / a in
    let oor = r mod a in
    let mx = if dl == dr then dr + oor
        else
            let dr1 = if oor==a-1 then dr else dr-1 in
            dr1 + a - 1 in
    (print_int mx; print_string "\n");;

let do_all () =
    let t = gr () in
    for i = 1 to t do
        do_one ()
    done;;

let main() =
	do_all ();;

main();;

let hasMax l r a = r-l+1 >= a || (r mod a < l mod a) ;;

let searchMax r a = let toto = r/a in if r mod a = a-1 then (toto + a-1) else toto-1 + a -1;;

let n = int_of_string(input_line stdin) in
for i = 0 to n-1 do
  let l,r,a = Scanf.sscanf(input_line stdin)" %d  %d  %d"(fun l r a->l,r,a) in
  let toto = if hasMax l r a then searchMax r a else (r/a + r mod a) in
  prerr_endline (string_of_int toto)
done;
;;


(* OCaml template *)
open Printf
open Scanf

(* Redefine operators for Int64 *)
let ( + ) = Int64.add;;
let ( - ) = Int64.sub;;
let ( * ) = Int64.mul;;
let ( / ) = Int64.div;;
let ( % ) = Int64.rem;;

(* Input *)
let read_int _ = bscanf Scanning.stdin "%d " @@ fun x -> x;;
let read_int64 _ = bscanf Scanning.stdin "%Ld " @@ fun x -> x;;

(* Output *)
let print_int n = printf "%d " n;;
let print_int_endl n = printf "%d\n" n;;
let print_int64 n = printf "%Ld " n;;
let print_int64_endl n = printf "%Ld\n" n;;

(* Utility functions *)
(*
let sum = List.fold_left (+) 0;;
*)

(* Solve test case *)
let rec solve n = if n = 2L then 1L else n * solve (n - 1L) % 1000000007L;;

(* Main *)
let t = read_int ();;

for t' = 1 to t do
	(* Solve test case here *)
	let n = read_int64 () in
		print_int64_endl @@ solve @@ 2L * n
done

(* OCaml template *)

(* Redefine operators for Int64 *)
let ( + ) = Int64.add;;
let ( - ) = Int64.sub;;
let ( * ) = Int64.mul;;
let ( / ) = Int64.div;;
let ( % ) = Int64.rem;;

(* Utility functions *)
let sum = List.fold_left (+) 0L;;

(* Main *)
let m = 1000000007L;;

let rec solve (n:int64) = if n = 2L then 1L else n * solve (n - 1L) % m;;

let t = read_int ();;

for t' = 1 to t do
	(* Solve test case here *)
	let n = read_int () in
		print_endline @@ Int64.to_string @@ solve @@ 2L * Int64.of_int n
done

(* OCaml template *)

(* Utility functions *)
let sum = List.fold_left (+) 0;;

(* Main *)
let m = 1000000007L;;

let rec solve (n:int64) = if n = 2L then 1L else Int64.rem (Int64.mul n (solve (Int64.pred n))) m;;

let t = read_int ();;

for t' = 1 to t do
	(* Solve test case here *)
	let n = read_int () in
		print_endline @@ Int64.to_string @@ solve @@ Int64.mul 2L (Int64.of_int n)
done

(* OCaml template *)

type int = int64;;

(* Utility functions *)
let print_int_endline n = print_endline @@ string_of_int n
let sum = List.fold_left (+) 0;;

let rec solve n = if n = 2 then 1 else n * solve (n - 1) mod 1000000007;;

(* Main *)
let t = read_int ();;

for t' = 1 to t do
	(* Solve test case here *)
	let n = read_int () in
		print_int_endline @@ solve @@ 2 * n
done

(* OCaml template *)

(* Utility functions *)
let sum = List.fold_left (+) 0;;

(* Main *)
let m = 1000000007;;

let rec solve (n:int) = if n = 2 then 1 else n * solve (n - 1) mod m;;

let t = read_int ();;

for t' = 1 to t do
	(* Solve test case here *)
	let n = read_int () in
		print_endline @@ string_of_int @@ solve @@ 2 * n;
done


let read1 () = Scanf.scanf "%d\n" ( fun x -> x );;
let read2 () = Scanf.scanf "%d %d\n" ( fun x y -> x, y );;
let read3 () = Scanf.scanf "%d %d %d\n" ( fun x y z -> x, y, z);;
let read x = (if x = 0 then Scanf.scanf "%d\n" else Scanf.scanf "%d ") ( fun x -> x );;

let (+$) x y =
  if x > max_int - y then max_int
  else x + y;;

let rec ( *$ ) x y =
  if y = 0 then 0 else
  if y mod 2 = 1 then x *$ (y-1) +$ x
  else let a = x *$ (y/2) in a +$ a;;

let (+|) = Int64.add;;
let (-|) = Int64.sub;;
let ( *| ) = Int64.mul;;
let ( /| ) = Int64.div;;
let two_64 = Int64.one +| Int64.one;;

let licz x = (x-|Int64.one)/|two_64;;

let _ =
  let (n,k) = Scanf.scanf "%d %d\n" (fun x y-> x, y) in
  let ile = Array.make 1000001 0
  and tab = Array.make 1000001 0
  and id = ref 1
  and wyn = ref 0
  and obc = ref 1
  and suma = ref 0 in
  for i=1 to n do
    let x = read (n-i) in
    tab.(i) <- x;
    if ile.(x) = 0 then incr suma;
    ile.(x) <- ile.(x) + 1;
    while !suma > k do
      ile.( tab.(!obc) ) <- ile.( tab.(!obc) ) - 1;
      if ile.( tab.(!obc) ) = 0 then suma := !suma - 1;
      incr obc
    done;
    if i - !obc + 1 > !wyn then begin
      id := !obc;
      wyn := i - !obc + 1
    end
  done;
  Printf.printf "%d %d\n" !id (!id + !wyn -1 ) ;;

let xint() = Scanf.scanf " %d" (fun x -> x)

let () =
  let n = xint() and k = xint() in
  let a = Array.make n 0 in
  let c = Array.make 1000001 0 in
  for i = 0 to n - 1 do
    a.(i) <- xint();
  done;
  let add x =
    c.(x) <- c.(x) + 1;
    if c.(x) = 1 then 1 else 0
  in
  let sub x =
    c.(x) <- c.(x) - 1;
    if c.(x) = 0 then 1 else 0;
  in
  let j = ref 0 and tot = ref 0 in
  let sx = ref 0 and sy = ref ~-1 in
  for i = 0 to n - 1 do
    tot := !tot + (add a.(i));
    while !tot > k do
      tot := !tot - (sub a.(!j));
      j := !j + 1;
    done;
    if i - !j > !sy - !sx then (
      sx := !j;
      sy := i;
    );
  done;
  sx := !sx + 1;
  sy := !sy + 1;
  Printf.printf "%d %d\n" !sx !sy;


module My_int64 =
struct
    let ( + ) = Int64.add
    let ( - ) = Int64.sub
    let zero = Int64.zero
    let one = Int64.one
end

open My_int64

let read () = Scanf.scanf "%Ld " (fun n -> n)

let input () =
    let houses = read () in
    let jobs = read () in
    let rec loop job_houses i =
        if i < jobs
        then
            let job_house = read () in
            loop (job_house :: job_houses) (i + one)
        else
            (houses, (List.rev job_houses))
    in loop [] zero

let solve (houses, job_houses) =
    let rec loop count last list =
        match list with
        | (head :: tail) ->
            if head < last
            then
                loop (count + (houses - last) + head) head tail
            else
                loop (count + head - last) head tail
        | [] -> count
    in loop zero one job_houses

let print result = Printf.printf "%Ld\n" result
let () = print (solve (input ()))

let (n, m) = Scanf.scanf "%Ld %d\n" (fun x y -> (x, y)) in
let pos = ref Int64.one in
let t = ref Int64.zero in
for i = 1 to m do
    let p = Scanf.scanf "%Ld%[ ]" (fun x _ -> x) in
    t := Int64.add !t (Int64.rem (Int64.sub (Int64.add p n) !pos) n) ;
    pos := p
done ;
Printf.printf "%Ld\n" !t ;;

let read () = Scanf.scanf "%d " (fun n -> n)

let input () =
    let houses = read () in
    let jobs = read () in
    let rec loop job_houses i =
        if i < jobs
        then
            let job_house = Scanf.scanf "%d " (fun n -> n) in
            loop (job_house :: job_houses) (i + 1)
        else
            (houses, jobs, (List.rev job_houses))
    in loop [] 0

let solve (houses, jobs, job_houses) =
    let rec loop count last list =
        match list with
        | (head :: tail) ->
            if head < last
            then
                loop (count + (houses - last) + head) head tail
            else
                loop (count + head - last) head tail
        | [] -> count
    in loop 0 1 job_houses

let print result = Printf.printf "%d\n" result
let () = print (solve (input ()))


let read () = Scanf.scanf "%d " (fun n -> n)

let solve () =
    let n = read () in
    let rec loop i unsolved police =
        if i < n
        then
            let temp = read () in
            if temp < 0
            then
                if police >= 1
                then
                    loop (i + 1) unsolved (police - 1)
                else
                    loop (i + 1) (unsolved + 1) police
            else
                loop (i + 1) unsolved (police + temp)
        else
            unsolved
    in loop 0 0 0

let print result = Printf.printf "%d\n" result
let () = print (solve ())

let read_int () = Scanf.scanf " %d" (fun x -> x)

let () =
  let n = read_int () in
  let rec loop unsolved police = function
    | 0 -> unsolved
    | n ->
        let x = read_int () in
        if x < 0 then
          if police > 0 then
            loop unsolved (police - 1)  (n - 1)
          else
            loop (unsolved + 1) police (n - 1)
        else
          loop unsolved (police + x) (n - 1)
  in Printf.printf "%d\n" (loop 0 0 n)

open Scanf
open Printf

let read_int () = scanf " %d" (fun x -> x)

let n = read_int ()
let a = Array.init n (fun i -> read_int ())

let comp (s, r) x =
    match (x, s) with
    | (-1, 0) -> (0, r + 1)
    | _       -> (s + x, r)

let () = printf "%d\n" (snd (Array.fold_left comp (0, 0) a))


open Scanf;;
open Printf;;
open Str;;

let split_by_space = split (regexp " +")

type token = P | I

let token_of_str = function
    "pair" -> P
  | "int" -> I
  | _ -> failwith "hoge"

let input () =
  let n = int_of_string(read_line ()) in
  let str = read_line () in
  (n, List.map token_of_str (split_by_space str))

type tree = Pair of (tree * tree) | Int

let solve ls =
  let rec solve = function
      [] -> failwith ""
    | P::ls ->
        let (res1, ls) = solve ls in
        let (res2, ls) = solve ls in
        (Pair (res1, res2), ls)
    | I::ls ->
        (Int, ls) in
  let (res, ls) = solve ls in
  match ls with
    [] -> res
  | _ -> failwith ""

let rec print_res = function
    Pair(x, y) ->
      print_string "pair<";
      print_res x;
      print_string ",";
      print_res y;
      print_string ">"
  | Int ->
      print_string "int"

let () =
  let (n, ss) = input () in
  (* List.iter (fun x -> printf "%s\n" x) ss; *)
  try
    let res = solve ss in
    print_res res;
    print_string "\n"
  with
    Failure _ -> print_endline "Error occurred"

type t0 = P | I
type t1 = Pair of t1 * t1 | Int

let _ =
    let rec dump k =
        match k with
        | Int -> print_string "int"
        | Pair (a, b) -> print_string "pair<";dump a;print_string ","; dump b; print_string ">"
    in

    let main () =
        let _ = read_int () in
        let s = read_line () in
        let l = String.length s in
        let rec loop p acc =
            if p >= l then acc else
            if s.[p] = 'p' then loop (p + 4) (P :: acc) else
            if s.[p] = 'i' then loop (p + 3) (I :: acc) else
            loop (p + 1) acc
        in
        let k = List.rev (loop 0 []) in
        let rec parse = function
            | [] -> None
            | I :: tl -> Some (Int, tl)
            | P :: tl -> (
                match parse tl with
                | None -> None
                | Some (a, tl2) -> (
                    match parse tl2 with
                    | None -> None
                    | Some (b, tl3) -> Some (Pair (a, b), tl3)
                )
            )
        in
        match parse k with
        | Some (a, []) -> dump a; print_newline ()
        | _ -> print_endline "Error occurred"
    in
    main ()


(* Input *)
let (num_students, num_drink_types) = Scanf.scanf "%d %d\n" (fun x y -> (x, y));;

let rec read_rev_int_list n =
  if n == 0
    then []
    else (Scanf.scanf "%d\n" (fun x -> x - 1)) :: read_rev_int_list(n - 1)
;;

let student_drink_types = List.rev (read_rev_int_list (num_students));;

(* Process *)
let favorite_counts = Array.make num_drink_types 0;;
List.iter (fun tp -> (favorite_counts.(tp) <- favorite_counts.(tp) + 1)) student_drink_types;;

let num_leftout = ref 0;;
Array.iter (fun cnt -> num_leftout := !num_leftout + (cnt mod 2)) favorite_counts;;

let result = num_students - !num_leftout + (!num_leftout + 1) / 2;;
Printf.printf "%d\n" result;;

(* Input *)
let (num_students, num_drink_types) = Scanf.scanf "%d %d\n" (fun x y -> (x, y));;
let student_drink_types =
  let rec read_int_list = function
    | 0 -> []
    | n -> (Scanf.scanf "%d\n" (fun x -> x - 1)) :: read_int_list (n - 1)
  in
    List.rev (read_int_list num_students)
;;

(* Process *)
let favorite_counts = Array.make num_drink_types 0;;
List.iter (fun tp -> (favorite_counts.(tp) <- favorite_counts.(tp) + 1)) student_drink_types;;

let num_leftout = Array.fold_left (fun a b -> a + b mod 2) 0 favorite_counts;;
let result = num_students - num_leftout + (num_leftout + 1) / 2;;
Printf.printf "%d\n" result;;


open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  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 (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  (* input *)
  let input_i64_array n = Array.init (i32 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 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)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  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 fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
module IMap = Map.Make(Int64)
let appearance a = (* (value,count) *)
  Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a
let () =
  let n,k = get_2_i64 0 in
  let a = input_i64_array n in
  let ls =
    let mp = appearance a in
    IMap.bindings mp |> List.map (fun (k,v) -> (v,k))
    |> List.sort (fun u v -> compare v u)
  in
  (* print_list (fun (v,k) -> sprintf "%Ld(%Ld) " v k) ls; *)
  let constr d =
    let ans = ref [] in
    List.iter (fun (c,v) ->
      let p = c / d in
      rep 1L p (fun _ -> ans := v::!ans)
    ) ls;
    (* printf "%Ld : %s\n" d (string_of_list ist !ans); *)
    !ans in
  let check d =
    if llen @@ constr d >= k then true
    else false
  in
  let d = binary_search n 0L (fun d -> check d) in
  (* constr d |> List.iter (fun v -> printf "%Ld " v) *)
  constr d |> of_list |> iteri (fun i v ->
    if i=0 then printf "%Ld" v
    else if i<i32 k then printf " %Ld" v
  )

(* Problem 2 of round 521*)
(* Comments:

   This is one type of binary_search problem. You will encounter many such
   problems. General binary_search which you might have studied(or will study)
   in the university is done over an array of numbers. In this kind of problems,
   you need to perform the binary_search over the entire solution space.

   For e.g.: In this problem, you can consider the entire solution space as all
   numbers ranging from 1 to n (as you cannot have more than "n" copies).

   So, step 1 of this problem is to find the maximum number of copies which can be
   cut out from the the given array. Let me call this value as val. How we are
   going to find val, I will come back to that later. Let us move to Step 2

*)
open Scanf;;
open Num;;
open Printf;;

(*These are some utility functions*)
module U = struct
  let mprint z =
    print_endline (Num.string_of_num z);;

  let read_one format = Scanf.scanf format (fun x -> x)

  let read_one_number () =
    let rslt= read_one "%d " in
    rslt

  let read_array n a =
    for i = 0 to n-1 do
      let r = read_one_number () in
      a.(i) <- r
    done

end

(*The solutions*)
let nn = 200002;;

let n = U.read_one_number ()
let k = U.read_one_number ()
let a = Array.make n 0
let b = Array.make nn 0
let () = U.read_array n a;;

let () = Array.iter (fun x-> b.(x) <- b.(x) + 1 ) a;;
let c = Array.mapi (fun i x -> (i,x) ) b;;

let my_compare h1 h2 =
  let (_,v1) = h1 in
  let (_,v2) = h2 in
  compare v2 v1;;

let d = c
        |> Array.to_list
        |> List.filter (fun h -> let (_,v) = h in v > 0 )
        |> List.sort (fun h1 h2 -> my_compare h1 h2)
        |> Array.of_list
;;

let dl = Array.length d;;

(* This function determines if cc copies is possible*)
let is_possible cc =
  let flag = true in
  let total = ref 0 in
    for i = 0 to dl -1 do
      let (_,v1) = d.(i) in
      total := !total + v1 / cc
    done;
    if !total < k then
      flag = false
    else
      true
;;

let rec binary_search s e =
  if s == e then
    s
  else if e - s == 1 then
    if is_possible e then
      e
    else
      s
  else
    begin
      let mid = (s+e) / 2 in
      if is_possible mid then
        binary_search mid  e
      else
        binary_search s (mid - 1)
    end
;;

let rslt = binary_search 1 n;;

(*
let () =
  Printf.printf "%B %d\n" (is_possible 2) rslt

let () =
  Array.iter (fun (k1,v1) -> Printf.printf "%d %d\n" k1 v1) d
   *)

let () =
  let nx = ref k in
  for i = 0 to dl -1 do
    let (k1,v1) = d.(i) in
    let m = v1 / rslt in
    if m > 0 && !nx >0 then
      let test = !nx - m in
      if test >=0 then
        begin
          for i = 0 to m-1 do
            Printf.printf "%d " k1
          done;
          nx := test
        end
      else
        begin
          for i = 0 to !nx-1 do
            Printf.printf "%d " k1
          done;
          nx := 0
        end
  done

(*This file is to test the environment used by the judge*)

print_int max_int; print_endline;;

(* Problem 2 of round 521*)
(* Comments:
   To make this program is even faster, I need to have in the function 'cut'
   l1 to be an array, use another integer (starting from k) to indicate stop.

   But this is so boring, I better use C.

*)
open Scanf;;
open String;;
open Num;;

(*These are some utility functions*)
module U = struct
  let mprint z =
    print_endline (Num.string_of_num z);;

  let read_one format =
    let n = Scanf.scanf format (fun x -> x) in
    n;;

  let read_one_number () =
    let n = read_one "%d " in
    n

  let read_array n a =
    for i = 0 to n-1 do
      let n = read_one_number () in
      a.(i) <- n
    done

end

(*The solutions*)

let n = U.read_one_number ()
let k = U.read_one_number ()
let a = Array.make n 0
let () = U.read_array n a

module H = Hashtbl
let t = H.create n

(*
let () =
  Array.iter (fun x-> print_int x; print_endline "") a
*)

let my_find s x =
  try Some (H.find s x)
  with
    Not_found -> None
;;

let () = Array.iter (fun x->
        match my_find t x with
          None -> H.add t x 1
        | Some z -> H.replace t x (1+z)
  ) a
;;

let my_compare h1 h2 =
  let (_,v1) = h1 in
  let (_,v2) = h2 in
  if v1 > v2 then 1
  else if v1 == v2 then 0
  else -1;;

let ll = H.fold (fun k v x -> (k,v) :: x) t [];;

if n==k then
  print_int (List.length ll); print_endline "";;

let lr = List.stable_sort my_compare ll
         |> List.rev;;
(*
let () =
  List.iter (fun h ->
      let (k,v) = h in Printf.printf "%d %d\n" k v
    ) lr;;
   *)

let rec cut l1 l2 =
  let n1 = List.length l1 in
  if List.length l2 == k then
    l2
  else
    begin
      if n1 == 1 then
        (List.hd l1) :: l2
      else
        begin
          let h1 :: _ = l1 in
          let h2 :: _ = List.tl l1 in
          let (k1,a1) = h1 in
          let (_,a2) = h2 in
          if a1 < 2*a2 then
            cut (List.tl l1) (h1 :: l2)
          else
            cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)
        end
    end
;;

if n==k then
  begin
    print_int (List.length lr); print_endline "";
    List.iter (fun h ->
        let (i,_) = h in Printf.printf "%d " i
      ) lr
  end
else
  begin
    let rslt = cut lr [] in
    if List.length rslt < k then
      begin
        print_int 0; print_endline ""
      end
    else
      List.iter (fun h ->
          let (i,_) = h in Printf.printf "%d " i
        ) rslt;
  end
;;

(* Problem 2 of round 521*)
(* Comments:
   To make this program is even faster, I need to have in the function 'cut'
   l1 to be an array, use another integer (starting from k) to indicate stop.

   But this is so boring, I better use C.

*)
open Scanf;;
open String;;
open Num;;

(*These are some utility functions*)
module U = struct
  let mprint z =
    print_endline (Num.string_of_num z);;

  let read_one format =
    let n = Scanf.scanf format (fun x -> x) in
    n;;

  let read_one_number () =
    let n = read_one "%d " in
    n

  let read_array n a =
    for i = 0 to n-1 do
      let n = read_one_number () in
      a.(i) <- n
    done

end

(*The solutions*)

let n = U.read_one_number ()
let k = U.read_one_number ()
let a = Array.make n 0
let () = U.read_array n a

module H = Hashtbl
let t = H.create n

(*
let () =
  Array.iter (fun x-> print_int x; print_endline "") a
*)

let my_find s x =
  try Some (H.find s x)
  with
    Not_found -> None

let total = ref 0

let () = Array.iter (fun x->
        let y = my_find t x in
        match y with
          None -> H.add t x 1
        | Some z -> H.replace t x (1+z)
  ) a
;;

let my_compare h1 h2 =
  let (_,v1) = h1 in
  let (_,v2) = h2 in
  if v1 > v2 then 1
  else if v1 == v2 then 0
  else -1;;

let ll = H.fold (fun k v x -> (k,v) :: x) t [];;

let lr = List.stable_sort my_compare ll
         |> List.rev;;
(*
let () =
  List.iter (fun h ->
      let (k,v) = h in Printf.printf "%d %d\n" k v
    ) lr;;
   *)

let rec cut l1 l2 =
  let n1 = List.length l1 in
  if List.length l2 == k then
    l2
  else
    begin
      if n1 == 1 then
        (List.hd l1) :: l2
      else
        begin
          let h1 :: _ = l1 in
          let h2 :: _ = List.tl l1 in
          let (k1,a1) = h1 in
          let (_,a2) = h2 in
          if a1 < 2*a2 then
            cut (List.tl l1) (h1 :: l2)
          else
            cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)
        end
    end
;;

if n==k then
  List.iter (fun h ->
      let (k,_) = h in Printf.printf "%d " k
    ) lr
else
  begin
    let rslt = cut lr [] in
    if List.length rslt < k then
      begin
        print_int 0; print_endline ""
      end
    else
      List.iter (fun h ->
          let (k,_) = h in Printf.printf "%d " k
        ) rslt;
  end
;;

(* Problem 2 of round 521*)
(* Comments:
   To make this program is even faster, I need to have in the function 'cut'
   l1 to be an array, use another integer (starting from k) to indicate stop.

   But this is so boring, I better use C.

*)
open Scanf;;
open String;;
open Num;;

(*These are some utility functions*)
module U = struct
  let mprint z =
    print_endline (Num.string_of_num z);;

  let read_one format =
    let n = Scanf.scanf format (fun x -> x) in
    n;;

  let read_one_number () =
    let n = read_one "%d " in
    n

  let read_array n a =
    for i = 0 to n-1 do
      let n = read_one_number () in
      a.(i) <- n
    done

end

(*The solutions*)

let n = U.read_one_number ()
let k = U.read_one_number ()
let a = Array.make n 0
let () = U.read_array n a

module H = Hashtbl
let t = H.create n

(*
let () =
  Array.iter (fun x-> print_int x; print_endline "") a
*)

let my_find s x =
  try Some (H.find s x)
  with
    Not_found -> None

let total = ref 0

let () = Array.iter (fun x->
        let y = my_find t x in
        match y with
          None -> H.add t x 1
        | Some z -> H.replace t x (1+z)
  ) a
;;

let my_compare h1 h2 =
  let (_,v1) = h1 in
  let (_,v2) = h2 in
  if v1 > v2 then 1
  else if v1 == v2 then 0
  else -1;;

let ll = H.fold (fun k v x -> (k,v) :: x) t [];;

let lr = List.stable_sort my_compare ll
         |> List.rev;;
(*
let () =
  List.iter (fun h ->
      let (k,v) = h in Printf.printf "%d %d\n" k v
    ) lr;;
   *)

let rec cut l1 l2 =
  let n1 = List.length l1 in
  if List.length l2 == k then
    l2
  else
    begin
      if n1 == 1 then
        (List.hd l1) :: l2
      else
        begin
          let h1 :: _ = l1 in
          let h2 :: _ = List.tl l1 in
          let (k1,a1) = h1 in
          let (_,a2) = h2 in
          if a1 < 2*a2 then
            cut (List.tl l1) (h1 :: l2)
          else
            cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)
        end
    end
;;

if n==k then
  begin
    print_int (List.length lr); print_endline "";
    List.iter (fun h ->
        let (i,_) = h in Printf.printf "%d " i
      ) lr
  end
else
  begin
    let rslt = cut lr [] in
    if List.length rslt < k then
      begin
        print_int 0; print_endline ""
      end
    else
      List.iter (fun h ->
          let (i,_) = h in Printf.printf "%d " i
        ) rslt;
  end
;;

(* Problem 2 of round 521*)
(* Comments:
   To make this program is even faster, I need to have in the function 'cut'
   l1 to be an array, use another integer (starting from k) to indicate stop.

   But this is so boring, I better use C.

*)
open Scanf;;
open String;;
open Num;;

(*These are some utility functions*)
module U = struct
  let mprint z =
    print_endline (Num.string_of_num z);;

  let read_one format =
    let n = Scanf.scanf format (fun x -> x) in
    n;;

  let read_one_number () =
    let n = read_one "%d " in
    n

  let read_array n a =
    for i = 0 to n-1 do
      let n = read_one_number () in
      a.(i) <- n
    done

end

(*The solutions*)

let n = U.read_one_number ()
let k = U.read_one_number ()
let a = Array.make n 0
let () = U.read_array n a

module H = Hashtbl
let t = H.create n

(*
let () =
  Array.iter (fun x-> print_int x; print_endline "") a
*)

let my_find s x =
  try Some (H.find s x)
  with
    Not_found -> None

let total = ref 0

let () = Array.iter (fun x->
        let y = my_find t x in
        match y with
          None -> H.add t x 1
        | Some z -> H.replace t x (1+z)
  ) a
;;

let my_compare h1 h2 =
  let (_,v1) = h1 in
  let (_,v2) = h2 in
  if v1 > v2 then 1
  else if v1 == v2 then 0
  else -1;;

let ll = H.fold (fun k v x -> (k,v) :: x) t [];;

let lr = List.stable_sort my_compare ll
         |> List.rev;;
(*
let () =
  List.iter (fun h ->
      let (k,v) = h in Printf.printf "%d %d\n" k v
    ) lr;;
   *)

let rec cut l1 l2 =
  let n1 = List.length l1 in
  if List.length l2 == k then
    l2
  else
    begin
      if n1 == 1 then
        (List.hd l1) :: l2
      else
        begin
          let h1 :: _ = l1 in
          let h2 :: _ = List.tl l1 in
          let (k1,a1) = h1 in
          let (_,a2) = h2 in
          if a1 < 2*a2 then
            cut (List.tl l1) (h1 :: l2)
          else
            cut ((k1,a1-a1/2) :: (List.tl l1)) ((k1,a1/2) :: l2)
        end
    end
;;

if n==k then
  List.iter (fun h ->
      let (i,_) = h in Printf.printf "%d " i
    ) lr
else
  begin
    let rslt = cut lr [] in
    if List.length rslt < k then
      begin
        print_int 0; print_endline ""
      end
    else
      List.iter (fun h ->
          let (i,_) = h in Printf.printf "%d " i
        ) rslt;
  end
;;

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  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 (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  (* input *)
  let input_i64_array n = Array.init (i32 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 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)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  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 fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
module IMap = Map.Make(Int64)
let appearance a = (* (value,count) *)
  Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a
let () =
  let n,k = get_2_i64 0 in
  let a = input_i64_array n in
  let ls =
    let mp = appearance a in
    IMap.bindings mp |> List.map (fun (k,v) -> (v,k))
    |> List.sort (fun u v -> compare v u)
  in
  (* print_list (fun (v,k) -> sprintf "%Ld(%Ld) " v k) ls; *)
  let constr d =
    let ans = ref [] in
    List.iter (fun (c,v) ->
      let p = c / d in
      rep 1L p (fun _ -> ans := v::!ans)
    ) ls;
    (* printf "%Ld : %s\n" d (string_of_list ist !ans); *)
    !ans in
  let check d =
    if llen @@ constr d >= k then true
    else false
  in
  let d = binary_search n 0L (fun d -> check d) in
  constr d |> print_list ist

  (* let r = make 20010 [] in
  IMap.iter (fun p q ->
    (* if q=k then r := (p+1L)::!r *)
    (* arr.(i32 q) <- p::arr.(i32 q) *)
    r.(i32 q) <- p::r.(i32 q)
  ) mp;
  let ls = ref [] in
  iteri (fun c v -> if List.length v<>0 then ls:=(c,v)::!ls) r;
  (* let r = List.sort (fun u v -> -compare u v) !r in *)
  let ls = !ls |> List.sort (fun u v -> -compare u v) in
  let d = binary_search n 0L (fun d ->
    (* printf "%Ld\n" d; *)
    let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in
    let _,f = List.fold_left (fun (sum,f) (v,ls) ->
      let ne = sum + v * (llen ls) in
      (* printf "%Ld %Ld\n" v ne; *)
      if ne >= k then (ne,true) else (ne,f)
    ) (0L,false) l
    in f
  ) in
  let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in
  let rest = ref k in
  let _,f = List.fold_left (fun (sum,f) (v,ls) ->
    let ne = (v * llen ls) in
    if ne <= !rest then (
      rep 0L (ne-1L) (fun i ->
        let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list
        in printf "%Ld " b.(i32 i)
      );
      rest -= ne; (sum,f)
    ) else (
      let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list in
      rep 0L (!rest) (fun i ->
        printf "%Ld " b.(i32 i)
      ); (sum,f)
    )
    (* if  >= k then (ne,true) else (ne,f) *)
  ) (0L,false) l
  in
  () *)

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  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 (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  (* input *)
  let input_i64_array n = Array.init (i32 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 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)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  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 fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
module IMap = Map.Make(Int64)
let appearance a = (* (value,count) *)
  Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a
let () =
  let n,k = get_2_i64 0 in
  let a = input_i64_array n in
  let ls =
    let mp = appearance a in
    IMap.bindings mp |> List.map (fun (k,v) -> (v,k))
    |> List.sort (fun u v -> compare v u)
  in
  (* print_list (fun (v,k) -> sprintf "%Ld(%Ld) " v k) ls; *)
  let constr d =
    let ans = ref [] in
    List.iter (fun (c,v) ->
      let p = c / d in
      rep 1L p (fun _ -> ans := v::!ans)
    ) ls;
    (* printf "%Ld : %s\n" d (string_of_list ist !ans); *)
    !ans in
  let check d =
    if llen @@ constr d >= k then true
    else false
  in
  let d = binary_search n 0L (fun d -> check d) in
  constr d |> List.iter (fun v -> printf "%Ld " v)

  (* let r = make 20010 [] in
  IMap.iter (fun p q ->
    (* if q=k then r := (p+1L)::!r *)
    (* arr.(i32 q) <- p::arr.(i32 q) *)
    r.(i32 q) <- p::r.(i32 q)
  ) mp;
  let ls = ref [] in
  iteri (fun c v -> if List.length v<>0 then ls:=(c,v)::!ls) r;
  (* let r = List.sort (fun u v -> -compare u v) !r in *)
  let ls = !ls |> List.sort (fun u v -> -compare u v) in
  let d = binary_search n 0L (fun d ->
    (* printf "%Ld\n" d; *)
    let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in
    let _,f = List.fold_left (fun (sum,f) (v,ls) ->
      let ne = sum + v * (llen ls) in
      (* printf "%Ld %Ld\n" v ne; *)
      if ne >= k then (ne,true) else (ne,f)
    ) (0L,false) l
    in f
  ) in
  let l = List.map (fun (c,v) -> ((i64 c)/d,v)) ls |> List.sort (fun u v -> compare v u) in
  let rest = ref k in
  let _,f = List.fold_left (fun (sum,f) (v,ls) ->
    let ne = (v * llen ls) in
    if ne <= !rest then (
      rep 0L (ne-1L) (fun i ->
        let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list
        in printf "%Ld " b.(i32 i)
      );
      rest -= ne; (sum,f)
    ) else (
      let b = init (i32 v) (fun _ -> ls) |> to_list |> List.flatten |> of_list in
      rep 0L (!rest) (fun i ->
        printf "%Ld " b.(i32 i)
      ); (sum,f)
    )
    (* if  >= k then (ne,true) else (ne,f) *)
  ) (0L,false) l
  in
  () *)

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  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 (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  (* input *)
  let input_i64_array n = Array.init (i32 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 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)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  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 fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
module IMap = Map.Make(Int64)
let appearance a = (* (value,count) *)
  Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a
let () =
  let n,k = get_2_i64 0 in
  let a = input_i64_array n in
  let ls =
    let mp = appearance a in
    IMap.bindings mp |> List.map (fun (k,v) -> (v,k))
    |> List.sort (fun u v -> compare v u)
  in
  (* print_list (fun (v,k) -> sprintf "%Ld(%Ld) " v k) ls; *)
  let constr d =
    let ans = ref [] in
    List.iter (fun (c,v) ->
      let p = c / d in
      rep 1L p (fun _ -> ans := v::!ans)
    ) ls;
    (* printf "%Ld : %s\n" d (string_of_list ist !ans); *)
    !ans in
  let check d =
    if llen @@ constr d >= k then true
    else false
  in
  let d = binary_search n 0L (fun d -> check d) in
  (* constr d |> List.iter (fun v -> printf "%Ld " v) *)
  constr d |> of_list |> iteri (fun i v ->
    (if i=0 then printf "%Ld"
    else printf " %Ld") v
  )

open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  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 (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module I64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  (* input *)
  let input_i64_array n = Array.init (i32 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 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)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  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 fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array
module IMap = Map.Make(Int64)
let arr = make 50 []
let appearance a = (* (value,count) *)
  let open IMap in Array.fold_left (fun u v -> IMap.add v (1L + try IMap.find v u with Not_found -> 0L) u) IMap.empty a
let () =
  let n,k = get_2_i64 0 in
  let a = input_i64_array n in
  let mp = appearance a in
  let r = ref [] in
  IMap.iter (fun p q ->
    (* if q=k then r := (p+1L)::!r *)
    arr.(i32 q) <- p::arr.(i32 q)
  ) mp;
  let n_max = IMap.fold (fun _ v u -> max v u) mp 0L in
  (* iteri (fun i r ->
    if List.length r<>0 then
    printf "%d : %s\n" i (string_of_list ist r);
  ) arr; *)
  let amari = ref 0 in
  (* let r_amari = ref [] in *)
  rep_rev n_max 1L (fun p ->
    let p = i32 p in
    if !amari +$ List.length arr.(p) >= i32 k then (
      (* print_list ist arr.(i32 p); *)
      if List.length arr.(p) >= i32 k then (
        let a = arr.(p) |> of_list in
        repi 0 (p) (fun i -> printf "%Ld " a.(i));
        exit 0;
      ) else (
        let rest = ref @@ i32 k -$ (List.length arr.(p)) in
        let a = arr.(p) |> of_list in
        repi 0 (length a-$1) (fun i -> printf "%Ld " a.(i));
        let q,res = ref @@ p+$1,ref [] in
        while !rest > 0 do
          (* printf "%d:\n  " !rest;
          print_list ist !res; *)
          match arr.(!q) with
          | [] -> (q := !q +$ 1)
          | ls -> (
            (* let b = arr.(!q) |> of_list in *)
            let v = List.length arr.(!q) in
            let lls = make !q 0L |> to_list |> List.map (fun _ -> ls) |> List.flatten
            |> of_list
            in
            (* print_array ist lls; *)
            let r = ref 0 in
            while !rest > 0 && !r < length lls do
              res := lls.(!r) :: !res;
              r := !r +$ 1;
              rest := !rest -$ 1
            done;
            if !rest = 0 then (
              print_list ist !res; exit 0
            ) else (q := !q +$ 1)
          )
        done

      )
    ) else (
      let q = List.length arr.(p) in
      amari := !amari +$ q *$ p;
      (* r_amari := ()::!r_amari *)
    )
  );
  (* print_array (string_of_list ist) arr; *)
  (* print_list ist !r *)


let read_pair () =
    let s = read_line () in
    let nums = List.map int_of_string (Str.split (Str.regexp " ") s) in
    match nums with
    | [a;b] -> (a, b)
    | _ -> (0, 0)

;;

let rec get_pair n (a, b)=
    if n > 0 then
        match read_pair () with
        | (x, y) -> if x > y then
                        get_pair (n-1) (a+1, b)
                     else if x < y then
                        get_pair (n-1) (a, b+1)
                    else
                        get_pair (n-1) (a, b)

    else
        (a, b)

;;

let read_nums () =
    let n = read_int () in
    let (a, b) = get_pair n (0, 0) in
    if a = b then
        print_string "Friendship is magic!^^\n"
    else if a > b then
        print_string "Mishka\n"
    else
        print_string "Chris\n"
;;

read_nums () ;;

let n = read_line () |> int_of_string in
let scores = Array.init n (fun x -> read_line())
  |> Array.map (fun x -> let b = Str.split (Str.regexp " *") x |> List.map int_of_string in (List.nth b 0, List.nth b 1)) |> Array.to_list in
let (m,c) = List.split scores in
let sum = List.fold_left ( + ) 0 in
print_string (match List.map2 compare m c |> sum with
  | 0 -> "Friendship is magic!^^"
  | e when e > 0 -> "Mishka"
  | _ -> "Chris"
)

let read () = Scanf.scanf "%d " (fun n -> n)
let print result = Printf.printf "%s\n" result

let count () =
    let n = read () in
    let rec loop i count_a count_b =
        if i < n
        then
            let a = read () in
            let b = read () in
            if a > b
            then
                loop (i + 1) (count_a + 1) count_b
            else
                if a < b
                then
                    loop (i + 1) count_a (count_b + 1)
                else
                    loop (i + 1) count_a count_b
        else
            (count_a, count_b)
    in loop 0 0 0

let solve (count_a, count_b) =
    if count_a > count_b
    then
        print "Mishka"
    else
        if count_a < count_b
        then
            print "Chris"
        else
            print "Friendship is magic!^^"

let () = solve (count ())

let read_pair () =
    let s = read_line () in
    let nums = List.map int_of_string (Str.split (Str.regexp " ") s) in
    match nums with
    | [a;b] -> (a, b)
    | _ -> (0, 0)

;;

let rec get_pair n (a, b)=
    if n > 0 then
        match read_pair () with
        | (a, b) -> if a > b then
                        get_pair (n-1) (a+1, b)
                     else if a < b then
                        get_pair (n-1) (a, b+1)
                    else
                        get_pair (n-1) (a, b)

    else
        (a, b)

;;

let read_nums () =
    let n = read_int () in
    let (a, b) = get_pair n (0, 0) in
    if a = b then
        print_string "Friendship is magic!^^\n"
    else if a > b then
        print_string "Mishka\n"
    else
        print_string "Chris\n"
;;

read_nums () ;;

let n = read_line () |> int_of_string in
let scores = Array.init n (fun x -> read_line())
  |> Array.map (fun x -> let b = Str.split (Str.regexp " *") x |> List.map int_of_string in (List.nth b 0, List.nth b 1)) |> Array.to_list in
let (m,c) = List.split scores in
let sum = List.fold_left ( + ) 0 in
print_string (match List.map2 compare m c |> sum with
  | 0 -> "Friendship is magic!^^"
  | e when e > 0 -> "Minska"
  | _ -> "Chris"
)


let n = int_of_string (read_line ())

let solve () =
  let s = read_line () in
  let first = (Char.code s.[0]) - 97 in
  let second = (Char.code s.[1]) - 97 in
  if second < first then
    Printf.printf "%d\n" ((26 * first) + second - (first - 1))
  else
    Printf.printf "%d\n" ((26 * first) + second - first)
;;
for i = 0 to n - 1 do
  solve ()
done;;

let readInt () = Scanf.scanf " %d" (fun x -> x);;
let readBerland () = Scanf.scanf " %c%c" (fun a b -> a, b);;

let convertCharsToAlphabetPos = function
  | a, b -> (Char.code a) - 97, (Char.code b) - 97
;;
let getBerlandPos = function
  | a, b ->
    if b<a then a*25+b
    else if b>a then a*25+b-1
    else raise (Failure "Value Err!")
;;

let rec iterator = function
  | 0 -> 0
  | n ->
    let a, b = convertCharsToAlphabetPos (readBerland ()) in
    (* Add 1 as we aren't zero indexing *)
    print_int ((getBerlandPos (a, b))+1);
    print_newline ();
    iterator (n-1)
;;

let test_cases = readInt () in iterator test_cases;;

let readInt () = Scanf.scanf " %d" (fun x -> x);;
let readBerland () = Scanf.scanf " %c%c" (fun a b -> a, b);;

let convertCharsToAlphabetPos = function
  | a, b -> (Char.code a) - 97, (Char.code b) - 97
;;
let getBerlandPos = function
  | a, b -> a*26+b
;;

let rec iterator = function
  | 0 -> 0
  | n ->
    let a, b = convertCharsToAlphabetPos (readBerland ()) in
    print_int (getBerlandPos (a, b));
    print_newline ();
    iterator (n-1)
;;

let test_cases = readInt () in iterator test_cases;;


let main () =
  let gr () = Scanf.scanf " %d" (fun i -> i) in
  let gs () = Scanf.scanf " %s" (fun i -> i) in

  let print_ans x y z s =
      Printf.printf "%d %d %d\n" (s - x) (s - y) (s - z)
  in
  let p = gr () in
  let r = gr() in
  let s = gr() in
  let t = gr() in
  if p+r+s == 2 * t then print_ans p r s t
  else if p + r + t == 2 * s then print_ans p r t s
  else if p + s + t == 2 * r then print_ans p s t r
  else print_ans r s t p

let _ = main();;

let scan_int () =
  Scanf.scanf " %d" (fun x -> x)
;;

let f () =
  let b = Array.init 4 (fun x -> scan_int ()) in
  Array.sort compare b;
  b
;;

let _ =
  let arr = f () in
  Printf.printf "%d %d %d\n" (arr.(3) - arr.(0)) (arr.(3) - arr.(1)) (arr.(3) - arr.(2))
;;


type 'a el = {
  v : 'a;
  mutable next : 'a el option;
  mutable prev : 'a el option;
}

let () = Scanf.scanf "%d %d\n" (fun n m ->
  (* book weights *)
  let w = Array.init n (fun _ -> Scanf.scanf "%d%_c" (fun x -> x)) in
  (* reading order *)
  let b = Array.init m (fun _ -> Scanf.scanf "%d%_c" (fun x -> x - 1)) in
  (* seen array *)
  let seen = Array.make n false in
  (* head of pile *)
  let p = { v = b.(0); next = None; prev = None } in
  let hd = ref p in
  (* tail of pile *)
  let tl = ref p in
  seen.(b.(0)) <- true;

  let add i =
    let el = { v = i; next = None; prev = Some !tl } in
    !tl.next <- Some el;
    tl := el
  in

  (* construct the pile *)
  Array.iter (fun b ->
    if not seen.(b) then begin
      add b;
      seen.(b) <- true
    end
  ) b;
  let c = Array.fold_left (fun acc b ->
    let rec part a h =
      if h.v = b then (a, h)
      else match h.next with
      | None -> failwith "No more list!"
      | Some n -> part (a + w.(h.v)) n
    in
    let (cost, h) = part 0 !hd in
    let () = match h.prev with
    | None -> () (* already at head *)
    | Some p -> begin
      p.next <- h.next;

      let () = match h.next with
      | None -> ()
      | Some n -> n.prev <- Some p
      in
      h.next <- Some !hd;
      h.prev <- None;
      !hd.prev <- Some h;
      hd := h
    end
    in
    acc + cost
  ) 0 b in
  Printf.printf "%d\n" c
)

open Printf
open Scanf

let rec fold i j f init = if i>j then init else fold (i+1) j f (f i init)
let sum i j f = fold i j (fun i a -> (f i) + a) 0

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let () =
  let n = read_int () in
  let m = read_int () in

  let w = Array.init n (fun _ -> read_int()) in
  let b = Array.init m (fun _ -> read_int() - 1) in

  let indices = Array.make n 0 in
  let locator = Array.make n 0 in

  let h = Hashtbl.create 10 in

  let place = ref 0 in

  for j=0 to m-1 do
    if not (Hashtbl.mem h b.(j)) then (
      Hashtbl.replace h b.(j) true;
      indices.(!place) <- b.(j);
      locator.(b.(j)) <- !place;
      place := !place + 1;
    )
  done;

  (* some books may never be read and thus not be in this data structure.
     I don't think this matters. They'll never be accessed below. *)

  let swap j =
    let (a,b) = (indices.(j), indices.(j+1)) in
    locator.(a) <- locator.(a) + 1;
    locator.(b) <- locator.(b) - 1;
    indices.(j) <- b;
    indices.(j+1) <- a;
  in

  let read_book k =
    let i = locator.(k) in
    let weight = ref 0 in
    for j=i-1 downto 0 do
      (* swap the books at positions j+1 and j *)
      weight := !weight + w.(indices.(j));
      swap j;
    done;
    !weight
  in

  let answer = sum 0 (m-1) (fun j -> read_book b.(j)) in

  printf "%d\n" answer


let input () =
  let l = ref []
  in let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let n = getNumber ()
  in begin
    for i = 0 to n - 1 do
      l := (getNumber ()) :: !l
    done;
    !l
  end;;

let divideList l =
  let l = List.sort compare l
  in let l1 = List.filter (fun x -> x = 1) l
  in let l2 = List.filter (fun x -> x = 2) l
  in (l1, l2)

let rec firstStep a l1 l2 =
  match l1, l2 with
  | x1 :: t1, x2 :: t2 -> firstStep (a + 1) t1 t2
  | _ -> (a, l1)

let rec secondStep a = function
  | x :: y :: z :: t -> secondStep (a + 1) t
  | _ -> a

let teams (l1, l2) =
  let n, newL1 = firstStep 0 l1 l2
  in secondStep n newL1

let main () =
  let l = input ()
  in let n = teams (divideList l)
  in Printf.printf "%d" n
;;

main ();;

let input () =
  let l = ref []
  in let getNumber () = Scanf.bscanf Scanf.Scanning.stdin " %d" (fun x -> x)
  in let n = getNumber ()
  in begin
    for i = 0 to n - 1 do
      l := (getNumber ()) :: !l
    done;
    !l
  end;;

let divideList l =
  let l = List.sort compare l
  in let l1 = List.filter (fun x -> x = 1) l
  in let l2 = List.filter (fun x -> x = 2) l
  in (l1, l2)

let rec firstStep a l1 l2 =
  match l1, l2 with
  | x1 :: t1, x2 :: t2 -> firstStep (a + 1) t1 t2
  | _ -> (a, l1)

let rec secondStep a = function
  | x :: y :: z :: t -> secondStep (a + 1) t
  | _ -> a

let teams (l1, l2) =
  let n, newL1 = firstStep 0 l1 l2
  in secondStep n newL1

let altMethod l =
  let rec int a1 a2 = function
    | 1 :: t -> int (a1 + 1) a2 t
    | 2 :: t -> int a1 (a2 + 1) t
    | _ -> (a1, a2)
  in let n1, n2 = int 0 0 l
  in if n1 > n2 then
    n2 + (n1 - n2) / 3
  else
    n1

let main () =
  let l = input ()
  in let n = altMethod l
  in Printf.printf "%d" n
;;

main ();;

open Printf
open Scanf

let read_int _ = bscanf Scanning.stdib " %d " (fun x -> x)

let () =
  let n = read_int () in

  let rec loop n1 n2 i = if i=n then (n1,n2) else
      if read_int() = 1 then loop (n1+1) n2 (i+1)
      else loop n1 (n2+1) (i+1)
  in

  let (n1, n2) = loop 0 0 0 in

  if n2 >= n1 then printf "%d\n" n1
  else printf "%d\n" (n2 + (n1-n2)/3)


(*
Consider the following:

i) kmod4=0:
 means bmod4=0
or anod4=0
or amod4=bmod4=2
-> (4,),(8,),...
-> (,4),(,8),...
-> (2,6),(10,14),...
-> (1,4),(3,8),(5,12),...
-> not possible

ii) kmod4=1
amod4=3 or bmod4=0
or (amod4=1 and bmod4=2)
->(1,2),(5,6),...
->(3,),(7,),...
->(,4),(8,),...
->(1,2),(3,4),(5,6),...
-> possible when n is even

iii) kmod4=2
amod4=2 or bmod4=0
or (amod4=0 and bmod4=2)
->(4,2),(8,6),(12,10),...
->(2,1),(6,5),(10,9)...
->(3,4),(7,8),(11,12),...
->(2,1),(3,4),(6,5),...
-> possible when n is even

iv) kmod4=3
amod4=1 or bmod4=0
or (amod4=3 and bmod4=2)
->(1,),(5,),(9,)...
->(,4),(,8),...
->(3,2),(7,6),...
->(1,2),(5,6),...
->(3,4),(7,8)...
->(1,2),(3,4),(5,6),....
-> possible when n is even
*)

let read_int () = Scanf.scanf " %d" (fun x->x);;
let read_long () = Scanf.scanf " %Ld" (fun l->l);;
let run_case = function
| () ->
     let n = read_long () in
     let k = read_long () in
     let remk = Int64.sub k (Int64.mul 4L (Int64.div k 4L)) in
     if (remk=0L) then Printf.printf "NO\n"
     else if (remk=2L) then begin
         Printf.printf "YES\n";
         let rec pairPrint = function
         | x, r ->
              if (x>n) then ()
              else if (r=false) then begin
                  Printf.printf "%Ld %Ld\n" x (Int64.succ x);
                  pairPrint ((Int64.add x 2L), true)
              end
              else begin
                  Printf.printf "%Ld %Ld\n" (Int64.succ x) x;
                  pairPrint ((Int64.add x 2L), false)
              end
          in pairPrint (1L,true)
     end
     else begin
         Printf.printf "YES\n";
         let rec pairPrint =function
         | x ->
              if (x>n) then ()
              else begin
                  Printf.printf "%Ld %Ld\n" x (Int64.succ x);
                  pairPrint (Int64.add x 2L)
              end
          in pairPrint 1L
     end
;;

let rec iter_cases = function
| 0 -> ()
| t -> run_case (); iter_cases (t-1)
;;

let t = read_int () in iter_cases t;;

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)

let () =
  let t = read_int () in
  for _ = 1 to t do
    let n = read_int () in
    let k' = read_int () in
    if (k' mod 4 = 0) then print_endline "NO"
    else begin
      print_endline "YES";
      let k = k' mod 4 in
      for i = 0 to n / 2 - 1 do
        let x = 2 * i + 1 in
        let y = 2 * i + 2 in
        if ((x + k) * y mod 4 = 0) then
          pf "%d %d\n" x y
        else
          pf "%d %d\n" y x
      done;
    end;
  done;


let scan_int () = Scanf.scanf " %d" (fun x -> x) in
let n = scan_int () in
let h = scan_int () in

let rec read_n_ints n =
        if n = 0 then []
        else (scan_int ()) :: (read_n_ints (n-1)) in

let l = read_n_ints n in

Printf.printf "%d\n" (n + (List.length (List.filter (fun hh -> hh > h) l)))

let read () = Scanf.scanf "%d " (fun n -> n)

let input () =
    let total = read () in
    let limit = read () in
    let rec loop heights i =
        if i < total
        then
            let height = Scanf.scanf "%d " (fun h -> h) in
            loop (height :: heights) (i + 1)
        else
            (total, limit, heights)
    in loop [] 0

let solve (total, limit, heights) =
    let double_width = List.length (List.filter (fun n -> n > limit) heights) in
    let single_width = total - double_width in
    let total_width = single_width + 2 * double_width in
    Printf.printf "%d\n" total_width

let () = solve (input ())

open !Scanf
open !Printf

let read_int () = bscanf Scanning.stdin "%d " (fun x -> x)

let () =
    let n = read_int () in
    let h = read_int () in

    let rec solve n h =
        match n with
        | 0 -> 0
        | _ -> (if read_int () <= h then 1 else 2) + solve (n-1) h

    in printf "%d" (solve n h)

(* Codeforces 677 A VaniaFence *)

(* you can use either gr or rdln but not both *)
let gr () = Scanf.scanf " %d" (fun i -> i);;
let grf () = Scanf.scanf " %f" (fun i -> i);;
let grl () = Scanf.scanf " %Ld" (fun i -> i);;
let rdln() = input_line stdin;;
(* let spli s = Str.split (Str.regexp " ") s;; *)
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;
let printarri ai = Array.iter (fun i -> (print_int i; print_string " ")) ai;;
let debug = false;;

let rec readlist n acc = match n with
	| 0 -> acc
	| _ -> readlist (n -1) (gr() :: acc);;
let printlisti li = List.iter (fun i -> (print_int i; print_string " ")) li;;

let rec widlist li zh = match li with
| [] -> 0
| h :: t -> (if (h > zh) then 2 else 1) +
	(widlist t zh);;

let main() =
	let n = gr() in
	let h = gr() in
	let a = readlist (n) [] in
	let wid = widlist a h in
	begin
		print_int wid;
		print_string "\n"
	end;;

main();;

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let h = Scanf.bscanf sb "%d " (fun s -> s) in
  let res = ref 0 in
    for i = 1 to n do
      let x = Scanf.bscanf sb "%d " (fun s -> s) in
	if x > h
	then res := !res + 2
	else res := !res + 1;
    done;
    Printf.printf "%d\n" !res

open Printf
open Scanf

let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac + (f i))

let read_int () = bscanf Scanning.stdib " %d " (fun x -> x)
let read_pair () = bscanf Scanning.stdib " %d %d " (fun x y -> (x,y))
let () =
  let n = read_int () in
  let h = read_int () in

  let answer = sum 1 n (
    fun _ -> let y = read_int() in
	     if y > h then 2 else 1
  ) 0 in

  printf "%d\n" answer


open Big_int;;

let main () =
	let (n,d) = Scanf.scanf "%d %d" (fun i j -> (i,j)) and l = ref []
	in
		for i=1 to n do
			Scanf.scanf " %d %s" (fun i j -> l := (i,big_int_of_string j)::!l);
		done;
	let tab = Array.of_list (List.sort (fun (i,_) (j,_) -> compare i j) !l) and i = ref 0
	and j = ref 0 in
	let act = ref (snd (tab.(0))) and maxi= ref (big_int_of_int 0) in
		while !j < n do
			if fst (tab.(!j)) - fst (tab.(!i)) < d
				then (
			maxi := max_big_int !maxi !act;incr j;if !j < n then act := add_big_int !act (snd (tab.(!j))))
				else (act := sub_big_int !act (snd (tab.(!i))); incr i);
		done;
	Printf.printf "%s" (string_of_big_int !maxi);;

main ();;

let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin " %s " (fun x -> Big_int.big_int_of_string x);;
let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x);;
let read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;
let comp (a, b) (c, d) = if (Big_int.compare_big_int a c) = 0 then Big_int.compare_big_int b d else Big_int.compare_big_int a c;;
let main () =
    let n = read_int () in
    let d = read_int64 () in
    let a = Array.init n read_pair in
    let _ = Array.sort comp a in
    let (i, j, k, c) = (ref 0, ref 0, ref (Big_int.big_int_of_int 0), ref (Big_int.big_int_of_int 0)) in (
        while !i < n do (
            match (a.(!i), a.(!j)) with
            | ((x, y), (z, w)) -> (
                if Big_int.compare_big_int (Big_int.sub_big_int x z) d < 0 then
                    (k := (Big_int.add_big_int !k y); c := (Big_int.max_big_int (!c) (!k)); incr i)
                else
                    (k := (Big_int.sub_big_int !k w); incr j)
            )
        )
        done;
        Printf.printf "%s\n" (Big_int.string_of_big_int !c)
    )
;;

main ();;

let read_int64 () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> Int64.of_int x);;
let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x);;
let read_pair _ = let x = read_int64 () in let y = read_int64 () in (x, y);;
let comp (a, b) (c, d) = if (Int64.compare a c) = 0 then Int64.compare b d else Int64.compare a c;;
let main () =
    let n = read_int () in
    let d = read_int64 () in
    let a = Array.init n read_pair in
    let _ = Array.sort comp a in
    let (i, j, k, c) = (ref 0, ref 0, ref 0L, ref 0L) in (
        while !i < n do (
            match (a.(!i), a.(!j)) with
            | ((x, y), (z, w)) -> (
                if Int64.compare (Int64.sub x z) d < 0 then
                    (k := (Int64.add !k y); c := (max (!c) (!k)); incr i)
                else
                    (k := (Int64.sub !k w); incr j)
            )
        )
        done;
        Printf.printf "%s\n" (Int64.to_string !c)
    )
;;
main ();;

let main () =
	let (n,d) = Scanf.scanf "%d %d" (fun i j -> (i,j)) and l = ref []
	in
		for i=1 to n do
			Scanf.scanf " %d %d" (fun i j -> l := (i,j)::!l);
		done;
	let tab = Array.of_list (List.sort compare !l) and i = ref 0
	and j = ref 0 in
	let act = ref (snd (tab.(0))) and maxi= ref 0 in
		while !j < n do
			if fst (tab.(!j)) - fst (tab.(!i)) < d
				then (
			maxi := max !maxi !act;incr j;if !j < n then act := !act + snd (tab.(!j)))
				else (act := !act - snd (tab.(!i)); incr i);
		done;
	Printf.printf "%d" !maxi;;

main ();;

let read_int () = Scanf.bscanf Scanf.Scanning.stdin " %d " (fun x -> x);;
let read_pair _ = let x = read_int () in let y = read_int () in (x, y);;
let comp a b = if a < b then -1 else if a = b then 0 else 1;;
let main () =
    let n = read_int () in
    let d = read_int () in
    let a = Array.init n read_pair in
    let _ = Array.sort comp a in
    let (i, j, k, c) = (ref 0, ref 0, ref 0, ref 0) in (
        while !i < n do (
            match (a.(!i), a.(!j)) with
            | ((x, y), (z, w)) -> (
                if x - z < d then
                    (k := !k + y; c := max (!c) (!k); incr i)
                else
                    (k := !k - w; incr j)
            )
        )
        done;
        Printf.printf "%d\n" (!c)
    )
;;

main ();;


let divBy3 x =
  let rec loop acc x' =
    if x' <= 1 then Some acc
    else if (x' mod 3) = 0 then loop (acc + 1) (x' / 3)
    else None
  in loop 0 x

let divBy6 x =
  let rec loop acc x' =
    if (x' mod 6) = 0 then loop (acc + 1) (x' / 6) else acc
  in loop 0 x

let rec without6 x =
  if (x mod 6) = 0 then without6 (x / 6) else x

let solveFor x =
  match divBy3 (without6 x) with
  | None -> -1
  | Some x' -> (divBy6 x) + (x' * 2)

let read_int () = Scanf.scanf "%d " (fun x -> x)

let () =
  for i = 1 to (read_int ()) do
    read_int ()
    |> solveFor
    |> Printf.printf "%d\n"
  done

open Printf

let rec divide a b c = if a mod b = 0 then divide (a / b) b (c + 1) else (a,c)

let main =
    let n = read_int() in
    for i = 1 to n do
        let x = read_int() in
        let (y,n2) = divide x 2 0 in
        let (z,n3) = divide y 3 0 in
        if z <> 1 || n2 > n3 then
            printf "-1\n"
        else
            printf "%d\n" (2 * n3 - n2)
    done


open Printf
open Scanf

let ( ++ ) a b = Int64.add a b
let long x = Int64.of_int x
let rec sum i j f ac = if i>j then ac else sum (i+1) j f (ac ++ (f i))

let read_string () = bscanf Scanning.stdib " %s " (fun x -> x)

let () =
  let a = read_string () in
  let b = read_string () in

  let n = String.length a in
  let m = String.length b in

  let a = Array.init n (fun i -> if a.[i] = '1' then 1 else 0) in
  let b = Array.init m (fun i -> if b.[i] = '1' then 1 else 0) in

  let sigma = Array.make (m+1) 0 in

  for i=1 to m do
    sigma.(i) <- sigma.(i-1) + b.(i-1)
  done;

  (* sigma.(x) = sum of b's from b.(0) to b.(x-1) *)

  let sum_range i j = sigma.(j+1) - sigma.(i) in

  let answer = sum 0 (n-1) (fun i ->
    let first = i in
    let last = m-n+i in
    let nones = sum_range first last in
    long (if a.(i) = 1 then (last-first+1) - nones else nones)
  ) 0L in

  printf "%Ld\n" answer

let v s i = int_of_char( s.[i] ) - 48 ;;
let a, b = Scanf.scanf "%s %s" (fun a b -> (a,b)) ;;

let rec bsum = function
    | 0 -> 0
    | i -> (v b (i-1) ) + bsum (i-1)
;;
let cmplen = String.length b - String.length a ;;
let (+^), to64 = Int64.(add, of_int) ;;
let rec f i cs =
    if i = String.length a
    then 0L
    else let cs2 = cs + v b (cmplen+i) in
        to64 (if v a i = 0 then cs2 else cmplen+1-cs2)
      +^ f (i+1) (cs2 - v b i)
;;
Printf.printf "%Ld" (f 0 (bsum cmplen))

let v s i = int_of_char( s.[i] ) - 48 ;;
let a, b = Scanf.scanf "%s %s" (fun a b -> (a,b)) ;;

let rec bsum = function
    | 0 -> 0
    | i -> (v b (i-1) ) + bsum (i-1)
;;
let cmplen = String.length b - String.length a ;;

let rec f i cs =
    if i = String.length a
    then 0
    else let cs2 = cs + v b (cmplen+i) in
        (if v a i = 0 then cs2 else cmplen+1-cs2)
      + f (i+1) (cs2 - v b i)
;;
print_int @@ f 0 (bsum cmplen)


open Scanf;;
let scan_int () = Scanf.scanf " %d" (fun x -> x);;
let scan_string () = Scanf.scanf " %s" (fun x -> x);;
let psp () = print_string " ";;
let b2i x = if x == true then 1 else 0;;

let n = scan_int() and maxN = 1007;;
let tab = Array.make maxN 0;;

for i = 1 to n do
  let x = scan_int() in
  tab.(x) <- (tab.(x) + 1);
done;;

let cnt = ref 0 and maxik = ref 0;;
for i = 1 to (maxN - 1) do
  cnt := (!cnt + b2i(tab.(i) > 0));
  maxik := max (!maxik) tab.(i);
done;;

print_int !maxik; psp(); print_int !cnt;

module Int = struct
	let compare = compare
	type t = int
end;;

module IntMap = Map.Make(Int);;

let rec solve i bruski =
	if i = 0 then (
		let l = IntMap.fold (fun _ _ l -> l + 1) bruski 0 in
		let max = IntMap.fold (fun _ h m -> max h m) bruski 0 in
		Printf.printf "%d %d" max l
	) else (
		let w = Scanf.scanf " %d" (fun i->i) in
		let nbruski = IntMap.add w ((if IntMap.mem w bruski
			then IntMap.find w bruski else 0) + 1) bruski in
		solve (i-1) nbruski
	)
;;

let () =
	solve (read_int()) IntMap.empty
;;