An exam for n students would take place in a long and narrow, so the students would sit in a line in some Order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by Si De and became friends and if they take a exam sitting next to all other, they would help each other for sure.
Your task is to choose the maximum number of students and make such a arrangement of students in the "the" that No. Dents with adjacent numbers sit side by side.
Input
A single line contains the integer n (1≤ n ≤5000)-the number of students at an exam.
Output
In the first line print integer k -the Maximum number of students who can is seated so and no, and students With adjacent numbers sit next to each other.
In the second line print k distinct integers a 1, a 2, ..., a K (1≤ a i ≤ n ), where < Span class= "Tex-span" > a i is the number of the student on the < Span class= "Tex-span" > i -th position. The students on adjacent positions Mustn ' t has adjacent numbers. Formally, the following should be True:| A i - a i + 1|≠1 for all i from 1 to K -1.
If there is several possible answers, output any of them.
Sample Test (s)input
6
Output
6
1 5 3 6 2 4
input
3
Output
2
1 3
Direct Special Award N<=4
For n>4, it must be all out.
Construction: Output all odd numbers first, and then output all even numbers
such as n=7, the output:
7
1 3 5 7 2 4 6
#include <cstdio>#include<iostream>using namespacestd;intMain () {intN; CIN>>N; if(n==1|| n==2) {cout<<"1\n1"<<Endl; } Else if(n==3) {cout<<"2\n1 3"<<Endl; } Else if(n==4) {cout<<"4\n2 4 1 3"<<Endl; } Else{cout<<n<<Endl; for(intI=1; i<=n;i+=2) cout<<i<<" "; for(intI=2; i<=n;i+=2) {cout<<i; if(i==n-1|| i==N) cout<<Endl; Elsecout<<" "; } } return 0;}
cf534a Exam Construction