Petya has n integers:
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
题目大意
思路
如果n是
如果n%4=1,那么将1分到某一组,然后剩下的按上面的分法分。
如果
如果n%4=3,那么将1和
这样的话所有的情况都讨论完了。
代码
#include <cstdio>
const int maxn=60000;
int n;
int main()
{
scanf("%d",&n);
if(n%4==0)
{
printf("0\n%d ",n/2);
for(register int i=1; i<=n/2; i+=2)
{
printf("%d %d ",i,n-i+1);
}
}
else if(n%4==1)
{
printf("1\n%d ",n/2);
for(register int i=2; i<=n/2+1; i+=2)
{
printf("%d %d ",i,n-i+2);
}
}
else if(n%4==2)
{
printf("1\n%d 1 ",n/2);
for(register int i=3; i<=n/2+1; i+=2)
{
printf("%d %d ",i,n-i+3);
}
}
else
{
printf("0\n%d 3 ",n/2);
for(register int i=4; i<=n/2+2; i+=2)
{
printf("%d %d ",i,n-i+4);
}
}
return 0;
}