import Control.Monad import Data.List main = do n <- read <$> getLine :: IO Int qsr_s <- replicateM (2^n) $ map head . words <$> getLine let qsr_s_reduced = map init $ filter (('1'==) . last) qsr_s putStrLn $ "A=" ++ if length qsr_s_reduced < 2^n then genCNF (map genClause qsr_s_reduced) else "⊤" genClause :: String -> String genClause qs = concat $ intersperse "∧" $ map genLiteral $ zip qs [1..] where genLiteral :: (Char, Int) -> String genLiteral (q,i) = (if q=='0' then "¬" else "") ++ "P_" ++ show i genCNF :: [String] -> String genCNF [] = "⊥" genCNF (c:[]) = "(" ++ c ++ ")" genCNF (c:cs) = "(" ++ c ++ ")∨" ++ genCNF cs