시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB542100.000%

문제

A propositional formula is generated by the following grammar:

 <formula> ::= <variable> | ~<formula> | ( <formula> ) | <formula> <operator> <formula>
<operator> ::= ^ | V
<variable> ::= a-zA-Z (except character V)

where ‘^’ encodes boolean AND, ‘V’ encodes boolean OR.

An interpretation is a truth-assignment for all variables ocurring in a formula. The truth-value of a formula with respect to an interpretation can be determined by applying boolean operations on the values of variables, in the standard way.

Two propositional formulae are equivalent if they produce the same truth-value for all possible interpretations.

입력

The input file will contain two formulae generated by the above grammar. The formulae are separated by the newline character. Variables are encoded by alphabetic characters, except the character ‘V’ which is reserved for encoding OR . Each formula will have at most 51 variables. Whitespaces can occur freely anywhere in the input. 

출력

The output must be 1 if the two formulae are equivalent, and 0 otherwise.

예제 입력 1

x ^ y
y ^ x

예제 출력 1

1

예제 입력 2

A ^ (~y V z)
(A^~y) V (A ^ z)

예제 출력 2

1

예제 입력 3

a V (b ^ ~b) V (c ^ ~c)
a

예제 출력 3

1

예제 입력 4

~x ^ ~y
~(x V y)

예제 출력 4

1

예제 입력 5

a ^ b ^ c ^ d
a V b V c V d

예제 출력 5

0

힌트

In your implementation, you do not need to take into account operator precedence (priority). For instance, a formula such as:

x ^ y V z

will be presented as either

(x ^y) V z or
x ^ (y V z).