CF1748F.Circular Xor Reversal

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have an array a0,a1,,an1a_0, a_1, \ldots, a_{n-1} of length nn . Initially, ai=2ia_i = 2^i for all 0i<n0 \le i \lt n . Note that array aa is zero-indexed.

You want to reverse this array (that is, make aia_i equal to 2n1i2^{n-1-i} for all 0i<n0 \le i \lt n ). To do this, you can perform the following operation no more than 250000250\,000 times:

  • Select an integer ii ( 0i<n0 \le i \lt n ) and replace aia_i by aia(i+1)modna_i \oplus a_{(i+1)\bmod n} .

Here, \oplus denotes the bitwise XOR operation.

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

输入格式

The first line contains a single integer nn ( 2n4002 \le n \le 400 ) — the length of the array aa .

输出格式

On the first line print one integer kk ( 0k2500000 \le k \le 250\,000 ) — the number of operations performed.

On the second line print kk integers i1,i2,,iki_1,i_2,\ldots,i_k ( 0ij<n0 \le i_j \lt n ). Here, iji_j should be the integer selected on the jj -th operation.

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

输入输出样例

  • 输入#1

    2

    输出#1

    3
    1 0 1
  • 输入#2

    3

    输出#2

    9
    1 0 1 0 2 1 0 1 0

说明/提示

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

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

[1,2][1,3][2,3][2,1][1,\color{red}{2}] \rightarrow [\color{red}{1},3] \rightarrow [2,\color{red}{3}] \rightarrow [2,1] .

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

[1,2,4][1,6,4][7,6,4][7,2,4][5,2,4][5,2,1][5,3,1][6,3,1][6,2,1][4,2,1][1,\color{red}{2},4] \rightarrow [\color{red}{1},6,4] \rightarrow [7,\color{red}{6},4] \rightarrow [\color{red}{7},2,4] \rightarrow [5,2,\color{red}{4}] \rightarrow [5,\color{red}{2},1] \rightarrow [\color{red}{5},3,1] \rightarrow [6,\color{red}{3},1] \rightarrow [\color{red}{6},2,1] \rightarrow [4,2,1] .

首页