#include #include #include #include using namespace std; void add(string &s, int &f, int &t) { cout << s << endl; for (int i = s.size()-2; i > 0; i--) { if (s[i] == '5' && s[i - 1] == '3') { s[i] = '3'; s[i - 1] = '5'; return; } } for (int i = s.size() - 2; i > 1; i--) { if (s[i] == '3' && s[i - 1] == '3' && s[i - 2] == '3') { s[i] = '5'; s[i - 1] = '5'; s[i - 2] = '5'; f += 3; t -= 3; return; } } int len = s.size() + 1; s = ""; for (int i = 0; i < len-3; i++) s += "3"; s += "555"; f = 3; t = s.size() - 3; } int main() { int n; cin >> n; string s = "555"; int f = 3; int t = 0; for (int i = 1; i < n; i++) add(s, f, t); cout << s << endl; //getchar(); getchar(); return 0; }