#include <bits/stdc++.h>

using namespace std;


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string s, t;

    cin >> s >> t;

    int n = s.size(), m = t.size();

    vector<int> iz(m);

    for(int i = 0; i < m; ++i){
        for(int j = 0; j < m; ++j){
            if(i == j) continue;
            if(t[i]==t[j]) ++iz[i];
        }
    }

    vector<vector<int>> brP;
    vector<int> tmp(m);

    int firInd = -1, lasInd = n;

    for(int i = 0; i < n; ++i){
        if(s[i] == t[0] && firInd == -1) firInd = i;
        else if(s[i] == t[m-1]) lasInd = i;
    }

    if(firInd == -1 || lasInd == n) { cout << 0 << '\n' << s << '\n'; return 0; } 
    
    for(int i = lasInd; i >= firInd; --i){
        for(int j = 0; j < m; ++j){
            if(s[i] == t[j]) ++tmp[j];
        }
        if(s[i] == t[0]) brP.push_back(tmp);
    }

    int minCnt = INT_MAX, tmpCnt = 0, ind = brP.size()-1, cnt = 0, chInd = 0;

    for(int i = firInd; i < lasInd; ++i){
        if(s[i] == t[0]){
            int tmpMin = brP[ind][0]-iz[0], tmpCh = 0;
            for(int j = 1; j < m; ++j){
                if(brP[ind][j]-iz[j] < tmpMin) { tmpMin = brP[ind][j]-iz[j]; tmpCh = j; }
            }
            if(tmpMin+tmpCnt < minCnt) { minCnt = tmpMin+tmpCnt; cnt = tmpCnt; chInd = tmpCh; }
            ++tmpCnt;
            --ind;
        }
    }

    if(minCnt == INT_MAX || minCnt == 0) cout << 0 << '\n' << s << '\n';
    else{
        char ch = t[chInd];
        int ans = minCnt;

        for(int i = firInd; i <= lasInd; ++i){
            if(s[i] == s[0] && cnt != 0){
                s[i] = '*';
                while(i < n && s[i] != t[0]) ++i;
                --i;
                --cnt;
                continue;
            }
            else if(s[i] == ch && cnt == 0 && minCnt > 0) s[i] = '*', --minCnt;
        }

        cout << ans << '\n' << s << '\n';
    }
    return 0;
}