Cod sursa(job #109333)
#include<stdio.h>
long n,i,s=0,u,cn;
int main()
{
freopen("multimi2.in","r",stdin);
freopen("multimi2.out","w",stdout);
scanf("%ld",&n);
cn=n;
if(n%4==0||n%4==2) s=n/2*(n+1);
if(n%4==3||n%4==1) s=(n/2+1)*n;
if(s%2==0)
{
printf("0\n");
s/=2;
while(s>=n)
{
s-=n;
n--;
u++;
}
if(s)
{
printf("%ld\n",u+1);
printf("%ld ",s);
}
else
printf("%ld\n",u);
for(i=n+1;i<=cn;i++)
printf("%ld ",i);
printf("\n");
u=s+n-s-1;
printf("%ld\n",u);
for(i=1;i<s;i++)
printf("%ld ",i);
for(i=s+1;i<=n;i++)
printf("%ld ",i);
}
else
{
printf("1\n");
s/=2;s++;
while(s>=n)
{
s-=n;
n--;
u++;
}
if(s)
{
printf("%ld\n",u+1);
printf("%ld ",s);
}
else printf("%ld\n",u+1);
for(i=n+1;i<=cn;i++)
printf("%ld ",i);
printf("\n");
if(s)
u=s+n-s-1;
else
u=n;
printf("%ld\n",u);
for(i=1;i<s;i++)
printf("%ld ",i);
for(i=s+1;i<=n;i++)
printf("%ld ",i);
}
fcloseall();
return 0;
}