Hide

Problem Y
Satisfaction Guaranteed

Consider a very simple programming language, with only three types of statements:

    if <boolean expression> then <statement list> fi

    if <boolean expression> then <statement list> else <statement list> fi

    checkpoint

All keywords are required to consist of all lower case letters. A <statement list> is obviously just a list of one or more statements, and an entire program is a single <statement list>.

A <boolean expression> consists of:

  • Variables: a single capital letter

  • Operators: unary ~ (NOT), binary & (AND), binary | (OR).

  • Operator precedence is: ~ > & > |

  • Parentheses

  • NO Spaces

Boolean expressions can be described by this grammar:

    <BE> -> ~<BE> or <BE>&<BE> or <BE>|<BE> or (<BE>) or [A-Z]

Given a syntactically correct program in this simple language, what values must the boolean variables hold in order to satisfy each of the checkpoints?

Input

Input will be a single syntactically correct program in this simple language. Keywords are guaranteed to be in all lower case, and boolean variables are guaranteed to each be a single upper case letter. White space (space, tab or newline) is guaranteed to separate keywords, and surround expressions. Expressions will not contain whitespace. Every <statement list> will contain at least one statement. The input program will not use more than $20$ of the available variables, and will not contain more than $5\, 000$ statements. No Boolean expression will be longer than $128$ characters.

Output

For each checkpoint, in the order they appear, output a single line, consisting of ’>’ followed by either a list of variables, or the word ’unreachable’. If the checkpoint is reachable, output a list of variables, in alphabetical order, with an upper case letter if it must be true, or a lower case letter if it must be false to reach the checkpoint. Omit the variable if it can be either. If the checkpoint is not reachable, then output the word ’unreachable’, entirely in lower case. Do not print any spaces, and do not print any blank lines between lines of output.

Sample Input 1 Sample Output 1
if A then
 checkpoint
 if ~A then
 checkpoint
 fi
else
 checkpoint
fi
if (A&B)|(~A&~B) then
 checkpoint
fi
if A|~A then checkpoint fi
if B then
 if ~A then checkpoint fi
fi
>A
>unreachable
>a
>
>
>aB

Please log in to submit a solution to this problem

Log in