import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto N = readln.chomp.to!int; auto nck = new int[][](31, 31); nck[0][0] = nck[1][0] = nck[1][1] = 1; foreach (i; 2..31) foreach (j; 0..i+1) nck[i][j] = (i == j || j == 0) ? 1 : nck[i-1][j-1] + nck[i-1][j]; int acm, keta; foreach (i; 3..31) { int incr = 0; foreach (j; iota(2, i, 3)) { incr += nck[i-1][j]; } if (acm + incr >= N) { keta = i.to!int; break; } acm += incr; } auto perms = new int[][](0); foreach (i; iota(2, keta, 3)) { auto p = new int[0]; foreach (j; 0..keta-1) { p ~= (j < i) ? 5 : 3; } p.sort(); perms ~= p.dup; while (nextPermutation(p)) { perms ~= p.dup; } } perms.sort(); perms[N-acm-1].map!(d => d.to!string).join("").write; 5.writeln; }