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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

constexpr char dir_letter[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
inline char digit(int x) { return '0' + x; }
inline int mod6(int x) { x %= 6; if (x < 0) x += 6; return x; }

string repeat(const string& pattern, ll n)
{
    //string result = n >= 9 ? string("9[") + repeat(pattern, n/9) + ']' : "";
    string result = "";
    if (n >= 9)
    {
        string partial_result = repeat(pattern, n/9);
        if (partial_result.size() == 1)
            result += string("9") + repeat(pattern, n/9);
        else
            result += string("9[") + repeat(pattern, n/9) + ']';
    }

    int x = n % 9;

    //if (x != 0)
    //    result += string() + digit(x) + '[' + pattern + ']';

    ///* // small optimalisation
    if (x > 0)
    {
        if (x == 1)
            result += pattern;
        else
        {
            if (pattern.size() == 1)
                result += string() + digit(x) + pattern;
            else
                result += string() + digit(x) + '[' + pattern + ']';
        }
    }
    //*/

    return result;
}

string line(int dir, ll n)
{
    return repeat(string(1, dir_letter[dir]), n);
}

string zigzag(int dir, ll n)
{
    return repeat(string() + dir_letter[dir] + dir_letter[mod6(dir-2)], n) + dir_letter[dir];
}

string truss(int dir, ll n, ll h)
{
    return repeat(line(dir, n) + zigzag(mod6(dir-2), n-1), h);
}

string truss(int dir, ll n)
{
    return truss(dir, n, n);
}

string triangle(int dir, ll n)
{
    if (n == 0)
        return string();

    if (n == 1)
        return string() + dir_letter[dir] + dir_letter[mod6(dir-2)] + dir_letter[mod6(dir-4)];

    if (n % 2 == 0)
    {
        ll truss_n = n/2;
        ll lower_triangle_n = n - truss_n;
        ll upper_triangle_n = n - truss_n - 1;

        return truss(dir, truss_n) + 
            line(dir, truss_n) + 
            triangle(mod6(dir+2), lower_triangle_n) + 
            zigzag(mod6(dir-2), truss_n-1) +
            triangle(dir, upper_triangle_n) + 
            line(mod6(dir+2), truss_n+1);
    }
    else
    {
        ll truss_n = n/2 + 1;
        ll lower_triangle_n = n - truss_n;
        ll upper_triangle_n = n - truss_n;

        return truss(dir, truss_n, truss_n-1) + 
            line(dir, truss_n) + 
            triangle(mod6(dir+2), lower_triangle_n) + 
            zigzag(mod6(dir-2), truss_n-1) +
            triangle(dir, upper_triangle_n) + 
            line(mod6(dir+2), truss_n);
    }
}


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //for (ll i = 0; i < 100; i++)
    //    cout << i << " -> " << zigzag(0, i) << "\n";
    //ll ten[19];
    //ten[0] = 1;
    //for (int i = 1; i <= 18; i++)
    //    ten[i] = ten[i-1] * 10;
    //ll n = ten[5];
    //ll n = 10;

    //for (ll i = 1; i <= ten[18]; i *= 2)
    //    cout << i << " -> " << triangle(0, i).size() << endl;
    //cout << triangle(0, n).size() << endl;

    ll n; cin >> n;
    cout << triangle(0, n) << "\n";
}