#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<stdio.h>
#include<bitset>
#include<vector>
#include<set>
#include<time.h>
using namespace std;
typedef long long ll;
const int N = 1002;
char a[N], b[N];
int dp[N][N];
int n, m;
vector<int>nxt[26];
int oo = 1e6;
int calc(int i, int j){
if (i == n)
return oo;
if (j == m)
return 1;
if (dp[i][j] != -1)
return dp[i][j];
int ret = calc(i + 1, j);
int idx = lower_bound(nxt[a[i] - 'a'].begin(), nxt[a[i] - 'a'].end(), j) - nxt[a[i] - 'a'].begin();
if (idx == nxt[a[i] - 'a'].size())
ret = min(ret, calc(i + 1, m));
else
ret = min(ret, calc(i + 1, nxt[a[i] - 'a'][idx] + 1) + 1);
return dp[i][j] = ret;
}
void print(int i, int j){
if (j == m){
printf("%c\n", a[i]);
return;
}
int best = calc(i, j);
int idx = lower_bound(nxt[a[i] - 'a'].begin(), nxt[a[i] - 'a'].end(), j) - nxt[a[i] - 'a'].begin();
if (idx == nxt[a[i] - 'a'].size() && best == 1){
printf("%c\n", a[i]);
return;
}
else if (best == calc(i + 1, nxt[a[i] - 'a'][idx] + 1) + 1){
printf("%c", a[i]);
print(i + 1, nxt[a[i] - 'a'][idx] + 1);
}
else print(i + 1, j);
}
int main(){
memset(dp, -1, sizeof(dp));
scanf("%s%s", &a, &b);
n = strlen(a);
m = strlen(b);
for (int i = 0; i < m; ++i)
nxt[b[i] - 'a'].push_back(i);
printf("%d\n", calc(0, 0));
print(0, 0);
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8bWVtb3J5Lmg+CiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPGJpdHNldD4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxzZXQ+CiNpbmNsdW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