Christmas permutation

3

2 votes
Mathematics, Hard, Approved
Problem

As the Christmas is coming, Little Santa is preparing the Christmas presents. Little Santa has N presents. All the presents are numbered from 1 to N. He noticed that different permutations of presents will have different beauty. Beauty of a permutation of N presents is the number of squares among the prefix sums. Little Santa wants to maximize the beauty.

Note: Prefix sums of a are . You can read about it here.

You do not have to find an optimal solution, so your score will depend on the beauty of the permutation that you output. A higher beauty will lead to a higher score.

enter image description here

Input format:

First line of input contains a single integer N - length of permutation.

Tests:

During the contest problem will contain 100 tests. The i-th test contains random number from segment .

After contest we will add 100 additional tests. We will use same generator but with differtent seed.

Scoring:

You score for each test is , where a is number of squares among the prefix sums in permutation printed by your solution.

Sample Input
3
Sample Output
1 2 3 
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In a sample we need to find a permutation of length 3. One possible solution is 1 2 3, it's prefix sums are 1, 3, 6. Among them onlу 1 is a perfect square.

Editor Image

?