#P3540. Formula

Formula

Description

Nick is a mathematician and his speciality is Boolean logic, especially repetition-free functions. The Boolean function is repetition-free if it can be represented as a repetition-free formula. Formula is repetition-free if each variable occurs in the formula only once.

Let us fix the syntax of considered logical formulae:

  • Variables — letters from ‘a’ to ‘k’;
  • Parentheses — if E is a formula, then (E) is another;
  • Negation — ¬E is a formula for any formula E;
  • Conjunction — E1E2 ∧ ⋯ ∧ En;
  • Disjunction — E1E2 ∨ ⋯ ∨ En.

The operations are listed from the highest priority to the lowest.

The problem is to represent given Boolean function by a repetition-free formula.

Input

The only line of input contains the Boolean function represented as a string consisting of characters ‘a’..‘k’, ‘(’, ‘)’, ‘~’, ‘&’ and ‘|’. The last three tokens stand for ¬, ∧ and ∨ respectively. Tokens can be separated by an arbitrary number of spaces. The line contains <nobr>1 000</nobr> characters at most. The formula in the file is syntactically correct.

Output

The first line of the output file must contain “Yes” if function is repetition-free and “No” otherwise.

In the former case the following line must contain the repetition-free formula for given Boolean function in the same format as in the input file. The line must contain no more than <nobr>1 000</nobr> characters.

<table style="border-color: black; border-collapse: collapse;" border="1"><tbody><tr><th>#1</th><td>(a | b) &amp; (a | c)</td></tr><tr><th>#2</th><td>d&amp;~d</td></tr><tr><th>#3</th><td>d &amp; ~d | ~((a|~b) &amp; (a|c))</td></tr><tr><th>#4</th><td>a &amp; b | ~ a &amp; ~b</td></tr></tbody></table>
<table style="border-color: black; border-collapse: collapse;" border="1"><tbody><tr><th>#1</th><td>Yes<br>a | b &amp; c</td></tr><tr><th>#2</th><td>No</td></tr><tr><th>#3</th><td>Yes<br>~a&amp;(b|~c)</td></tr><tr><th>#4</th><td>No</td></tr></tbody></table>

Source

Northeastern Europe 2007

, Northern Subregion