using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.SymbolStore;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Numerics;
//using System.Data;
//using System.Drawing;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            int n = s1.Length;
            int m = s2.Length;
            int[,] dp = new int[n, m];
            for (int j = 0; j < m; j++)
            {
                if (s1[0] == s2[j])
                {
                    dp[0, j] = 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] = Math.Min(dp[i, j], dp[i - 1, j - 1]);
                    }
                    else
                    {
                        dp[i, j] = dp[i - 1, j];
                    }
                }
            }
            Console.WriteLine(dp[n - 1, m - 1]);
            Console.WriteLine(s1);


        }
    }
}