{- Author: Robin Nittka -}
{-# OPTIONS_GHC -O2 #-}

module Main
	where

import System.IO
import Data.Maybe

ops :: [(String, Int -> Int -> Bool)]
ops = [
		("=", (==)),
		("<=", (<=)),
		(">=", (>=)),
		("<", (<)),
		(">", (>))
	]

parse :: [String] -> (String, Int)
parse [p,v] = (p, round $ (10 * ) $ read v)

split :: String -> ([String], String, String)
split line = (map snd $ filter (odd . fst) $ zip [1..] c, b, a)
	where ([a,b],c) = splitAt 2 $ reverse $ words line

judge :: [(String, Int)] -> ([String], String, String) -> Bool
judge table (ps, op, val) = (fromJust $ lookup op ops) (foldl1 (+) $ map (fromJust . (flip lookup) table) ps) ((*10) $ read $ val)

main :: IO ()
main = do
	file <- openFile "ballot.in" ReadMode
	(pre:input) <- hGetContents file >>= return . lines
	let [p,g] = map read $ words $ pre
	let (parties,guesses) = splitAt p input
	let table = map (parse . words) parties
	let statements = map (judge table . split) guesses
	mapM_ output $ zip [1..] statements
		where output (i,b) = putStrLn $ "Guess #" ++ show i ++ " was " ++ (if b then "" else "in") ++ "correct."
