Tautology or not?

Decide whether a formula is a tautology (true in every row), a contradiction (false in every row) or a contingency (neither).

The formula is written in Python with the letters p, q, r and s (not necessarily all of them), using and, or, not, brackets, == for ↔, != for ⊕, and <= for → (as in the previous problem).

Input

One line: the formula.

Output

TAUTOLOGY, CONTRADICTION or CONTINGENCY.

Examples

Example 1 · Input
p or not p
Expected output
TAUTOLOGY
Example 2 · Input
p <= q
Expected output
CONTINGENCY

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

itertools.product([True, False], repeat=4) gives all 16 rows of p, q, r and s.

Hint 2

A letter that does not appear in the formula does not change its value, so testing all four letters always works.

Hint 3

all(values) means a tautology; not any(values) means a contradiction.

Solution

Show one correct solution (try it yourself first)
from itertools import product

formula = input()
values = [eval(formula, dict(zip("pqrs", row))) for row in product([True, False], repeat=4)]
if all(values):
    print("TAUTOLOGY")
elif not any(values):
    print("CONTRADICTION")
else:
    print("CONTINGENCY")

Lesson: Logical equivalence →