type hand = Rock | Paper | Scissors

type result = Win | Lose | Draw

module HandSet = Set.Make (
                     struct
                       type t = hand
                       let compare (a : hand) b = compare a b
                     end)

let hand_of_int = function
  | 1 -> Some Rock
  | 2 -> Some Paper
  | 3 -> Some Scissors
  | _ -> None

let int_of_result = function
  | Win -> 1
  | Lose -> 2
  | Draw -> 3

exception BreakLoop

let read_hands () =
  try
    let hands = Array.init
                  5
                  (fun _ -> match read_int () |> hand_of_int with
                            | None -> raise BreakLoop
                            | Some hand -> hand) in
    Some (Array.to_list hands)
  with BreakLoop -> None

let match_ hands =
  let set = HandSet.of_list hands in
  if HandSet.cardinal set <> 2 then Array.make 5 Draw |> Array.to_list
  else
    let defeats a b =
      match a, b with
      | Rock, Paper -> false
      | Rock, Scissors -> true
      | Paper, Rock -> true
      | Paper, Scissors -> false
      | Scissors, Rock -> false
      | Scissors, Paper -> true
      | _ -> invalid_arg "defeats" in
    List.map
      (fun hand ->
       let match_ = HandSet.remove hand set |> HandSet.choose in
       if defeats hand match_ then Win else Lose)
      hands

let rec solve () =
  match read_hands () with
  | None -> ()
  | Some hands ->
     let results = match_ hands in
     List.iter
       (fun result ->
        int_of_result result |> print_int;
        print_newline ())
       results;
     solve ()

let () = solve ()