#include <iostream>
#include <string>
#include <vector>
using namespace std;
void combinations(const string& s, vector<int>& pos, int n) {
if (n == s.size()) {
for (int i = 0 ; i != n ; i++) {
cout << s[pos[i]];
}
cout << endl;
return;
}
for (int i = 0 ; i != s.size(); i++) {
pos[n] = i;
combinations(s, pos, n+1);
}
}
int main() {
string s("ABC");
vector<int> pos(s.size(), 0);
combinations(s, pos, 0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBjb21iaW5hdGlvbnMoY29uc3Qgc3RyaW5nJiBzLCB2ZWN0b3I8aW50PiYgcG9zLCBpbnQgbikgewogICAgaWYgKG4gPT0gcy5zaXplKCkpIHsKICAgICAgICBmb3IgKGludCBpID0gMCA7IGkgIT0gbiA7IGkrKykgewogICAgICAgICAgICBjb3V0IDw8IHNbcG9zW2ldXTsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBlbmRsOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGZvciAoaW50IGkgPSAwIDsgaSAhPSBzLnNpemUoKTsgaSsrKSB7CiAgICAgICAgcG9zW25dID0gaTsKICAgICAgICBjb21iaW5hdGlvbnMocywgcG9zLCBuKzEpOwogICAgfQp9CgppbnQgbWFpbigpIHsKCXN0cmluZyBzKCJBQkMiKTsKCXZlY3RvcjxpbnQ+IHBvcyhzLnNpemUoKSwgMCk7CiAgICBjb21iaW5hdGlvbnMocywgcG9zLCAwKTsKCXJldHVybiAwOwp9