open Scanf;;
scanf "%d %d\n" (fun n m ->
  let mat=Array.make_matrix n m 0 in
  let set i j x= mat.(i).(j) <- x in
  for i=0 to n-1 do
    for j=0 to m-2 do
      scanf "%d " (set i j)
    done;
    scanf "%d\n" (set i (m-1))
  done;
  let all_N' = List.fold_left (fun f x->f&&x>0) true in
  let rec r_to_list x j=
    if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in
  let rec c_to_list y i=
    if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in
  let test_r r=r_to_list r 0 |> all_N' in
  let test_c c=c_to_list c 0 |> all_N' in
  let do_r r=
    for j=0 to m-1 do
      mat.(r).(j)<-mat.(r).(j)-1
    done; "row "^(string_of_int (r+1)) in
  let do_c c=
    for i=0 to n-1 do
      mat.(i).(c)<-mat.(i).(c)-1
    done; "col "^(string_of_int (c+1)) in
  let solve() =
    let rec solve_r r acc=match test_r r with
    | true -> solve_r r (do_r r ::acc)
    | false -> if r=n-1 then acc else solve_r (r+1) acc in
    let rec solve_c c acc=match test_c c with
    | true -> solve_c c (do_c c ::acc)
    | false -> if c=m-1 then acc else solve_c (c+1) acc in
    if n>m then solve_r 0 [] @ solve_c 0 [] else solve_c 0 [] @ solve_r 0 [] in
  let flag_N'=ref false in
  let test_N'() =
    for i=0 to n-1 do
      for j=0 to m-1 do
        if mat.(i).(j)>0 then flag_N':=true
      done
    done in
  let write l=
    let rec print_list =function
    | [] -> ()
    | h :: t -> print_endline h;print_list t in
    print_int (List.length l);
    print_newline();
    print_list l in
  let ans=solve() in
    test_N'();
    if !flag_N' then print_endline "-1" else write ans
)

open Scanf;;
scanf "%d %d" (fun n m ->
  let mat=Array.make_matrix n m 0 in
  for i=0 to n-1 do
    for j=0 to m-1 do
      scanf " %d" (fun x->mat.(i).(j) <- x)
    done;
  done;
  let all_N' =List.for_all (fun x->x>0) in
  let rec r_to_list x j=
    if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in
  let rec c_to_list y i=
    if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in
  let test_r r=r_to_list r 0 |> all_N' and test_c c=c_to_list c 0 |> all_N' in
  let dec i j = mat.(i).(j)<-mat.(i).(j)-1 in
  let do_r r=
    for j=0 to m-1 do
      dec r j
    done; "row "^(string_of_int (r+1))
  and do_c c=
    for i=0 to n-1 do
      dec i c
    done; "col "^(string_of_int (c+1)) in
  let solve() =
    let rec solve_r r acc=match test_r r with
    | true -> solve_r r (do_r r ::acc)
    | false -> if r=n-1 then acc else solve_r (r+1) acc
    and solve_c c acc=match test_c c with
    | true -> solve_c c (do_c c ::acc)
    | false -> if c=m-1 then acc else solve_c (c+1) acc in
    if n<m then let rl=solve_r 0 [] in let cl= solve_c 0 [] in rl@cl
      else let cl=solve_c 0 [] in let rl= solve_r 0 [] in rl@cl in
  let flag_N'=ref false in
  let test_N'() =
    for i=0 to n-1 do
      for j=0 to m-1 do
        if mat.(i).(j)>0 then flag_N':=true
      done
    done in
  let write l=
    let rec print_list =function
    | [] -> ()
    | h :: t -> print_endline h;print_list t in
    print_int (List.length l);
    print_newline();
    print_list l in
  let ans=solve() in
    test_N'();
    if !flag_N' then print_endline "-1" else write ans
)

open Scanf;;
scanf "%d %d\n" (fun n m ->
  let mat=Array.make_matrix n m 0 in
  let set i j x= mat.(i).(j) <- x in
  for i=0 to n-1 do
    for j=0 to m-2 do
      scanf "%d " (set i j)
    done;
    scanf "%d\n" (set i (m-1))
  done;
  let has_N' = List.fold_left (fun f x->f&&x>0) true in
  let rec r_to_list x j=
    if j=m-1 then [] else mat.(x).(j) :: r_to_list x (j+1) in
  let rec c_to_list y i=
    if i=n-1 then [] else mat.(i).(y) :: c_to_list y (i+1) in
  let test_r r=r_to_list r 0 |> has_N' in
  let test_c c=c_to_list c 0 |> has_N' in
  let do_r r=
    for j=0 to m-1 do
      mat.(r).(j)<-mat.(r).(j)-1
    done; "row "^(string_of_int (r+1)) in
  let do_c c=
    for i=0 to n-1 do
      mat.(i).(c)<-mat.(i).(c)-1
    done; "col "^(string_of_int (c+1)) in
  let do_point_rf r c =match test_r r, test_c c with
    | true ,_ -> do_r r
    | _ , true -> do_c c
    | _  ->raise Not_found  in
  let do_point_cf r c =match test_r r, test_c c with
    | _ , true -> do_c c
    | true ,_ -> do_r r
    | _  ->raise Not_found  in
  let do_point r c = if r<c then do_point_rf r c else do_point_cf r c in
  let next =function
    |r,c when r=n-1 && c=m-1 -> (-1,-1)
    |r,c when c=m-1 -> (r+1,0)
    |r,c -> (r,c+1) in
  let test_point r c = mat.(r).(c)>0 in
  let solve() =
    let rec solve_inn r c acc=match test_point r c with
    | true -> solve_inn r c (do_point r c ::acc)
    | false ->
      match next (r,c) with
      | -1,-1 ->acc
      | nr,nc ->solve_inn nr nc acc  in solve_inn 0 0 [] in
  let write l=
    let rec print_list =function
    | [] -> ()
    | h :: t -> print_endline h;print_list t in
    print_int (List.length l);
    print_newline();
    print_list l in
  try write (solve()) with
    Not_found -> print_endline "-1"
)

open Scanf;;
scanf "%d %d\n" (fun n m ->
  let mat=Array.make_matrix n m 0 in
  let set i j x= mat.(i).(j) <- x in
  for i=0 to n-1 do
    for j=0 to m-2 do
      scanf "%d " (set i j)
    done;
    scanf "%d\n" (set i (m-1))
  done;
  let all_N' = List.fold_left (fun f x->f&&x>0) true in
  let rec r_to_list x j=
    if j=m then [] else mat.(x).(j) :: r_to_list x (j+1) in
  let rec c_to_list y i=
    if i=n then [] else mat.(i).(y) :: c_to_list y (i+1) in
  let test_r r=r_to_list r 0 |> all_N' in
  let test_c c=c_to_list c 0 |> all_N' in
  let do_r r=
    for j=0 to m-1 do
      mat.(r).(j)<-mat.(r).(j)-1
    done; "row "^(string_of_int (r+1)) in
  let do_c c=
    for i=0 to n-1 do
      mat.(i).(c)<-mat.(i).(c)-1
    done; "col "^(string_of_int (c+1)) in
  let solve() =
    let rec solve_r r acc=match test_r r with
    | true -> solve_r r (do_r r ::acc)
    | false -> if r=n-1 then acc else solve_r (r+1) acc in
    let rec solve_c c acc=match test_c c with
    | true -> solve_c c (do_c c ::acc)
    | false -> if c=m-1 then acc else solve_c (c+1) acc in
    if n<m then solve_r 0 [] @ solve_c 0 [] else solve_c 0 [] @ solve_r 0 [] in
  let flag_N'=ref false in
  let test_N'() =
    for i=0 to n-1 do
      for j=0 to m-1 do
        if mat.(i).(j)>0 then flag_N':=true
      done
    done in
  let write l=
    let rec print_list =function
    | [] -> ()
    | h :: t -> print_endline h;print_list t in
    print_int (List.length l);
    print_newline();
    print_list l in
  let ans=solve() in
    test_N'();
    if !flag_N' then print_endline "-1" else write ans
)

open Scanf;;
scanf "%d %d\n" (fun n m ->
  let mat=Array.make_matrix n m 0 in
  let set i j x= mat.(i).(j) <- x in
  for i=0 to n-1 do
    for j=0 to m-2 do
      scanf "%d " (set i j)
    done;
    scanf "%d\n" (set i (m-1))
  done;
  let has_N' = List.fold_left (fun f x->f&&x>0) true in
  let rec r_to_list x j=
    if j=m-1 then [] else mat.(x).(j) :: r_to_list x (j+1) in
  let rec c_to_list y i=
    if i=n-1 then [] else mat.(i).(y) :: c_to_list y (i+1) in
  let test_r r=r_to_list r 0 |> has_N' in
  let test_c c=c_to_list c 0 |> has_N' in
  let do_r r=
    for j=0 to m-1 do
      mat.(r).(j)<-mat.(r).(j)-1
    done; "row "^(string_of_int (r+1)) in
  let do_c c=
    for i=0 to n-1 do
      mat.(i).(c)<-mat.(i).(c)-1
    done; "col "^(string_of_int (c+1)) in
  let do_point r c =match test_r r, test_c c with
    | true ,_ -> do_r r
    | _ , true -> do_c c
    | _  ->raise Not_found  in
  let next =function
    |r,c when r=n-1 && c=m-1 -> (-1,-1)
    |r,c when c=m-1 -> (r+1,0)
    |r,c -> (r,c+1) in
  let test_point r c = mat.(r).(c)>0 in
  let solve() =
    let rec solve_inn r c acc=match test_point r c with
    | true -> solve_inn r c (do_point r c ::acc)
    | false ->
      match next (r,c) with
      | -1,-1 ->acc
      | nr,nc ->solve_inn nr nc acc  in solve_inn 0 0 [] in
  let write l=
    let rec print_list =function
    | [] -> ()
    | h :: t -> print_endline h;print_list t in
    print_int (List.length l);
    print_newline();
    print_list l in
  try write (solve()) with
    Not_found -> print_endline "-1"
)


open Scanf
open Printf

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

type 'a employee = 'a * 'a list (*int is employee's immediate manager; int list are her subordinates*)

let a = Array.make (n+1) (0,[]);;

let manager (z:int employee) =
  match z with
  | (i,_) -> i

let subo (z:int employee) =
  match z with
  | (_,il) -> il

let adds (t:int employee) x =
  match t with
  (_,z) -> x::z

for i = 1 to n do
  let j = Scanf.scanf "%d " ( fun x -> x ) in
  if j = -1 then
    begin
      let il = subo a.(i) in
      let i2 = adds a.(0) i in
      a.(i) <- (manager a.(i),il); a.(0) <- (manager a.(0),i2)
    end
  else
    begin
      a.(i) <- (j,subo a.(i)); a.(j) <- (manager a.(j), adds a.(j) i)
    end
done

(*
let printe (z:int employee) =
  match z with
  | (i,il) -> printf "%d " i; List.iter (fun x -> printf "%d " x) il

let () = printe a.(11)

let () = print_endline ""
*)

let rec height (z:int employee) =
  match z with
  |(_,[]) -> 1
  |(_,il) ->
      List.fold_right (fun x y -> max x y)
      ( List.map (fun i -> 1 + (height a.(i))) il) (-1)
in
let m = height a.(0) in
printf "%d\n" (m-1)

type tree = Leaf of int
          | Node of tree list

let rec makeList numList num =
  match numList with
  | h :: t -> (num, h) :: (makeList t (num+1))
  | _ -> []

let rec findOrigin numList =
  match numList with
  | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)
                    else findOrigin t
  | _ -> []

let rec findNum numList num =
  match numList with
  | (h, n) :: t -> if (n == num) then h :: (findNum t num)
                    else findNum t num
  | _ -> []

let makeTree numList =
  let originList = findOrigin numList in
  let rec makeList nList =
    match nList with
    | h :: t ->
      let newList = findNum numList h in
      Node(Leaf(h) :: makeList newList) :: (makeList t)
    | _ -> [] in
  makeList originList

let nodeCount tree =
  let rec node tree count =
    match tree with
    | Node(h::t) :: tail ->
      let c = node (h::t) (count+1) in
      c @ (node tail count)
    | Leaf(h) :: t ->
      node t count
    | _ -> count ::[] in
  let countList = node tree 1 in
  let rec maxCount cList max =
    match cList with
    | h :: t -> if (max > h) then maxCount t max
                else maxCount t h
    | _ -> max in
  maxCount countList 1

let printLeaf leaf =
  match leaf with
  | Leaf(h) -> let _ = print_string ("Leaf ") in
    let _ = print_int h in
    print_string " "
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node(h :: t) :: tail -> let _ = print_string ("[Node ") in
    let _ = printLeaf h in
    let _ = printNode t in
    let _ = print_string "] " in
    printNode tail
  | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in
    printNode tail
  | _ -> print_string " "

let num = read_int()

let rec inputList num =
  if (num != 0) then
    let k = read_int() in
    k :: (inputList (num-1))
  else
    []
let numList = makeList (inputList num) 1
let k = makeTree numList
(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1

let k = makeTree numList

let _ = printNode k

let _ = print_string"\n\n"
*)
let _ = print_int((nodeCount k)-1)

type tree = Leaf of int
          | Node of tree list

let rec makeList numList num =
  match numList with
  | h :: t -> (num, h) :: (makeList t (num+1))
  | _ -> []

let rec findOrigin numList =
  match numList with
  | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)
                    else findOrigin t
  | _ -> []

let rec findNum numList num =
  match numList with
  | (h, n) :: t -> if (n == num) then h :: (findNum t num)
                    else findNum t num
  | _ -> []

let makeTree numList =
  let originList = findOrigin numList in
  let rec makeList nList =
    match nList with
    | h :: t ->
      let newList = findNum numList h in
      Node(Leaf(h) :: makeList newList) :: (makeList t)
    | _ -> [] in
  makeList originList

let nodeCount tree =
  let rec node tree count =
    match tree with
    | Node(h::t) :: tail ->
      let c = node (h::t) (count+1) in
      c @ (node tail count)
    | Leaf(h) :: t ->
      node t count
    | _ -> count ::[] in
  let countList = node tree 1 in
  let rec maxCount cList max =
    match cList with
    | h :: t -> if (max > h) then maxCount t max
                else maxCount t h
    | _ -> max in
  let rec printList m =
    match m with
    | h :: t -> let _ = print_int h in
    let _ = print_string " " in
      printList t
    | _ -> print_string " \n\n" in
  let _ = printList countList in
  maxCount countList 1

let printLeaf leaf =
  match leaf with
  | Leaf(h) -> let _ = print_string ("Leaf ") in
    let _ = print_int h in
    print_string " "
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node(h :: t) :: tail -> let _ = print_string ("[Node ") in
    let _ = printLeaf h in
    let _ = printNode t in
    let _ = print_string "] " in
    printNode tail
  | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in
    printNode tail
  | _ -> print_string " "

let num = read_int()

let rec inputList num =
  if (num != 0) then
    let k = read_int() in
    k :: (inputList (num-1))
  else
    []
let numList = makeList (inputList num) 1
let k = makeTree numList
(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1

let k = makeTree numList

let _ = printNode k

let _ = print_string"\n\n"
*)
let _ = print_int((nodeCount k)-1)

type tree = Leaf of int
          | Node of tree list

let rec makeList numList num =
  match numList with
  | h :: t -> (num, h) :: (makeList t (num+1))
  | _ -> []

let rec findOrigin numList =
  match numList with
  | (h, n) :: t -> if (n == -1) then h :: (findOrigin t)
                    else findOrigin t
  | _ -> []

let rec findNum numList num =
  match numList with
  | (h, n) :: t -> if (n == num) then h :: (findNum t num)
                    else findNum t num
  | _ -> []

let makeTree numList =
  let originList = findOrigin numList in
  let rec makeList nList =
    match nList with
    | h :: t ->
      let newList = findNum numList h in
      Node(Leaf(h) :: makeList newList) :: (makeList t)
    | _ -> [] in
  makeList originList

let nodeCount tree =
  let rec node tree count =
    match tree with
    | Node(h::t) :: tail ->
      let c = node t count in
      c @ (node t (count+1))
    | _ -> count ::[] in
  let countList = node tree 1 in
  let rec maxCount cList max =
    match cList with
    | h :: t -> if (max > h) then maxCount t max
                else maxCount t h
    | _ -> max in
  maxCount countList 1

let printLeaf leaf =
  match leaf with
  | Leaf(h) -> let _ = print_string ("Leaf ") in
    let _ = print_int h in
    print_string " "
  | _ -> print_string " "

let rec printNode node =
  match node with
  | Node(h :: t) :: tail -> let _ = print_string ("[Node ") in
    let _ = printLeaf h in
    let _ = printNode t in
    let _ = print_string "] " in
    printNode tail
  | Leaf(h) :: tail -> let _ = printLeaf (Leaf(h)) in
    printNode tail
  | _ -> print_string " "

let num = read_int()

let rec inputList num =
  if (num != 0) then
    let k = read_int() in
    k :: (inputList (num-1))
  else
    []
let numList = makeList (inputList num) 1
let k = makeTree numList

(*let numList = makeList (-1::1::2::3::2::5::1::[]) 1

let k = makeTree numList

let _ = printNode k

let _ = print_string"\n\n"
*)
let _ = print_int((nodeCount k)-1)

open Scanf
open Printf

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

type 'a employee = 'a * 'a list (*int is employee's immediate manager; int list are her subordinates*)

let a = Array.make (n+1) (0,[]);;

let manager (z:int employee) =
  match z with
  | (i,_) -> i

let subo (z:int employee) =
  match z with
  | (_,il) -> il

let adds (t:int employee) x =
  match t with
  (_,z) -> x::z

for i = 1 to n do
  let j = Scanf.scanf "%d " ( fun x -> x ) in
  if j = -1 then
    begin
      let il = subo a.(i) in
      let i2 = adds a.(0) i in
      a.(i) <- (0,il); a.(0) <- (0,i2)
    end
  else
    begin
      a.(i) <- (j,[]); a.(j) <- (manager a.(j), adds a.(j) i)
    end
done

(*
let printe (z:int employee) =
  match z with
  | (i,il) -> printf "%d " i; List.iter (fun x -> printf "%d " x) il

let () = printe a.(0)
*)

let rec height (z:int employee) =
  match z with
  |(_,[]) -> 1
  |(_,il) ->
      List.fold_right (fun x y -> max x y)
      ( List.map (fun i -> 1 + (height a.(i))) il) (-1)
in
let m = height a.(0) in
printf "%d\n" (m-1)


(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type sgn = POS | NEG;;
let mul x y = match (x, y) with
	| (POS, x) -> x
	| (NEG, POS) -> NEG
	| (NEG, NEG) -> POS
;;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (sgn * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (POS, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (NEG, (a, b)))
	| a::b::l -> (
		let x = xy a in
		let y = xy b in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (POS, (a, b)))::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (NEG, (a, b)))::l)
		else (
			let c::l = l in
			let z = xy c in
			if (r (plus x z)) <= 1000000000000L then
				fix (Combine((plus x z), (POS, (a, c)))::b::l)
			else if (r (minus x z)) <= 1000000000000L then
				fix (Combine((minus x z), (NEG, (a, c)))::b::l)
			else if (r (plus y z)) <= 1000000000000L then
				fix (Combine((plus y z), (POS, (b, c)))::a::l)
			else if (r (minus y z)) <= 1000000000000L then
				fix (Combine((minus y z), (NEG, (b, c)))::a::l)
			else
				failwith "lochas"
		)
	)
;;
let ret = Array.make n NEG;;
let rec find w l = match l with
	| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2
;;
find POS (fix (read 0));;
Array.iter (fun x -> match x with POS -> puts "1 " | NEG -> puts "-1 ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (int * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (1, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (-1, (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (1, (a, b)))::c::l)
		else if (r (plus x z)) <= 1000000000000L then
			fix (Combine((plus x z), (1, (a, c)))::b::l)
		else if (r (plus y z)) <= 1000000000000L then
			fix (Combine((plus y z), (1, (b, c)))::a::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (-1, (a, b)))::c::l)
		else if (r (minus x z)) <= 1000000000000L then
			fix (Combine((minus x z), (-1, (a, c)))::b::l)
		else if (r (minus y z)) <= 1000000000000L then
			fix (Combine((minus y z), (-1, (b, c)))::a::l)
		else
			failwith "lochas"
	)
;;
let ret = Array.make n 0;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2
;;
let c = fix (read 0);;
let (x, y) = xy c;;
find 1 c;;
Array.iter (fun x -> if x = 1 then puts "1 " else puts "-1 ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
open Printf
open Scanf
let scan_int() = bscanf Scanning.stdib " %d " (fun x -> x);;
let print_int x = printf "%d" x;;
let puts s = printf s;;
let n = scanf "%d" (fun x -> x);;
type sgn = POS | NEG;;
let mul x y = match (x, y) with
	| (POS, x) -> x
	| (NEG, POS) -> NEG
	| (NEG, NEG) -> POS
;;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (sgn * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (POS, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (NEG, (a, b)))
	| a::b::l -> (
		let x = xy a in
		let y = xy b in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (POS, (a, b)))::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (NEG, (a, b)))::l)
		else (
			let c::l = l in
			let z = xy c in
			if (r (plus x z)) <= 1000000000000L then
				fix (Combine((plus x z), (POS, (a, c)))::b::l)
			else if (r (minus x z)) <= 1000000000000L then
				fix (Combine((minus x z), (NEG, (a, c)))::b::l)
			else
				fix ((
					if (r (plus y z)) <= 1000000000000L then
						Combine((plus y z), (POS, (b, c)))
					else
						Combine((minus y z), (NEG, (b, c)))
				)::a::l)
		)
	)
;;
let ret = Array.make n NEG;;
let rec find w l = match l with
	| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2
;;
find POS (fix (read 0));;
Array.iter (fun x -> match x with POS -> puts "1 " | NEG -> puts "-1 ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * ((int * int) * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> Leaf((-1, -1), -1)
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), ((1, 1), (a, b)))
		else
			Combine((minus (xy a) (xy b)), ((1, -1), (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), ((1, 1), (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), ((1, 1), (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), ((1, 1), (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), ((1, -1), (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), ((1, -1), (a, c)))::b::l)
		else if ryzm = rmin then
			fix (Combine((minus y z), ((1, -1), (b, c)))::a::l)
		else
			failwith "lochas"
	)
;;
let ret = Array.make n 0;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2
;;
let rec check l = match l with
	| Leaf((x,y), i) -> puts "(";print_int y;puts ")";
	| Combine((x, y), ((w1, w2), (l1, l2)))->
	puts "(";
	check l1;
	puts (if(w2==1) then "+" else "-");
	check l2;
	puts ")";
;;
let c = fix (read 0);;
if r (xy c) > (Int64.mul 1500000L 1500000L)
	then failwith "Oh shit";;
let (x, y) = xy c;;
(*Printf.printf "%d %d\n" x y;;
puts "\n";
check c;;*)
find 1 c;;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type sgn = POS | NEG;;
let mul x y = match (x, y) with
	| (POS, x) -> x
	| (NEG, POS) -> NEG
	| (NEG, NEG) -> POS
;;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (sgn * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (POS, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (NEG, (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (POS, (a, b)))::c::l)
		else if (r (plus x z)) <= 1000000000000L then
			fix (Combine((plus x z), (POS, (a, c)))::b::l)
		else if (r (plus y z)) <= 1000000000000L then
			fix (Combine((plus y z), (POS, (b, c)))::a::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (NEG, (a, b)))::c::l)
		else if (r (minus x z)) <= 1000000000000L then
			fix (Combine((minus x z), (NEG, (a, c)))::b::l)
		else if (r (minus y z)) <= 1000000000000L then
			fix (Combine((minus y z), (NEG, (b, c)))::a::l)
		else
			failwith "lochas"
	)
;;
let ret = Array.make n NEG;;
let rec find w l = match l with
	| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2
;;
let c = fix (read 0);;
let (x, y) = xy c;;
find POS c;;
Array.iter (fun x -> match x with POS -> puts "1 " | NEG -> puts "-1 ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type sgn = POS | NEG;;
let mul x y = match (x, y) with
	| (POS, x) -> x
	| (NEG, POS) -> NEG
	| (NEG, NEG) -> POS
;;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (sgn * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (POS, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (NEG, (a, b)))
	| a::b::l -> (
		let x = xy a in
		let y = xy b in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (POS, (a, b)))::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (NEG, (a, b)))::l)
		else (
			let c::l = l in
			let z = xy c in
			if (r (plus x z)) <= 1000000000000L then
				fix (Combine((plus x z), (POS, (a, c)))::b::l)
			else if (r (minus x z)) <= 1000000000000L then
				fix (Combine((minus x z), (NEG, (a, c)))::b::l)
			else
				fix ((
					if (r (plus y z)) <= 1000000000000L then
						Combine((plus y z), (POS, (b, c)))
					else
						Combine((minus y z), (NEG, (b, c)))
				)::a::l)
		)
	)
;;
let ret = Array.make n NEG;;
let rec find w l = match l with
	| Leaf(_, i) -> (match w with POS -> (ret.(i) <- POS) | NEG -> ())
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (mul w w2) l2
;;
find POS (fix (read 0));;
Array.iter (fun x -> match x with POS -> puts "1 " | NEG -> puts "-1 ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (int * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (1, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (-1, (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		if (r (plus x y)) <= 1000000000000L then
			fix (Combine((plus x y), (1, (a, b)))::c::l)
		else if (r (plus x z)) <= 1000000000000L then
			fix (Combine((plus x z), (1, (a, c)))::b::l)
		else if (r (plus y z)) <= 1000000000000L then
			fix (Combine((plus y z), (1, (b, c)))::a::l)
		else if (r (minus x y)) <= 1000000000000L then
			fix (Combine((minus x y), (-1, (a, b)))::c::l)
		else if (r (minus x z)) <= 1000000000000L then
			fix (Combine((minus x z), (-1, (a, c)))::b::l)
		else if (r (minus y z)) <= 1000000000000L then
			fix (Combine((minus y z), (-1, (b, c)))::a::l)
		else
			failwith "lochas"
	)
;;
let ret = Array.make n 0;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2
;;
let c = fix (read 0);;
let (x, y) = xy c;;
find 1 c;;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = Scanf.scanf "%d" (fun x -> x);;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * (int * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		let x = scan_int() in
		let y = scan_int() in
		Leaf((x, y), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a <= c then a else c
;;
let rec fix l = match l with
	| [] -> failwith "empty list"
	| [a] -> a
	| [a; b] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), (1, (a, b)))
		else
			Combine((minus (xy a) (xy b)), (-1, (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), (1, (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), (1, (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), (1, (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), (-1, (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), (-1, (a, c)))::b::l)
		else if ryzm = rmin then
			fix (Combine((minus y z), (-1, (b, c)))::a::l)
		else
			failwith "lochas"
	)
;;
let ret = Array.make n 0;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, (w2, (l1, l2))) -> find w l1;find (w * w2) l2
;;
let c = fix (read 0);;
let (x, y) = xy c;;
find 1 c;;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
1000000 0
0 1000000
1000000 0
0 1000000
1000000 0
0 1000000
1000000 0
0 1000000
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = scan_int();;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * ((int * int) * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		Leaf((scan_int(), scan_int()), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a < c then a else c
;;
let rec fix l = match l with
	| [] -> Leaf((-1, -1), -1)
	| [Leaf(x, y)] -> Leaf(x, y)
	| [Combine(x, y)] -> Combine(x, y)
	| a::b::[] ->
		if ((r (plus (xy a) (xy b)))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), ((1, 1), (a, b)))
		else
			Combine((minus (xy a) (xy b)), ((1, -1), (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), ((1, 1), (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), ((1, 1), (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), ((1, 1), (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), ((1, -1), (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), ((1, -1), (a, c)))::b::l)
		else
			fix (Combine((minus y z), ((1, -1), (b, c)))::a::l)
	)
;;
let ret = Array.make n 1;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2
;;
let c = fix (read 0);;
if r (xy c) > (Int64.mul 1500000L 1500000L)
	then failwith "Oh shit";;
find 1 c;;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = scan_int();;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * ((int * int) * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		Leaf((scan_int(), scan_int()), i)::(read (i + 1));;
let r (x, y) = x * x + y * y;;
let rec min l = match l with
	| [] -> failwith "empty list minimum"
	| [x] -> x
	| a::b -> let c = (min b) in if a < c then a else c
;;
let rec fix l = match l with
	| [] -> Leaf((-1, -1), -1)
	| [Leaf(x, y)] -> Leaf(x, y)
	| [Combine(x, y)] -> Combine(x, y)
	| a::b::[] ->
		if (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), ((1, 1), (a, b)))
		else
			Combine((minus (xy a) (xy b)), ((1, -1), (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), ((1, 1), (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), ((1, 1), (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), ((1, 1), (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), ((1, -1), (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), ((1, -1), (a, c)))::b::l)
		else
			fix (Combine((minus y z), ((1, -1), (b, c)))::a::l)
	)
;;
let ret = Array.make n 1;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2
;;
find 1 (fix (read 0));;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = scan_int();;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * ((int * int) * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		Leaf((scan_int(), scan_int()), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list"
	| [x] -> x
	| a::b -> let c = (min b) in if a < c then a else c
;;
let rec fix l = match l with
	| [] -> Leaf((-1, -1), -1)
	| [Leaf(x, y)] -> Leaf(x, y)
	| [Combine(x, y)] -> Combine(x, y)
	| a::b::[] ->
		if (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), ((1, 1), (a, b)))
		else
			Combine((minus (xy a) (xy b)), ((1, -1), (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), ((1, 1), (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), ((1, 1), (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), ((1, 1), (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), ((1, -1), (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), ((1, -1), (a, c)))::b::l)
		else
			fix (Combine((minus y z), ((1, -1), (b, c)))::a::l)
	)
;;
let ret = Array.make n 1;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2
;;
let c = fix (read 0);;
let (x, y) = xy c;;
Printf.eprintf "%d %d\n" x y;;
find 1 c;;
Array.iter (fun x -> print_int x;puts " ") ret;;

(*input
8
-67761 603277
640586 -396671
46147 -122580
569609 -2112
400 914208
131792 309779
-850150 -486293
5272 721899
*)
let scan_int() = Scanf.scanf " %d" (fun x -> x);;
let print_int x = Printf.printf "%d" x;;
let puts s = Printf.printf s;;
let n = scan_int();;
type vect =
	| Leaf of (int * int) * int
	| Combine of (int * int) * ((int * int) * (vect * vect))
;;
let xy l = match l with
	| Leaf((x, y), _) -> (x, y)
	| Combine((x, y), _) -> (x, y)
;;
let plus (a, b) (x, y) = (a + x, b + y);;
let minus (a, b) (x, y) = (a - x, b - y);;
let rec read i =
	if i >= n then
		[]
	else
		Leaf((scan_int(), scan_int()), i)::(read (i + 1));;
let r (x, y) =
	let a = Int64.of_int x in
	let b = Int64.of_int y in
	Int64.add (Int64.mul a a) (Int64.mul b b)
;;
let rec min l = match l with
	| [] -> failwith "empty list minimum"
	| [x] -> x
	| a::b -> let c = (min b) in if a < c then a else c
;;
let rec fix l = match l with
	| [] -> Leaf((-1, -1), -1)
	| [Leaf(x, y)] -> Leaf(x, y)
	| [Combine(x, y)] -> Combine(x, y)
	| a::b::[] ->
		if (r (plus (xy a) (xy b))) < (r (minus (xy a) (xy b))) then
			Combine((plus (xy a) (xy b)), ((1, 1), (a, b)))
		else
			Combine((minus (xy a) (xy b)), ((1, -1), (a, b)))
	| a::b::c::l -> (
		let x = xy a in
		let y = xy b in
		let z = xy c in
		let rxyp = r (plus x y) in
		let rxzp = r (plus x z) in
		let ryzp = r (plus y z) in
		let rxym = r (minus x y) in
		let rxzm = r (minus x z) in
		let ryzm = r (minus y z) in
		let rmin = min [rxyp; rxzp; ryzp; rxym; rxzm; ryzm] in
		if rxyp = rmin then
			fix (Combine((plus x y), ((1, 1), (a, b)))::c::l)
		else if rxzp = rmin then
			fix (Combine((plus x z), ((1, 1), (a, c)))::b::l)
		else if ryzp = rmin then
			fix (Combine((plus y z), ((1, 1), (b, c)))::a::l)
		else if rxym = rmin then
			fix (Combine((minus x y), ((1, -1), (a, b)))::c::l)
		else if rxzm = rmin then
			fix (Combine((minus x z), ((1, -1), (a, c)))::b::l)
		else
			fix (Combine((minus y z), ((1, -1), (b, c)))::a::l)
	)
;;
let ret = Array.make n 1;;
let rec find w l = match l with
	| Leaf(_, i) -> (ret.(i) <- w)
	| Combine(_, ((w1, w2), (l1, l2))) -> find (w * w1) l1;find (w * w2) l2
;;
find 1 (fix (read 0));;
Array.iter (fun x -> print_int x;puts " ") ret;;


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

let () =
	let n = read_int ()
	and suma = ref 0
	and mini = ref 10007
	and maxi = ref (-10007) in

	for i = 1 to n do
		let a = read_int () in
		if a > 0 then begin
			suma := !suma + a;
			if a mod 2 = 1 then
				mini := min !mini a
		end else if abs (a mod 2) = 1 then
			maxi := max !maxi a;
	done;

	if !suma mod 2 = 1 then
		printf "%d\n" !suma
	else
		printf "%d\n" (max (!suma - !mini) (!suma + !maxi))

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 read_int in
    let sum = Array.fold_left (fun acc x -> if x > 0 then acc + x else acc) 0 a in
    let max_neg = Array.fold_left (fun acc x -> if x < 0 && abs x mod 2 = 1 then max acc x else acc) (-1000000000) a in
    let min_pos = Array.fold_left (fun acc x -> if x > 0 && abs x mod 2 = 1 then min acc x else acc) (1000000000) a in
    let ans =
        if sum mod 2 = 1 then sum
        else max (sum - min_pos) (sum + max_neg) in
    printf "%d\n" ans


open Printf
open Scanf

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

let graph_cyclic edge_list =
  let map = Hashtbl.create 5 in
  let vn = ref 0 in
  let set_map u =
    if not (Hashtbl.mem map u) then (
      Hashtbl.add map u !vn;
      vn := !vn+1
    )
  in
  let get_map u = Hashtbl.find map u in
  List.iter (fun (u,v) -> set_map u; set_map v) edge_list;

  let parent = Array.make !vn (-1) in
  let rec find i = if parent.(i) < 0 then i else (
    parent.(i) <- find (parent.(i));
    parent.(i)
  ) in
  let union u v = parent.(u) <- v in

  let rec find_cycle li =
    match li with
      |	[] -> false
      | (u,v)::tail ->
	let cu = find (get_map u) in
	let cv = find (get_map v) in
	if cu = cv then true else (
	  union cu cv;
	  find_cycle tail
	)
  in
  find_cycle edge_list

let () =
  let (n,m) = read_2 () in

  let v1 = Array.make m 0 in
  let v2 = Array.make m 0 in
  let w = Array.make m 0 in

  for i=0 to m-1 do
    v1.(i) <- read_int() -1;
    v2.(i) <- read_int() -1;
    w.(i) <- read_int();
  done;

  let q = read_int() in
  let query = Array.make q ([],[[]]) in

  for i=0 to q-1 do
    let k = read_int() in
    let rec loop j ac = if j=k then ac else loop (j+1) ((read_int()-1) :: ac) in
    let qlist = loop 0 [] in

    let h = Hashtbl.create 5 in
    List.iter (fun e ->
      let li = try Hashtbl.find h w.(e) with Not_found -> [] in
      Hashtbl.replace h w.(e) (e :: li)
    ) qlist;

    query.(i) <- (qlist, Hashtbl.fold (fun _ v ac -> v::ac) h [])
    (* it's a list of lists of edges of the same weight *)
  done;

  let parent = Array.make n (-1) in
  let size = Array.make n 1 in
  let edge_no = Array.make n (-1) in

  let union a b edge =
  (* assume a and b are canonoical elements *)
    let (a,b) = if size.(a) <= size.(b) then (a,b) else (b,a) in
    parent.(a) <- b;
    size.(b) <- size.(b) + size.(a);
    edge_no.(a) <- edge
  in
  let rec find i = if parent.(i) < 0 then i else find parent.(i) in

  let perm = Array.init m (fun i -> i) in

  Array.sort (fun a b -> compare w.(a) w.(b)) perm;

  for i=0 to m-1 do
    let i = perm.(i) in
    let (a,b) = (find v1.(i), find v2.(i)) in
    if a<>b then union a b i
  done;

  for i=0 to q-1 do
    let (qlist, qlistlist) = query.(i) in
    (* first determine if the queries form a cycle *)
    let graph = List.map (fun e -> (v1.(e), v2.(e))) qlist in
    if graph_cyclic graph then printf "NO\n" else (
      let edge_set_valid es =
	let rec find_canon j ew =
	  if parent.(j) >= 0 && w.(edge_no.(j)) < ew then find_canon parent.(j) ew
	  else j
	in

	let graph = List.map (fun e -> (find_canon v1.(e) w.(e), find_canon v2.(e) w.(e))) es in
	not (graph_cyclic graph)
      in

      if List.for_all edge_set_valid qlistlist then printf "YES\n" else printf "NO\n"
    )
  done

(* keywords: union-find, MST
   Really nice problem involving understainding the MST algorithm, and
   how to use the union/find data structure without path compression.
*)

open Printf
open Scanf

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

let graph_cyclic edge_list =
  let map = Hashtbl.create 5 in
  let vn = ref 0 in
  let set_map u =
    if not (Hashtbl.mem map u) then (
      Hashtbl.add map u !vn;
      vn := !vn+1
    )
  in
  let get_map u = Hashtbl.find map u in
  List.iter (fun (u,v) -> set_map u; set_map v) edge_list;

  let parent = Array.make !vn (-1) in
  let rec find i = if parent.(i) < 0 then i else (
    parent.(i) <- find (parent.(i));
    parent.(i)
  ) in
  let union u v = parent.(u) <- v in

  let rec find_cycle li =
    match li with
      |	[] -> false
      | (u,v)::tail ->
	let cu = find (get_map u) in
	let cv = find (get_map v) in
	if cu = cv then true else (
	  union cu cv;
	  find_cycle tail
	)
  in
  find_cycle edge_list

let () =
  let (n,m) = read_2 () in

  let v1 = Array.make m 0 in
  let v2 = Array.make m 0 in
  let w = Array.make m 0 in

  for i=0 to m-1 do
    v1.(i) <- read_int() -1;
    v2.(i) <- read_int() -1;
    w.(i) <- read_int();
  done;

  let q = read_int() in
  let query = Array.make q [] in

  for i=0 to q-1 do
    let k = read_int() in
    let rec loop j ac = if j=k then ac else loop (j+1) ((read_int()-1) :: ac) in
    query.(i) <- loop 0 []
  done;

  let parent = Array.make n (-1) in
  let size = Array.make n 1 in
  let edge_no = Array.make n (-1) in

  let union a b edge =
  (* assume a and b are canonoical elements *)
    let (a,b) = if size.(a) <= size.(b) then (a,b) else (b,a) in
    parent.(a) <- b;
    size.(b) <- size.(b) + size.(a);
    edge_no.(a) <- edge
  in
  let rec find i = if parent.(i) < 0 then i else find parent.(i) in

  let perm = Array.init m (fun i -> i) in

  Array.sort (fun a b -> compare w.(a) w.(b)) perm;

  for i=0 to m-1 do
    let i = perm.(i) in
    let (a,b) = (find v1.(i), find v2.(i)) in
    if a<>b then union a b i
  done;

  for i=0 to q-1 do
    (* first determine if the queries form a cycle *)
    let graph = List.map (fun e -> (v1.(e), v2.(e))) query.(i) in
    if graph_cyclic graph then printf "NO\n" else (
      let rec find_canon j ew =
	if parent.(j) >= 0 && w.(edge_no.(j)) < ew then find_canon parent.(j) ew
	else j
      in

      let graph = List.map (fun e -> (find_canon v1.(e) w.(e), find_canon v2.(e) w.(e))) query.(i) in
      if graph_cyclic graph then printf "NO\n" else printf "YES\n"
    )
  done