cf #452(div2) C

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

Copy

4

Output

Copy

0
2 1 4 

Input

Copy

2

Output

Copy

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.

题目链接:http://codeforces.com/contest/899/problem/C

题意:将1-n的数分成几个部分,使这几个部分相差最小,输出几个部分,第一部分里面的数。
思维题将1-n的数累加起来,分成两部分,和是偶数就是相差0奇数相差是1。

#include<iostream>
#include<cstdio>
using namespace std;

typedef long long ll;
ll n;

int main()
{
	while(cin >> n)
	{
		int sum = (n+1)*n/2;
		if(sum%2 == 0)
		{
			cout << 0 << endl;
			cout << n/2 << " ";
			int j = 1;
			int k = n;
			int i = 1;
			for(long long j = 0,i = n; i > 1; i -= 2, j = !j)
        		    cout << i-j << " ";
     
			cout << endl;
		}
		else
		{
			cout << 1 << endl;
			cout << n/2 << " ";
			for(long long j = 0,i = n; i > 1; i -= 2, j = !j)
        		    cout << i-j << " ";
			cout << endl;
		}
	}
	return 0;
}

07-18 15:35 cb 创建了文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值