{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \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\n \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\n \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\n \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\n \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\n \u003cp\u003eThe machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.\u003c/p\u003e\n \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\n \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\n \u003c/div\u003e\n\n为了追求ACM比赛的公平性,所有用作ACM比赛的电脑性能是一样的,而ACM董事会专门有一条生产线来生产这样的电脑,随着比赛规模的越来越大,生产线的生产能力不能满足需要,所以说ACM董事会想要重新建造一条生产线。\n生产线是全自动化的,所以需要机器来组成生产线,给定有多少中种机器,标准ACM用电脑有多少部份,每种机器将什么样的ACM电脑半成品处理成什么样的电脑半成品(对于输入的电脑半成品,每部分有0,1,2三种状态:代表着 0、这部分必须没有我才能处理,1、这部分必须有我才能处理,2、这部分有没有我都能处理。对于输出的电脑半成品有0,1两种状态:代表着0,处理完后的电脑半成品里没有这部分,1、处理完的电脑半成品有这部分),每一个机器每小时可以处理Q个半成品(输入数据中的Qi)。\n求组装好的成产线的最大工作效率(每小时最多生成多少成品,成品的定义就是所有部分的状态都是“1”)\n第一行输入两个数:一个P代表有P个零件, 一个 N代表有N台机器。\n接下来N行,每行第一个数字有Qi,代表 第i个零件每小时能加工的半成品零件个数。然后是2*P个数字,前P个数字是加工前半成品需要满足的条件,后P个数表示加工后的半成品的数量。\n"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \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\n \u003cp\u003e\u003cb\u003eConstraints\u003c/b\u003e\u003c/p\u003e\n \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\n \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \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\n \u003cp\u003eIf several solutions exist, output any of them.\u003c/p\u003e\n \u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e\u003cb\u003eSample input 1\u003c/b\u003e\n3 4\n15 0 0 0 0 1 0\n10 0 0 0 0 1 1\n30 0 1 2 1 1 1\n3 0 2 1 1 1 1\n\u003cb\u003eSample input 2\u003c/b\u003e\n3 5\n5 0 0 0 0 1 0\n100 0 1 0 1 0 1\n3 0 1 0 1 1 0\n1 1 0 1 1 1 0\n300 1 1 2 1 1 1\n\u003cb\u003eSample input 3\u003c/b\u003e\n2 2\n100 0 0 1 0\n200 0 1 1 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e\u003cb\u003eSample output 1\u003c/b\u003e\n25 2\n1 3 15\n2 3 10\n\u003cb\u003eSample output 2\u003c/b\u003e\n4 5\n1 3 3\n3 5 3\n1 2 1\n2 4 1\n4 5 1\n\u003cb\u003eSample output 3\u003c/b\u003e\n0 0\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n Bold texts appearing in the sample sections are informative and do not form part of the actual data.\n \u003c/div\u003e\n"}}]}