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

//      Starting Kit     (START)
typedef long long ll;
#define INF INT_MAX
#define MOD (1e9+7)

#define pii pair<int, int>
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vii vector<pii>
#define pb push_back
#define print_vect(v) for (auto it : v) cout << it << " ";
//      Starting Kit     (END)

void izbroj(string T, string X) {

    int N = T.size();
    int M = X.size();

    int dp[N][M] = {};

    for (int j = 0; j < M; j++) {
        if (T[0] == X[j]) {
            dp[0][j] = 1;
        }
    }

    for (int i = 1; i < N; i++) {
        for (int j = 0; j < M; j++) {

            if (T[i] == X[j]) {
                dp[i][j] = dp[i - 1][j] + 1;
                if (j != 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
            }
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    cout << dp[N - 1][M - 1] << endl;
    cout << T << endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string T; cin >> T;
    string S; cin >> S;
    izbroj(T, S);

    return 0;
}