#include <bits/stdc++.h>

using namespace std;

int resi(string s1, string s2) {
    int n = s1.size(), m = s2.size();
    int dp[n][m];
    for(int i = 0;i < m;i++)
        if(s1[0] == s2[i])
            dp[0][i] = 1;
    for(int i = 1;i < n;i++)
        for(int j = 0;j < m;j++) {
            if(s1[i] == s2[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];
            }
        }
    return dp[n-1][m-1];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    cout << resi(s1, s2) << '\n';
    cout << s1;
    return 0;
}