Things Got Out of Hand
Time limit1sMemory limit1024 MB
Arrange 1 to N in a permutation so that multiplying at odd positions and adding at even positions gives the largest final value of X, starting from 1.
- Level
Medium5 of 10
- Topics
- Greedy, Implementation
- Solved
- No attempts yet
Problem
Woojin arranges the integers 1, 2, \cdots, N in any order to make a permutation . He then uses this permutation to grow an integer X that he holds. The initial value of X is 1.
For each i from 1 to N, Woojin can grow X using p_i as follows.
- If i is odd, multiply X by p_i.
- If i is even, add p_i to X.
For example, when N = 4 and p = [1, 2, 3, 4], X changes as , , , .
Given N, find how to arrange the integers 1, 2, \cdots, N so that X grows as large as possible.
Input
A single integer () is given.
Output
Print the permutation that makes X as large as possible, with the values separated by spaces. If several permutations maximize X, print any one of them.