// accepted
module solution;
// version = IO_FILES;
import std.math;
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 solveTrianglesRecurFast (long n)
{
long [size] res;
debug {long calls = 0;}
bool recur (int pos, long rem)
{
debug {calls += 1;}
if (pos == size)
{
return rem == 0;
}
auto cur = triangleIndex (rem);
foreach_reverse (temp; 0..cur + 1)
{
res[pos] = temp + 1;
if (recur (pos + 1, rem - triangleArea (temp)))
{
return true;
}
if (pos == size - 1)
{
break;
}
}
return false;
}
if (!recur (0, n))
{
assert (false);
}
debug {writeln ("n = ", n + 1, ", recur calls: ", calls);}
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 = solveTrianglesRecurFast (n - 1);
writefln ("%s\n%(%s %)", 6, ans[]);
}
}
Ly8gYWNjZXB0ZWQKbW9kdWxlIHNvbHV0aW9uOwovLyB2ZXJzaW9uID0gSU9fRklMRVM7CmltcG9ydCBzdGQubWF0aDsKaW1wb3J0IHN0ZC5zdGRpbzsKCmltbXV0YWJsZSBzdHJpbmcgUFJPQkxFTV9OQU1FID0gImNhcHMtYW5kLWNha2VzIjsKCmF1dG8gdHJpYW5nbGVBcmVhIChsb25nIG4pCnsKCXJldHVybiBuICogKG4gKyAxKSAvIDI7Cn0KCmF1dG8gdHJpYW5nbGVJbmRleCAobG9uZyBuKQp7Cglsb25nIG51bSA9IGNhc3QgKGxvbmcpIChzcXJ0IChuICogMi4wTCkpOwoJcmV0dXJuIG51bSAtICh0cmlhbmdsZUFyZWEgKG51bSkgPiBuKTsKfQoKaW1tdXRhYmxlIGludCBzaXplID0gNjsKCmF1dG8gc29sdmVUcmlhbmdsZXNSZWN1ckZ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