#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#define ll long long
#define ull unsigned long long

using namespace::std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string t, s;
    cin >> t >> s;
    int acnt = 0;
    for(auto i : t) acnt += i == 'a';
    bool sonlya = true;
    for(auto i : s) if(i != 'a') sonlya = false;
    if(s == "a"){
        cout << acnt << endl;
        for(auto i : t) {
            if(i == 'a') cout << '*';
            else cout << i;
        }
        cout << endl;
    }
    else if(sonlya){
        cout << max(acnt - s.length() + 1, (ull) 0) << endl;
        int br = max(acnt - s.length() + 1, (ull) 0);
        for(auto i : t){
            if(br > 0 && i == 'a') cout << '*', br--;
            else cout << i;
        }
        cout << endl;
    }
    else if(s == "ab"){
        int tsize = t.length(), ssize = s.length();
        int baftera = 0, abeforeb = 0;
        bool isA = false, isB = false;
        for(int i=0;i<tsize;++i){
            if(t[i] == 'a') isA = true;
            if(t[i] == 'b' && isA) baftera++;
        }
        for(int i=tsize-1;i>=0;--i){
            if(t[i] == 'b') isB = true;
            if(t[i] == 'a' && isB) abeforeb++;
        }
        if(baftera < abeforeb){
            cout << baftera << endl;
            isA = false;
            for(int i=0;i<tsize;++i){
                if(t[i] == 'a') isA = true;
                if(t[i] == 'b' && isA) cout << '*';
                else cout << t[i];
            }
        }
        else{
            cout << abeforeb << endl;
            for(int i=0;i<tsize;++i){
                if(abeforeb > 0 && t[i] == 'a') cout << '*', abeforeb--;
                else cout << t[i];
            }
        }
        cout << endl;
    }
    else if(s == "abc") {
        int tsize = t.length(), ssize = s.length();
        int brA = 0, brB = 0, brC = 0;
        bool isA = false, isB = false;
        string tA = t, tB = t, tC = t;
        for(int i=0;i<tsize;i++){
            if(t[i] == 'a') isA = true;
            if(t[i] == 'b' && isA) isB = true;
            if(t[i] == 'c' && isA && isB) brC++, tC[i] = '*';
        }
        isB = false; bool isC = false;
        for(int i=tsize-1;i>=0;i--){
            if(t[i] == 'c') isC = true;
            if(t[i] == 'b' && isC) isB = true;
            if(t[i] == 'a' && isB && isC) brA++, tA[i] = '*';
        }
        int firstA = -1, lastC = -1;
        for(int i=0;i<tsize;i++){
            if(firstA == -1 && t[i] == 'a') firstA = i;
            if(t[i] == 'c') lastC = i;
        }
        if(firstA != -1 && lastC != -1){
            for(int i=firstA;i<=lastC;i++){
                if(t[i] == 'b') brB++, tB[i] = '*';
            }
        }
        int minBr = min(brA, min(brB, brC));
        cout << minBr << endl;
        if(minBr == brA) cout << tA << endl;
        else if(minBr == brB) cout << tB << endl;
        else cout << tC << endl;
    }
    else{
        int tsize = t.length(), ssize = s.length();
        vector<vector<int>> mask(tsize, vector<int>(ssize));
        vector<bool> izbrisan(tsize, false);
        char izbrisanoSlovo = t[0];
        for(int i=0;i<ssize;++i) mask[0][i] = t[0] == s[i], izbrisan[0] = izbrisan[0] || (t[0] == s[i]); 
        for(int i=1;i<tsize;++i){
            for(int j=0;j<ssize;++j){
                if(t[i] == s[j]){
                    //izbrisan[i] = true;
                    mask[i][j] = mask[i-1][j] + 1;
                    if(j > 0){
                        mask[i][j] = min(mask[i][j], mask[i-1][j-1]);
                        izbrisan[i] = mask[i][j] < mask[i-1][j-1];
                        //izbrisan[i-1] = mask[i][j] >= mask[i-1][j-1];
                        izbrisanoSlovo = mask[i][j] < mask[i-1][j-1] ? s[j] : izbrisanoSlovo;
                    }
                }
                else{
                    mask[i][j] = mask[i-1][j];
                }
            }
        }

        cout << mask[tsize-1][ssize-1] << endl;
        int br = 0;
        for(int i=0;i<tsize;++i){
            if(izbrisan[i] && t[i] == izbrisanoSlovo) cout << '*', br++;
            else cout << t[i];
        }
        cout << endl;
    }
    return 0;
}