Router 2

Build a unique-path layered router digraph with N inputs and N outputs, at most M_lim edges, node power at most P_lim, printing the lexicographically smallest edge list.

Hard8GraphGreedyImplementationCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

Henry and Hetty were hired by a networking company. Their first project is a new router, the Connect Ethernet Operating Interface 2016, built from:

  • NN input nodes, numbered from 11 to NN;
  • NN output nodes, numbered from N+1N+1 to 2N2N;
  • KK internal nodes, numbered from 2N+12N+1 to 2N+K2N+K;
  • MM unidirectional direct connections between pairs of distinct nodes.

A node XX can send data to a node YY (equivalently, YY can receive data from XX) if one of the following holds:

  • X=YX = Y;
  • there is a node ZZ such that XX can send data to ZZ and a direct connection runs from ZZ to YY.

If XYX \neq Y and XX can send data to YY, a data path from XX to YY is a set of direct connections {(A1,A2),(A2,A3),,(AL1,AL)}\{(A_1, A_2), (A_2, A_3), \dots, (A_{L-1}, A_L)\} for some L2L \ge 2 with A1=XA_1 = X and AL=YA_L = Y.

A router works properly if all of the following hold:

  • every input node can send data to every output node;
  • every input node receives data only from itself;
  • every output node sends data only to itself;
  • if XYX \neq Y and XX can send data to YY, then YY cannot send data to XX;
  • if XYX \neq Y and XX can send data to YY, the data path from XX to YY is unique. In particular, at most one direct connection joins any two nodes.

The power needed to operate a node XX is PX=INX×OUTXP_X = IN_X \times OUT_X, where INXIN_X is the number of input nodes that can send data to XX and OUTXOUT_X is the number of output nodes that can receive data from XX. The maximum power used by the router is Pmax=max(P1,P2,,P2N+K)P_{max} = \max(P_1, P_2, \dots, P_{2N+K}).

Build a router that satisfies all of the following:

  • it has exactly NN input nodes and exactly NN output nodes;
  • it uses at most MlimM_{lim} direct connections;
  • its maximum power is at most PlimP_{lim};
  • it uses at most 500000500\,000 nodes in total, that is Ntot=2N+K500000N_{tot} = 2N + K \le 500\,000.

Several routers meet these requirements, so only one of them counts as correct: the lexicographically smallest one under the rule given in the output format.

Input

The first and only line contains three integers NN, MlimM_{lim} and PlimP_{lim}, separated by spaces. NN is the number of input nodes and also the number of output nodes, MlimM_{lim} is the largest number of direct connections allowed, and PlimP_{lim} is the largest power the router may use.

1N2501 \le N \le 250, 1Mlim10000001 \le M_{lim} \le 1\,000\,000, 1Plim10000001 \le P_{lim} \le 1\,000\,000. The input always satisfies N2MlimN^2 \le M_{lim} and NPlimN \le P_{lim}.

Output

On the first line print the total number of nodes Ntot=2N+KN_{tot} = 2N + K and the number of direct connections MM, separated by a space. On each of the next MM lines print one direct connection as a pair XX YY, meaning a direct connection runs from node XX to node YY. Print the connections sorted by increasing XX, and by increasing YY when XX ties.

Read the whole output as the integer sequence Ntot,M,X1,Y1,,XM,YMN_{tot}, M, X_1, Y_1, \dots, X_M, Y_M. Among the outputs of all routers that meet the requirements, print the lexicographically smallest such sequence.