#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string r,a;
    cin>>r>>a;
    int c,brp=0,mi=10e5,p=0,b=0,bri=0,poz=0,bjb=0;
    c=r.length();
    for(int i=0;i<=c-1;i++){
        if(r[i]==a[b]&&p==0)
            {brp=i; bri=1; bjb=0;mi=10e7;}
        if(r[i]==a[b]&&p==1)bri+=1;
        if(r[i]==a[b+1]){
            if(mi>bri)
                mi=bri;
                poz=brp;
            bri=1;
            brp=i;
            bjb+=1;
            b++;
        }
        else 
            p=0;}
    r+="*";
    for(int j=poz;j<=(mi+poz);j++)
        {swap(r[j],r[r.length()]);}
    r.erase (r.length());
    cout<<mi<<endl<<r;
return 0;
    }