(* It's a DP algorithm.  Keep y_opt.(i) which is the natural place
   where the point y.(i) will land when considering only points 0, 1,
   2... i.

   To compute y_opt.(i) we assume we have already computed the
   previous ones.  What we do now is see if y.(i) acting alone would
   be within the window defined by y_opt.(i-1).  If it is, we're done
   with y_opt.(i).  Say y.(i) is too high to be compatible with
   y_opt.(i-1).  Then we glue these two points together by asserting
   y.(i)-y.(i-1)=b.  (Analogously, if y.(i) is too low compared to
   y_opt.(i-1) we assert y.(i)-y.(i-1)=a instead.)  This pair of
   points has a natural position uninfluenced by anything outside of
   them.  If this position is compatible with y_opt.(i-2) then we're
   done, otherwise we add y.(i-2) to the chain and continue.  So the
   elements are chained together by a sequence of as and bs,
   intermixed.

   We can prove by induction that the solution that this finds is
   optimal.  The base case is when y.(i) is within the window allowed
   by y_opt.(i-1).  Clearly this is the right answer.  Now suppose
   that we have established that in the optimal solution some chain of
   differences relating y.(k),...,y.(i-2), y.(i) must occur.  This
   means that when searching for the optimal solution we need only
   consider these values moving in lockstep as specified by the chain.
   Looking at point k-1 if the chain is too low, then the optimal
   solution must also have y.(k-1) in the chain being a below y.(k),
   and if point k-1 is too high then it must be in the chain b below
   y.(i).  (The intuition is that of a spring.  If you move your
   finger toward a spring and you touch the spring, pushing harder on
   the spring will keep your finger in contact with the spring.  The
   spring will not suddenly pull away from your finger as you push
   harder.  The (x-y)^2 cost function ensures that this is the correct
   model.)

   So the algorithm is O(n^2).  It might be possible to work out a
   version of this algorithm that is O(n log n) by keeping the chains
   in a search tree.  Then instead of starting from scratch each time
   when adding a new point, it would edit the current chain.  It is
   not clear that this can be made to work.

               Danny Sleator <sleator@cs.cmu.edu>
*)

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

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.0
let sq x = x *. x
let (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)

let quad_min (a,b,c) = -. (b /. (2.0 *. a))
  (* ax^2 + bx + c is our quadratic.  Return the value of x that minimizes it *)
  (* a cannot be zero *)

let () =
  let n = read_int 0 in
  let q0 = read_float 0 in
  let a0 = read_float 0 in
  let b0 = read_float 0 in

  let x = Array.init n read_float in
  let y_opt = Array.copy x in
  let chain = Array.make n 0.0 in

  let bound h v = max (1.0+.h) (min q0 v) in

  let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else
    (* Set the group of points j+1, j+2, ... i all to differ by cumulative h
       the quadratic represented by this group is q. *)
    let yi_nat = bound h (quad_min q) in
      if y_opt.(j) < yi_nat -. h -. b0 then
	let ny = x.(j) +. h +. b0 in
	  chain.(j) <- b0;
	  pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else if y_opt.(j) > yi_nat -. h -. a0 then
	let ny = x.(j) +. h +. a0 in
	  chain.(j) <- a0;
	  pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else
	(yi_nat, j)
  in

    for i=1 to n-1 do
      let myq = (1.0, -2.0*.x.(i), sq x.(i)) in
      let (yopt, j) = pull_chain (i-1) 0.0 myq in
	y_opt.(i) <- yopt;
    done;

    let rec fill_in_y i = if i<0 then () else
      let (_, j) = pull_chain (i-1) 0.0 (1.0, -2.0*.x.(i), sq x.(i)) in
	for k=i-1 downto j+1 do
	  y_opt.(k) <- y_opt.(k+1) -. chain.(k);
	done;
	fill_in_y j
    in
      fill_in_y (n-1);

      let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in

	for i=0 to n-1 do
	  Printf.printf "%.8f " y_opt.(i);
	done;
	print_newline();
	Printf.printf "%.8f\n" total;

(* It's a DP algorithm.  Keep y_opt.(i) which is the natural place
   where the point y.(i) will land when considering only points 0, 1,
   2... i.

   To compute y_opt.(i) we assume we have already computed the
   previous ones.  What we do now is see if y.(i) acting alone would
   be within the window defined by y_opt.(i-1).  If it is, we're done
   with y_opt.(i).  Say y.(i) is too high to be compatible with
   y_opt.(i-1).  Then we glue these two points together by asserting
   y.(i)-y.(i-1)=b.  (Analogously, if y.(i) is too low compared to
   y_opt.(i-1) we assert y.(i)-y.(i-1)=a instead.)  This pair of
   points has a natural position uninfluenced by anything outside of
   them.  If this position is compatible with y_opt.(i-2) then we're
   done, otherwise we add y.(i-2) to the chain and continue.  So the
   elements are chained together by a sequence of as and bs,
   intermixed.

   We can prove by induction that the solution that this finds is
   optimal.  The base case is when y.(i) is within the window allowed
   by y_opt.(i-1).  Clearly this is the right answer.  Now suppose
   that we have established that in the optimal solution some chain of
   differences relating y.(k),...,y.(i-2), y.(i) must occur.  This
   means that when searching for the optimal solution we need only
   consider these values moving in lockstep as specified by the chain.
   Looking at point k-1 if the chain is too low, then the optimal
   solution must also have y.(k-1) in the chain being a below y.(k),
   and if point k-1 is too high then it must be in the chain b below
   y.(i).  (The intuition is that of a spring.  If you move your
   finger toward a spring and you touch the spring, pushing harder on
   the spring will keep your finger in contact with the spring.  The
   spring will not suddenly pull away from your finger as you push
   harder.  The (x-y)^2 cost function ensures that this is the correct
   model.)

   So the algorithm is O(n^2).  It might be possible to work out a
   version of this algorithm that is O(n log n) by keeping the chains
   in a search tree.  Then instead of starting from scratch each time
   when adding a new point, it would edit the current chain.  It is
   not clear that this can be made to work.

               Danny Sleator <sleator@cs.cmu.edu>
*)

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

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.0
let sq x = x *. x
let (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)

let quad_min (a,b,c) = -. (b /. (2.0 *. a))
  (* ax^2 + bx + c is our quadratic.  Return the value of x that minimizes it *)
  (* a cannot be zero *)

let () =
  let n = read_int 0 in
  let q0 = read_float 0 in
  let a0 = read_float 0 in
  let b0 = read_float 0 in

  let x = Array.init n read_float in
  let y_opt = Array.copy x in
  let chain = Array.make n 0.0 in

  let bound h v = max (1.0+.h) (min q0 v) in

  let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else
    (* Set the group of points j+1, j+2, ... i all to differ by cumulative h
       the quadratic represented by this group is q. *)
    let yi_nat = bound h (quad_min q) in
      if y_opt.(j) < yi_nat -. h -. b0 then
	let ny = x.(j) +. h +. b0 in
	  chain.(j) <- b0;
	  pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else if y_opt.(j) > yi_nat -. h -. a0 then
	let ny = x.(j) +. h +. a0 in
	  chain.(j) <- a0;
	  pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else
	(yi_nat, j)
  in

    for i=1 to n-1 do
      let myq = (1.0, -2.0*.x.(i), sq x.(i)) in
      let (yopt, j) = pull_chain (i-1) 0.0 myq in
	y_opt.(i) <- yopt;
    done;

    let rec fill_in_y i = if i<0 then () else
      let (_, j) = pull_chain (i-1) 0.0 (1.0, -2.0*.x.(i), sq x.(i)) in
	for k=i-1 downto j+1 do
	  y_opt.(k) <- y_opt.(k+1) -. chain.(k);
	done;
	fill_in_y j
    in
      fill_in_y (n-1);

      let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in

	for i=0 to n-1 do
	  Printf.printf "%.8f " y_opt.(i);
	done;
	Printf.printf "%.8f\n" total;

(* It's a DP algorithm.  Keep y_opt.(i) which is the natural place
   where the point y.(i) will land when considering only points 0, 1,
   2... i.

   To compute y_opt.(i) we assume we have already computed the
   previous ones.  What we do now is see if y.(i) acting alone would
   be within the window defined by y_opt.(i-1).  If it is, we're done
   with y_opt.(i).  Say y.(i) is too high to be compatible with
   y_opt.(i-1).  Then we glue fix y.(i-1)=y.(i)-b and compute the
   natural position for this pair of points using the sum of their
   potentials.  If this is compatible with y_opt.(i-2) then we're
   done, otherwise we add that to the group and continue.  The chain
   can consist of a sequence of as and bs, intermixed.

   So the algorithm is O(n^2).  It could be optimized as follows.
   Remember how far back the block went and continuing from where we
   left off computing y_opt.(i).  So if y.(i+1) also is pulling up we
   can continue from where we left off.  Can this be turned into an
   O(n) algorithm?
*)

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

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.0

let sq x = x *. x

let (++) (a,b,c) (d,e,f) = (a+.d, b+.e, c+.f)

let quad_min (a,b,c) =
  (* ax^2 + bx + c is our quadratic.  Return the value of x that minimizes it *)
  (* a cannot be zero *)
  -. (b /. (2.0 *. a))

let quad_eval (a,b,c) x = a *. (sq x) +. b *. x +. c

let () =
  let n = read_int 0 in
  let q0 = read_float 0 in
  let a0 = read_float 0 in
  let b0 = read_float 0 in

  let x = Array.init n read_float in
  let y_opt = Array.copy x in
  let chain = Array.make n 0.0 in
  let jarray = Array.make n (-1) in

  let bound h v = max (1.0+.h) (min q0 v) in

  let rec pull_chain j h q = if j<0 then (bound h (quad_min q), j) else
    (* set the group of points j+1, j+2, ... i all to differ by cumulative h
       the quadratic represented by this group is q. Find its natural position. *)
    let yi_nat = bound h (quad_min q) in
      if y_opt.(j) < yi_nat -. h -. b0 then
	let ny = x.(j) +. h +. b0 in
	  chain.(j) <- b0;
	  pull_chain (j-1) (h+.b0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else if y_opt.(j) > yi_nat -. h -. a0 then
	let ny = x.(j) +. h +. a0 in
	  chain.(j) <- a0;
	  pull_chain (j-1) (h+.a0) (q ++ (1.0, -2.0 *. ny, sq ny))
      else
	(yi_nat, j)
  in

    for i=1 to n-1 do
      let myq = (1.0, -2.0*.x.(i), sq x.(i)) in
      let (yopt, j) = pull_chain (i-1) 0.0 myq in
	y_opt.(i) <- yopt;
	jarray.(i) <- j;
    done;

    let rec fill_in_y i = if i<0 then () else
      let myq = (1.0, -2.0*.x.(i), sq x.(i)) in
      let (_, j) = pull_chain (i-1) 0.0 myq in
      let rec loop k = if k<=j then () else
	let delta = chain.(k) in
	  y_opt.(k) <- y_opt.(k+1) -. delta;
	  loop (k-1)
      in
	loop (i-1);
	fill_in_y j
    in

      fill_in_y (n-1);

      let total = sum 0 (n-1) (fun i-> sq (y_opt.(i) -. x.(i))) in

	for i=0 to n-1 do
	  Printf.printf "%.8f " y_opt.(i);
	done;
	print_newline();
	Printf.printf "%.8f\n" total;


let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [1] (a-1)
	  | x :: [] -> ah (x :: x :: []) a
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [1] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let n = read_int() in
  let a = read_int() in
  let b = read_int() in

  let m = 50000 in

(* i = seen already.  current = value of last one seen.  sum=sum of all previous*)
  let rec loop i sum current a b print =
    if print then Printf.printf "%d " current;
    if current > m then false
    else if i = n then a+b=0
    else (
      if b>0 then loop (i+1) (sum+(2*current)) (2*current) a (b-1) print
      else if a>0 then (
	if (current+1 > sum) then loop (i+1) (sum+current) current a b print else loop (i+1) (sum+current+1) (current+1) (a-1) b print
      ) else loop (i+1) (sum+current) current a b print
    )
  in
    if not (loop 1 1 1 a b false) then Printf.printf "-1"
    else ignore (loop 1 1 1 a b true);
    print_newline()

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [1] (a-1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [1] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [2] (a - 1)
	  | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*)
	if lst = [] then
	  ogo [1] b
	else
	  ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [2] (a - 1)
	  | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*)
	if lst = [] then
	  ogo [1] b
	else
	  ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [2] a
	  | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    match b with
	0 -> lst
      | _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [1] (a - 1)
	  | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [1] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

let rec print_list lst =
  match lst with
    | [] -> ()
    | h :: [] -> print_int h
    | h :: t -> Printf.printf "%s " (string_of_int h); print_list t
in
let make_ah_ogo a b =
  (* Sum of list *)
  let rec lsum lst acc =
    match lst with
	[] -> acc
      | h :: tail -> lsum tail (acc + h)
  in
  let rec ogo lst b =
    let cur_sum = lsum lst 0 in
    if lst = [] then
      ogo [1] b
    else
      match b with
	  0 -> lst
	| _ -> (*Printf.printf "Cur ogo sum:%d\n" cur_sum;*) ogo (cur_sum + 1 :: lst) (b - 1)
  in
  let rec ah lst a =
    match a with
	0 -> lst
      | _ -> match lst with
	  [] -> ah [2] (a - 1)
	  | 1 :: [] -> ah (1 :: 1 :: []) (a - 1)
	  | h :: t -> (*Printf.printf "Incr ah %d\n" h;*) ah (h + 1 :: h :: t) (a - 1)
  in
  let logo = ogo [] b in (* Ogo! list *)
  ah logo a (* Ogo! + Ah! list *)
in
let create inp =
  let parse_input x =
    let rx = Str.regexp "\\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)" in
    if Str.string_match rx x 0 then
      let i ii = int_of_string (Str.matched_group ii x) in
      Some (i 1, i 2, i 3)
    else
      None
  in
  let n, a, b = match parse_input inp with
      None -> raise Not_found
    | Some (x1, x2, x3) -> x1, x2, x3
  in
  (*Printf.printf "n=%d a=%d b=%d\n" n a b;*)
  let result = make_ah_ogo a b in
  let create_remain todo =
    let rec rem list todo =
      match todo with
	  x when x <= 0 -> list
	| _ -> rem (1 :: list) (todo - 1)
    in
    rem [] todo
  in
  let len_remain = n - (List.length result) in
  (*Printf.printf "Remain to %d length: %d; done %d\n" n len_remain (List.length result);*)
  let result = (List.rev result) @ (create_remain len_remain) in
  let len = List.length result in
  if len <= n then
    result
  else begin
    [-1]
  end
in
let init_data = read_line () in
let init_list = create init_data in
let result_list = init_list in
print_list result_list

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let n = read_int() in
  let a = read_int() in
  let b = read_int() in

  let m = 50000 in

(* i = seen already.  current = value of last one seen *)
  let rec loop i current a b print =
    if print then Printf.printf "%d " current;
    if current > m then false
    else if i = n then true
    else (
      if b>0 then loop (i+1) (2*current) a (b-1) print
      else if a>0 then loop (i+1) (current+1) (a-1) b print
      else loop (i+1) current a b print
    )
  in
    if loop 1 1 a b false
    then ignore (loop 1 1 a b true)
    else Printf.printf "-1";
    print_newline()

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let n = read_int() in
  let a = read_int() in
  let b = read_int() in

  let m = 50000 in

(* i = seen already.  current = value of last one seen *)
  let rec loop i current a b print =
    if print then Printf.printf "%d " current;
    if current > m then false
    else if i = n then true
    else (
      if b>0 then loop (i+1) (2*current) a (b-1) print
      else if a>0 then loop (i+1) (current+1) (a-1) b print
      else loop (i+1) current a b print
    )
  in
    if a=n-1 || (not (loop 1 1 a b false)) then Printf.printf "-1"
    else ignore (loop 1 1 a b true);
    print_newline()

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let n = read_int() in
  let a = read_int() in
  let b = read_int() in

  let m = 50000 in

(* i = seen already.  current = value of last one seen *)
  let rec loop i current a b print =
    if print then Printf.printf "%d " current;
    if current > m then false
    else if i = n then true
    else (
      if a>0 then loop (i+1) (2*current) (a-1) b print
      else if b>0 then loop (i+1) (current+1) a (b-1) print
      else loop (i+1) current a b print
    )
  in
    if loop 1 1 a b false
    then ignore (loop 1 1 a b true)
    else Printf.printf "-1";
    print_newline()

(* codeforces 105.  Danny Sleator *)
let read_int () = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_string () = Scanf.bscanf Scanf.Scanning.stdib " %s " (fun x -> x)

let () =
  let n = read_int() in
  let a = read_int() in
  let b = read_int() in

  let m = 50000 in

(* i = seen already.  current = value of last one seen *)
  let rec loop i current a b print =
    if print then Printf.printf "%d " current;
    if current > m then false
    else if i = n then true
    else (
      if b>0 then loop (i+1) (2*current) a (b-1) print
      else if a>0 then loop (i+1) (current+1) (a-1) b print
      else loop (i+1) current a b print
    )
  in
    if (a=n-1 && n>1) || (not (loop 1 1 a b false)) then Printf.printf "-1"
    else ignore (loop 1 1 a b true);
    print_newline()


Scanf.(Array.(scanf " %d" @@ fun q ->
  init q (fun _ -> scanf " %d %s" @@ fun _ s ->
    Printf.(
      if String.length s = 2 && s.[0] >= s.[1] then printf "NO\n"
      else printf "YES\n2\n%c %s\n" s.[0] @@ String.sub s 1 (String.length s - 1)))))

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_lim,min_i64_lim = Int64.(max_int,min_int)
  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L
  (* 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 Int64_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
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  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 slen s = String.length s
  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

let () =
  let q = gi 0 in
  rep 1L q (fun _ ->
    let n = gi 0 in
    let s = scanf " %s" @@ id in
    if String.length s = 2 && s.[0] >= s.[1] then (
      printf "NO\n"
    ) else (
      printf "YES\n2\n%c %s\n" s.[0] @@ String.sub s 1 (String.length s-$1)
    )
  )

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_lim,min_i64_lim = Int64.(max_int,min_int)
  let max_i64,min_i64 = 2000000000000000000L,-2000000000000000000L
  (* 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 Int64_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
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v)) let iia = input_i64_array
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v) let gi = get_i64
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v) let g2 = get_2_i64
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w) let g3 = get_3_i64
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x) let g4 = get_4_i64
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y) let g5 = get_5_i64
  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 slen s = String.length s
  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

let () =
  let q = gi 0 in
  rep 1L q (fun _ ->
    let n = gi 0 in
    let s = scanf " %s" @@ id in
    let f = ref true in
    String.iter (fun c -> if c <> s.[0] then f := false) s;
    if !f && String.length s = 2 then (
      printf "NO\n"
    ) else (
      printf "YES\n2\n%c %s\n" s.[0] @@ String.sub s 1 (String.length s-$1)
    )
    (* let prev = ref 0L in
    let a = ref 0L in
    let ex = make 10 false in
    String.iter (fun c ->
      let p = !a * 10L + i64 (int_of_char c -$ int_of_char '0') in
      if ex.(int_of_char c) then (
        if !prev > p then (

        )
      ) else
      if !prev > p then (

      )
    ) *)
  )


let n = read_int ()

let rec find a b i m = if i>m-2 then -1 else if String.sub a i 2 = b then i else find a b (i+1) m ;;

for i=1 to n do
    let s = read_line () in
    let z = String.length s in
    let t = find s "11" 0 z in
    if t = -1 then print_string "YES\n" else
    if find (String.sub s t (z-t)) "00" 0 (z-t) = -1 then print_string "YES\n" else print_string "NO\n"
done

let n = read_int () ;;

let translate_to str=
let len = String.length(str)  in
let rec sup_fun i l=
if i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in
sup_fun (len-1) [];;

let rec read_fucking_sheet n =
if n = 0 then []
else (translate_to (read_line ()) :: read_fucking_sheet (n-1))
;;

let rec print_yes t =
if t = true then print_string "YES"
else print_string "NO"
;;

let rec solve l flag =
match l with
hd :: hd1 :: tl ->
	if flag = 1 && hd = 1
		then (solve (hd1 :: tl) 1)
	else if flag = 1 && hd = 0 && hd1 = 0
		then false
	else if flag = 1 && hd = 0 && hd1 = 1
		then (solve tl 1)
	else if flag = 0 && hd = 0
		then (solve (hd1 :: tl) 0)
	else if flag = 0 && hd = 1 && hd1 = 0
		then (solve tl 1) || (solve tl 0 )
	else if flag = 0 && hd = 1 && hd1 = 1
		then (solve tl 1)
        else false
|_-> true
;;

let rec print_list l =
match l with
hd:: tl -> print_int hd ; print_list tl
|_-> print_string "  " ;;

let rec flum l =
match l with
hd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string "\n" ; flum tl
|_-> () ;;

(*print_list (translate_to "111000") ;;*)

flum (List.rev(read_fucking_sheet n))

(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)

(*let spisok = [1;1;0;0] ;;

print_yes (solve spisok 0) ;;*)

let n = read_int () ;;

let translate_to str=
let len = String.length(str)  in
let rec sup_fun i l=
if i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in
sup_fun (len-1) [];;

let rec read_fucking_sheet n =
if n = 0 then []
else (translate_to (read_line ()) :: read_fucking_sheet (n-1))
;;

let rec print_yes t =
if t = true then print_string "YES"
else print_string "NO"
;;

let rec solve l flag =
match l with
hd :: hd1 :: tl ->
	if flag = 1 && hd = 1
		then (solve (hd1 :: tl) 1)
	else if flag = 1 && hd = 0 && hd1 = 0
		then false
	else if flag = 1 && hd = 0 && hd1 = 1
		then (solve tl 1)
	else if flag = 0 && hd = 0
		then (solve (hd1 :: tl) 0)
	else if flag = 0 && hd = 1 && hd1 = 0
		then (solve tl 1) || (solve tl 0 )
	else if flag = 0 && hd = 1 && hd1 = 1
		then (solve tl 1)
        else false
|_-> true
;;

let rec print_list l =
match l with
hd:: tl -> print_int hd ; print_list tl
|_-> print_string "  " ;;

let rec flum l =
match l with
hd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string "\n" ; flum tl
|_-> () ;;

(*print_list (translate_to "111000") ;;*)

let rec revers l =
match l with
hd::tl -> hd :: (revers tl)
|_-> []
;;

flum (revers(read_fucking_sheet n))

(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)

(*let spisok = [1;1;0;0] ;;

print_yes (solve spisok 0) ;;*)

let n = read_int () ;;

let translate_to str=
let len = String.length(str)  in
let rec sup_fun i l=
if i = -1 then l else (sup_fun (i-1) ((int_of_char(str.[i])-int_of_char('0')) :: l)) in
sup_fun (len-1) [];;

let rec read_fucking_sheet n =
if n = 0 then []
else (translate_to (read_line ()) :: read_fucking_sheet (n-1))
;;

let rec print_yes t =
if t = true then print_string "YES"
else print_string "NO"
;;

let rec solve l flag =
match l with
hd :: hd1 :: tl ->
	if flag = 1 && hd = 1
		then (solve (hd1 :: tl) 1)
	else if flag = 1 && hd = 0 && hd1 = 0
		then false
	else if flag = 1 && hd = 0 && hd1 = 1
		then (solve tl 1)
	else if flag = 0 && hd = 0
		then (solve (hd1 :: tl) 0)
	else if flag = 0 && hd = 1 && hd1 = 0
		then (solve tl 1) || (solve tl 0 )
	else if flag = 0 && hd = 1 && hd1 = 1
		then (solve tl 1)
        else false
|_-> true
;;

let rec print_list l =
match l with
hd:: tl -> print_int hd ; print_list tl
|_-> print_string "  " ;;

let rec flum l =
match l with
hd :: tl -> (*print_list hd ;*) print_yes (solve hd 0) ; print_string "\n" ; flum tl
|_-> () ;;

(*print_list (translate_to "111000") ;;*)

flum (read_fucking_sheet n)

(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)

(*let spisok = [1;1;0;0] ;;

print_yes (solve spisok 0) ;;*)

let n = read_int () ;;

let translate_to str=
let len = String.length(str)  in
let rec sup_fun i l=
if i = len then [] else (sup_fun (i+1) (int_of_char(str.[i]) :: l)) in
sup_fun 0 [];;

let rec read_fucking_sheet n =
if n = 0 then []
else (translate_to (read_line ()))

let rec print_yes t =
if t = true then print_string "YES"
else print_string "NO"
;;

let rec solve l flag =
match l with
hd :: hd1 :: tl ->
	if flag = 1 && hd = 1
		then (solve (hd1 :: tl) flag)
	else if flag = 1 && hd = 0 && hd1 = 0
		then false
	else if flag = 1 && hd = 0 && hd1 = 1
		then (solve tl flag)
	else if flag = 0 && hd = 0
		then (solve (hd1 :: tl) flag)
	else if flag = 0 && hd = 1 && hd1 = 0
		then (solve tl 1) || (solve tl flag )
	else if flag = 0 && hd = 1 && hd1 = 1
		then (solve tl 1)
        else false
|_-> true
;;

let rec flum l =
match l with
hd :: tl -> print_yes (solve hd 0) ; flum tl
|_-> () ;;

flum (read_fucking_sheet n)

(*print_yes (solve (translate_to l ((string.length (l)) -1) ) 0) ;;*)

(*let spisok = [1;0;0;1;1;1;0;0;1] ;;

print_yes (solve spisok 0) ;;*)


let read_int _ = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_pair _ = let u = read_int 0 in (u,read_int 0)

let ( ++ ) a b = Int64.add a b

let () =
  let n = read_int 0 in
  let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in
  let outcome = Array.make_matrix (n+1) 2 0 in

  let next_state (x,s) = (* s=0 means the initial state of the process, before "step 2" *)
    if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))
  in

  let rec fill_table (x,s) =
    if x<1 || x>n then 4
    else if x = 1 then 2+s (* 2 or 3 *)
    else if outcome.(x).(s) = 0 then (
      outcome.(x).(s) <- 5;
      outcome.(x).(s) <- fill_table (next_state (x,s));
      outcome.(x).(s)
    )
    else if outcome.(x).(s) = 5 then (
      outcome.(x).(s) <- 1;
      1
    )
    else outcome.(x).(s)
  in

  let () = for i=2 to n do
    ignore (fill_table (i,0));
    ignore (fill_table (i,1))
  done in

  let cycles i =
    let a = outcome.(i+1).(1) in
    let b = outcome.(i+1).(0) in
      a = 1 || a = 2 || (a = 3 && (b = 1 || b = 2 || b = 3))
  in

  let yval = Array.make_matrix (n+1) 2 (-1L) in

  let rec fill_in_y i (x,s) =
    if x<1 || x>n then 0L
    else if (x,s) = (1,1) then Int64.of_int i
    else if yval.(x).(s) >= 0L then yval.(x).(s)
    else (
      yval.(x).(s) <- (Int64.of_int a.(x)) ++ (fill_in_y i (next_state (x,s)));
      yval.(x).(s)
    )
  in

    for i=1 to n-1 do
      if cycles i then print_string ("-1\n")
      else Printf.printf "%Ld\n" ((Int64.of_int i)++(fill_in_y i (i+1,1)))
    done

let read_int _ = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_pair _ = let u = read_int 0 in (u,read_int 0)

let ( ++ ) a b = Int64.add a b

let () =
  let n = read_int 0 in
  let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in
  let outcome = Array.make_matrix (n+1) 2 0 in
    (* this table has the following meaning:
       0 unknown
       1 cyclic
       2 reaches (1,0)
       3 reaches (1,1)
       4 termates
       5 current search *)

  let next_state (x,s) = (* s=0 means the initial state of the process, before "step 2" *)
    if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))
  in

  let rec fill_table (x,s) =
    if x<1 || x>n then 4
    else if x = 1 then 2+s (* 2 or 3 *)
    else if outcome.(x).(s) = 0 then (
      outcome.(x).(s) <- 5;
      outcome.(x).(s) <- fill_table (next_state (x,s));
      outcome.(x).(s)
    )
    else if outcome.(x).(s) = 5 then (
      outcome.(x).(s) <- 1;
      1
    )
    else outcome.(x).(s)
  in

  let () = for i=2 to n do
    ignore (fill_table (i,0));
    ignore (fill_table (i,1))
  done in

  let cycles i =
    let a = outcome.(i+1).(1) in
    let b = outcome.(i+1).(0) in
      a = 1 || a = 2 || (a = 3 && (b = 1 || b = 2 || b = 3))
  in

  let yval = Array.make_matrix (n+1) 2 (-1L) in

  let rec fill_in_y i (x,s) =
    if x<1 || x>n then 0L
    else if (x,s) = (1,1) then Int64.of_int i
    else if yval.(x).(s) >= 0L then yval.(x).(s)
    else (
      yval.(x).(s) <- (Int64.of_int a.(x)) ++ (fill_in_y i (next_state (x,s)));
      yval.(x).(s)
    )
  in

    for i=1 to n-1 do
      if cycles i then print_string ("-1\n")
      else Printf.printf "%Ld\n" ((Int64.of_int i)++(fill_in_y i (i+1,1)))
    done

let read_int _ = Scanf.bscanf Scanf.Scanning.stdib " %d " (fun x -> x)
let read_pair _ = let u = read_int 0 in (u,read_int 0)

let () =
  let n = read_int 0 in
  let a = Array.init (n+1) (fun i -> if i<=1 then 0 else read_int 0) in
  let outcome = Array.make_matrix (n+1) 2 0 in
(* this table has the following meaning:
   0 unknown
   1 cyclic
   2 reaches (1,0)
   3 reaches (1,1)
   4 termates
   5 current search *)

  let next_state (x,s) = (* s=0 means the initial state of the process, before "step 2" *)
    if s=0 then (x+a.(x), (1-s)) else (x-a.(x), (1-s))
  in

  let rec find_path (x,s) =
    if x<1 || x>n then 4
    else if x = 1 then 2+s (* 2 or 3 *)
    else if outcome.(x).(s) <> 0 then outcome.(x).(s)
    else (
      outcome.(x).(s) <- 5;
      find_path (next_state(x,s))
    )
  in

  let rec label_path (x,s) l =
    if x<1 || x>n then ()
    else if outcome.(x).(s) = 5 then (
      outcome.(x).(s) <- l;
      label_path (next_state(x,s)) l
    )
  in

  let fill_table (x,s) =
    let l = find_path(x,s) in
      label_path (x,s) (if l=5 then 1 else l)
  in

  let () = for i=1 to n-1 do
    fill_table (i+1,1)
  done in

  let cycles i =
    outcome.(i+1).(1) = 1 || outcome.(i+1).(1) = 2
  in

  let yval = Array.make_matrix (n+1) 2 (-1) in

  let rec testoverflow i = if i=0 then 0 else i+(testoverflow (i-1)) in

    Printf.printf "testoverflow 10 = %d\n" (testoverflow 1000000);

  let rec fill_in_y i (x,s) =
    if x<1 || x>n then 0
    else if (x,s) = (1,1) then i
    else if yval.(x).(s) >= 0 then yval.(x).(s)
    else (
      yval.(x).(s) <- a.(x) + fill_in_y i (next_state (x,s));
      yval.(x).(s)
    )
  in

    for i=1 to n-1 do
      if cycles i then print_string ("-1\n")
      else Printf.printf "%d\n" (i+(fill_in_y i (i+1,1)))
    done;

    Printf.printf "testoverflow 10 = %d\n" (testoverflow 1000000)


(* row : [(row_number,(min_column,max_column));...]
 * col : [(col_number,(min_row,max_row));...]
 * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))]
 * where d = Row-Col || d = Row + Col
 *)

let solve =
  let n,m = Scanf.scanf "%d %d\n" (fun n m -> (n,m)) in
  let readPos() = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
  let rowsHash = Hashtbl.create n in
  let colsHash = Hashtbl.create n in
  let diagsHash = Hashtbl.create n in
  let diagsInvHash = Hashtbl.create n in
  let rec readBoard i acc =
    match i with
      | 0 -> acc
      | i -> let (row,col) = readPos() in
          readBoard (i-1) ((row,col)::acc)
  in
  let rec createRow queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
                              | None -> Hashtbl.add rowsHash row (col,col); createRow xs;
                              | Some (minCol,maxCol) ->
                                  if (col < minCol)
                                  then
                                    (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)
                                  else if (col > maxCol) then
                                    (Hashtbl.replace rowsHash row (minCol,col); createRow xs)
                                  else
                                    createRow xs
        )
  in
  let rec createCol queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
                              | None -> Hashtbl.add colsHash col (row,row); createCol xs;
                              | Some (minRow,maxRow) ->
                                  if (row < minRow)
                                  then
                                    (Hashtbl.replace colsHash col (row,maxRow); createCol xs)
                                  else if (row > maxRow) then
                                    (Hashtbl.replace colsHash col (minRow,row); createCol xs)
                                  else
                                    createCol xs
        )
  in
  let createDiag queens f dHash =
    let rec aux queens =
      match queens with
        | []    -> ()
        | (row,col) :: xs -> let d = f row col in
            (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with
               | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;
               | Some ((minRow,minCol),(maxRow,maxCol)) ->
                   if (row < minRow)
                   then
                     (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)
                   else if (row > maxRow) then
                     (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)
                   else
                     aux xs
            )
    in
      aux queens
  in
  let rec check queens rows cols diag1 diag2 t =
    let checkRow (row,col) =
      match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minCol,maxCol) ->
            if (col > minCol) then
              begin
                if (col < maxCol) then 2 else 1
              end
            else
              if (col < maxCol) then 1 else 0
    in
    let checkCol (row,col) =
      match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minRow,maxRow) ->
            if (row > minRow) then
              begin
                if (row < maxRow) then 2 else 1
              end
            else
              if (row < maxRow) then 1 else 0
    in
    let checkDiag (row,col) dHash f =
      let d = f row col in
        match (try Some (Hashtbl.find dHash d) with Not_found -> None) with
          | None -> failwith "if nasa launched sattelites with bugs then
              I am allowed to fuck this up no strings attached!"
          | Some ((minRow,minCol),(maxRow,maxCol)) ->
              if (row > minRow) then
                begin
                  if (row < maxRow) then 2 else 1
                end
              else
                if (row < maxRow) then 1 else 0
    in
      match queens with
        | [] -> t
        | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) +
                                           (checkDiag (row,col) diagsHash ( - )) +
                                           (checkDiag (row,col) diagsInvHash ( + ))
          in
            (match (try Some (List.assoc threats t) with Not_found -> None) with
               | None -> check xs rows cols diag1 diag2 ((threats,1)::t)
               | Some prevThreats -> check xs rows cols diag1 diag2 ((threats,prevThreats + 1)::(List.remove_assoc threats t)))
  in
  let board = readBoard m [] in
  let rows  = createRow  board in
  let cols  = createCol  board in
  let diag1 = createDiag board ( - ) diagsHash in
  let diag2 = createDiag board ( + ) diagsInvHash in
  let tSeq = check board rows cols diag1 diag2 [] in
  let print lst =
    let rec aux i =
      match i with
        | 9 -> Printf.printf "\n"
        | i ->
            (match (try Some (List.assoc i lst) with Not_found -> None) with
               | None -> Printf.printf "0 "; aux (i+1)
               | Some v -> Printf.printf "%d " v; aux (i+1))
    in
      aux 0
  in
    print tSeq
;;

(* row : [(row_number,(min_column,max_column));...]
 * col : [(col_number,(min_row,max_row));...]
 * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))]
 * where d = Row-Col || d = Row + Col
 * Implemented with hash tables
 *)

let solve =
  let n,m = Scanf.scanf "%d %d\n" (fun n m -> (n,m)) in
  let readPos() = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
  let rowsHash = Hashtbl.create n in
  let colsHash = Hashtbl.create n in
  let diagsHash = Hashtbl.create n in
  let diagsInvHash = Hashtbl.create n in
  let rec readBoard i acc =
    match i with
      | 0 -> acc
      | i -> let (row,col) = readPos() in
          readBoard (i-1) ((row,col)::acc)
  in
  let rec createRow queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
                              | None -> Hashtbl.add rowsHash row (col,col); createRow xs;
                              | Some (minCol,maxCol) ->
                                  if (col < minCol)
                                  then
                                    (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)
                                  else if (col > maxCol) then
                                    (Hashtbl.replace rowsHash row (minCol,col); createRow xs)
                                  else
                                    createRow xs
        )
  in
  let rec createCol queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
                              | None -> Hashtbl.add colsHash col (row,row); createCol xs;
                              | Some (minRow,maxRow) ->
                                  if (row < minRow)
                                  then
                                    (Hashtbl.replace colsHash col (row,maxRow); createCol xs)
                                  else if (row > maxRow) then
                                    (Hashtbl.replace colsHash col (minRow,row); createCol xs)
                                  else
                                    createCol xs
        )
  in
  let createDiag queens f dHash =
    let rec aux queens =
      match queens with
        | []    -> ()
        | (row,col) :: xs -> let d = f row col in
            (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with
               | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;
               | Some ((minRow,minCol),(maxRow,maxCol)) ->
                   if (row < minRow)
                   then
                     (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)
                   else if (row > maxRow) then
                     (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)
                   else
                     aux xs
            )
    in
      aux queens
  in
  let check queens =
    let rec checkAux queens t =
    let checkRow (row,col) =
      match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minCol,maxCol) ->
            if (col > minCol) then
              begin
                if (col < maxCol) then 2 else 1
              end
            else
              if (col < maxCol) then 1 else 0
    in
    let checkCol (row,col) =
      match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minRow,maxRow) ->
            if (row > minRow) then
              begin
                if (row < maxRow) then 2 else 1
              end
            else
              if (row < maxRow) then 1 else 0
    in
    let checkDiag (row,col) dHash f =
      let d = f row col in
        match (try Some (Hashtbl.find dHash d) with Not_found -> None) with
          | None -> failwith "if nasa launched sattelites with bugs then
              I am allowed to fuck this up no strings attached!"
          | Some ((minRow,minCol),(maxRow,maxCol)) ->
              if (row > minRow) then
                begin
                  if (row < maxRow) then 2 else 1
                end
              else
                if (row < maxRow) then 1 else 0
    in
      match queens with
        | [] -> t
        | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) +
                                           (checkDiag (row,col) diagsHash ( - )) +
                                           (checkDiag (row,col) diagsInvHash ( + ))
          in
            (match (try Some (List.assoc threats t) with Not_found -> None) with
               | None -> checkAux xs ((threats,1)::t)
               | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))
    in
      checkAux queens []
  in
  let board = readBoard m [] in
  let _  = createRow  board in
  let _  = createCol  board in
  let _ = createDiag board ( - ) diagsHash in
  let _ = createDiag board ( + ) diagsInvHash in
  let tSeq = check board in
  let print lst =
    let rec printAux i =
      match i with
        | 9 -> Printf.printf "\n"
        | i ->
            (match (try Some (List.assoc i lst) with Not_found -> None) with
               | None -> Printf.printf "0 "; printAux (i+1)
               | Some v -> Printf.printf "%d " v; printAux (i+1))
    in
      printAux 0
  in
    print tSeq
;;

(* row : [(row_number,(min_column,max_column));...]
 * col : [(col_number,(min_row,max_row));...]
 * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))]
 * where d = Row-Col || d = Row + Col
 *)

let solve =
  let n,m = Scanf.scanf "%d %d\n" (fun n m -> (n,m)) in
  let readPos() = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
  let rowsHash = Hashtbl.create n in
  let colsHash = Hashtbl.create n in
  let diagsHash = Hashtbl.create n in
  let diagsInvHash = Hashtbl.create n in
  let rec readBoard i acc =
    match i with
      | 0 -> acc
      | i -> let (row,col) = readPos() in
          readBoard (i-1) ((row,col)::acc)
  in
  let rec createRow queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
                              | None -> Hashtbl.add rowsHash row (col,col); createRow xs;
                              | Some (minCol,maxCol) ->
                                  if (col < minCol)
                                  then
                                    (Hashtbl.replace rowsHash row (col,maxCol); createRow xs)
                                  else if (col > maxCol) then
                                    (Hashtbl.replace rowsHash row (minCol,col); createRow xs)
                                  else
                                    createRow xs
        )
  in
  let rec createCol queens =
    match queens with
      | []      -> ()
      | (row,col) :: xs -> (match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
                              | None -> Hashtbl.add colsHash col (row,row); createCol xs;
                              | Some (minRow,maxRow) ->
                                  if (row < minRow)
                                  then
                                    (Hashtbl.replace colsHash col (row,maxRow); createCol xs)
                                  else if (row > maxRow) then
                                    (Hashtbl.replace colsHash col (minRow,row); createCol xs)
                                  else
                                    createCol xs
        )
  in
  let createDiag queens f dHash =
    let rec aux queens =
      match queens with
        | []    -> ()
        | (row,col) :: xs -> let d = f row col in
            (match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with
               | None -> Hashtbl.add dHash d ((row,col),(row,col)); aux xs;
               | Some ((minRow,minCol),(maxRow,maxCol)) ->
                   if (row < minRow)
                   then
                     (Hashtbl.replace dHash d ((row,col),(maxRow,maxCol)); aux xs)
                   else if (row > maxRow) then
                     (Hashtbl.replace dHash d ((minRow,minCol),(row,col)); aux xs)
                   else
                     aux xs
            )
    in
      aux queens
  in
  let check queens rows cols diag1 diag2 =
    let rec checkAux queens t =
    let checkRow (row,col) =
      match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minCol,maxCol) ->
            if (col > minCol) then
              begin
                if (col < maxCol) then 2 else 1
              end
            else
              if (col < maxCol) then 1 else 0
    in
    let checkCol (row,col) =
      match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minRow,maxRow) ->
            if (row > minRow) then
              begin
                if (row < maxRow) then 2 else 1
              end
            else
              if (row < maxRow) then 1 else 0
    in
    let checkDiag (row,col) dHash f =
      let d = f row col in
        match (try Some (Hashtbl.find dHash d) with Not_found -> None) with
          | None -> failwith "if nasa launched sattelites with bugs then
              I am allowed to fuck this up no strings attached!"
          | Some ((minRow,minCol),(maxRow,maxCol)) ->
              if (row > minRow) then
                begin
                  if (row < maxRow) then 2 else 1
                end
              else
                if (row < maxRow) then 1 else 0
    in
      match queens with
        | [] -> t
        | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) +
                                           (checkDiag (row,col) diagsHash ( - )) +
                                           (checkDiag (row,col) diagsInvHash ( + ))
          in
            (match (try Some (List.assoc threats t) with Not_found -> None) with
               | None -> checkAux xs ((threats,1)::t)
               | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))
    in
      checkAux queens []
  in
  let board = readBoard m [] in
  let rows  = createRow  board in
  let cols  = createCol  board in
  let diag1 = createDiag board ( - ) diagsHash in
  let diag2 = createDiag board ( + ) diagsInvHash in
  let tSeq = check board rows cols diag1 diag2 in
  let print lst =
    let rec printAux i =
      match i with
        | 9 -> Printf.printf "\n"
        | i ->
            (match (try Some (List.assoc i lst) with Not_found -> None) with
               | None -> Printf.printf "0 "; printAux (i+1)
               | Some v -> Printf.printf "%d " v; printAux (i+1))
    in
      printAux 0
  in
    print tSeq
;;

(* row : [(row_number,(min_column,max_column));...]
 * col : [(col_number,(min_row,max_row));...]
 * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))]
 * where d = Row-Col || d = Row + Col
 *)

let solve =
  let n,m = Scanf.scanf "%d %d\n" (fun n m -> (n,m)) in
  let readPos() = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
  let rowsHash = Hashtbl.create n in
  let colsHash = Hashtbl.create n in
  let diagsHash = Hashtbl.create n in
  let diagsInvHash = Hashtbl.create n in
  let rec readBoard i acc =
    match i with
      | 0 -> acc
      | i -> let (row,col) = readPos() in
          readBoard (i-1) ((row,col)::acc)
  in
  let rec createLists queens  =
    match queens with
      | [] -> ()
      | (row,col) :: xs ->   let createRow () =
                                match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
                                   | None -> Hashtbl.add rowsHash row (col,col);
                                   | Some (minCol,maxCol) ->
                                       if (col < minCol)
                                       then
                                         Hashtbl.replace rowsHash row (col,maxCol)
                                       else if (col > maxCol) then
                                         Hashtbl.replace rowsHash row (minCol,col)
                                       else
                                         ()
                              in
                              let createCol () =
                                match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
                                   | None -> Hashtbl.add colsHash col (row,row);
                                   | Some (minRow,maxRow) ->
                                       if (row < minRow)
                                       then
                                         Hashtbl.replace colsHash col (row,maxRow)
                                       else if (row > maxRow) then
                                         Hashtbl.replace colsHash col (minRow,row)
                                       else
                                         ()
                              in
                              let createDiag  dHash f =
                                let d = f row col in
                                  match (try Some (Hashtbl.find dHash d ) with Not_found -> None) with
                                     | None -> Hashtbl.add dHash d ((row,col),(row,col));
                                     | Some ((minRow,minCol),(maxRow,maxCol)) ->
                                         if (row < minRow)
                                         then
                                           Hashtbl.replace dHash d ((row,col),(maxRow,maxCol))
                                         else if (row > maxRow) then
                                           Hashtbl.replace dHash d ((minRow,minCol),(row,col))
                                         else
                                           ()
                              in
                                createRow ();
                                createCol ();
                                createDiag diagsHash ( - );
                                createDiag diagsInvHash ( + );
                                createLists xs
  in
  let check queens =
    let rec checkAux queens t =
    let checkRow (row,col) =
      match (try Some (Hashtbl.find rowsHash row) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minCol,maxCol) ->
            if (col > minCol) then
              begin
                if (col < maxCol) then 2 else 1
              end
            else
              if (col < maxCol) then 1 else 0
    in
    let checkCol (row,col) =
      match (try Some (Hashtbl.find colsHash col) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minRow,maxRow) ->
            if (row > minRow) then
              begin
                if (row < maxRow) then 2 else 1
              end
            else
              if (row < maxRow) then 1 else 0
    in
    let checkDiag (row,col) dHash f =
      let d = f row col in
        match (try Some (Hashtbl.find dHash d) with Not_found -> None) with
          | None -> failwith "if nasa launched sattelites with bugs then
              I am allowed to fuck this up no strings attached!"
          | Some ((minRow,minCol),(maxRow,maxCol)) ->
              if (row > minRow) then
                begin
                  if (row < maxRow) then 2 else 1
                end
              else
                if (row < maxRow) then 1 else 0
    in
      match queens with
        | [] -> t
        | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) +
                                           (checkDiag (row,col) diagsHash ( - )) +
                                           (checkDiag (row,col) diagsInvHash ( + ))
          in
            (match (try Some (List.assoc threats t) with Not_found -> None) with
               | None -> checkAux xs ((threats,1)::t)
               | Some prevThreats -> checkAux xs ((threats,prevThreats + 1)::(List.remove_assoc threats t)))
    in
      checkAux queens []
  in
  let board = readBoard m [] in
  let _ = createLists board in
  let tSeq = check board in
  let print lst =
    let rec aux i =
      match i with
        | 9 -> Printf.printf "\n"
        | i ->
            (match (try Some (List.assoc i lst) with Not_found -> None) with
               | None -> Printf.printf "0 "; aux (i+1)
               | Some v -> Printf.printf "%d " v; aux (i+1))
    in
      aux 0
  in
    print tSeq
;;

let read_stuff () =
  let m = Scanf.scanf " %d %d" (fun _ a -> a)
  and l = ref [] in
    for i = 1 to m do
      let pair = Scanf.scanf " %d %d" (fun a b -> (a, b, 0)) in
      l := pair :: !l;
    done;
    !l

let postprocess queens =
  let res = Array.create 9 0
  in List.iter (fun (_, _, sz) -> (res.(sz) <- (res.(sz) + 1))) queens; res

let print_res res =
  Array.iter (fun el -> Printf.printf "%d " el) res;
  print_endline ""

let cmp a b =
  if a == b
  then 0
  else if a > b
  then 1
  else -1

let solve_one queens pred =
  let proc2 q r =
    let (x, y, v) = q in
      if abs(pred q r) == 2
      then (x, y, v + 1)
      else q
  in let proc = function
    | h :: t ->
        snd (List.fold_left
          (* Sprawdz wszystko oprocz glowy *)
          (fun (last, acc) h ->
             (h, (proc2 h last)::acc))
          (h, [h])
          t)
    | foo -> foo
  and sorted = List.sort pred queens
  in proc (proc (sorted))

let rec solve queens preds =
  match preds with
    | [] -> queens
    | p0 :: ps -> solve (solve_one queens p0) ps

let oq a b =
  if a == 0 then 2 * b else a
;;

let predicates =
  [
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp x1 x2) (cmp y1 y2));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp y1 y2) (cmp x1 x2));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 - y1) (x2 - y2)) (cmp (x1 + y1) (x2 + y2)));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 + y1) (x2 + y2)) (cmp (x1 - y1) (x2 - y2)))
  ]
in
  print_res (postprocess (solve (read_stuff()) predicates))

(* row : [(row_number,(min_column,max_column));...]
 * col : [(col_number,(min_row,max_row));...]
 * diags : [(d, ((minRow,minCol),(maxRow,maxCol)))]
 * where d = Row-Col || d = Row + Col
 *)

let solve =
  let n,m = Scanf.scanf "%d %d\n" (fun n m -> (n,m)) in
  let readPos() = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
  let rec readBoard i acc =
    match i with
      | 0 -> List.rev acc
      | i -> let (row,col) = readPos() in
          readBoard (i-1) ((row,col)::acc)
  in
  let rec createRow queens acc =
    match queens with
      | []      -> List.rev acc
      | (row,col) :: xs -> (match (try Some (List.assoc row acc) with Not_found -> None) with
                              | None -> createRow xs ((row,(col,col)) :: acc)
                              | Some (minCol,maxCol) ->
                                  if (col < minCol)
                                  then
                                    createRow xs ((row,(col,maxCol))::(List.remove_assoc row acc))
                                  else if (col > maxCol) then
                                    createRow xs ((row,(minCol,col))::(List.remove_assoc row acc))
                                  else
                                    createRow xs acc
        )
  in
  let rec createCol queens acc =
    match queens with
      | []      -> List.rev acc
      | (row,col) :: xs -> (match (try Some (List.assoc col acc) with Not_found -> None) with
                              | None -> createCol xs ((col,(row,row)) :: acc)
                              | Some (minRow,maxRow) ->
                                  if (row < minRow)
                                  then
                                    createCol xs ((col,(row,maxRow))::(List.remove_assoc col acc))
                                  else if (row > maxRow) then
                                    createCol xs ((col,(minRow,row))::(List.remove_assoc col acc))
                                  else
                                    createCol xs acc
        )
  in
  let rec createDiag queens acc f =
    match queens with
      | []    -> List.rev acc
      | (row,col) :: xs -> let d = f row col in
          (match (try Some (List.assoc d acc) with Not_found -> None) with
             | None -> createDiag xs ((d,( (row,col), (row,col) )) :: acc) f
             | Some ((minRow,minCol),(maxRow,maxCol)) ->
                 if (row < minRow)
                 then
                   createDiag xs ((d, ((row,col),(maxRow,maxCol))) :: (List.remove_assoc d acc)) f
                 else if (row > maxRow) then
                   createDiag xs ((d, ((minRow,minCol),(row,col))) :: (List.remove_assoc d acc)) f
                 else
                   createDiag xs acc f
          )
  in
  let rec check queens rows cols diag1 diag2 t =
    let checkRow (row,col) =
      match (try Some (List.assoc row rows) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minCol,maxCol) ->
            if (col > minCol) then
              begin
                if (col < maxCol) then 2 else 1
              end
            else
              if (col < maxCol) then 1 else 0
    in
    let checkCol (row,col) =
      match (try Some (List.assoc col cols) with Not_found -> None) with
        | None -> failwith "nothing to see here, move on"
        | Some (minRow,maxRow) ->
            if (row > minRow) then
              begin
                if (row < maxRow) then 2 else 1
              end
            else
              if (row < maxRow) then 1 else 0
    in
    let checkDiag (row,col) diag f =
      let d = f row col in
        match (try Some (List.assoc d diag) with Not_found -> None) with
          | None -> failwith "if nasa launched sattelites with bugs then
              I am allowed to fuck this up no strings attached!"
          | Some ((minRow,minCol),(maxRow,maxCol)) ->
              if (row > minRow) then
                begin
                  if (row < maxRow) then 2 else 1
                end
              else
                if (row < maxRow) then 1 else 0
    in
      match queens with
        | [] -> t
        | (row,col) :: xs -> let threats = checkRow (row,col) + checkCol (row,col) +
                                           (checkDiag (row,col) diag1 ( - )) +
                                           (checkDiag (row,col) diag2 ( + ))
          in
            (match (try Some (List.assoc threats t) with Not_found -> None) with
               | None -> check xs rows cols diag1 diag2 ((threats,1)::t)
               | Some prevThreats -> check xs rows cols diag1 diag2 ((threats,prevThreats + 1)::(List.remove_assoc threats t)))
  in
  let board = readBoard m [] in
  let rows  = createRow  board [] in
  let cols  = createCol  board [] in
  let diag1 = createDiag board [] ( - ) in
  let diag2 = createDiag board [] ( + ) in
  let tSeq = check board rows cols diag1 diag2 [] in
  let normalize lst =
    let rec aux lst i acc =
      match i,lst with
        | 9,_ -> List.rev acc
        | i,[] -> aux [] (i+1) ((i,0)::acc)
        | i,((j,v)::t) -> if (i = j) then aux t (i+1) ((j,v) :: acc)
          else
            aux ((j,v)::t) (i+1) ((i,0) :: acc)
    in
      aux lst 0 []
  in
  let tOut = normalize tSeq in
    List.iter (fun (_,v2) -> Printf.printf "%d " v2) tOut;
    Printf.printf "\n"
;;

let read_stuff () =
  let m = Scanf.scanf " %d %d" (fun _ a -> a)
  and l = ref [] in
    for i = 1 to m do
      let pair = Scanf.scanf " %d %d" (fun a b -> (a, b, 0)) in
      l := pair :: !l;
    done;
    !l

let postprocess queens =
  let res = Array.create 10 0
  in List.iter (fun (_, _, sz) -> (res.(sz) <- (res.(sz) + 1))) queens; res

let print_res res =
  Array.iter (fun el -> Printf.printf "%d " el) res;
  print_endline ""

let cmp a b =
  if a == b
  then 0
  else if a > b
  then 1
  else -1

let solve_one queens pred =
  let proc2 q r =
    let (x, y, v) = q in
      if abs(pred q r) == 2
      then (x, y, v + 1)
      else q
  in let proc = function
    | h :: t ->
        snd (List.fold_left
          (* Sprawdz wszystko oprocz glowy *)
          (fun (last, acc) h ->
             (h, (proc2 h last)::acc))
          (h, [h])
          t)
    | foo -> foo
  and sorted = List.sort pred queens
  in proc (proc (sorted))

let rec solve queens preds =
  match preds with
    | [] -> queens
    | p0 :: ps -> solve (solve_one queens p0) ps

let oq a b =
  if a == 0 then 2 * b else a
;;

let predicates =
  [
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp x1 x2) (cmp y1 y2));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp y1 y2) (cmp x1 x2));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 - y1) (x2 - y2)) (cmp (x1 + y1) (x2 + y2)));
    (fun (x1, y1, _) (x2, y2, _) -> oq (cmp (x1 + y1) (x2 + y2)) (cmp (x1 - y1) (x2 - y2)))
  ]
in
  print_res (postprocess (solve (read_stuff()) predicates))


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

let tab = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun x -> x));;

let valide = ref (tab.(0).[0] <> tab.(0).[1]);;

for i = 0 to n-1 do
for j = 0 to n-1 do
  if i = j
    then (if tab.(i).[j] <> tab.(0).[0] then valide := false)
  else if n-j-1 = i
    then (if tab.(i).[j] <> tab.(0).[0] then valide := false)
  else
    if tab.(i).[j] <> tab.(0).[1] then valide := false
done;
done;

if !valide
  then print_endline "YES"
  else print_endline "NO"

let n=read_int();;

let tab=Array.make n " ";;

for i=0 to n-1 do
   tab.(i)<-read_line()
done;;

let a=tab.(0).[0];;
let v=tab.(0).[1];;
let b=ref true;;

for i=0 to n-1 do
   for j=0 to n-1 do
      if (i=j)||(i+j=n-1) then b:= !b&&(tab.(i).[j]=a)
      else b:= !b&&(tab.(i).[j]=v)
   done
done;;

if a=v then b:=false;;

if !b then print_string "YES" else print_string "NO";;

let n=read_int();;

let tab=Array.make n " ";;

for i=0 to n-1 do
   tab.(i)<-read_line()
done;;

let a=tab.(0).[0];;
let v=tab.(0).[1];;
let b=ref true;;

for i=0 to n-1 do
   for j=0 to n-1 do
      if (i=j)||(i+j=n-1) then b:= !b&&(tab.(i).[j]=a)
      else b:= !b&&(tab.(i).[j]=v)
   done
done;;

if !b then print_string "YES" else print_string "NO";;

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

let tab = Array.init n (fun _ -> Scanf.scanf "%s\n" (fun x -> x));;

let valide = ref true;;

for i = 0 to n-1 do
for j = 0 to n-1 do
  if i = j
    then (if tab.(i).[j] <> tab.(0).[0] then valide := false)
  else if n-j-1 = i
    then (if tab.(i).[j] <> tab.(0).[0] then valide := false)
  else
    if tab.(i).[j] <> tab.(0).[1] then valide := false
done;
done;

if !valide
  then print_endline "YES"
  else print_endline "NO"


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.0

open Printf
open Scanf

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

let construct_a n =
  let nn = n*n in
  let a = Array.make_matrix nn nn 0.0 in

  (* the pair of positions (i,j) is mapped into i+j*n of the vector *)

  (* the flips in the permutation are for a range [p,q], where p <= q *)
  (* for pair (i,j) and for each flip [p,q] see what happens to (i,j) and
     add this probability to the matrix a *)

  let ind i j = i + j*n in
  let fn = float n in
  let pr = 2.0 /. (fn *. (fn +. 1.0)) in

  for i=0 to n-1 do
    for j=0 to n-1 do
      if i <> j then (
	for p=0 to n-1 do
	  for q=p to n-1 do
	    let map i = if i<p then i else if i>q then i else q - (i-p) in
	    let (i',j') = (map i, map j) in
	    a.(ind i' j').(ind i j) <- a.(ind i' j').(ind i j) +. pr
	  done
	done
      )
    done
  done;
  a

let () =
  let n = read_int () in
  let k = read_int () in
  let perm = Array.init n (fun _ -> read_int()) in
  let nn = n*n in

  let ind i j = i + j*n in
  let dot a b = sum 0 (nn-1) (fun i -> a.(i) *. b.(i)) in

  let mult a b =
    let c = Array.make nn 0.0 in

    for i=0 to nn-1 do
      for j=0 to nn-1 do
	c.(i) <- c.(i) +. a.(i).(j) *. b.(j)
      done
    done;
    c
  in

  let power a b p =
    let rec loop ac i = if i=p then ac else
	loop (mult a ac) (i+1)
    in
    loop b 0
  in

  let a = construct_a n in

  let b = Array.make nn 0.0 in
  let b' = Array.make nn 0.0 in

  for i=0 to n-2 do
    for j=i+1 to n-1 do
      let ii = ind i j in
      if perm.(i) < perm.(j)
      then b.(ii) <- 1.0
      else b'.(ii) <- 1.0
    done
  done;

  let c = power a b k in
  let c' = power a b' k in

  let s = Array.make nn 0.0 in
  let s' = Array.make nn 0.0 in

  for i=0 to n-1 do
    for j=0 to n-1 do
      let ii = ind i j in
      if i<j then s.(ii) <- 1.0 else if i>j then s'.(ii) <- 1.0
    done
  done;

  printf "%12.12f\n" ((dot c' s) +. (dot c s'))

open Printf
open Scanf

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

let construct_a n =
  let nn = n*n in
  let a = Array.make_matrix nn nn 0.0 in

  (* the pair of positions (i,j) is mapped into i+j*n of the vector *)

  (* the flips in the permutation are for a range [p,q], where p <= q *)
  (* for pair (i,j) and for each flip [p,q] see what happens to (i,j) and
     add this probability to the matrix a *)

  let ind i j = i + j*n in

  let fn = float n in
  let pr = 2.0 /. (fn *. (fn +. 1.0)) in

  for i=0 to n-1 do
    for j=0 to n-1 do
      if i <> j then (
	for p=0 to n-1 do
	  for q=p to n-1 do
	    let map i = if i<p then i else if i>q then i else q - (i-p) in
	    let (i',j') = (map i, map j) in
	    a.(ind i' j').(ind i j) <- a.(ind i' j').(ind i j) +. pr
	  done
	done
      )
    done
  done;
  a

let () =
  let n = read_int () in
  let k = read_int () in
  let perm = Array.init n (fun _ -> read_int()) in

  let nn = n*n in

  let mult a b =
    let c = Array.make nn 0.0 in

    for i=0 to nn-1 do
      for j=0 to nn-1 do
	c.(i) <- c.(i) +. a.(i).(j) *. b.(j)
      done
    done;
    c
  in

  let power a b p =
    let rec loop ac i = if i=p then ac else
	loop (mult a ac) (i+1)
    in
    loop b 0
  in

  let a = construct_a n in

  let ind i j = i + j*n in
  let unind ii = (ii - n*(ii/n), ii/n) in

  let exp = ref 0.0 in

  for i=0 to n-2 do
    for j=i+1 to n-1 do
      let flipprob = ref 0.0 in
      let b = Array.init nn (fun ii-> if ii = ind i j then 1.0 else 0.0) in
      let c = power a b k in
      for ii=0 to nn-1 do
	let (i',j') = unind ii in
	if i'<>j' && ((i'<j') <> (i<j)) then flipprob := !flipprob +. c.(ii)
      done;
      if perm.(i) < perm.(j) then
	exp := !exp +. !flipprob
      else
	exp := !exp +. (1.0 -. !flipprob)
    done
  done;

  printf "%12.12f\n" !exp