For a given *n* there are always
*2^n* ways, as for each position we can
choose 2 differents symbols. For a general number
of symbols, the usual approach would be
backtracking, but since you only have two symbols,
an easier approach using bitmasks works.

Notice that the numbers between *0* and
*2^n - 1* written in binary contain all
possible bitmasks of lenght *n*, so you can
just "print the numbers in binary, writing A or B
depending if the bit is a 0 or a 1.

```
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < (1 << n); ++i) {
for (int j = 0; j < n; ++j) {
cout << (((i >> j) & 1) ?
"B" : "A");
}
cout << endl;
}
}
```