#B4068. Recamán Sequence Sorted Order

    ID: 11725 Type: Default 1000ms 256MiB

Recamán Sequence Sorted Order

Recamán Sequence Sorted Order

The Recamán sequence is defined as follows:

  1. \(a_1 = 1\).
  2. For \(k \ge 2\), if \(a_{k-1} - k\) is a positive integer and has not appeared in the sequence before, then \(a_k = a_{k-1} - k\); otherwise, \(a_k = a_{k-1} + k\).

Your task is to generate the first \(n\) terms of the Recamán sequence and then output these terms sorted in ascending order.

inputFormat

The input consists of a single integer \(n\) representing the number of terms to generate.

\(1 \le n\)

outputFormat

Output the first \(n\) terms of the Recamán sequence sorted in ascending order. The numbers should be separated by a single space.

sample

1
1