题目描述
Problem Description
Given three sets of random boolean variables \( v_{i,1}, ..., v_{i,n} \) (where \( 1 \leq i \leq 3 \)), each containing \( n \) variables, you need to construct several conditions about boolean variables \( x_1, ..., x_n \) such that the assignments of boolean variables that satisfy all conditions are exactly \( (v_{i,1}, ..., v_{i,n}) \) for \( 1 \leq i \leq 3 \).
Due to machine limitations, each condition you construct should be in the form: \( A \rightarrow B \). This condition implies that when \( A \) is 1, \( B \) must be 1. Here, \( A \) and \( B \) can be:
- \( x_i \): Represents the value of the \( i \)-th variable.
- \( !x_i \): Represents the negated value of the \( i \)-th variable.
For example, if you construct \( x_1 \rightarrow x_2 \), it means that when \( x_1 = 1 \), \( x_2 \) must be 1; if you construct \( !x_1 \rightarrow x_2 \), it means that when \( x_1 = 0 \), \( x_2 \) must be 1. You need to find a way to satisfy the problem statement using no more than 500 conditions, or determine that such a combination of conditions is impossible. If there are multiple solutions, any one will be accepted.
The data guarantees \( 2 \leq n \leq 50 \) and \( v_{i,j} \in \{0, 1\} \) (where \( 1 \leq i \leq 3 \) and \( 1 \leq j \leq n \)).
Input Format
The first line contains an integer \( n \) (where \( 2 \leq n \leq 50 \)) — the number of variables. Three lines follow, each describing one assignment. The \( k \)-th line contains \( n \) space-separated integers \( v_1^k, v_2^k, \cdots, v_n^k \), where each \( v_i^k \) is either 0 or 1 and denotes the value of the variable \( x_i \) in the \( k \)-th assignment. All three assignments will be different.
Output Format
If there is no solution, output a single line containing the integer \(-1\).
Otherwise, the first line should contain an integer \( m \) where \( 1 \leq m \leq 500 \) — the number of constraints in your solution. The \( k \)-th of the following \( m \) lines should contain the \( k \)-th constraint. Each constraint should be a string constructed according to the following rules:
- A variable is a string of the form “$\texttt{x}i$” where \( i \) is an integer between 1 and \( n \) inclusive written without leading zeros.
- A literal is a string consisting of a variable possibly preceded by the “$\texttt{!}$” character.
- A constraint is a string of the form “$a\texttt{ -> }b$” where both \( a \) and \( b \) are literals. The implication sign consists of the “minus” character and the “greater-than” character and there is a single space character both before and after the implication sign.
Sample Input and Output
Input Sample #1
3
0 0 0
0 1 0
1 0 0
Output Sample #1
3
x1 -> !x2
x3 -> x1
x3 -> x2
Input Sample #2
4
0 0 1 0
1 0 0 0
1 0 1 1
Output Sample #2
-1
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分