{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eAs 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.\u003c/p\u003e\u003cp\u003eEvery 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.\u003c/p\u003e\u003cp\u003eComputer manufacturing is fully automated by using \u003ci\u003eN\u003c/i\u003e 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.\u003c/p\u003e\u003cp\u003eInput 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 \u003ci\u003eP\u003c/i\u003e 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\u0027t matter.\u003c/p\u003e\u003cp\u003eOutput specification describes the result of the operation, and is a set of \u003ci\u003eP\u003c/i\u003e numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.\u003c/p\u003e\u003cp\u003eThe machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.\u003c/p\u003e\u003cp\u003eAfter 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.\u003c/p\u003e\u003cp\u003eAs 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.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eInput file contains integers \u003ci\u003eP\u003c/i\u003e \u003ci\u003eN\u003c/i\u003e, then \u003ci\u003eN\u003c/i\u003e descriptions of the machines. The description of \u003ci\u003ei\u003c/i\u003eth machine is represented as by 2 \u003ci\u003eP\u003c/i\u003e + 1 integers \u003ci\u003eQ\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e \u003ci\u003eS\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,1\u003c/sub\u003e \u003ci\u003eSi\u003c/i\u003e\u003csub\u003e,2\u003c/sub\u003e...\u003ci\u003eS\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,\u003ci\u003eP\u003c/i\u003e\u003c/sub\u003e \u003ci\u003eD\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,1\u003c/sub\u003e \u003ci\u003eD\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,2\u003c/sub\u003e...\u003ci\u003eD\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,\u003ci\u003eP\u003c/i\u003e\u003c/sub\u003e, where \u003ci\u003eQ\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e specifies performance, \u003ci\u003eS\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,\u003ci\u003ej\u003c/i\u003e\u003c/sub\u003e — input specification for part \u003ci\u003ej\u003c/i\u003e, \u003ci\u003eD\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e\u003csub\u003e,\u003ci\u003ek\u003c/i\u003e\u003c/sub\u003e — output specification for part \u003ci\u003ek\u003c/i\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eConstraints\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1 ≤ \u003ci\u003eP\u003c/i\u003e ≤ 10, 1 ≤ \u003ci\u003eN \u003c/i\u003e≤ 50, 1 ≤ \u003ci\u003eQ\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e ≤ 10000 \u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput the maximum possible overall performance, then \u003ci\u003eM\u003c/i\u003e — number of connections that must be made, then \u003ci\u003eM\u003c/i\u003e descriptions of the connections. Each connection between machines \u003ci\u003eA\u003c/i\u003e and \u003ci\u003eB\u003c/i\u003e must be described by three positive numbers \u003ci\u003eA\u003c/i\u003e \u003ci\u003eB\u003c/i\u003e \u003ci\u003eW\u003c/i\u003e, where \u003ci\u003eW\u003c/i\u003e is the number of computers delivered from \u003ci\u003eA\u003c/i\u003e to \u003ci\u003eB\u003c/i\u003e per hour.\u003c/p\u003e\u003cp\u003eIf several solutions exist, output any of them.\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e\u0026lt;b\u0026gt;Sample input 1\u0026lt;/b\u0026gt;\r\n3 4\r\n15 0 0 0 0 1 0\r\n10 0 0 0 0 1 1\r\n30 0 1 2 1 1 1\r\n3 0 2 1 1 1 1\r\n\u0026lt;b\u0026gt;Sample input 2\u0026lt;/b\u0026gt;\r\n3 5\r\n5 0 0 0 0 1 0\r\n100 0 1 0 1 0 1\r\n3 0 1 0 1 1 0\r\n1 1 0 1 1 1 0\r\n300 1 1 2 1 1 1\r\n\u0026lt;b\u0026gt;Sample input 3\u0026lt;/b\u0026gt;\r\n2 2\r\n100 0 0 1 0\r\n200 0 1 1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u0026lt;b\u0026gt;Sample output 1\u0026lt;/b\u0026gt;\r\n25 2\r\n1 3 15\r\n2 3 10\r\n\u0026lt;b\u0026gt;Sample output 2\u0026lt;/b\u0026gt;\r\n4 5\r\n1 3 3\r\n3 5 3\r\n1 2 1\r\n2 4 1\r\n4 5 1\r\n\u0026lt;b\u0026gt;Sample output 3\u0026lt;/b\u0026gt;\r\n0 0\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"Bold texts appearing in the sample sections are informative and do not form part of the actual data."}}]}