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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) ;
#endif

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, n, m) for (int i = (n); i < (m); ++i)

#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define reppr(i, n, m) for (int i = (m) - 1; i >= (n); --i)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T, typename V> void mini(T& a, V b) {if (b < a) a = b; }
template <typename T, typename V> void maxi(T& a, V b) {if (b > a) a = b; }

vector<ll> base9(ll x) {
    assert(x > 0);

    if (x <= 9)
        return {x};

    auto v = base9(x / 9);
    v.push_back(x % 9);

    // debug(x, v);

    return v;
}

struct node {
    ll rep = 1;
    vector<node> subnodes;
    char letter;

    string str_no_rep() const {
        if (subnodes.empty())
            return string(1, letter);

        string ret;

        for (const node &o : subnodes)
            ret += o.str();

        return ret;
    }

    string str() const {
        assert(rep > 0);

        string no_rep = str_no_rep(), ret;

        if (rep == 1)
            return no_rep;

        string safe_no_rep = no_rep.size() > 1 ? '[' + no_rep + ']' : no_rep;

        auto vb = base9(rep);

        for (int i : vb) {
            string nret;

            if (ret.size()) {
                if (ret.size() > 1)
                    nret += "9[" + ret + ']';
                else
                    nret += '9' + ret;
            }
            if (i) {
                if (i > 1)
                    nret += to_string(i) + safe_no_rep;
                else
                    nret += no_rep;
            }

            swap(nret, ret);
        }

        return ret;
    }
};

node make_node(ll rep, char ch) {
    node ret;
    ret.rep = rep;
    ret.letter = ch;
    return ret;
}

node make_node(ll rep, char ch1, char ch2) {
    node ret;
    ret.rep = rep;
    ret.subnodes.emplace_back(make_node(1, ch1));
    ret.subnodes.emplace_back(make_node(1, ch2));
    return ret;
}

node rhombus(ll n) {
    node ret;
    ret.rep = n;

    ret.subnodes.emplace_back(make_node(1, 'A'));
    ret.subnodes.emplace_back(make_node(n, 'E', 'A'));
    ret.subnodes.emplace_back(make_node(n, 'C'));

    return ret;
}

node triangle(ll n) {
    debug(n);
    node ret;

    if (n == 1)
        return make_node(1, 'B');

    if (n % 2 == 0) {
        ret.subnodes.emplace_back(triangle(n - 1));
        ret.subnodes.emplace_back(make_node(n - 1, 'D'));
        ret.subnodes.emplace_back(make_node(n - 1, 'B', 'F'));
        ret.subnodes.emplace_back(make_node(1, 'B'));
        return ret;
    }

    ret.subnodes.emplace_back(triangle(n / 2));
    ret.subnodes.front().rep *= 2;

    ret.subnodes.emplace_back(make_node(n - 1, 'C', 'E'));
    ret.subnodes.emplace_back(rhombus(n / 2));
    ret.subnodes.emplace_back(make_node(n / 2, 'A'));
    ret.subnodes.emplace_back(make_node(1, 'B'));

    return ret;
}

node fulltriangle(ll n) {
    node ret;

    ret.subnodes.emplace_back(triangle(n));
    ret.subnodes.emplace_back(make_node(n, 'D'));
    ret.subnodes.emplace_back(make_node(n, 'F'));

    return ret;
}

void solve() {
    ll n;
    cin >> n;

    node sol = fulltriangle(n);
    string str = sol.str();
    debug(str.size());
    cout << str << '\n';
}

int main() {
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int z = 1;
    // scanf("%d", &z);
    while (z--)
        solve();
    return 0;
}