Interpolate

아직 제출이 없습니다시간 제한4초메모리 제한256 MB

문제

A Zhegalkin polynomial is a boolean function f(x_1,,x_n)f(x\_1,\dots,x\_n) which is represented as follows:

\[f(x_{1},\dots,x_{n}) = \bigoplus_{S \subseteq \{1, 2, \ldots, n\}} a_S \cdot \bigwedge_{i \in S} x_i,\]

where \oplus and \wedge stand for XOR and AND boolean operations respectively, XOR is taken over all subsets of variables, and a_S0,1a\_S \in \\{0, 1\\} for each subset SS of 1,2,,n\\{1, 2, \ldots, n\\}.

In this task you are given mm sets of variable values (v_i_1,,v_i_n)({v\_i}\_{1},\dots,{v\_i}\_{n}) and mm boolean values y_i0,1y\_i \in \\{0, 1\\}. You have to construct a Zhegalkin polynomial with at most 90009000 non-zero terms satisfying f(v_i_1,,v_i_n)=y_if({v\_i}\_{1},\dots,{v\_i}\_{n}) = y\_i for each i=1,2,,mi = 1, 2, \ldots, m.

입력

The first line contains two integers nn and mm --- the number of variables and the number of given variable values (1n,m20001 \leq n, m \leq 2000).

Each of the following mm lines contains a string of nn characters 00 or 11 representing the ii-th set of variable values, followed by the integer y_iy\_i.

It is guaranteed that all sets of variable values are distinct and y_i=1y\_i=1 for at least one set.

출력

Your polynomial has to contain at most 90009000 terms having a_S=1a\_S = 1. For each such term print its corresponding subset SS of variables as a string of nn characters 00 or 11 such that ii-th character equals 11 if iSi \in S and 00 otherwise. You can output the terms in any order but there should be no repeating subsets. 

If there are multiple possible answers, output any of them. If the solution does not exist, output 1-1

It is guaranteed that if the solution exists, then the solution with at most 90009000 terms SS having a_S=1a\_S = 1 exists as well.

힌트

One of the possible answers to the first sample is f(x_1,x_2)=1f(x\_1,x\_2)=1.

In the second sample f(x_1,x_2,x_3)=x_1x_2x_3f(x\_1,x\_2,x\_3)=x\_1\oplus x\_2\oplus x\_3 is one of the possible answers.