#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define sz(x) ((int)(x).size())
#define pb push_back
#define vec vector
#define fi first
#define se second
#define ends "\n"
#define sp ' '
#define fun function
#define ar(x) array<int, x>
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const long long MOD=1e9+7; 

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int mxX = 2e7;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
 	
    string s1, s2;
    cin >> s2 >> s1;
    int n = sz(s1), m = sz(s2);
    
    map<char, vec<int>> mp;

    for(int i = 1; i <= n; ++i)
        mp[s1[i - 1]].pb(i);
    
 	vec<vec<int>> dp_l(n + 1, vec<int> (m + 1));
    vec<vec<int>> dp_r(n + 2, vec<int> (m + 2));

    dp_l[0][0] = 1;

    for(int j = 1; j <= m; ++j){
        if(mp.find(s2[j - 1]) != mp.end()){
            for(auto i : mp[s2[j - 1]]){
                dp_l[i][j] = dp_l[i - 1][j - 1];
            }
        }

        for(int i = 0; i <= n; ++i)
            dp_l[i][j] += dp_l[i][j - 1];
    }

    dp_r[n + 1][m + 1] = 1;

    for(int j = m; j >= 1; --j){
        if(mp.find(s2[j - 1]) != mp.end()){
            for(auto i : mp[s2[j - 1]]){
                dp_r[i][j] = dp_r[i + 1][j + 1];
            }
        }

        for(int i = 1; i <= n + 1; ++i)
            dp_r[i][j] += dp_r[i][j + 1];

    }

    map<char, int> mpAns;

    for(int j = 1; j <= m; ++j){
        if(mp.find(s2[j - 1]) != mp.end()){
            bool ok = false;
            for(auto i : mp[s2[j - 1]]){
               ok = ok || (dp_l[i][j] && dp_r[i][j]);
            }
            if(ok)
                mpAns[s2[j - 1]]++;
        }
    }

    int ans = mxX;
    char c = 'a';
    for(auto &x : mpAns){
        if(x.se < ans){
            c = x.fi;
            ans = x.se;
        }
    }

    if(ans == mxX)
        cout << 0 << ends;
    else{
        cout << ans << ends;
        for(int j = 1; j <= m; ++j){
            if(s2[j - 1] == c){
                bool ok = false;
                for(auto i : mp[s2[j - 1]]){
                   ok = ok || (dp_l[i][j] && dp_r[i][j]);
                }
                if(ok)
                    s2[j - 1] = '*';
            }
        }
        cout << s2 << ends;

    }

}