def rep(s, t): if t == 0: return '' if t == 1: return s if t <= 9: return f'{t}[{s}]' return rep(rep(s, t // 9), 9) + rep(s, t % 9) def tri(n): if n == 1: return 'B' l = n // 2 r = n - l out = tri(l) line = rep('D', l) + rep('BF', l - 1) + 'B' out += rep(line, r) out += rep('F', r) out += tri(r) return out def tri2(n): assert n > 0 if n == 1: return 'B' if n % 2 == 0: s = tri2(n - 1) line = rep('D', n - 1) + rep('BF', n - 1) + 'B' return s + line m = n // 2 #assert m % 2 == 1 rec = tri2(m) out = rep(rec, 2) out += rep('D', m) out += rep('F', m) out += rep('D', m) line = rep('BF', m - 1) + 'B' + rep('D', m) out += rep(line, m) out += rep('BF', m + m) + 'B' return out n = int(input()) print(tri2(n) + rep('D', n) + rep('F', n))
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 | def rep(s, t): if t == 0: return '' if t == 1: return s if t <= 9: return f'{t}[{s}]' return rep(rep(s, t // 9), 9) + rep(s, t % 9) def tri(n): if n == 1: return 'B' l = n // 2 r = n - l out = tri(l) line = rep('D', l) + rep('BF', l - 1) + 'B' out += rep(line, r) out += rep('F', r) out += tri(r) return out def tri2(n): assert n > 0 if n == 1: return 'B' if n % 2 == 0: s = tri2(n - 1) line = rep('D', n - 1) + rep('BF', n - 1) + 'B' return s + line m = n // 2 #assert m % 2 == 1 rec = tri2(m) out = rep(rec, 2) out += rep('D', m) out += rep('F', m) out += rep('D', m) line = rep('BF', m - 1) + 'B' + rep('D', m) out += rep(line, m) out += rep('BF', m + m) + 'B' return out n = int(input()) print(tri2(n) + rep('D', n) + rep('F', n)) |