Under construction

Still being built. Things may change

G++ Language

Time limit0.1sMemory limit256 MB

Summary
Write a G++ program that reads H and W, then leaves the sum of the cells in the rectangle from (a, b) to (c, d) in memory 0 and zeros elsewhere.
Level

Hard8 of 10

Topics
Bit manipulation, Implementation, Math
Solved
No attempts yet

Problem

The genius Kyojun spent several years of research and built a new programming language, G++. G++ supports the following operations:

  • "INPUT xx": Reads one integer from the input and writes it to memory xx. If there are no more integers to read, an Input Error occurs.
  • "NOT xx yy": Writes the logical negation of the value in memory xx to memory yy.
  • "BNOT xx yy": Writes the bitwise NOT of the value in memory xx to memory yy.
  • "AND nn x_1x\_1 … x_nx\_n yy": Writes the bitwise AND of the nn values in memories x_1x\_1 … x_nx\_n to memory yy. x_1x\_1, …, x_nx\_n must all be different, and n≥2n≥2. If this is not satisfied, an Index Error occurs.
  • "OR nn x_1x\_1 … x_nx\_n yy": Writes the bitwise OR of the nn values in memories x_1x\_1 … x_nx\_n to memory yy. x_1x\_1, …, x_nx\_n must all be different, and n≥2n≥2. If this is not satisfied, an Index Error occurs.
  • "XOR nn x_1x\_1 … x_nx\_n yy": Writes the bitwise XOR of the nn values in memories x_1x\_1 … x_nx\_n to memory yy. x_1x\_1, …, x_nx\_n must all be different, and n≥2n≥2. If this is not satisfied, an Index Error occurs.
  • "LSHIFT x_1x\_1 x_2x\_2 yy": Writes the value in memory x_1x\_1 shifted left bitwise by the value in memory x_2x\_2 to memory yy.
  • "RSHIFT x_1x\_1 x_2x\_2 yy": Writes the value in memory x_1x\_1 shifted right bitwise by the value in memory x_2x\_2 to memory yy.

A G++ program runs its operations in order, starting from the first. Right when it starts, memory is allocated for 10310^3 int variables. If your code accesses memory xx, then 0≤x<1030≤x<10^3 must hold. Otherwise, a Memory Error occurs. At the start, all 10310^3 variables are initialized to 00.

The total number of operations in a G++ program must not exceed 10510^5. Otherwise, a Time Limit Exceeded Error occurs.

The total number of memory accesses in a G++ program must not exceed 10510^5. Otherwise, an Access Limit Exceeded Error occurs.

Kyojun is a perfectionist. Your G++ code must not contain unnecessary spaces or line breaks. The last character of the G++ code must be a newline character. Otherwise, a Compile Error occurs.

In addition, if your G++ code causes Undefined Behavior, a Runtime Error occurs. The following cases cause Undefined Behavior when a G++ program runs:

  • When shifting xx left by yy bits, y≥0y≥0 and x×2y<231x × 2^y < 2^{31} must both hold. Also, if x<0x<0, then y=0y=0 must hold. Otherwise, Undefined Behavior occurs.
  • When shifting xx right by yy bits, if y≥0y≥0 does not hold, Undefined Behavior occurs.

For the input "2 16 5", the following G++ code writes the value 5 to memory 4.

INPUT 2
NOT 2 3
NOT 3 2
INPUT 0
INPUT 0
XOR 3 0 1 2 1
OR 3 3 1 2 4

You must now solve the following problem in G++:

There is a two-dimensional grid of size H×WH×W, with WW cells wide and HH cells tall. The top-left cell has coordinates (0,0)(0, 0), and the bottom-right cell has coordinates (H−1,W−1)(H-1, W-1). The cell at coordinates (i,j)(i, j) contains the number Ai×W+jA_{i×W+j}.

Consider a rectangle in the grid whose top-left corner is (a,b)(a, b) and whose bottom-right corner is (c,d)(c, d). Let SS be the sum of the numbers in the cells inside this rectangle. You must write a G++ code that, for the following input, leaves SS in memory 0 after running, and leaves 00 in every other memory.

The input given to the G++ program is as follows:

HH WW A0A_0 A1A_1 … AH×W−1A_{H×W-1} aa bb cc dd

Input

You are given only two integers, HH and WW. In other words, your submitted code can read only the values of HH and WW. Note that the values of A0A_0, …, AH×W−1A_{H×W-1}, aa, bb, cc, and dd are not provided.

Output

After running, memory 0 must contain SS, and every other memory must contain 00. Print the G++ code.

Constraints

All data satisfy the following conditions:

  • HH, WW, A0A_0, …, AH×W−1A_{H×W-1} are all positive integers.
  • H×W≤16H×W≤16.
  • For every integer ii with 0≤i<H×W0 ≤ i < H×W, Ai≤100A_i ≤ 100.
  • aa, bb, cc, dd are all integers.
  • 0≤a≤c<H0 ≤ a ≤ c < H, 0≤b≤d<W0 ≤ b ≤ d < W.

Examples1

  1. Example 1

    Input
    1 1
    
    Expected output
    INPUT 0
    INPUT 0
    INPUT 0