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
#include <cstdio>

const int max_n = 1000000;

int len;
char output[max_n];

void triangle(long long n, int direction);

inline int move(int direction, int steps) {
 return (direction + steps) % 6;
}

void line(long long n, int direction) {
  if (n % 9 > 0) {
    if (n % 9 >= 4) {
      output[len++] = '0' + n % 9;
      output[len++] = '[';
      output[len++] = 'A' + direction;
      output[len++] = ']';
    } else {
      for (int i = 0; i < n % 9; ++i) {
        output[len++] = 'A' + direction;
      }
    }
    line(n - n % 9, direction);
  } else if (n > 0) {
    output[len++] = '9';
    output[len++] = '[';
    line(n / 9, direction);
    output[len++] = ']';
  }
}

void stairs(long long n, int directionA, int directionB) {
  if (n % 9 > 0) {
    if (n % 9 >= 3) {
      output[len++] = '0' + n % 9;
      output[len++] = '[';
      output[len++] = 'A' + directionA;
      output[len++] = 'A' + directionB;
      output[len++] = ']';
    } else {
      for (int i = 0; i < n % 9; ++i) {
        output[len++] = 'A' + directionA;
        output[len++] = 'A' + directionB;
      }
    }
    stairs(n - n % 9, directionA, directionB);
  } else if (n > 0) {
    output[len++] = '9';
    output[len++] = '[';
    stairs(n / 9, directionA, directionB);
    output[len++] = ']';
  }
}

void semi_triangle(long long n, int direction) {
  if (n == 0) {
    // none
  } else if (n == 1) {
    output[len++] = 'A' + direction;
  } else if (n == 2) {
    output[len++] = 'A' + direction;
    output[len++] = 'A' + move(direction, 4);
    output[len++] = 'A' + direction;
    output[len++] = 'A' + move(direction, 2);
    output[len++] = 'A' + direction;
  } else { // n > 2
    line(n - 1, direction);
    output[len++] = 'A' + move(direction, 4);
    stairs(n - 3, move(direction, 2), move(direction, 4));
    triangle(n - 3, direction);
    output[len++] = 'A' + move(direction, 2);
    stairs(n - 1, move(direction, 4), direction);
    stairs(n - 1, move(direction, 2), direction);
  }
}

void tooth(long long n, long long m, int directionA, int directionB, int directionC) {
  if (n % 9 > 0) {
    if (n % 9 > 1) {
      output[len++] = '0' + n % 9;
      output[len++] = '[';
    }
    line(m, directionA);
    stairs(m, directionB, directionC);
    output[len++] = 'A' + directionB;
    if (n % 9 > 1) {
      output[len++] = ']';
    }
  }
  n -= n % 9;
  if (n > 0) {
    output[len++] = '9';
    output[len++] = '[';
    tooth(n / 9, m, directionA, directionB, directionC);
    output[len++] = ']';
  }
}

void triangle(long long n, int direction) {
  if (n == 0) {
    // nothing to do
  } else if (n == 1) {
    output[len++] = 'A' + direction;
    output[len++] = 'A' + move(direction, 4);
    output[len++] = 'A' + move(direction, 2);
  } else if (n % 2 == 1) {
    output[len++] = 'A' + direction;
    triangle(n - 1, direction);
    stairs(n - 1, move(direction, 4), direction);
    output[len++] = 'A' + move(direction, 4);
    line(n, move(direction, 2));
  } else { // n = 2k
    output[len++] = '2';
    output[len++] = '[';
    semi_triangle(n / 2, direction);
    output[len++] = ']';
    line(n / 2, move(direction, 4));
    tooth(n / 2, n / 2, move(direction, 4), move(direction, 2), direction);
    line(n / 2, move(direction, 4));
    line(n / 2, move(direction, 2));
  }
}

int main() {
  long long n;
  scanf("%lld", &n);
  len = 0;
  triangle(n, 0);
  output[len] = 0;
//  printf("%d\n", len);
  printf("%s\n", output);
  return 0;
}