#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int kol = 0;
    for (int i = 0; i < m; i++) {
        kol += (t[i] == t[0]);
    }
    if (kol == m) {
        int k = 0;
        for (int i = 0; i < n; i++) {
            k += (s[i] == t[0]);
        }
        int ans = k - kol + 1;
        cout << ans << en;
        for (int i = 0; i < n; i++) {
            if (s[i] == t[0] && ans > 0) {
                s[i] = '*';
                ans -= 1;
            }
        }
        cout << s << en;
        return 0;
    }
    vector<int> cnt(m);
    vector<vector<int>> dp(n, vector<int>(m + 1, 1e9));
    int sol = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        vector<int> pos;
        int best = 1e9;
        vector<int> has(26);
        for (int j = 0; j < m; j++) {
            has[t[j] - 'a'] += 1;
            if (s[i] == t[j]) pos.push_back(j);
            if (j < m - 1) best = min(best, cnt[j] - has[t[j] - 'a'] + 1);
        }
        best = max(best, 0);
        int q = pos.size();
        if (i == 0) {
            if (q > 0) {
                dp[i][m] = 1;
                for (auto u : pos) {
                    cnt[u] += 1;
                    dp[i][u] = 0;
                }
            }
            continue;
        }
        if (q == 0) {
            for (int j = 0; j <= m; j++) dp[i][j] = ans;
            continue;
        }
        for (auto u : pos) {
            if (u < m - 1) dp[i][u] = ans;
            else dp[i][u] = best;
        }
        dp[i][m] = ans + 1;
        ans = 0;
        for (auto u : pos) {
            cnt[u] += 1;
            ans = max(ans, dp[i][u]);
        }
        ans = min(ans, dp[i][m]);
        sol = max(sol, ans);
    }
    cout << sol << en;
    return 0;

}