Codeforces Round #452 (Div. 2) C

来源:互联网 发布:公租房信息管理 源码 编辑:程序博客网 时间:2024/05/21 00:54

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.


这个题上次 b 找bug 找了一个小时当时没有做出来 唉

还是自己智障!

#include<bits/stdc++.h>using namespace std;int a[100000+100];int main(){  int n;  cin>>n;  for(int j=1;j<=n;j++){     a[j]=j;  }  long long s1=0,s2=0;  if(n==2){     cout<<'1'<<endl;     cout<<'1'<<" "<<'1'<<endl;  }  else if(n==3){     cout<<'0'<<endl;     cout<<'2'<<" "<<'1'<<' '<<'2'<<endl;  }  else{    if(n%2==1){       if(n/2%2==0){         cout<<"1"<<endl;         cout<<(n+1)/2<<" ";         cout<<'1'<<' ';         for(int j=2;j<=n/2;j+=2){            cout<<j<<" "<<n-j+2<<" ";         }       }       else{          cout<<"0"<<endl;          cout<<(n+1)/2<<" ";          for(int j=1;j<=n/2;j+=2){             cout<<j<<" "<<n-j<<" ";          }       }    }    else{       if(n/2%2==0){          cout<<"0"<<endl;          cout<<n/2<<" ";          for(int j=1;j<n/2;j+=2){             cout<<a[j]<<" "<<a[n-j+1]<<" ";          }       }       else{          cout<<'1'<<endl;          cout<<n/2<<" ";          for(int j=1;j<n/2;j=j+2){             cout<<a[j]<<" "<<a[n-j+1]<<" ";          }          cout<<n/2<<endl;       }    }  }  return 0;}