GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 15 November 2022

[Solution] Circular Xor Reversal Codeforces Solution



F. Circular Xor Reversal
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array a0,a1,,an1 of length n. Initially, ai=2i for all 0i<n. Note that array a is zero-indexed.

You want to reverse this array (that is, make ai equal to 2n1i for all 0i<n). To do this, you can perform the following operation no more than 250000 times:

  • Select an integer i (0i<n) and replace ai by aia(i+1)modn.

Here,  denotes the bitwise XOR operation.

Your task is to find any sequence of operations that will result in the array a being reversed. It can be shown that under the given constraints, a solution always exists.

Input

The first line contains a single integer n (2n400) — the length of the array a.

Output

On the first line print one integer k (0k250000) — the number of operations performed.

On the second line print k integers i1,i2,,ik (0ij<n). Here, ij should be the integer selected on the j-th operation.

Note that you don't need to minimize the number of operations.

Note

In the notes, the elements on which the operations are performed are colored red.

In the first test case, array a will change in the following way:

[1,2][1,3][2,3][2,1].

In the second test case, array a will change in the following way:

No comments:

Post a Comment