structure Bag = struct datatype 'a tree = Leaf | Node of 'a * int * 'a tree * 'a tree val empty = Leaf fun size Leaf = 0 | size (Node (k, v, left, right)) = 1 + size left + size right fun add Leaf newKey = Node (newKey, 1, Leaf, Leaf) | add (Node (nodeKey, nodeValue, left, right)) newKey = if nodeKey = newKey then (Node (nodeKey, nodeValue + 1, left, right)) else if nodeKey < newKey then Node (nodeKey, nodeValue, left, add right newKey) else Node (nodeKey, nodeValue, add left newKey, right) fun fromList l = List.foldl (fn (x, acc) => add acc x) empty l fun values Leaf = [] | values (Node (_, v, left, right)) = [v] @ values left @ values right end fun readInt () = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn) fun quicksort [] = [] | quicksort (h::tl) = let val (s, b) = List.foldl (fn (x, (small, big)) => if x <= h then (x::small, big) else (small, x::big)) ([], []) tl in (quicksort s) @ [h] @ (quicksort b) end fun findAns [3, 2] = "FULL HOUSE" | findAns (3::_) = "THREE CARD" | findAns [2, 2, 1] = "TWO PAIR" | findAns (2::_) = "ONE PAIR" | findAns _ = "NO HAND" val () = let val a1 = readInt () val a2 = readInt () val a3 = readInt () val a4 = readInt () val a5 = readInt () val bag = Bag.fromList [a1, a2, a3, a4, a5] val cards = List.rev (quicksort (Bag.values bag)) val ans = findAns cards in print (ans ^ "\n") end