#t139. Recamán 数列

Recamán 数列

Recamán Sequence

Problem Description

Xiaoyang recently discovered the interesting Recamán sequence, generated as follows:

  • The first term a1a_1 is 11.
  • If ak−1−ka_{k-1} - k is a positive integer and has never appeared in the sequence, then the kk-th term ak=ak−1−ka_k = a_{k-1} - k; otherwise ak=ak−1+ka_k = a_{k-1} + k.

Xiaoyang wants the first nn terms of the Recamán sequence, sorted in ascending order. Manual calculation is very hard, so he hopes you can solve it for him.

Input Format

The first line contains one positive integer nn.

Output Format

One line: nn integers separated by spaces, the first nn terms of the Recamán sequence sorted in ascending order.

Sample Input

Sample Input 1

5

Sample Input 2

8

Sample Output

Sample Output 1

1 2 3 6 7

Sample Output 2

1 2 3 6 7 12 13 20

Sample Explanation

For the first sample, n=5n = 5, and the sequence is generated as:

  • a1=1a_1 = 1;
  • a1−2=−1a_1 - 2 = -1, not a positive integer, so a2=a1+2=3a_2 = a_1 + 2 = 3;
  • a2−3=0a_2 - 3 = 0, not a positive integer, so a3=a2+3=6a_3 = a_2 + 3 = 6;
  • a3−4=2a_3 - 4 = 2, a positive integer and not yet in the sequence, so a4=a3−4=2a_4 = a_3 - 4 = 2;
  • a4−5=−3a_4 - 5 = -3, not a positive integer, so a5=a4+5=7a_5 = a_4 + 5 = 7.

The first 55 terms are 1,3,6,2,71, 3, 6, 2, 7; sorted ascending they become 1,2,3,6,71, 2, 3, 6, 7, matching the output.

Constraints

For all test points, 1≤n≤30001 \le n \le 3000.