1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//Franciszek Witt
//NIENAWIDZE CF-LIKE CONSTRUCTIVE ZADAN
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    auto tos = [&] (int x) {
        assert(1 <= x && x <= 9);
        return string("") + char(x + '0');
    };

    function<string(const string, ll)> rp = [&] (const string s, ll n) {
        if(n == 0 || ssize(s) == 0)
            return string("");
        if(n == 1)
            return s;
        if(n < 10)
            return tos(n) + "[" + s + "]";
        if(n % 9 == 0)
            return "9[" + rp(s, n / 9) + "]";
        return rp(s, n % 9) + rp(s, n - (n % 9));
    };

    const string RI = "A", RD = "B", LD = "C", LE = "D", LU = "E", RU = "F";

    auto trap = [&] (ll n) {
        if(n == 0)
            return string("");
        return rp(rp(LD + LU, n - 1) + LD + rp(RI, n), n) + rp(LU, n);
    };

    //jezeli ramka to wracamy w to samo miejsce
    //jak bez ramki to przechodzimy krawedzia z ramka
    function<string(ll, bool)> solver = [&] (ll n, bool ramka) {
        debug(n, ramka);
        if(n == 0)
            return string("");
        if(n == 1) {
            string ret = RU;
            if(ramka)
                ret += RD + LE;
            return ret;
        }
        if(n == 3) {
            debug("3!");
            if(!ramka) {
                return RU+RI+RI+LD+LU+LU+RI+LD+LD+LU+RU+RU;
            }
        }
        if(n & 1) {
            assert(ramka);
            string ret = RU + solver(n - 1, true) + rp(RD + RU, n - 1) + RD + rp(LE, n);
            return ret;
        }
        else {
            string ret = "";
            if(n % 4 == 2) {
                ret = RU + rp(solver((n - 2) / 2, false), 2);
                ret += rp(RD, (n - 2) / 2) + trap((n - 2) / 2) + rp(LE, (n - 2) / 2) + rp(RD, (n - 2) / 2) + rp(LE, (n - 2) / 2);
            }
            else {
                debug("!!!");
                ret = RU + solver(n - 2, true);
            }
            ret += rp(RD + RU, n - 2) + RD + RU + rp(LE + RU, n - 1);
            if(ramka)
                ret += rp(RD, n) + rp(LE, n);
            return ret;
        }

    };

    ll n;
    string s;
    cin >> n ;
    cout << solver(n, true).data() << endl;

}