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

let n = get_i64 0
let nn =
	let r = ref 1L in
	while !r*2L <= n do
		r *= 2L
	done; !r
let f v =
	let r = ref 1L in
	while !r*v <= n do r *= v
	done; !r
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n / !v) * !v);
			(* print_endline "";
			printf "%Ld\n" nn;
			printf "%Ld %Ld %Ld\n" ((n/2L)*2L) (f !v) ((n / !v) * !v); *)
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

let split_on_char sep s =
  let r = ref [] in
  let j = ref (String.length s) in
  for i = String.length s - 1 downto 0 do
    if String.unsafe_get s i = sep then begin
      r := String.sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  String.sub s 0 !j :: !r
;;

exception Found;;

let last_big l a =
  let tmp = ref 0 in
  try
    for i = l-1 downto 0 do
      if a.(i) then (tmp := i + 1; raise Found)
    done;
    !tmp
  with Found -> !tmp
;;

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
let last = ref n in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      if j  = !last && !continue = n - 2  then begin
        Printf.printf "%i " !div;
        incr continue;
        Printf.printf "%i " !last;
      end else Printf.printf "%i " !div;
      incr continue;
      b.(j-1) <- false;
      if j = !last then last := last_big !last b
    end
  done;
  div := 2 * !div;
done;
print_newline ()

let split_on_char sep s =
  let r = ref [] in
  let j = ref (String.length s) in
  for i = String.length s - 1 downto 0 do
    if String.unsafe_get s i = sep then begin
      r := String.sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  String.sub s 0 !j :: !r
;;

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      incr continue;
      Printf.printf "%i " (if n = 3 && !continue = n then n else !div);
    end
  done;
  div := 2 * !div;
done;
print_newline ()

let split_on_char sep s =
  let r = ref [] in
  let j = ref (String.length s) in
  for i = String.length s - 1 downto 0 do
    if String.unsafe_get s i = sep then begin
      r := String.sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  String.sub s 0 !j :: !r
;;

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let b = Array.make n true in
let div = ref 1 in
let continue = ref true in
while !continue do
  continue := false;
  for j = 1 to n do
    if b.(j-1) then continue := true;
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      print_int !div;
    end
  done;
  div := 2 * !div;
done;
print_newline ()

let split_on_char sep s =
  let r = ref [] in
  let j = ref (String.length s) in
  for i = String.length s - 1 downto 0 do
    if String.unsafe_get s i = sep then begin
      r := String.sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  String.sub s 0 !j :: !r
;;

let n = Scanf.sscanf (read_line ()) "%i" (fun n -> n) in
let b = Array.make n true in
let div = ref 1 in
let continue = ref 0 in
while !continue != n do
  for j = 1 to n do
    if b.(j-1) && j mod (2 * !div) != 0 then begin
      b.(j-1) <- false;
      if j = n && !continue = n - 2  then begin
        Printf.printf "%i " !div;
        incr continue;
        Printf.printf "%i " n;
      end else Printf.printf "%i " !div;
      incr continue;
    end
  done;
  div := 2 * !div;
done;
print_newline ()

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

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" n;
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

(*
let n = get_i64 0
let mx = i32 n +$ 24

let prime = Array.make (mx) true
let preprocess _ =
	prime.(0) <- false;
	prime.(1) <- false;
	repi 2 mx (fun u ->
		if prime.(u) then (
			repi (u*$2) mx (fun v ->
				prime.(v) <- false;
				`Ok
			)
		);
		`Ok
	)

let () =
 *)

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

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n/2L)*2L);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

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

let n = get_i64 0
let nn =
	let r = ref 1L in
	while !r*2L <= n do
		r *= 2L
	done; !r
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" nn;
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

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

let n = get_i64 0
let () =
	if n = 1L then printf "1\n"
	else if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L (!p-1L) (fun _ -> printf "%Ld " !v; `Ok);
			printf "%Ld\n" ((n/2L)*2L);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;

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

let n = get_i64 0
let () =
	if n = 2L then printf "1 2\n"
	else if n = 3L then printf "1 1 3\n"
	else
	let p,v = ref n,ref 1L in
	while !p > 0L do
		if !p >= 4L then (
			rep 1L (!p - !p / 2L) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L !p (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L;
		)
		(* let c = !p - !p / 2L in
		if c >= 2L then (
			rep 1L (c) (fun _ -> printf "%Ld " !v; `Ok);
			v *= 2L;
			p /= 2L;
		) else (
			rep 1L c (fun _ -> printf "%Ld " !v; `Ok);
			p := 0L
		) *)
	done;


let () = Scanf.scanf "%s\n" (fun s ->
    (* characters that can be the middle of a string *)
    let mid = ['A'; 'H'; 'I'; 'M'; 'O'; 'o'; 'T'; 'U'; 'V'; 'v'; 'W'; 'w'; 'X'; 'x'; 'Y']
    (* mirrored pairs *)
    and pairs = ['b', 'd'; 'd', 'b'; 'p', 'q'; 'q', 'p'] in

    let n = String.length s in

    print_endline (
        if (n mod 2 = 0 || List.mem s.[n / 2] mid) &&
           Array.fold_left (&&) true (Array.init (n / 2) (fun i ->
               (s.[i] = s.[n - i - 1] && List.mem s.[i] mid) ||
               (List.mem_assoc s.[i] pairs && List.assoc s.[i] pairs = s.[n - i - 1])))
        then "TAK" else "NIE"))

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let res = ref true in
  let sym =
    function
      | 'A' -> 'A'
      | 'b' -> 'd'
      | 'd' -> 'b'
      | 'H' -> 'H'
      | 'I' -> 'I'
      | 'M' -> 'M'
      | 'O' -> 'O'
      | 'o' -> 'o'
      | 'T' -> 'T'
      | 'U' -> 'U'
      | 'V' -> 'V'
      | 'v' -> 'v'
      | 'W' -> 'W'
      | 'w' -> 'w'
      | 'X' -> 'X'
      | 'x' -> 'x'
      | 'Y' -> 'Y'
      | 'p' -> 'q'
      | 'q' -> 'p'
      | _ -> '\000'
  in
    for i = 0 to (n - 1) / 2 do
      if s.[i] <> sym s.[n - i - 1]
      then res := false
    done;
    if !res
    then Printf.printf "TAK\n"
    else Printf.printf "NIE\n"

let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let res = ref true in
  let sym =
    function
      | 'A' -> 'A'
      | 'b' -> 'd'
      | 'd' -> 'b'
      | 'H' -> 'H'
      | 'I' -> 'I'
      | 'M' -> 'M'
      | 'O' -> 'O'
      | 'o' -> 'o'
      | 'T' -> 'T'
      | 'U' -> 'U'
      | 'V' -> 'V'
      | 'v' -> 'v'
      | 'W' -> 'W'
      | 'w' -> 'w'
      | 'X' -> 'X'
      | 'x' -> 'x'
      | 'Y' -> 'Y'
      | _ -> '\000'
  in
    for i = 0 to (n - 1) / 2 do
      if s.[i] <> sym s.[n - i - 1]
      then res := false
    done;
    if !res
    then Printf.printf "TAK\n"
    else Printf.printf "NIE\n"


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
	(* 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
	(* io *)
	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 *)
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
end open Lib

open I64_infix
let undef = -77L
let () =
	let tbl = Hashtbl.create ~random:true 10014 in
	rep 0L 3L (fun t ->
		rep 0L 3L (fun a ->
			rep 0L 3L (fun b ->
				let ls = ref (-1L) in
				rep 0L 3L (fun tt ->
					if a = t lor tt && b = t land tt then ls := tt
				);
				if !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls
				else Hashtbl.add tbl (t,a,b) undef
			)
		)
	);
	let n = get_i64 0 in
	let a = input_i64_array (n-1L) in
	let b = input_i64_array (n-1L) in
	let t = Array.make (i32 n) 0L in
	rep 0L 3L (fun t0 ->
		t.(0) <- t0;
		let f = ref true in
		repf 1L (n-1L) (fun i ->
			let i = i32 i in
			let v = Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1))
			in if v = undef then (f := false; `Break)
			else (t.(i) <- v; `Ok)
		);
		if !f then (
			printf "YES\n";
			dump_array Int64.to_string t; exit 0
		)
	);
	printf "NO\n";

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
	(* 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
	(* io *)
	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 *)
	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
	(* imperative *)
	let rep f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i + 1L done
	let repf f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i + 1L done
	let repm f t 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 + 1L done; !m
	let repi f t fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ 1 done
	let repif f t fbod = let i,c = ref f,ref true in while !i <= t && !c do
		match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ 1 done
	let repim f t 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 +$ 1 done; !m
	(* debug *)
	let dump_list f ls = string_of_list f ls |> print_endline
	let dump_array f a = string_of_array f a |> print_endline
end open Lib

open I64_infix
let () =
	let tbl = Hashtbl.create ~random:true 10014 in
	rep 0L 3L (fun t ->
		rep 0L 3L (fun a ->
			rep 0L 3L (fun b ->
				let ls = ref (-1L) in
				rep 0L 3L (fun tt ->
					if a = t lor tt && b = t land tt then ls := tt
				);
				if !ls >= 0L then Hashtbl.add tbl (t,a,b) @@ !ls

			)
		)
	);
	let n = get_i64 0 in
	let a = input_i64_array (n-1L) in
	let b = input_i64_array (n-1L) in
	let t = Array.make (i32 n) 0L in
	rep 0L 3L (fun t0 ->
		t.(0) <- t0;
		let f = ref true in
		repf 1L (n-1L) (fun i ->
			let i = i32 i in
			try
				t.(i) <- Hashtbl.find tbl (t.(i-$1),a.(i-$1),b.(i-$1));
				`Ok
			with | Not_found -> (
				f := false; `Break
			)
		);
		if !f then (
			printf "YES\n";
			dump_array Int64.to_string t; exit 0
		)
	);
	printf "NO\n";

let rec read_int_seq n stream =
	if n = 1 then Scanf.bscanf stream "%i" (fun x -> [x])
	else Scanf.bscanf stream "%i " (fun x -> x::(read_int_seq (n - 1) stream))
;;

let rec into_bits nums =
	match nums with
	| h::t -> (h / 2, h mod 2)::(into_bits t)
	| [] -> []
;;

let append_to_option head tail =
	match tail with
	| Some t -> Some (head::t)
	| None -> None
;;

let either f g =
	match f () with
	| Some a -> Some a
	| None -> match g () with
		| Some a -> Some a
		| None -> None
;;

let unwrap op =
	match op with
	| Some a -> a
	| None -> failwith "no value in option"
;;

let contradict_barrier want_to_place hint x =
	match hint with
	| Some a when a = want_to_place -> x
	| None -> x
	| _ -> None
;;

let rec solve nums_a nums_b current_hint_l current_hint_r =
	let infer_l a_bit b_bit a_tail b_tail =
		let infer_r l_res next_hint_l =
			match (snd a_bit, snd b_bit, current_hint_r) with
			| (0, 0, _) -> contradict_barrier 0 current_hint_r (append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0)))
			| (1, 1, _) -> contradict_barrier 1 current_hint_r (append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1)))
			| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))
			| (0, 1, _) -> None
			| _ -> failwith "corrupt data"
		in
		match (fst a_bit, fst b_bit, current_hint_l) with
		| (0, 0, _) -> contradict_barrier 0 current_hint_l (infer_r 0 (Some 0))
		| (1, 1, _) -> contradict_barrier 1 current_hint_l (infer_r 1 (Some 1))
		| (1, 0, Some 0) -> infer_r 0 (Some 1)
		| (1, 0, Some 1) -> infer_r 1 (Some 0)
		| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))
		| (0, 1, _) -> None
		| _ -> failwith "corrupt data"
	in
	match (nums_a, nums_b) with
	| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2
	| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]
;;

let n = read_int();;
let input_len = n - 1;;
let nums_a = read_line();;
let nums_b = read_line();;
let nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;
let nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;
let nums_a = into_bits nums_a;;
let nums_b = into_bits nums_b;;

let solution = solve nums_a nums_b None None;;
match solution with
	| Some solution -> (Printf.printf "YES\n"; List.iter (fun (x, y) -> Printf.printf "%i " (2*x + y)) solution)
	| None -> Printf.printf "NO\n"
;;

let rec read_int_seq n stream =
	if n = 1 then Scanf.bscanf stream "%i" (fun x -> [x])
	else Scanf.bscanf stream "%i " (fun x -> x::(read_int_seq (n - 1) stream))
;;

let rec into_bits nums =
	match nums with
	| h::t -> (h / 2, h mod 2)::(into_bits t)
	| [] -> []
;;

let append_to_option head tail =
	match tail with
	| Some t -> Some (head::t)
	| None -> None
;;

let either f g =
	match f () with
	| Some a -> Some a
	| None -> match g () with
		| Some a -> Some a
		| None -> None
;;

let unwrap op =
	match op with
	| Some a -> a
	| None -> failwith "no value in option"
;;

let rec solve nums_a nums_b current_hint_l current_hint_r =
	let infer_l a_bit b_bit a_tail b_tail =
		let infer_r l_res next_hint_l =
			match (snd a_bit, snd b_bit, current_hint_r) with
			| (0, 0, _) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 1, _) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 0) -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))
			| (1, 0, Some 1) -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0))
			| (1, 0, None) -> either (fun () -> append_to_option (l_res, 0) (solve a_tail b_tail next_hint_l (Some 1))) (fun () -> append_to_option (l_res, 1) (solve a_tail b_tail next_hint_l (Some 0)))
			| (0, 1, _) -> None
			| _ -> failwith "corrupt data"
		in
		match (fst a_bit, fst b_bit, current_hint_l) with
		| (0, 0, _) -> infer_r 0 (Some 0)
		| (1, 1, _) -> infer_r 1 (Some 1)
		| (1, 0, Some 0) -> infer_r 0 (Some 1)
		| (1, 0, Some 1) -> infer_r 1 (Some 0)
		| (1, 0, None) -> either (fun () -> infer_r 0 (Some 1)) (fun () -> infer_r 1 (Some 0))
		| (0, 1, _) -> None
		| _ -> failwith "corrupt data"
	in
	match (nums_a, nums_b) with
	| (h1::t1, h2::t2) -> infer_l h1 h2 t1 t2
	| _ -> Some [(unwrap current_hint_l, unwrap current_hint_r)]
;;

let n = read_int();;
let input_len = n - 1;;
let nums_a = read_line();;
let nums_b = read_line();;
let nums_a = read_int_seq input_len (Scanf.Scanning.from_string nums_a);;
let nums_b = read_int_seq input_len (Scanf.Scanning.from_string nums_b);;
let nums_a = into_bits nums_a;;
let nums_b = into_bits nums_b;;

let solution = solve nums_a nums_b None None;;
match solution with
	| Some solution -> (Printf.printf "YES\n"; List.iter (fun (x, y) -> Printf.printf "%i " (2*x + y)) solution)
	| None -> Printf.printf "NO\n"
;;


let n = read_int () in
let g = ref 1 in
let l = ref '2' in
for i = 1 to n do
    match read_line () with
        "01" -> if !l = '0' then g := !g + 1; l := '1'
      | "10" -> if !l = '1' then g := !g + 1; l := '0'
done ;
print_int !g ; print_newline () ;;

let solve () =
    let n = Pervasives.read_int () in
    let rec loop i last count =
        if i <= n
        then
            let current = Pervasives.read_line () in
            if String.compare current last = 0
            then
                loop (i + 1) last count
            else
                loop (i + 1) current (count + 1)
        else
            count
    in loop 2 (Pervasives.read_line ()) 1

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

let () = print (solve ())

let n = int_of_string (read_line ()) in
let g = Array.init n (fun i -> int_of_string (read_line ())) |> Array.to_list in
print_int (List.fold_left (fun (b,c) a -> (a, c + if a != b then 1 else 0)) (List.hd g, 1) (List.tl g)  |> snd)


type state =
  | Start
  | Word of Buffer.t
  | Mark

let _ =
  let s = input_line stdin in
  let s = s ^ " " in
  let n = String.length s in
  let state = ref Start in
    for i = 0 to n - 1 do
      let c = s.[i] in
	match c with
	  | 'a'..'z' -> (
	      match !state with
		| Start ->
		    let b = Buffer.create 10 in
		      Buffer.add_char b c;
		      state := Word b
		| Word b ->
		    Buffer.add_char b c
		| Mark ->
		    output_char stdout ' ';
		    let b = Buffer.create 10 in
		      Buffer.add_char b c;
		      state := Word b
	    )
	  | '.' | ',' | '!' | '?' -> (
	      match !state with
		| Start ->
		    output_char stdout c;
		    state := Mark
		| Word b ->
		    output_string stdout (Buffer.contents b);
		    output_char stdout c;
		    state := Mark;
		| Mark ->
		    output_char stdout c;
	    )
	  | ' ' -> (
	      match !state with
		| Start -> ()
		| Word b ->
		    output_string stdout (Buffer.contents b);
		    state := Mark
		| Mark -> ()
	    )
	  | _ -> assert false
    done


let id x = x

let div_of_rating rating =
  let ns =
    match rating with
    | r when r <= 1399 -> "4"
    | r when r <= 1599 -> "3"
    | r when r <= 1899 -> "2"
    | _ -> "1"
  in
  "Division " ^ ns

let solve () =
  let t = Scanf.scanf "%d\n" id in
  let () =
    for i = 1 to t do
      let r = Scanf.scanf "%d\n" (fun x -> x) in
      print_endline (div_of_rating r)
    done
  in
  ()

let main = solve ()

let getInt () = Scanf.scanf " %d" (fun i -> i);;
let f((x: int)) =
if x >= 1900 then 1
else if x >= 1600 then 2
else if x >= 1400 then 3
else 4;;

let main() =
  let t = getInt() in
  for i = 1 to t do
    let x = getInt() in print_endline("Division " ^ string_of_int(f(x)))
  done;;

main();;


let () = Scanf.scanf "%d\n" (fun n ->
    let read _ = Scanf.scanf "%d%_c" (fun x -> x) in

    let a1 = Array.init (n - 1) read
    and a2 = Array.init (n - 1) read
    and b  = Array.init n       read in

    (* calculate cumulative sum of a1
     * and reverse cumulative sum of a2 *)
    let s1 = Array.of_list (List.rev (Array.fold_left (fun (hd::_ as acc) x -> (x + hd) :: acc) [0] a1))
    and s2 = Array.of_list (Array.fold_right (fun x (hd::_ as acc) -> (x + hd) :: acc) a2 [0]) in

    let best = ref (-1) in

    (* first crossing *)
    for i = 0 to n - 2 do
        (* second crossing *)
        for j = i + 1 to n - 1 do
            let sum = s1.(i) + s2.(j) + s1.(j) + s2.(i) + b.(i) + b.(j) in
            if !best = (-1) || sum < !best
            then best := sum
        done
    done;

    Printf.printf "%d\n" !best)

let a = ref [] in
let b = ref [] in
let c = ref [] in
let n = read_int () in
	(let l = Scanf.Scanning.from_string (read_line ()) in
	for j = 1 to n-1 do
		try let k = Scanf.bscanf l "%d " (fun x -> x) in a := k::(!a) with _ ->
		let k = Scanf.bscanf l "%d" (fun x -> x) in a := k::(!a)
	done);
	(let l = Scanf.Scanning.from_string (read_line ()) in
	for j = 1 to n-1 do
		try let k = Scanf.bscanf l "%d " (fun x -> x) in b := k::(!b) with _ ->
		let k = Scanf.bscanf l "%d" (fun x -> x) in b := k::(!b)
	done);
	(let l = Scanf.Scanning.from_string (read_line ()) in
	for j = 1 to n do
		try let k = Scanf.bscanf l "%d " (fun x -> x) in c := k::(!c) with _ ->
		let k = Scanf.bscanf l "%d" (fun x -> x) in c := k::(!c)
	done);

let al = List.rev (!a) in
let bl = List.rev (!b) in
let cl = List.rev (!c) in

let rec trav i where st =
	match where with
		true ->
			let k2 = trav i false (2::st) in
			if i = n-1 then ((fst k2) + List.nth cl i, snd k2)
			else
				let k1 = trav (i+1) true (0::st) in
				let i2 = List.nth cl i in
				let t = min (fst k1 + List.nth al i) (fst k2 + i2) in
				if t = (i2 + fst k2) then (t, snd k2)
				else (t, snd k1)
		| false ->
			if i = n-1 then (0, st)
			else let k2 = trav (i+1) false (1::st) in
			(fst k2 + (List.nth bl i), snd k2)
	in
let (stv, stl) = trav 0 true [] in
let st = List.rev stl in

let rec trav2 i where ed w =
	match where with
		false ->
			let k2 = trav2 i true (2::ed) 2 in
			if i = 0 then ((fst k2) + List.nth cl i, snd k2)
			else
				let k1 = trav2 (i-1) false (1::ed) 1 in
				let i2 = List.nth cl i in
				let t = min (fst k1 + List.nth bl (i-1)) (fst k2 + i2) in
				if t = (i2 + fst k2) then (t, snd k2)
				else (t, snd k1)
		| true ->
			if i = 0 then
				(let bb = ed <> st in
				if bb then (0, ed) else (99999999, ed))
			else let k2 = trav2 (i-1) true (0::ed) 0 in
			(fst k2 + (List.nth al (i-1)), snd k2)
	in
let (edv, edl) = trav2 (n-1) false [] 2 in

print_int (stv + edv);;

let n= read_int () and ans = ref max_int;;
let a= Array.append
	[|( Array.of_list (List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()))))|]
    [|( Array.of_list (List.map (int_of_string) (Str.split (Str.regexp " ") (read_line ()))))|];;
let b=  Array.of_list (List.map(int_of_string) (Str.split (Str.regexp " ") (read_line ())));;
let f1= Array.create n 0 and f2= Array.create n 0;;
for i= 1 to n - 1 do Array.set f1 i (f1.(i - 1) + a.(1).(i - 1)) done;;
for i= n - 2 downto 0 do Array.set f2 i (f2.(i + 1) + a.(0).(i)) done;;
for i= 0 to n - 1 do for j= 0 to n - 1 do if i <> j then
	ans:= min !ans (f1.(i) + b.(i) + f2.(i) + f2.(j) + f1.(j) + b.(j))
done done;;
print_int !ans;;