// accepted
module solution;
// version = IO_FILES;
import std.math;
import std.random;
import std.stdio;
immutable string PROBLEM_NAME = "caps-and-cakes";
auto triangleArea (long n)
{
return n * (n + 1) / 2;
}
auto triangleIndex (long n)
{
long num = cast (long) (sqrt (n * 2.0L));
return num - (triangleArea (num) > n);
}
immutable int size = 6;
auto solveTrianglesRandom (long n)
{
long [size] res;
debug {long steps = 0;}
while (true)
{
debug {steps += 1;}
long rem = n;
foreach (pos; 0..size)
{
auto cur = triangleIndex (rem);
if (pos < size - 1)
{
cur -= uniform (0, 1 + uniform (0, 1 +
uniform (0, 1 + cur)));
}
res[pos] = cur + 1;
rem -= triangleArea (cur);
}
if (rem == 0)
{
debug {writeln ("n = ", n + 1, ", steps ", steps);}
return res;
}
}
}
void main ()
{
version (IO_FILES)
{
stdin = File (PROBLEM_NAME ~ ".in", "rt");
stdout = File (PROBLEM_NAME ~ ".out", "wt");
}
long n;
while (readf (" %s", &n) > 0)
{
auto ans = solveTrianglesRandom (n - 1);
writefln ("%s\n%(%s %)", 6, ans[]);
stdout.flush ();
}
}
Ly8gYWNjZXB0ZWQKbW9kdWxlIHNvbHV0aW9uOwovLyB2ZXJzaW9uID0gSU9fRklMRVM7CmltcG9ydCBzdGQubWF0aDsKaW1wb3J0IHN0ZC5yYW5kb207CmltcG9ydCBzdGQuc3RkaW87CgppbW11dGFibGUgc3RyaW5nIFBST0JMRU1fTkFNRSA9ICJjYXBzLWFuZC1jYWtlcyI7CgphdXRvIHRyaWFuZ2xlQXJlYSAobG9uZyBuKQp7CglyZXR1cm4gbiAqIChuICsgMSkgLyAyOwp9CgphdXRvIHRyaWFuZ2xlSW5kZXggKGxvbmcgbikKewoJbG9uZyBudW0gPSBjYXN0IChsb25nKSAoc3FydCAobiAqIDIuMEwpKTsKCXJldHVybiBudW0gLSAodHJpYW5nbGVBcmVhIChudW0pID4gbik7Cn0KCmltbXV0YWJsZSBpbnQgc2l6ZSA9IDY7CgphdXRvIHNvbHZlVHJpYW5nbGVzUmF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