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
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	i64 n;
	cin >> n;
	function<string(string, i64)> get = [&] (string str, i64 cnt) -> string {
		if(cnt < 10) {
			return string(1, cnt + '0') + "[" + str + "]";
		} else {
			return "9[" + get(str, cnt / 9) + "]" + get(str, cnt % 9);
		}
	};
	function<string(i64)> solve = [&] (i64 n) -> string {
		if(n <= 2) {
			if(n == 1) {
				return "B";
			} else if(n == 2) {
				return "BDBFB";
			}
		}
		if(n & 1) {
			i64 m = n - 1 >> 1;
			string res = solve(m);
			string ans = get(res, 2);
			ans += get("CE", n - 1);
			ans += get(get("AE", m) + "A" + get("C", m), m);
			ans += get("A", m);
			ans += "B";
			return ans;
		} else {
			string res = solve(n - 1);
			string ans = res + get("D", n - 1) + get("BF", n - 1) + "B";
			return ans;
		}
	};
	string ans = solve(n) + get("D", n) + get("F", n);
	cout << ans << '\n';
	return 0;
}