#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

bool check(int begin, int end, vector<vector<int> > &ind){
  if(begin>end)return false;
  for(int i = 0; i < (int)ind.size(); ++i){
    if(ind[i].size()==0)return false;
    vector<int>::iterator it_b = lower_bound(ind[i].begin(),ind[i].end(),begin);
    vector<int>::iterator it_e = lower_bound(ind[i].begin(),ind[i].end(),end);

    // cout << begin << ' ' << end << ' ' << i << ' ' << it_b-ind[i].begin() << ' ' << it_e-ind[i].begin() << endl;

    bool next_b = false;
    if(it_b==ind[i].end()){
      next_b=false;
    }else{
      if(begin<=*it_b&&*it_b<=end)next_b=true;
    }

    bool next_e = false;
    if(it_e==ind[i].end())--it_e;
    while(it_e!=ind[i].begin()){
      if(begin<=*it_e&&*it_e<=end){
        next_e = true;
        break;
      }
      --it_e;
    }
    if(it_e==ind[i].begin()){
      if(begin<=*it_e&&*it_e<=end){
        next_e=true;
      }
    }
    // cout << next_b << ' ' << next_e << endl;
    if(!next_b||!next_e)return false;
  }
  return true;
}

int main()
{
  bool first = true;
  while(true){
    string text, dam;
    while(true){
      string tmp;
      // if(!getline(cin,tmp))return 0;
      getline(cin,tmp);
      text+=tmp;
      if(tmp.length()==0)break;
    }
    if(text.length()==0) break;
    string key;
    getline(cin,key);
    getline(cin,dam);

    // cout << text.length() <<endl;


    //if(first)first=false;
    //else puts("");

    sort(key.begin(),key.end());
    key.erase( unique(key.begin(), key.end()), key.end() );
    vector< vector<int> > ind(key.length());
    
    // cout << key << endl;
    for(int i = 0; i < (int)text.length();++i){
      string::iterator it = lower_bound(key.begin(),key.end(),text[i]);
      if(it!=key.end()){
        if( *it == text[i] ){
          ind[it-key.begin()].push_back(i);
        }
      }
    }

    /*
    for(int i = 0; i < (int)ind.size(); ++i){
      for(int j = 0; j < (int)ind[i].size(); ++j){
        cout << ind[i][j] << ' ';
      }
      cout << endl;
    }
    cout << "---"<<endl;
    */

    int res_cnt = 0;
    int res_b = -1;
    int res_e = (int)text.length();
    for(int x = 0; x < (int)ind.size(); ++x){
      for(int i = 0; i < (int)ind[x].size(); ++i){
        int begin = ind[x][i];
        int left = begin;
        int right = text.length();
        int end;
        // int cnt = 0;
        while(left+1<right){
          end = (left+right)/2;
          if(check(begin,end,ind)){
            right = end;
          }else left = end;
        }
        for(int k = -2; k <= 2; ++k){
          int tend=end+k;
          // cout << begin << ' ' << tend << endl;
          if(check(begin,tend,ind)){
            if(res_e-res_b>tend-begin){
              res_e = tend;
              res_b = begin;
              res_cnt = 1;
            }else if( res_e-res_b==tend-begin){
              ++res_cnt;
              if( begin<res_b){
                res_e = tend;
                res_b = begin;
              }
            }
            // cout << begin<<' ' <<tend<<' '<<tend-begin<<endl;
            break;
          }
        }
      }
    }

    // cout << res_b << ' ' << res_e << endl;
    if(res_cnt==0){
      printf("0\n");
    }else{
      int cnt = 0;
      printf("%d\n\n",res_cnt);
      for(int i = res_b; i <= res_e; ++i){
        putchar(text[i]);
        ++cnt;
        if(cnt==72){putchar('\n');cnt=0;}
      }
      if(cnt>0){
        puts("");
      }
    }
    puts("");
    
  }
  return 0;
}

Measured memory_bytes: 1736