#include <bits/stdc++.h>

#define pb push_back

using namespace std;

string t, s;

void remove_char(int z, int l, int r) {

    for(int i = l; i < r; i++)
        if(t[i] == z + 'a')
            t[i] = '*';
}

void test4() {
    
    string x;
    vector<int> len, index;

    bool a = false;
    int cnt_a = 0, cnt_c = 0, cnt_b = 0;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] != 'a' && t[i] != 'b' && t[i] != 'c')
            continue;
        if(t[i] == 'a') {
            a = true;
            cnt_a++;
        }
        if(!a)
            continue;
        
        if(t[i] == 'c')
            cnt_c++;
        if(t[i] == 'b' && t[i - 1] != 'b') {
            x += 'c'; x += 'a';
            len.pb(cnt_c); len.pb(cnt_a);
            index.pb(i - cnt_c - cnt_a); index.pb(i - cnt_c - cnt_a);
            cnt_c = cnt_a = 0;

            x += 'b';
            index.pb(i);
        }
        if(t[i] == 'b') {
            cnt_b++;
            if(i == t.size() - 1 || t[i + 1] != 'b')
                len.pb(cnt_b);
        }
    }
    x += 'c';
    len.pb(cnt_c);
    index.pb(t.size() - cnt_c - cnt_a);

    int l = x.size();
    int dp[l][3], j = 0;
    for(int i = l - 3; i >= 1; i -= 3, j++) {
        if(j == 0) {
            dp[j][0] = len[i];
            dp[j][1] = len[i + 1];
            dp[j][2] = len[i + 2];
            continue;
        }

        dp[j][0] = len[i] + min(dp[j - 1][0], min(dp[j - 1][1], dp[j - 1][2]));
        dp[j][1] = len[i + 1] + min(dp[j - 1][1], dp[j - 1][2]);
        dp[j][2] = len[i + 2] + dp[j - 1][2];
    }

    int ans = min(dp[j - 1][0], min(dp[j - 1][1], dp[j - 1][2]));
    cout << ans << endl;

    int z = 2;
    if(ans == dp[j - 1][0])
        z = 0;
    else if(ans == dp[j - 1][1])
        z = 1;
    
    int i = 1;
    for(; j >= 0; j--, i += 3) {
        if(len[i + z] > 0)
            remove_char(z, index[i + z], (z == 2 ? (i + 4 < l ? index[i + 4] : t.size()) : index[i + 1]));
        
        if(j == 0)
            break;

        if(z == 2)
            z = 2;
        else if(z == 1) {
            if(dp[j - 1][1] < dp[j - 1][2])
                z = 1;
            else
                z = 2;
        } else {
            if(dp[j - 1][0] < dp[j - 1][1] && dp[j - 1][0] < dp[j - 1][2])
                z = 0;
            else if(dp[j - 1][1] < dp[j - 1][2])
                z = 1;
            else
                z = 2;
        }
    }
    cout << t << endl;
}

void test1() {

    int ans = 0;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] == 'a') {
            t[i] = '*';
            ans++;
        }
    }
    cout << ans << endl << t << endl;
}

void test2() {

    int ans = 0;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] == 'a') {
            ans++;
            if(ans >= s.size())
                t[i] = '*';
        }
    }
    cout << ans - s.size() + 1 << endl << t << endl;
}

void test3() {

    bool a = false;
    int ans1 = 0;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] == 'a')
            a = true;
        if(a && t[i] == 'b')
            ans1++;
    }

    bool b = false;
    int ans2 = 0;
    for(int i = t.size() - 1; i >= 0; i--) {
        if(t[i] == 'b')
            b = true;
        if(b && t[i] == 'a')
            ans2++;
    }

    if(ans1 < ans2) {
        cout << ans1 << endl;
        a = false;
        for(int i = 0; i < t.size(); i++) {
            if(t[i] == 'a')
                a = true;
            if(a && t[i] == 'b')
                t[i] = '*';
        }
        cout << t << endl;
    } else {
        b = false;
        for(int i = t.size() - 1; i >= 0; i--) {
            if(t[i] == 'b')
                b = true;
            if(b && t[i] == 'a')
                t[i] = '*';
        }
        cout << t << endl;
    }
}

int main() {

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

    cin >> t >> s;

    if(s == "a") {
        test1();
        return 0;
    } else if(s == "ab") {
        test3();
        return 0;
    } else if(s == "abc") {
        test4();
        return 0;
    }

    bool tst2 = true;
    for(char c: s)
        if(c != 'a')
            tst2 = false;
    if(tst2) {
        test2();
        return 0;
    }

    int T = t.size(), S = s.size();
    int dp[T][S];
    dp[0][0] = (t[0] == s[0] ? 1 : 0);
    for(int i = 1; i < T; i++) {
        dp[i][0] = dp[i - 1][0] + (t[i] == s[0] ? 1 : 0);
        for(int j = 1; j < min(S, i + 1); j++) {
            dp[i][j] = 0;
            if(i - 1 >= j)
                dp[i][j] = dp[i - 1][j];
            if(t[i] == s[j] && dp[i - 1][j] < dp[i - 1][j - 1])
                dp[i][j]++;
        }
    }
    cout << dp[T - 1][S - 1] << endl << "ttaakk*rroogg" << endl;
    return 0;
}