#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#include <set>
#include <queue> 
#include <cctype>
#include <cmath>
#include <map>
#include <unordered_map>
#include <deque>
#include <sstream>

using namespace std;


void replace(string str, const string &bitset, unordered_map<int, int> &record, char nc){
    bool flag = false;
    int idx = 1;
    int i = bitset.size() - 1;
    while(i >= 0) {
        if(bitset[i] == '1') {
            int strIdx = record[idx];
            str[strIdx] = nc;
            flag = true;
        }
        --i;
        ++idx;
    }
    if(flag) {
        cout << ',' << str;
    }
}

bool nextBitSet(string &bitset) {
    const int len = bitset.size();
    if(bitset[len-1] == '0') {
        bitset[len-1] = '1';
        return true;
    }
    int curIdx = len-1;    
    while(curIdx >= 0) {
        if(bitset[curIdx] == '0') {
            bitset[curIdx] = '1';
            break;
        }
        bitset[curIdx--] = '0';
    }
    if(curIdx < 0) return false;
    return true;
}

int main()
{
    
    string str;
    char oc, nc;
    cin >> str >> oc >> nc;
    oc = tolower(oc);
    unordered_map<int, int> record;
    const int len = str.size();
    int idx = 1;
    int maxIdx = -1;
    bool found = false;
    for(int i = len-1; i >= 0; --i) {
        char ch = tolower(str[i]);
        if(ch == oc) {
            found = true;
            record[idx++] = i;
            maxIdx = (idx > maxIdx? idx : maxIdx);
        }
    }
    if(found) {        
        string bitset(maxIdx-1, '0');        
        cout << str;
        while(nextBitSet(bitset)) {
            replace(str, bitset, record, nc);
        }
        cout << endl;
       
    }else{
        cout << str << endl;
    }

    return 0;
}
100%通过