let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let a = Array.make n 0 in
    for i = 0 to n - 1 do
      a.(i) <- Scanf.bscanf sb "%d " (fun s -> s) - 1
    done;
    let u = Array.make n false in
    let cs = ref [] in
    let _ =
      for i = 0 to n - 1 do
	if not u.(i) then (
	  let pos = ref i in
	  let c = ref [] in
	    while not u.(!pos) do
	      u.(!pos) <- true;
	      c := !pos :: !c;
	      pos := a.(!pos);
	    done;
	    let c = Array.of_list (List.rev !c) in
	      cs := (Array.length c, c) :: !cs
	)
      done;
    in
    let cs = Array.of_list !cs in
    let res = Array.make n 0 in
    let skip = ref false in
      Array.sort compare cs;
      for i = 0 to Array.length cs - 1 do
	if not !skip then (
	let (k, p) = cs.(i) in
(*Printf.printf "qwe %d\n" k;*)
	  if k mod 2 <> 0 then (
	    for j = 0 to k - 1 do
	      res.(p.(j)) <- p.((j + k / 2 + 1) mod k)
	    done;
	  ) else (
	    if i + 1 < Array.length cs && fst (cs.(i + 1)) = k then (
	      let (_, p') = cs.(i + 1) in
		for j = 0 to k - 1 do
(*Printf.printf "asd %d %d %d %d\n" i k p.(j) p'.(j);*)
		  res.(p.(j)) <- p'.(j);
		  res.(p'.(j)) <- p.((j + 1) mod k)
		done;
		skip := true;
	    ) else (
	      Printf.printf "-1\n";
	      exit 0;
	    )
	  )
	) else skip := false
      done;
      for i = 0 to n - 1 do
	Printf.printf "%d " (res.(i) + 1);
      done;
      Printf.printf "\n"

open Scanf
open Printf

let length = Array.length
let print_array l = Array.iter (fun a -> printf "%d " (a+1)) l
let print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l
let square p =
    let n = Array.length p in
    Array.init n (fun a -> p.(p.(a)))

let read_int _ = scanf " %d" (fun x -> x)
let read_perm _ = scanf " %d" (fun x -> (x-1))
let read_array num =
    Array.init num read_perm

let add x l =
    l := (x :: !l)

type permutation = int array

let split_cycles ar =
    let n = Array.length ar in
    let visited = Array.make n false
    and out = ref [] in
    for i = 0 to n-1 do
        if not visited.(i) then
            begin
                let per = ref [] and x = ref i in
                while not visited.(!x) do
                    add (!x) per;
                    visited.(!x) <- true;
                    x := ar.(!x)
                done;
                let x = Array.of_list (List.rev !per)
                in add x out
            end
    done;
    Array.of_list !out

let cmp a b =
    Array.length a - Array.length b

let root_odd ar =
    let n = Array.length ar in
    let m = (n+1)/2 in
    assert (n mod 2 = 1);
    Array.init n (fun x -> if x mod 2 = 0 then ar.(x/2) else ar.(m + x/2))

let root_even a b =
    assert (Array.length a = Array.length b);
    assert (Array.length a mod 2 = 0);
    let n = Array.length a in
    Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))

let get_answer ar = (* assume sorted *)
    let n = Array.length ar
    and i = ref 0
    and out = ref []
    and error = ref false in
    while !i < n do
        let l = Array.length ar.(!i) in
        if l mod 2 = 0 then
            begin
                if !i = n - 1 then (incr i; error := true)
                else if Array.length ar.(!i + 1) <> l then (i := n; error := true)
                else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)
            end
        else
            begin
                add (root_odd ar.(!i)) out;
                incr i
            end
    done;
    if !error then [||]
    else Array.of_list !out

let convert n ar =
    let out = Array.make n 0
    and k = Array.length ar in
    for i = 0 to k - 1 do
        let a = ar.(i) in
        let l = Array.length a in
        for j = 0 to l - 1 do
            if j = l - 1 then out.(a.(j)) <- a.(0)
            else out.(a.(j)) <- a.(j+1)
        done
    done;
    out

let n = read_int ()
let ar = read_array n
let cycles = split_cycles ar
let () = Array.sort cmp cycles
(*let () = print_array2 cycles; print_endline "===================="*)
let ans = get_answer cycles
let () =
    if ans = [||] then printf "-1\n"
    else
        let out = convert n ans in
        print_array out (*; print_string "\nSquare:\n"; print_array (square out) *)

open Scanf
open Printf

let length = Array.length
let print_array l = Array.iter (fun a -> printf "%d " a) l
let print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l
let square p =
    let n = Array.length p in
    Array.init n (fun a -> p.(p.(a)-1))

let read_int _ = scanf " %d" (fun x -> x)
let read_array num =
    Array.init num read_int

let add x l =
    l := (x :: !l)

type permutation = int array

let split_cycles ar =
    let n = Array.length ar in
    let visited = Array.make n false
    and out = ref [] in
    for i = 0 to n-1 do
        if not visited.(i) then
            let per = ref [] and x = ref i in
            while not visited.(!x) do
                add (!x + 1) per;
                visited.(!x) <- true;
                x := ar.(!x) - 1
            done;
            let x = Array.of_list (List.rev !per)
            in add x out
    done;
    Array.of_list !out

let cmp a b =
    Array.length a - Array.length b

let root_odd ar =
    let n = Array.length ar in
    assert (n mod 2 = 1);
    Array.init n (fun a -> ar.(2*a mod n))

let root_even a b =
    assert (Array.length a = Array.length b);
    assert (Array.length a mod 2 = 0);
    let n = Array.length a in
    Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))

let get_answer ar = (* assume sorted *)
    let n = Array.length ar
    and i = ref 0
    and out = ref []
    and error = ref false in
    while !i < n do
        let l = Array.length ar.(!i) in
        if l mod 2 = 0 then
            begin
                if !i = n - 1 then (incr i; error := true)
                else if Array.length ar.(!i + 1) <> l then (i := n; error := true)
                else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)
            end
        else
            begin
                add (root_odd ar.(!i)) out;
                incr i
            end
    done;
    if !error then [||]
    else Array.of_list !out

let convert n ar =
    let out = Array.make n 0
    and k = Array.length ar in
    for i = 0 to k - 1 do
        let a = ar.(i) in
        let l = Array.length a in
        for j = 0 to l - 1 do
            if j = l - 1 then out.(a.(j)-1) <- a.(0)
            else out.(a.(j)-1) <- a.(j+1)
        done
    done;
    out

let n = read_int ()
let ar = read_array n
let cycles = split_cycles ar
let () = Array.sort cmp cycles
(*let () = print_array2 cycles; print_endline "===================="*)
let ans = get_answer cycles
let () =
    if ans = [||] then printf "-1\n"
    else
        let out = convert n ans in
        print_array out (*; print_string "\nSquare:\n"; print_array (square out) *)

open Scanf
open Printf

let length = Array.length
let print_array l = Array.iter (fun a -> printf "%d " a) l
let print_array2 l = Array.iter (fun a -> print_array a; print_newline ()) l

let read_int _ = scanf " %d" (fun x -> x)
let read_array num =
    Array.init num read_int

let add x l =
    l := (x :: !l)

type permutation = int array

let split_cycles ar =
    let n = Array.length ar in
    let visited = Array.make n false
    and out = ref [] in
    for i = 0 to n-1 do
        if not visited.(i) then
            let per = ref [] and x = ref i in
            while not visited.(!x) do
                add (!x + 1) per;
                visited.(!x) <- true;
                x := ar.(!x) - 1
            done;
            let x = Array.of_list !per
            in add x out
    done;
    Array.of_list !out

let cmp a b =
    Array.length a - Array.length b

let root_odd ar =
    let n = Array.length ar in
    assert (n mod 2 = 1);
    Array.init n (fun a -> ar.(2*a mod n))

let root_even a b =
    assert (Array.length a = Array.length b);
    assert (Array.length a mod 2 = 0);
    let n = Array.length a in
    Array.init (2*n) (fun x -> if x mod 2 = 0 then a.(x/2) else b.(x/2))

let get_answer ar = (* assume sorted *)
    let n = Array.length ar
    and i = ref 0
    and out = ref []
    and error = ref false in
    while !i < n do
        let l = Array.length ar.(!i) in
        if l mod 2 = 0 then
            begin
                if !i = n - 1 then (incr i; error := true)
                else if Array.length ar.(!i + 1) <> l then (i := n; error := true)
                else (add (root_even ar.(!i) ar.(!i + 1)) out; i := !i + 2)
            end
        else
            begin
                add (root_odd ar.(!i)) out;
                incr i
            end
    done;
    if !error then [||]
    else Array.of_list !out

let convert n ar =
    let out = Array.make n 0
    and k = Array.length ar in
    for i = 0 to k - 1 do
        let a = ar.(i) in
        let l = Array.length a in
        for j = 0 to l - 1 do
            if j = l - 1 then out.(a.(j)-1) <- a.(0)
            else out.(a.(j)-1) <- a.(j+1)
        done
    done;
    out

let n = read_int ()
let ar = read_array n
let cycles = split_cycles ar
let _ = Array.sort cmp cycles
let ans = get_answer cycles
let () =
    if ans = [||] then printf "-1\n"
    else
        let out = convert n ans in
        print_array out


module type ExtremumType =
sig
  type t
  val extremum : t -> t -> bool
end

module type RMQ =
sig
  type t
  type elt
  val of_array : elt array -> t
  val rmq : t -> int -> int -> int
end

module type RMQMake =
sig
  module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t
end

module RMQST =
struct
  module Make(Ext : ExtremumType) : RMQ with type elt = Ext.t =
  struct
    type elt = Ext.t
    type t = {a : elt array;
	      m : int array array}
    let ext = Ext.extremum
    let of_array a =
      let n = Array.length a in
      let k = ref 0
      and d = ref 1 in
	while !d <= n do
	  d := 2 * !d;
	  incr k
	done;
	let k = !k in
	let m = Array.make_matrix k n 0 in
	  for i = 0 to n - 1 do
	    m.(0).(i) <- i;
	  done;
	  for j = 1 to k - 1 do
	    for i = 0 to n - (1 lsl j) do
	      let i2 = i + (1 lsl (j - 1)) in
		m.(j).(i) <-
		  if ext a.(m.(j - 1).(i)) a.(m.(j - 1).(i2))
		  then m.(j - 1).(i)
		  else m.(j - 1).(i2)
	    done
	  done;
	  {a = a;
	   m = m}
    let rmq data x y =
      let a = data.a
      and m = data.m in
      let l = y - x + 1 in
      let k = ref 0
      and d = ref 1 in
	while !d <= l do
	  d := 2 * !d;
	  incr k
	done;
	let k = !k - 1 in
	let i2 = y - (1 lsl k) + 1 in
	  if ext a.(m.(k).(x)) a.(m.(k).(i2))
	  then m.(k).(x)
	  else m.(k).(i2)
  end
end

module RMQSTmin =
  RMQST.Make(
    struct
      type t = int
      let extremum (x : t) (y : t) = x < y
    end
  )

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let es = Array.make n [] in
  let () =
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let is_bridge = ref false in
	es.(u) <- (v, is_bridge) :: es.(u);
	es.(v) <- (u, is_bridge) :: es.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Array.make k 0 in
  let l = Array.make k 0 in
  let () =
    for i = 0 to k - 1 do
      s.(i) <- Scanf.bscanf sb "%d " (fun s -> s) - 1;
      l.(i) <- Scanf.bscanf sb "%d " (fun s -> s) - 1;
    done
  in
  let min (x : int) y = if x < y then x else y in
  let used = Array.make n false in
  let t = ref 0 in
  let e = Array.make n 0 in
  let up = Array.make n 0 in
  let rec dfs u prev =
    used.(u) <- true;
    e.(u) <- !t;
    up.(u) <- !t;
    incr t;
    for i = 0 to Array.length es.(u) - 1 do
      let (v, is_bridge) = es.(u).(i) in
	if v <> prev then (
	  if not used.(v) then (
	    dfs v u;
	    up.(u) <- min up.(u) up.(v);
	    if up.(v) > e.(u) then (
	      is_bridge := true;
	      (*Printf.printf "bridge %d %d\n" u v*)
	    )
	  ) else (
	    up.(u) <- min up.(u) e.(v);
	  )
	)
    done;
  in
  let stack = Array.make (2 * n) (fun _ -> ()) in
  let stack_pos = ref 0 in
  let rec execute () =
    if !stack_pos > 0 then (
      decr stack_pos;
      let f = stack.(!stack_pos) in
	f ();
	execute ()
    )
  in
  let rec dfs u prev =
    used.(u) <- true;
    e.(u) <- !t;
    up.(u) <- !t;
    incr t;
    let rec aux i =
      if i < Array.length es.(u) then (
	stack.(!stack_pos) <- (fun () -> aux (i + 1));
	incr stack_pos;
	let (v, is_bridge) = es.(u).(i) in
	  if v <> prev then (
	    if not used.(v) then (
	      let f () =
		up.(u) <- min up.(u) up.(v);
		if up.(v) > e.(u) then (
		  is_bridge := true;
		  (*Printf.printf "bridge %d %d\n" u v*)
		)
	      in
		stack.(!stack_pos) <- f;
		incr stack_pos;
		stack.(!stack_pos) <- (fun () -> dfs v u);
		incr stack_pos;
	    ) else (
	      up.(u) <- min up.(u) e.(v);
	    )
	  );
      )
    in
      aux 0
  in
  let color = Array.make n (-1) in
  let c = ref 0 in
  let rec dfs2 u =
    used.(u) <- true;
    color.(u) <- !c;
    for i = 0 to Array.length es.(u) - 1 do
      let (v, is_bridge) = es.(u).(i) in
	if not used.(v) && not !is_bridge then (
	  dfs2 v
	)
    done
  in
  let rec dfs2 u =
    used.(u) <- true;
    color.(u) <- !c;
    let rec aux i =
      if i < Array.length es.(u) then (
	stack.(!stack_pos) <- (fun () -> aux (i + 1));
	incr stack_pos;
	let (v, is_bridge) = es.(u).(i) in
	    if not used.(v) && not !is_bridge then (
	      stack.(!stack_pos) <- (fun () -> dfs2 v);
	      incr stack_pos;
	    )
      )
    in
      aux 0
  in
    for i = 0 to n - 1 do
      if not used.(i) then (
	stack_pos := 0;
	dfs i (-1);
	execute ()
      )
    done;
    for j = 0 to n - 1 do
      used.(j) <- false
    done;
    for i = 0 to n - 1 do
      if not used.(i) then (
	stack_pos := 0;
	dfs2 i;
	execute ();
	incr c
      )
    done;
    let c = !c in
    let es2 = Array.make c [] in
    let () =
      for i = 0 to n - 1 do
	for j = 0 to Array.length es.(i) - 1 do
	  let (v, is_bridge) = es.(i).(j) in
	    if !is_bridge then (
	      let u = color.(i)
	      and v = color.(v) in
		es2.(u) <- v :: es2.(u);
		es2.(v) <- u :: es2.(v);
	    )
	done
      done
    in
    let es = Array.map Array.of_list es2 in
    let used = Array.make c false in
    let d = Array.make (2 * c) 0 in
    let de = Array.make (2 * c) 0 in
    let g1 = Array.make c 0 in
    let g2 = Array.make c 0 in
    let pos = ref 0 in
    let rec dfs3 u depth =
      used.(u) <- true;
      g1.(u) <- !pos;
      d.(!pos) <- depth;
      de.(!pos) <- u;
      incr pos;
      for i = 0 to Array.length es.(u) - 1 do
	let v = es.(u).(i) in
	  if not used.(v) then (
	    dfs3 v (depth + 1);
	    g2.(u) <- !pos;
	    d.(!pos) <- depth;
	    de.(!pos) <- u;
	    incr pos;
	  )
      done
    in
    let rec dfs3 u depth =
      used.(u) <- true;
      g1.(u) <- !pos;
      d.(!pos) <- depth;
      de.(!pos) <- u;
      incr pos;
      let rec aux i =
	if i < Array.length es.(u) then (
	  stack.(!stack_pos) <- (fun () -> aux (i + 1));
	  incr stack_pos;
	  let v = es.(u).(i) in
	    if not used.(v) then (
	      let f () =
		g2.(u) <- !pos;
		d.(!pos) <- depth;
		de.(!pos) <- u;
		incr pos;
	      in
		stack.(!stack_pos) <- f;
		incr stack_pos;
		stack.(!stack_pos) <- (fun () -> dfs3 v (depth + 1));
		incr stack_pos;
	    )
	)
      in
	aux 0
    in
      stack_pos := 0;
      dfs3 0 0;
      execute ();
      let rmq = RMQSTmin.of_array d in
	for i = 0 to k - 1 do
	  let u = color.(s.(i))
	  and v = color.(l.(i)) in
	  let w =
	    if g1.(u) < g1.(v)
	    then RMQSTmin.rmq rmq g1.(u) g1.(v)
	    else RMQSTmin.rmq rmq g1.(v) g1.(u)
	  in
	  let depth = d.(w) in
	  let res = d.(g1.(u)) - depth + d.(g1.(v)) - depth in
	    Printf.printf "%d\n" res;
	done

let _ =
  let sb = Scanf.Scanning.stdib in
  let n = Scanf.bscanf sb "%d " (fun s -> s) in
  let m = Scanf.bscanf sb "%d " (fun s -> s) in
  let es = Array.make n [] in
  let () =
    for i = 1 to m do
      let u = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let v = Scanf.bscanf sb "%d " (fun s -> s) - 1 in
      let is_bridge = ref false in
	es.(u) <- (v, is_bridge) :: es.(u);
	es.(v) <- (u, is_bridge) :: es.(v);
    done
  in
  let es = Array.map Array.of_list es in
  let k = Scanf.bscanf sb "%d " (fun s -> s) in
  let s = Array.make k 0 in
  let l = Array.make k 0 in
  let () =
    for i = 0 to k - 1 do
      s.(i) <- Scanf.bscanf sb "%d " (fun s -> s) - 1;
      l.(i) <- Scanf.bscanf sb "%d " (fun s -> s) - 1;
    done
  in
  let min (x : int) y = if x < y then x else y in
  let used = Array.make n false in
  let t = ref 0 in
  let e = Array.make n 0 in
  let up = Array.make n 0 in
  let rec dfs u prev =
    used.(u) <- true;
    e.(u) <- !t;
    up.(u) <- !t;
    incr t;
    for i = 0 to Array.length es.(u) - 1 do
      let (v, is_bridge) = es.(u).(i) in
	if v <> prev then (
	  if not used.(v) then (
	    dfs v u;
	    up.(u) <- min up.(u) up.(v);
	    if up.(v) > e.(u) then (
	      is_bridge := true;
	      (*Printf.printf "bridge %d %d\n" u v*)
	    )
	  ) else (
	    up.(u) <- min up.(u) e.(v);
	  )
	)
    done;
  in
  let res = ref 0 in
  let rec dfs2 u dest dist =
    used.(u) <- true;
    if u = dest then (
      res := dist
    );
    for i = 0 to Array.length es.(u) - 1 do
      let (v, is_bridge) = es.(u).(i) in
	if not used.(v) then (
	  let dist =
	    if !is_bridge
	    then dist + 1
	    else dist
	  in
	    dfs2 v dest dist;
	)
    done;
  in
    for i = 0 to n - 1 do
      if not used.(i)
      then dfs i (-1)
    done;
    for i = 0 to k - 1 do
      for j = 0 to n - 1 do
	used.(j) <- false
      done;
      dfs2 s.(i) l.(i) 0;
      Printf.printf "%d\n" !res;
    done


open List
let read_int _ = Scanf.scanf " %d" (fun x -> x);;

let min x y = if x < y then x else y;;

let rec read_list l n =
    if n = 0 then l
    else let x = read_int() and y = read_int() in
    read_list (l @ [(x, y)]) (n-1);;

let rec answer l r n = match (l, r) with
      | ([], []) -> n
      | ((x, y) :: l, []) -> n + y
      | ([], (x, y)::l) -> n + y
      | ((x1, y1) :: l', (x2, y2) :: r') -> answer l' r' (n + y1 + y2);;

let mysort (x1, y1) (x2, y2) = x1 - x2;;

let () =
    let n = read_int () in
    let xa = read_list [] n in
    let left = filter (fun (x, y) -> (x < 0)) xa and right = filter (fun (x, y) -> (x > 0)) xa in
    let left = sort mysort left and right = sort mysort right in
    let ans = answer (rev left) right 0 in
    Printf.printf "%d\n" ans
;;

open Printf
open Scanf

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

  let rec make_lists l r i = if i=n then (l,r) else
      let (x,a) = d.(i) in
      if x < 0 then make_lists ((-x,a)::l) r (i+1)
      else make_lists l ((x,a)::r) (i+1)
  in

  let (l,r) = make_lists [] [] 0 in

  let l = List.sort compare l in
  let r = List.sort compare r in

  let (nl, nr) = (List.length l, List.length r) in

  let (l,r) = if nl < nr then (r,l) else (l,r) in
  let (nl,nr) = (max nl nr, min nl nr) in

  let sum_r = List.fold_left (fun t (_,a) -> t+a) 0 r in

  let (sum_l,_) = List.fold_left (fun (t,i) (_,a) -> if (i>=nr+1) then (t,i+1) else (t+a,i+1)) (0,0) l in

  printf "%d\n" (sum_l + sum_r)


let solve n s =
  let elts = n/2 + 1 in
  s/elts;;

let divide s =
  let l = String.length s in
  let rec aux i =
     if s.[i] = ' ' then i else aux (i+1) in
  let space = aux 0 in
  let a = String.sub s 0 space and b = String.sub s (space+1) (l-space-1) in
  (int_of_string a, int_of_string b);;

let read_test i =
  let test = read_line () in divide test;;

let t = read_int ();;

let process x =
  let (n, s) = read_test () in print_int(solve n s); print_newline ();;

let rec execute i =
  if i < t then
  begin
    process i; execute (i+1)
  end;;

let () = execute 0;;

let w = read_int () in
let rec aux z = (if z > 0 then
    (
    let y = read_line () in
    let len = String.length y in
    let resolution y =
        let rec breaker = (function
            (a,b) when y.[b] = ' ' -> (int_of_string(String.sub y 0 b), int_of_string(String.sub y (b+1) (len-(b+1))))
            |(a,b) -> breaker(a,b+1)) in
        let a = breaker (y,0) in let (x,y) = a in
        print_int (match x with
            1 -> y
            |x when x mod 2 = 0 -> y/(x-((x-1)/2))
            |x -> y/(x-(x/2))); print_newline ()
        in
    (resolution y; aux(z-1) )
    )) in aux (w);;


let _ =
   let n = Scanf.scanf "%d" (fun i -> i) in
   let tab = Array.init n (fun _ -> Scanf.scanf " %d" (fun j -> j)) in
   let perm i j =
      let z = tab.(i) in
         tab.(i) <- tab.(j);
         tab.(j) <- z
   in
   let a = ref (-1) in
      while !a < n-1 do
         if !a < 0
         then incr a
         else if tab.(!a) > tab.(1 + !a)
              then begin
                   perm !a (1 + !a);
                   Printf.printf "%d %d\n" (1 + !a) (2 + !a);
                   decr a
                   end
              else incr a;
      done

open Printf
open Scanf

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

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

  for i=1 to n-1 do
    for j=i downto 1 do
      if a.(j-1) > a.(j) then (
	printf "%d %d\n" (j) (j+1);
	let (x,y) = (a.(j-1), a.(j)) in
	a.(j-1) <- y;
	a.(j) <- x
      )
    done
  done

let n = read_int ()
let a = read_line () |> Str.(split (regexp " ")) |> List.map int_of_string |> Array.of_list

let () =
  for i = 0 to n - 2 do
    let min = ref i in
    for j = i + 1 to n - 1 do
      if a.(j) < a.(!min) then
        min := j
    done;

    for j = !min - 1 downto i do
      Printf.printf "%d %d\n" (j+1) (j+2);
      let tmp = a.(j) in
      a.(j) <- a.(j+1);
      a.(j+1) <- tmp
    done
  done

open Printf
open Scanf

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

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

  for i=0 to n-2 do
    for j=i to n-2 do
      if a.(j) > a.(j+1) then (
	printf "%d %d\n" (j+1) (j+2);
	let (x,y) = (a.(j), a.(j+1)) in
	a.(j) <- y;
	a.(j+1) <- x
      )
    done
  done


module A = Array
module L = List
module I = Int64

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let max_n = 200000

module SegTree = struct
  type t = int64 array

  let init n = A.make (2 * n) I.zero

  let add t i x =
    let v = ref i in
    let n = A.length t in
    while !v < n do
      t.(!v) <- I.add t.(!v) x;
      v := !v lor (!v + 1);
    done

  let pref_sum t i =
    let r = ref i in
    let res = ref I.zero in
    while !r >= 0 do
      res := I.add !res t.(!r);
      r := (!r land (!r + 1)) - 1;
    done;
    !res

  let sum t l r =  I.sub (pref_sum t r) (pref_sum t (l - 1))
end

module L_ = struct
  let filter_map f =
    let rec aux accu = function
      | [] -> L.rev accu
      | x :: l ->
          match f x with
          | None -> aux accu l
          | Some v -> aux (v :: accu) l
    in
    aux []
end

type query = {
  l: int;
  q_index: int;
}

let find_first_div n =
  let i = ref 2 in
  let found = ref (-1) in
  while !i * !i <= n && !found = -1 do
    if (n mod !i = 0) then found := !i;
    i := !i + 1;
  done;
  if (!found = -1) then n
  else !found

let () =
  let q = read_int () in
  let original_queries: (int * int) array = Array.make q (0, 0) in
  let ans = Array.make q I.zero in
  let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in
  for i = 0 to q - 1 do
    let l = read_int () in
    let r = read_int () in
    original_queries.(i) <- (l, r);
    events.(r) <- {l; q_index = i;} :: events.(r);
  done;

  let (divisors: int list array) = Array.make (max_n + 1) [] in
  let pw2 = Array.make (max_n + 1) 0 in
  divisors.(1) <- [1];

  let inc_tree = SegTree.init max_n in
  for k = 2 to max_n do
    let fd = find_first_div k in
    let divs_prev = divisors.(k / fd) in
    divisors.(k) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);
    if (k mod 2 = 0) then pw2.(k) <- pw2.(k / 2) + 1;

    let divs = divisors.(k) in
    let divs_num = L.length divs in
    L.iteri (fun idx i ->
      if (i <> k) then
        SegTree.add inc_tree i @@ I.of_int @@ divs_num - idx - 2;
    ) divs;
    let p = pw2.(k) in

    let new_divs =
        A.of_list @@
        L.tl @@
        L.fast_sort (fun x y -> -compare x y) @@
        divs @ L_.filter_map (fun d ->
          if (d * 2 < k && pw2.(d) == p) then Some (d * 2)
          else None
        ) divs in
    let sj_p = ref 0 and ptr_j = ref (-1) in
    A.iteri (fun idx i ->
      while (!ptr_j <> -1 && new_divs.(!ptr_j) + i <= k) do
        let cd = new_divs.(!ptr_j) in
        if (pw2.(cd) = p + 1) then sj_p := !sj_p - 1;
        ptr_j := !ptr_j - 1
      done;

      if (pw2.(i) = p + 1) then
        SegTree.add inc_tree i @@ I.of_int @@ !ptr_j + 1
      else
        SegTree.add inc_tree i @@ I.of_int !sj_p;

      while (!ptr_j + 1 <= idx && new_divs.(!ptr_j + 1) + i > k) do
        let cd = new_divs.(!ptr_j + 1) in
        if (pw2.(cd) = p + 1) then sj_p := !sj_p + 1;
        ptr_j := !ptr_j + 1
      done;
    ) new_divs;

    L.iter (fun q ->
      ans.(q.q_index) <- SegTree.sum inc_tree q.l k;
    ) events.(k)
  done;

  for i = 0 to q - 1 do
    let n = snd original_queries.(i) - fst original_queries.(i) + 1 in
    let real_ans =
      I.(sub
        (div
          (mul (mul (of_int n) (of_int @@ n - 1)) (of_int @@ n - 2))
          (of_int 6))
        ans.(i)) in
    pf "%Ld\n" real_ans;
  done;

module A = Array
module L = List
module I = Int64

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let max_n = 200000

module SegTree = struct
  type t = int64 array

  let init n = A.make n I.zero

  let add t i x =
    let v = ref i in
    let n = A.length t in
    while !v < n do
      t.(!v) <- I.add t.(!v) x;
      v := !v lor (!v + 1);
    done

  let pref_sum t i =
    let r = ref i in
    let res = ref I.zero in
    while !r >= 0 do
      res := I.add !res t.(!r);
      r := (!r land (!r + 1)) - 1;
    done;
    !res

  let sum t l r =  I.sub (pref_sum t r) (pref_sum t (l - 1))
end

module L_ = struct
  let filter_map f =
    let rec aux accu = function
      | [] -> L.rev accu
      | x :: l ->
          match f x with
          | None -> aux accu l
          | Some v -> aux (v :: accu) l
    in
    aux []
end

type query = {
  l: int;
  q_index: int;
}

let find_first_div n =
  let i = ref 2 in
  let found = ref (-1) in
  while !i * !i <= n && !found = -1 do
    if (n mod !i = 0) then found := !i;
    i := !i + 1;
  done;
  if (!found = -1) then n
  else !found

let () =
  let q = read_int () in
  let original_queries: (int * int) array = Array.make q (0, 0) in
  let ans = Array.make q I.zero in
  let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in
  for i = 0 to q - 1 do
    let l = read_int () in
    let r = read_int () in
    original_queries.(i) <- (l, r);
    events.(r) <- {l; q_index = i;} :: events.(r);
  done;

  let (divisors: int list array) = Array.make (max_n + 1) [] in
  let pw2 = Array.make (max_n + 1) 0 in
  divisors.(1) <- [1];

  let inc_tree = SegTree.init (max_n + 1) in
  for k = 2 to max_n do
    let fd = find_first_div k in
    let divs_prev = divisors.(k / fd) in
    divisors.(k) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);
    if (k mod 2 = 0) then pw2.(k) <- pw2.(k / 2) + 1;

    let divs = divisors.(k) in
    let divs_num = L.length divs in
    L.iteri (fun idx i ->
      if (i <> k) then
        SegTree.add inc_tree i @@ I.of_int @@ divs_num - idx - 2;
    ) divs;
    let p = pw2.(k) in

    let new_divs =
        A.of_list @@
        L.tl @@
        L.fast_sort (fun x y -> -compare x y) @@
        divs @ L_.filter_map (fun d ->
          if (d * 2 < k && pw2.(d) == p) then Some (d * 2)
          else None
        ) divs in
    let sj_p = ref 0 and ptr_j = ref (-1) in
    A.iteri (fun idx i ->
      while (!ptr_j <> -1 && new_divs.(!ptr_j) + i <= k) do
        let cd = new_divs.(!ptr_j) in
        if (pw2.(cd) = p + 1) then sj_p := !sj_p - 1;
        ptr_j := !ptr_j - 1
      done;

      if (pw2.(i) = p + 1) then
        SegTree.add inc_tree i @@ I.of_int @@ !ptr_j + 1
      else
        SegTree.add inc_tree i @@ I.of_int !sj_p;

      while (!ptr_j + 1 <= idx && new_divs.(!ptr_j + 1) + i > k) do
        let cd = new_divs.(!ptr_j + 1) in
        if (pw2.(cd) = p + 1) then sj_p := !sj_p + 1;
        ptr_j := !ptr_j + 1
      done;
    ) new_divs;

    L.iter (fun q ->
      ans.(q.q_index) <- SegTree.sum inc_tree q.l k;
    ) events.(k)
  done;

  for i = 0 to q - 1 do
    let n = snd original_queries.(i) - fst original_queries.(i) + 1 in
    let real_ans =
      I.(sub
        (div
          (mul (mul (of_int n) (of_int @@ n - 1)) (of_int @@ n - 2))
          (of_int 6))
        ans.(i)) in
    pf "%Ld\n" real_ans;
  done;

module A = Array
module L = List
module I = Int64

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let max_n = 200000

module SegTree = struct
  let init = ()
  let add _i (_x: int64) = ()

  let sum _l _r: int64 = I.zero

end

type query = {
  l: int;
  q_index: int;
}

let find_first_div n =
  let i = ref 2 in
  let found = ref (-1) in
  while !i * !i <= n && !found = -1 do
    if (n mod !i = 0) then found := !i;
    i := !i + 1;
  done;
  if (!found = -1) then n
  else !found

let () =
  (* let q = read_int () in
  let original_queries: (int * int) array = Array.make q (0, 0) in
  let ans = Array.make q I.zero in
  let (events: query list array) = Array.init (max_n + 1) (fun _ -> []) in
  for i = 0 to q - 1 do
    let l = read_int () in
    let r = read_int () in
    original_queries.(i) <- (l, r);
    events.(r) <- {l; q_index = i;} :: events.(r);
  done; *)

  let (divisors: int list array) = Array.make (max_n + 1) [] in
  let pw2 = Array.make (max_n + 1) 0 in
  divisors.(1) <- [1];

  for i = 2 to max_n do
    let fd = find_first_div i in
    let divs_prev = divisors.(i / fd) in
    divisors.(i) <- L.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);
    if (i mod 2 = 0) then pw2.(i) <- pw2.(i / 2) + 1;
  done;

module A = Array
module L = List
module I = Int64

let pf = Printf.printf
let sf = Scanf.scanf
let read_int () = sf " %d" (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())

let max_n = 200000

module SegTree = struct
  let init = ()
  let add _i (_x: int64) = ()

  let sum _l _r: int64 = I.zero

end

type query = {
  l: int;
  q_index: int;
}

let find_first_div n =
  let i = ref 2 in
  let found = ref (-1) in
  while !i * !i <= n && !found = -1 do
    if (n mod !i = 0) then found := !i;
    i := !i + 1;
  done;
  if (!found = -1) then n
  else !found

let () =
  (* let q = read_int () in
  let original_queries: (int * int) array = Array.make q (0, 0) in
  let (events: query list array) = Array.init max_n (fun _ -> []) in
  for i = 0 to q - 1 do
    let l = read_int () in
    let r = read_int () in
    original_queries.(i) <- (l, r);
    events.(r) <- {l; q_index = i;} :: events.(r);
  done; *)

  let (divisors: int list array) = Array.make (max_n + 1) [] in
  let pw2 = Array.make (max_n + 1) 0 in
  divisors.(0) <- [1];

  for i = 2 to max_n do
    let fd = find_first_div i in
    let divs_prev = divisors.(i / fd) in
    divisors.(i) <- List.sort_uniq compare (divs_prev @ List.map (fun x -> x * fd) divs_prev);
    if (i mod 2 = 0) then pw2.(i) <- pw2.(i / 2) + 1;
  done;


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

open Printf
open Array

let rec exists f a =
  fold_right f a false
;;
let run () =
  let n = scan_int () in
  let k1 = scan_int () in
  let k2 = scan_int () in
  let a = init k1 (fun _x -> scan_int ()) in
  let _b = init k2 (fun _x -> scan_int ()) in
  if exists (fun x y -> x = n or y) a then
    printf "YES\n"
  else printf "NO\n"
;;

let () =
  let t = scan_int () in
  for i = 1 to t do
    run ()
  done
;;

open Printf
open Scanf

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let read_pair _ = bscanf Scanning.stdin " %d %d " (fun x y -> (x,y))
let rec exists i j f = (i<=j) && ((f i) || exists (i+1) j f)

let () =

  let cases = read_int() in
  for case = 1 to cases do
    let n = read_int() in
    let (k1,k2) = read_pair() in
    let cards1 = Array.init k1 read_int in
    let _ = Array.init k2 read_int in
    if exists 0 (k1-1) (fun i -> cards1.(i) = n) then printf "YES\n" else printf "NO\n"
  done


let f (mx,cur) next =
    let nx = if next then cur+1 else 0 in
        (max mx nx, nx)
in let rec g q x =
    if q = 0 then x else g (q - 1) (f x (String.contains (Scanf.scanf " %s" (fun x->x)) '0'))
in print_int @@ fst @@ Scanf.scanf "%_d %d" (fun d -> g d (0,0))

let () =
  match read_line () |> Str.(split (regexp " ")) |> List.map int_of_string with
  | [n; d] ->
     let cur = ref 0 in
     let r = ref 0 in
     for i = 1 to d do
       let present = read_line () |> Str.(split (regexp "")) |> List.map int_of_string in
       if List.exists (fun x -> x == 0) present then (
         incr cur;
         if !cur > !r then
           r := !cur
       ) else
         cur := 0
     done;
     Printf.printf "%d\n" !r
  | _ -> assert false

open Printf
open Scanf

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

let () =
  let n = read_int () in
  let d = read_int () in

  let all = String.make n '1' in

  let win_all = Array.init d (fun i ->
    read_string() <> all
  ) in

  let rec scan i len max_len = if i=d then max_len else
      let opt1 = if win_all.(i) then len+1 else 0 in
      scan (i+1) opt1 (max opt1 max_len)
  in

  let answer = scan 0 0 0 in

  printf "%d\n" answer


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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 1e-12 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L && (
    let a = !x in
    let b = d -. a in
    abs_float ((a +. b) -. (a *. b))>10e-6 ||
    abs_float ((a +. b) -. d) > 10e-6 ||
    abs_float ((a *. b) -. d) > 10e-6
  ) then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      if (
        abs_float ((a +. b) -. (a *. b)) > 10e-6 ||
        abs_float ((a +. b) -. d) > 10e-6 ||
        abs_float ((a *. b) -. d) > 10e-6
      ) then printf "N\n"
      else printf "Y %.16f %.16f\n" (max a b) (min a b);
      (* printf "    %.12f %.12f\n" (a+.b) (a*.b); *)
    )
  )

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

let bsf ng ok f = let d = if ng < ok then 1. else -1. in
  let rec f0 c ng ok =
    if abs_float (ok -. ng) <= 10e-12 || c < 0L then ok
    else let mid = ng +. (ok -. ng) /. 2. in
      if f mid then f0 (c-1L) ng mid else f0 (c-1L) mid ok
  in f0 100000L ng ok
let ok a b d =
  abs_float ((a +. b) -. (a *. b)) > 10e-6 ||
  abs_float ((a +. b) -. d) > 10e-6
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    if d = 0. then (
      printf "Y 0.000000000000 0.000000000000\n"
    ) else (
      let b = bsf 0. (d /. 2.) (fun b ->
        let a = d -. b in
        if a *. b > d then true else false
      ) in
      let a = d -. b in
      if abs_float (a *. b -. d) > 10e-6 || ok a b d then (
        printf "N\n"
      ) else (
        printf "Y %.14f %.14f\n" a b
      )
    )
  )

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

let newton start ?(count=100000L) ?(eps=1e-13) f f' =
  let g v = v -. f v /. f' v in
  let rec lp a = function
  | 0L -> a
  | c  ->
    let b = g a in
    if abs_float (b -. a) <= eps then a
    else lp b (c-1L)
  in lp start count

let ok a b d =
  abs_float ((a +. b) -. (a *. b)) <= 10e-6 &&
  abs_float ((a +. b) -. d) <= 10e-6 &&
  abs_float ((a *. b) -. d) <= 10e-6

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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 10e-12 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L && (
    let a = !x in
    let b = d -. a in
    abs_float ((a +. b) -. (a *. b))>10e-6 ||
    abs_float ((a +. b) -. d) > 10e-6
  ) then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      if (
        abs_float ((a +. b) -. (a *. b)) > 10e-6 ||
        abs_float ((a +. b) -. d) > 10e-6
      ) then printf "N\n"
      else printf "Y %.16f %.16f\n" (max a b) (min a b);
      (* printf "    %.12f %.12f\n" (a+.b) (a*.b); *)
    )
  )

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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 10e-8 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      printf "Y %.12f %.12f\n" (max a b) (min a b);
    )
  )

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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 10e-9 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L && (
    let a = !x in
    let b = d -. a in
    abs_float ((a +. b) -. (a *. b))>10e-6 ||
    abs_float ((a +. b) -. d) > 10e-6
  ) then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      if (
        abs_float ((a +. b) -. (a *. b)) > 10e-6 ||
        abs_float ((a +. b) -. d) > 10e-6
      ) then printf "N\n"
      else printf "Y %.16f %.16f\n" (max a b) (min a b);
      (* printf "    %.12f %.12f\n" (a+.b) (a*.b); *)
    )
  )

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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 10e-8 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      printf "Y %.12f %.12f\n" a b;
    )
  )

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

let newton d =
  let x = ref 0. in
  let f v = v -. (v*.v -. d*.v +. d) /. (2.*.v -. d) in
  let b = ref @@ f !x in
  let c = ref 10000L in
  while !c > 0L && abs_float (!b -. !x) > 10e-9 do
    c -= 1L;
    x := !b;
    b := f !x;
  done;
  (* printf "%f %f : %f\n" !x (d -. !x) !b; *)
  if !c = 0L && (
    abs_float ((!x+. !b) -. (!x*. !b))>10e-6 ||
    abs_float ((!x+. !b) -. d) > 10e-6
  ) then None else Some !x
let () =
  let t = get_i64 0 in
  rep 1L t (fun _ ->
    let d = scanf " %f" @@ id in
    match newton d with
    | None -> printf "N\n"
    | Some a -> (
      let b = d -. a in
      printf "Y %.12f %.12f\n" (max a b) (min a b);
      (* printf "    %.12f %.12f\n" (a+.b) (a*.b); *)
    )
  )


let _ =
  let sb = Scanf.Scanning.stdib in
  let s = Scanf.bscanf sb "%s " (fun s -> s) in
  let n = String.length s in
  let z = ref 0 in
  let o = ref 0 in
  let q = ref 0 in
  let z2 = ref 0 in
  let o2 = ref 0 in
  let q2 = ref 0 in
    for i = 0 to n - 3 do
      match s.[i] with
	| '0' -> incr z
	| '1' -> incr o
	| '?' -> incr q
	| _ -> assert false
    done;
    for i = n - 2 to n - 1 do
      match s.[i] with
	| '0' -> incr z2
	| '1' -> incr o2
	| '?' -> incr q2
	| _ -> assert false
    done;
    let ht = Hashtbl.create 4 in
    let solve' s =
      let s = ref s in
      let d = ref 1 in
	while String.length !s > 2 do
	  (*Printf.printf "asd %s %d\n" !s !d;*)
	  (try
	     let i = String.index !s (Char.chr (!d + Char.code '0')) in
	       s := String.sub !s 0 i ^
		 String.sub !s (i + 1) (String.length !s - i - 1);
	   with
	     | Not_found ->
		 s := String.sub !s 1 (String.length !s - 1)
	  );
	  d := 1 - !d;
	done;
	Hashtbl.replace ht !s ()
    in
    let solve _s z o q z2 o2 tail =
      (*for d = 0 to q do
	let z = z + d
	and o = o + (q - d) in*)
	  (*Printf.printf "asd zoq %d %d %d\n" z o q;*)
	  if n mod 2 = 0 then (
	    if z + q >= o + 4
	    then solve' ("0000" ^ tail);
	    if z < o + q + 4 && z + q >= o + 2
	    then solve' ("00" ^ tail);
	    if o + q >= z + 4
	    then solve' ("1111" ^ tail);
	    if o < z + q + 4 && o + q >= z + 2
	    then solve' ("11" ^ tail);
	    if z <= o + q && o <= z + q
	    then Hashtbl.replace ht tail ();
	  ) else (
	    if z + q >= o + 5
	    then solve' ("00000" ^ tail);
	    if z <= o + q + 5 && z + q >= o + 3
	    then solve' ("000" ^ tail);
	    if o + q >= z + 5
	    then solve' ("11111" ^ tail);
	    if o < z + q + 5 && o + q >= z + 3
	    then solve' ("111" ^ tail);
	    if z <= o + q + 1 && o + 1 <= z + q
	    then solve' ("0" ^ tail);
	    if z + 1 <= o + q && o <= z + 1 + q
	    then solve' ("1" ^ tail);
	  )
      (*done*)
    in
      (match s.[n - 2], s.[n - 1] with
	 | '?', '?' ->
	     solve s !z !o !q 2 0 "00";
	     solve s !z !o !q 1 1 "01";
	     solve s !z !o !q 1 1 "10";
	     solve s !z !o !q 0 2 "11";
	 | '?', _ ->
	     solve s !z !o !q (!z2 + 1) !o2 ("0" ^ String.make 1 s.[n - 1]);
	     solve s !z !o !q !z2 (!o2 + 1) ("1" ^ String.make 1 s.[n - 1]);
	 | _, '?' ->
	     solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ "0");
	     solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ "1");
	 | _ ->
	     solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);
      );
      if Hashtbl.mem ht "00" then Printf.printf "00\n";
      if Hashtbl.mem ht "01" then Printf.printf "01\n";
      if Hashtbl.mem ht "10" then Printf.printf "10\n";
      if Hashtbl.mem ht "11" then Printf.printf "11\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 z = ref 0 in
      let o = ref 0 in
      let q = ref 0 in
      let z2 = ref 0 in
      let o2 = ref 0 in
      let q2 = ref 0 in
        for i = 0 to n - 3 do
          match s.[i] with
            | '0' -> incr z
            | '1' -> incr o
            | '?' -> incr q
            | _ -> assert false
        done;
        for i = n - 2 to n - 1 do
          match s.[i] with
            | '0' -> incr z2
            | '1' -> incr o2
            | '?' -> incr q2
            | _ -> assert false
        done;
        let ht = Hashtbl.create 4 in
        let solve' s =
          let s = ref s in
          let d = ref 1 in
            while String.length !s > 2 do
              (*Printf.printf "asd %s\n" !s;*)
              (try
                 let i = String.index !s (Char.chr (!d + Char.code '0')) in
                   s := String.sub !s 0 i ^
                     String.sub !s (i + 1) (String.length !s - i - 1);
               with
                 | Not_found ->
                     s := String.sub !s 1 (String.length !s - 1)
              );
              d := 1 - !d;
            done;
            Hashtbl.replace ht !s ()
        in
        let solve _s z o q z2 o2 tail =
          for d = 0 to q do
            let z = z + d
            and o = o + (q - d) in
              (*Printf.printf "asd zoq %d %d %d\n" z o q;*)
              if n mod 2 = 0 then (
                if z >= o + 4
                then solve' ("0000" ^ tail)
                else if o >= z + 4
                then solve' ("1111" ^ tail)
                else if z >= o + 2
                then solve' ("00" ^ tail)
                else if o >= z + 2
                then solve' ("11" ^ tail)
                else if z = o
                then Hashtbl.replace ht tail ()
                else assert false
              ) else (
                if z >= o + 5
                then solve' ("00000" ^ tail)
                else if o >= z + 5
                then solve' ("11111" ^ tail)
                else if z >= o + 3
                then solve' ("000" ^ tail)
                else if o >= z + 3
                then solve' ("111" ^ tail)
                else if z = o + 1
                then solve' ("0" ^ tail)
                else if z + 1 = o
                then solve' ("1" ^ tail)
                else assert false
              )
          done
        in
          (match s.[n - 2], s.[n - 1] with
             | '?', '?' ->
                 solve s !z !o !q 2 0 "00";
                 solve s !z !o !q 1 1 "01";
                 solve s !z !o !q 1 1 "10";
                 solve s !z !o !q 0 2 "11";
             | '?', _ ->
                 solve s !z !o !q (!z2 + 1) !o2 ("0" ^ String.make 1 s.[n - 1]);
                 solve s !z !o !q !z2 (!o2 + 1) ("1" ^ String.make 1 s.[n - 1]);
             | _, '?' ->
                 solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ "0");
                 solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ "1");
             | _ ->
                 solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);
          );
          if Hashtbl.mem ht "00" then Printf.printf "00\n";
          if Hashtbl.mem ht "01" then Printf.printf "01\n";
          if Hashtbl.mem ht "10" then Printf.printf "10\n";
          if Hashtbl.mem ht "11" then Printf.printf "11\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 z = ref 0 in
  let o = ref 0 in
  let q = ref 0 in
  let z2 = ref 0 in
  let o2 = ref 0 in
  let q2 = ref 0 in
    for i = 0 to n - 3 do
      match s.[i] with
	| '0' -> incr z
	| '1' -> incr o
	| '?' -> incr q
	| _ -> assert false
    done;
    for i = n - 2 to n - 1 do
      match s.[i] with
	| '0' -> incr z2
	| '1' -> incr o2
	| '?' -> incr q2
	| _ -> assert false
    done;
    let ht = Hashtbl.create 4 in
    let solve' s =
      let s = ref s in
      let d = ref 1 in
	while String.length !s > 2 do
	  (*Printf.printf "asd %s\n" !s;*)
	  (try
	     let i = String.index !s (Char.chr (!d + Char.code '0')) in
	       s := String.sub !s 0 i ^
		 String.sub !s (i + 1) (String.length !s - i - 1);
	   with
	     | Not_found ->
		 s := String.sub !s 1 (String.length !s - 1)
	  );
	  d := 1 - !d;
	done;
	Hashtbl.replace ht !s ()
    in
    let solve _s z o q z2 o2 tail =
      (*for d = 0 to q do
	let z = z + d
	and o = o + (q - d) in*)
	  (*Printf.printf "asd zoq %d %d %d\n" z o q;*)
	  if n mod 2 = 0 then (
	    if z + q >= o + 4
	    then solve' ("0000" ^ tail);
	    if o + q >= z + 4
	    then solve' ("1111" ^ tail);
	    if z + q >= o + 2
	    then solve' ("00" ^ tail);
	    if o + q >= z + 2
	    then solve' ("11" ^ tail);
	    if 0 <= o - z + q && o - z <= q
	    then Hashtbl.replace ht tail ();
	  ) else (
	    if z + q >= o + 5
	    then solve' ("00000" ^ tail);
	    if o + q >= z + 5
	    then solve' ("11111" ^ tail);
	    if z + q >= o + 3
	    then solve' ("000" ^ tail);
	    if o + q >= z + 3
	    then solve' ("111" ^ tail);
	    if 0 <= o - z + q + 1 && o - z + 1 <= q
	    then solve' ("0" ^ tail);
	    if 0 <= o - z + q - 1 && o - z - 1 <= q
	    then solve' ("1" ^ tail);
	  )
      (*done*)
    in
      (match s.[n - 2], s.[n - 1] with
	 | '?', '?' ->
	     solve s !z !o !q 2 0 "00";
	     solve s !z !o !q 1 1 "01";
	     solve s !z !o !q 1 1 "10";
	     solve s !z !o !q 0 2 "11";
	 | '?', _ ->
	     solve s !z !o !q (!z2 + 1) !o2 ("0" ^ String.make 1 s.[n - 1]);
	     solve s !z !o !q !z2 (!o2 + 1) ("1" ^ String.make 1 s.[n - 1]);
	 | _, '?' ->
	     solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ "0");
	     solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ "1");
	 | _ ->
	     solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);
      );
      if Hashtbl.mem ht "00" then Printf.printf "00\n";
      if Hashtbl.mem ht "01" then Printf.printf "01\n";
      if Hashtbl.mem ht "10" then Printf.printf "10\n";
      if Hashtbl.mem ht "11" then Printf.printf "11\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 z = ref 0 in
  let o = ref 0 in
  let q = ref 0 in
  let z2 = ref 0 in
  let o2 = ref 0 in
  let q2 = ref 0 in
    for i = 0 to n - 3 do
      match s.[i] with
	| '0' -> incr z
	| '1' -> incr o
	| '?' -> incr q
	| _ -> assert false
    done;
    for i = n - 2 to n - 1 do
      match s.[i] with
	| '0' -> incr z2
	| '1' -> incr o2
	| '?' -> incr q2
	| _ -> assert false
    done;
    let ht = Hashtbl.create 4 in
    let solve' s =
      let s = ref s in
      let d = ref 1 in
	while String.length !s > 2 do
	  (*Printf.printf "asd %s %d\n" !s !d;*)
	  (try
	     let i = String.index !s (Char.chr (!d + Char.code '0')) in
	       s := String.sub !s 0 i ^
		 String.sub !s (i + 1) (String.length !s - i - 1);
	   with
	     | Not_found ->
		 s := String.sub !s 1 (String.length !s - 1)
	  );
	  d := 1 - !d;
	done;
	Hashtbl.replace ht !s ()
    in
    let solve _s z o q z2 o2 tail =
      (*for d = 0 to q do
	let z = z + d
	and o = o + (q - d) in*)
	  (*Printf.printf "asd zoq %d %d %d\n" z o q;*)
	  if n mod 2 = 0 then (
	    if z + q >= o + 4
	    then solve' ("0000" ^ tail)
	    else if z + q >= o + 2
	    then solve' ("00" ^ tail);
	    if o + q >= z + 4
	    then solve' ("1111" ^ tail)
	    else if o + q >= z + 2
	    then solve' ("11" ^ tail);
	    if z <= o + q && o <= z + q
	    then Hashtbl.replace ht tail ();
	  ) else (
	    if z + q >= o + 5
	    then solve' ("00000" ^ tail)
	    else if z + q >= o + 3
	    then solve' ("000" ^ tail);
	    if o + q >= z + 5
	    then solve' ("11111" ^ tail)
	    else if o + q >= z + 3
	    then solve' ("111" ^ tail);
	    if z <= o + q + 1 && o + 1 <= z + q
	    then solve' ("0" ^ tail);
	    if z + 1 <= o + q && o <= z + 1 + q
	    then solve' ("1" ^ tail);
	  )
      (*done*)
    in
      (match s.[n - 2], s.[n - 1] with
	 | '?', '?' ->
	     solve s !z !o !q 2 0 "00";
	     solve s !z !o !q 1 1 "01";
	     solve s !z !o !q 1 1 "10";
	     solve s !z !o !q 0 2 "11";
	 | '?', _ ->
	     solve s !z !o !q (!z2 + 1) !o2 ("0" ^ String.make 1 s.[n - 1]);
	     solve s !z !o !q !z2 (!o2 + 1) ("1" ^ String.make 1 s.[n - 1]);
	 | _, '?' ->
	     solve s !z !o !q (!z2 + 1) !o2 (String.make 1 s.[n - 2] ^ "0");
	     solve s !z !o !q !z2 (!o2 + 1) (String.make 1 s.[n - 2] ^ "1");
	 | _ ->
	     solve s !z !o !q !z2 !o2 (String.sub s (n - 2) 2);
      );
      if Hashtbl.mem ht "00" then Printf.printf "00\n";
      if Hashtbl.mem ht "01" then Printf.printf "01\n";
      if Hashtbl.mem ht "10" then Printf.printf "10\n";
      if Hashtbl.mem ht "11" then Printf.printf "11\n";