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
#include<bits/stdc++.h>
using namespace std;
using lld = long long;

string repeat(const string& s, lld n) {
	if(n == 0) return "";

	string rem;
	string bl = "[", br = "]";
	if(s.length() == 1) bl = br = "";

	switch(n%9) {
		case 0: rem = ""; break;
		case 1: rem = s; break;
		case 2: rem = (s.length() <= 2 ? s+s : "2"+bl+s+br); break;
		default: rem = to_string(n%9)+bl+s+br;
	}

	string result = repeat(s,n/9);
	bl = "[", br = "]";
	if(result.length() == 1) bl = "", br = "";
	if(result != "") result = "9"+bl+result+br;
	return result+rem;
}

string solve(lld n) {
	if(n == 0) return "";
	if(n == 1) return "FBD";

	if(n%2 != 1) {
		string result = solve(n-1);
		return "F"+result+repeat("BF", n-1)+"B"+repeat("D",n);
	} else {
		string result = "";
		string small = solve(n/2-1);
		result += repeat("F" + small + repeat("BF", n/2-1) + "B", 2);
		result += repeat("FD", n/2) + "F";
		result += repeat(repeat("DB", n/2) + "D" + repeat("F", n/2+1), n/2);
		result += repeat("B", n);
		result += repeat("D", n);
		return result;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	lld n;
	cin >> n;

	string result = solve(n);
	cout << result << "\n";

	return 0;	
}