{- Author: Robin Nittka  -}
module Main
	where

import System.IO
import Data.HashTable
import Data.Maybe
import Prelude hiding (lookup)

eps :: Double
eps = 10 ** (-3)

judge :: HashTable String Double -> String -> IO Bool
judge table guess = do
		real <- collect $ tail tokens
		let res = case op of
			"=" -> abs (real - g) < eps
			"<" -> real < g - eps
			">" -> real > g + eps
			"<=" -> real < g + eps
			">=" -> real > g - eps
		return res
	where
		tokens = reverse $ words guess
		op = tokens !! 1
		g = read $ head tokens
		collect [] = return 0.0
		collect (_:x:l) = do
			a <- lookup table x
			b <- collect l
			return (fromJust a+b)


main :: IO ()
main = do
	file <- openFile "ballot.in" ReadMode
	(pre:input) <- hGetContents file >>= return . lines
	let [p,g] = map read $ words $ pre
	table <- new (==) hashString
	let (parties,guesses) = splitAt p input
	sequence_ [ insert table party (read num) | [party,num] <- map words parties ]
	correct <- mapM (judge table) guesses
	mapM_ (\(i,b) -> putStrLn $ "Guess #" ++ show i ++ " was " ++ (if b then "" else "in") ++ "correct.") $ zip [1..] correct
