您的位置:首页 > 其它

[Codeforces Round #452 (Div. 2)] Dividing the numbers

2017-12-19 17:37 274 查看
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.

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 (2 ≤ n ≤ 60 000) — the number of integers Petya has.

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 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.

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.

题目大意

1−n分成两组,询问两组和的差值的最小值,并打印一组中元素。

思路

如果n是4的整数倍的话,那么可以将1和n分到一组,将2和n−1分到另一组;将3和n−2分到一组,将4和n−3分到另一组……将n/2−1和n/2+2分到一组,将n/2和n/2+1分到另一组。

如果n%4=1,那么将1分到某一组,然后剩下的按上面的分法分。

如果n%4=2,那么将1分到某一组,将2分到另一组,然后剩下的按上面的方法分。

如果n%4=3,那么将1和2分到同一组,将3分到另一组,然后剩下的还是按上面的方法分。

这样的话所有的情况都讨论完了。

代码

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces