CodeForce 899C

来源:互联网 发布:Python开发安卓 编辑:程序博客网 时间:2024/06/07 06:42

C. Dividing the numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
02 1 4 
input
2
output
11 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.


题意:给出一个数字n,将数字1~n分成两个部分,要求两部分的差的绝对值最小。输出差的绝对值和第一部分的数的个数以及第一部分的数。

不难得出,两部分相差不是0,就是1

设一个整数x,x+{x-3)=(x-1)+(x-2),所以我们将n和n-3放入第一部分,将n-1和n-2放入第二部分,n不断递减即可。

#include<bits/stdc++.h>#define ll long longusing namespace std;int main(){    ll n;    while(scanf("%lld",&n)!=EOF)    {        ll a=n*(n+1)/2%2;        printf("%lld\n",a);        printf("%lld",n/2);        for(ll i=n,j=0;i>1;i-=2,j=!j)        {            printf(" %lld",i-j);        }        printf("\n");    }    return 0;}