atcoder#ARC089C. [ARC089E] GraphXY

[ARC089E] GraphXY

Score : 900900 points

Problem Statement

AtCoDeer the deer wants a directed graph that satisfies the following conditions:

  • The number of vertices, NN, is at most 300300.
  • There must not be self-loops or multiple edges.
  • The vertices are numbered from 11 through NN.
  • Each edge has either an integer weight between 00 and 100100 (inclusive), or a label X or Y.
  • For every pair of two integers (x,y)(x,y) such that 1xA1 \leq x \leq A, 1yB1 \leq y \leq B, the shortest distance from Vertex SS to Vertex TT in the graph where the edges labeled X have the weight xx and the edges labeled Y have the weight yy, is dx,yd_{x,y}.

Construct such a graph (and a pair of SS and TT) for him, or report that it does not exist. Refer to Output section for output format.

Constraints

  • 11 \leq A,BA,B \leq 1010
  • 11 \leq dx,yd_{x,y} \leq 100100 (11 \leq xx \leq AA, 11 \leq yy \leq BB)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

AA BB

d1,1d_{1,1} d1,2d_{1,2} .... d1,Bd_{1,B}

d2,1d_{2,1} d2,2d_{2,2} .... d2,Bd_{2,B}

::

dA,1d_{A,1} dA,2d_{A,2} .... dA,Bd_{A,B}

Output

If no graph satisfies the condition, print Impossible.

If there exists a graph that satisfies the condition, print Possible in the first line. Then, in the subsequent lines, print the constructed graph in the following format:

NN MM

u1u_1 v1v_1 c1c_1

u2u_2 v2v_2 c2c_2

:

uMu_M vMv_M cMc_M

SS TT

Here, MM is the number of the edges, and uiu_i, viv_i, cic_i represent edges as follows: there is an edge from Vertex uiu_i to Vertex viv_i whose weight or label is cic_i.

Also refer to Sample Outputs.

2 3
1 2 2
1 2 3
Possible
3 4
1 2 X
2 3 1
3 2 Y
1 3 Y
1 3
1 3
100 50 1
Impossible