$k=<>; while(!($k&1)){ $k>>=1; ++$a; } while(1){ $b=int sqrt$k*2; if($k==$b*($b+1)/2){ print$a+$b+1,$/,"0 "x$a,"1 "x$b,1; exit; } $k<<=1; --$a; }