#P6720. [BalkanOI 2011] decrypt

[BalkanOI 2011] decrypt

Description

We randomly choose three numbers R0,R1,R2R_0, R_1, R_2, and generate the whole sequence RR by the following rule:

Rn=Rn2Rn1R_n = R_{n-2} \oplus R_{n-1}

Here, \oplus denotes the XOR operation.

In addition, we have a function MM, which is a bijection. That is, we guarantee that for xyx \not= y, M(x)M(y)M(x) \not= M(y).

Your goal is to determine R0,R1,R2,M(0),M(1),,M(255)R_0, R_1, R_2, M(0), M(1), \ldots, M(255) after making multiple queries.

Interaction

Your program should read from standard input and write to standard output.

You may output an integer AA to standard output. If this is your NN-th query, you will read:

M(ARN1)M(A \oplus R_{N-1})

If you have obtained all answers, output a line with the string SOLUTION, and then output 259259 lines, which are R0,R1,R2,M(0),M(1),,M(255)R_0, R_1, R_2, M(0), M(1), \ldots, M(255).

Remember to flush the output buffer after printing each line.

Output Format

Hint

Sample

(Because the sample testdata is hard to present, it is placed here.)

We manually set $R_0 = 0, R_1 = 1, R_2 = 3, M(i) = (i + 1) \bmod 256$.

Then R3=1R_3 = 1.

Output Input Explanation
1010 1111 M(100)=M(10)=11M(10 \oplus 0) = M(10) = 11
1212 M(101)=M(11)=12M(10 \oplus 1) = M(11) = 12
1111 99 M(113)=M(8)=9M(11 \oplus 3) = M(8) = 9
1212 1414 M(121)=M(13)=14M(12 \oplus 1) = M(13) = 14
Some outputs are omitted.
SOLUTION

Constraints and limits

For 100%100\% of the testdata, it is guaranteed that the input numbers, output numbers, the array RR, and both xx and M(x)M(x) in M(x)M(x) are all 0\ge 0 and 255\le 255.

Scoring policy

If the number you output is not within the range above, you will fail.

Your number of queries must be less than 320320, otherwise, you will fail.

Hint

Sample

(Because the sample testdata is hard to present, it is placed here.)

We manually set $R_0 = 0, R_1 = 1, R_2 = 3, M(i) = (i + 1) \bmod 256$.

Then R3=1R_3 = 1.

Output Input Explanation
1010 1111 M(100)=M(10)=11M(10 \oplus 0) = M(10) = 11
1212 M(101)=M(11)=12M(10 \oplus 1) = M(11) = 12
1111 99 M(113)=M(8)=9M(11 \oplus 3) = M(8) = 9
1212 1414 M(121)=M(13)=14M(12 \oplus 1) = M(13) = 14
Some outputs are omitted.
SOLUTION

Constraints and limits

For 100%100\% of the testdata, it is guaranteed that the input numbers, output numbers, the array RR, and both xx and M(x)M(x) in M(x)M(x) are all 0\ge 0 and 255\le 255.

Scoring policy

If the number you output is not within the range above, you will fail.

Your number of queries must be less than 320320, otherwise, you will fail.

Hint

How to flush the output buffer:

C:

printf("%d\n", q);
fflush(stdout); 

C++:

cout<<q<< '\n';
cout.flush();

Pascal:

writeln(q);
flush(output);

Note

This problem is translated from Balkan Olympiad in Informatics 2011 Day 1 T2 decrypt.

Thanks to

https://www.luogu.com.cn/user/60864
ing the interactive library.

Translated by ChatGPT 5