CodeForce 899C

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
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.


题意:给出一个数字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 long
using 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值