# 描述

As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.

Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn’t matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.

The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.

After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.

As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.

## Input

Input file contains integers $P\ N$, then $N$ descriptions of the machines. The description of ith machine is represented as by $2 P + 1$ integers $Q_i\ S_{i,1}\ S_{i,2}\ …\ S_{i,P}\ D_{i,1}\ D_{i,2}\ …D_{i,P}$, where $Q_i$ specifies performance, $S_{i,j}$ — input specification for part $j, D_{i,k}$ — output specification for part $k$.

## Constraints

$1\ ≤\ P\ ≤\ 10,\ 1\ ≤\ N\ ≤\ 50,\ 1\ ≤\ Q_i\ ≤\ 10000$

## Output

Output the maximum possible overall performance, then $M$ — number of connections that must be made, then $M$ descriptions of the connections. Each connection between machines $A$ and $B$ must be described by three positive numbers $A\ B\ W$, where $W$ is the number of computers delivered from $A$ to $B$ per hour.

If several solutions exist, output any of them.

• intput

• output

# 思路

• 如果一个机器的产出和另一个机器的需求一样的话，就可以连一条边，如果一个机器输入的的零件没有1的话，就和s连一条边，如果输出全为1（即成品），就与t连一条边。跑最大流。
• 由于每个机器输出是有限的，所以还是一样通过拆点来加以限制，对于每个机器 i都拆成 i，i’两个节点，再连一条权值为产量的边。
• 这道题需要记录路径，在跑完最大流之后，对所有边判断一下是否有流量。还要排除原本没有的点，比如链接到s和t的边、拆点之后i和i’之间的边。

# 代码

-------------本文结束 感谢您的阅读-------------