- Time limit: 1.00 s
- Memory limit: 512 MB
"In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals" (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form)
In the other words, CNF is a formula of type
, where represents a logical "AND" (conjunction), represents a logical "OR" (disjunction), and are some boolean variables or their negations. Each statement in brackets is called a clause, and are called literals.
The problem of determining values of variables where the CNF value is true is CNF-SAT. In this problem you have solve a special case of CNF-SAT, called Lucky-SAT. In Lucky-SAT each clause has exactly literals and literals in each clause are distinct.
Input
The first line contains integers and , the number of clauses and the number of variables.
The next lines each contain the description of each clause. The th line contains integers, , the literals of the th clause. If literal , it is the negation of variable and if it is the variable .
Output
If there exists a variable assignment such that CNF value is true, output SAT
in the first line and a string of length consisting of zeros and ones in the second line. The th character of the string should be 1
if variable is assigned to true in the solution and 0
if variable is assigned to false in the solution. You can output any valid solution.
If there is no such variable assignment, output UNSAT
Constraints
Example
Input:
8 10 4 -8 7 -10 -3 -1 2 -8 3 10 4 2 -5 9 6 4 2 -7 3 -5 8 7 9 -4 -5 3 10 6 5 -8 3 2 -7 -6 -1 -2 -8 -10 -7 -9 -3 -4 1 -9 -7 -2 10 5 4 5 8 -4 10 -3 -6 -9
Output:
SAT 1011110011