Under construction

Still being built. Things may change

Matrix Operations (Making a Beautiful Matrix)

Time limit2sMemory limit1024 MB

Summary
From the N by N upper triangular matrix of ones, add p/q to whole rows or columns within 2N operations so every absolute row and column sum is at most N/4.
Level

Medium7 of 10

Topics
Matrix, Math, Implementation
Solved
No attempts yet

Problem

N×NN \times N matrix UN=(uij)U_N = (u_{ij}) is defined as follows. uiju_{ij} is the value in row ii and column jj.

uij={1if i≤j0if i>ju_{ij} = \begin{cases} 1 & \text{if } i \le j\\ 0 & \text{if } i > j \end{cases}

In other words, UNU_N has 11 on the main diagonal and on every position above it, and 00 everywhere else. For example:

U1=(1),  U2=(1101),  U3=(111011001),  U4=(1111011100110001)U_1 = \begin{pmatrix} 1 \end{pmatrix}, \; U_2 = \begin{pmatrix} 1 & 1\\ 0 & 1 \end{pmatrix}, \; U_3 = \begin{pmatrix} 1 & 1 & 1\\ 0 & 1 & 1\\ 0 & 0 & 1 \end{pmatrix}, \; U_4 = \begin{pmatrix} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & 1 & 1\\ 0 & 0 & 0 & 1 \end{pmatrix}

The following operations can be applied to this matrix.

  • 11 rr pp qq: Choose integers rr, pp, qq. Add pq\frac{p}{q} to every element in row rr. (1≤r≤N1 \le r \le N, −1012≤p≤1012-10^{12} \le p \le 10^{12}, 1≤q≤1061 \le q \le 10^6)
  • 22 cc pp qq: Choose integers cc, pp, qq. Add pq\frac{p}{q} to every element in column cc. (1≤c≤N1 \le c \le N, −1012≤p≤1012-10^{12} \le p \le 10^{12}, 1≤q≤1061 \le q \le 10^6)

A matrix is called beautiful if, for every row and every column, the sum of the absolute values of its elements is at most N4\frac{N}{4}. Formally, an NN by NN matrix A=(aij)A = (a_{ij}) is beautiful if the following holds for all 1≤r≤N1 \le r \le N and 1≤c≤N1 \le c \le N.

∑j=1N∣arj∣≤N4,∑i=1N∣aic∣≤N4\sum_{j=1}^{N} \left|a_{rj}\right| \le \frac{N}{4}, \quad \sum_{i=1}^{N} \left|a_{ic}\right| \le \frac{N}{4}

Starting from UNU_N, you can apply at most 2N2N operations to turn the matrix into a beautiful matrix. Find one such sequence of operations and output it.

Input

The first line contains the integer NN, the size of the matrix. (1≤N≤4001 \le N \le 400)

Output

On the first line, print the number of operations QQ. It must satisfy 0≤Q≤2N0 \le Q \le 2N.

On each of the next QQ lines, print four integers separated by spaces that describe one operation. Each operation must be one of the following.

  • 11 rr pp qq (1≤r≤N1 \le r \le N, −1012≤p≤1012-10^{12} \le p \le 10^{12}, 1≤q≤1061 \le q \le 10^6)
  • 22 cc pp qq (1≤c≤N1 \le c \le N, −1012≤p≤1012-10^{12} \le p \le 10^{12}, 1≤q≤1061 \le q \le 10^6)

After all operations are applied in order to the matrix initialized as UNU_N, the result must be a beautiful matrix.

Examples2

  1. Example 1

    Input
    1
    
    Expected output
    2
    1 1 -7 6
    2 1 1 6
    
  2. Example 2

    Input
    2
    
    Expected output
    2
    1 1 -1 2
    2 2 -1 2