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

#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string t;
	cin >> t;
	string s;
	cin >> s;

	int n = (int)t.size();
	int m = (int)s.size();


	multiset<pair<int, char>> poc; 
    vector<int> kraj(10, -1);
	int j = 0;
	for (int i = 0; i < n && j < m; i++) {
		// trazimo prvo pojavljivanje elemenata
		if (t[i] == s[j]) {
			poc.insert({i, t[i]});
			++j;
		}
	}

	if (j != m) {
		cout << 0 << "\n" << t << "\n";
		return 0;
	}

	j = m - 1;
	for (int i = n - 1; i >= 0 && j >= 0; i--) {
		// trazimo poslednje pojavljivanje elemenata
		if (t[i] == s[j] && kraj[j] == -1) {
			kraj[j] = i;
			--j;
		}
	}

/*	for (int k : kraj) cout << k << " ";
	cout << "\n"; */

	int cnt = 2e5 + 6;
	int tr_ind = 0;
	
	string odg = "";
	for (auto it : poc) {
		char c = it.second;
		int brisi = 0;
		string temp = t;
		bool usao = false;
		
		for (int i = it.first; i < n; i++) {
			if (t[i] == c){ 
				if (tr_ind != m - 1) {
					if (i > kraj[tr_ind + 1]) {
						break;
					}
				}
				++brisi;
				temp[i] = (char)42;
				usao = true;
			}
		}
		if (cnt > brisi && usao) {
			cnt = brisi;
			odg = temp;
		}
		++tr_ind;
	}
	cout << cnt << "\n" << odg << "\n";
	return 0;
}