#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
using namespace std;
char a[115][40];
char b[115][40];
int dp[115][115];
int acnt, bcnt;
bool flag = 0;
void output( int i, int j)
{
if(dp[i][j] == 0)
return;
if(dp[i][j] == dp[i-1][j-1] + 1 && strcmp(a[i], b[j]) == 0)
{
output(i-1, j-1);
if(flag)
cout<<" ";
cout<<a[i];
flag = 1;
}
else if(dp[i][j] == dp[i-1][j])
output(i-1, j);
else
output(i, j-1);
}
int main()
{
acnt = 1, bcnt = 1;
while(scanf("%s",a[acnt++]) != EOF)
{
while(scanf("%s",a[acnt++]))
if(strcmp(a[acnt-1],"#") == 0)
break;
while(scanf("%s",b[bcnt++]))
if(strcmp(b[bcnt-1],"#") == 0)
break;
memset(dp ,0 ,sizeof(dp));
for(int i = 1; i < acnt-1; i++)
{
for( int j = 1; j < bcnt-1; j++)
{
if(strcmp(a[i], b[j]) == 0)
dp[i][j] = dp[i-1][j-1] + 1;
else
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
flag = false;
output( acnt-2, bcnt-2);
acnt = bcnt =1;
cout<<endl;
}
}
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
using namespace std;
char a[115][40];
char b[115][40];
int dp[115][115];
int acnt, bcnt;
bool flag = 0;
void output( int i, int j)
{
if(dp[i][j] == 0)
return;
if(dp[i][j] == dp[i-1][j-1] + 1 && strcmp(a[i], b[j]) == 0)
{
output(i-1, j-1);
if(flag)
cout<<" ";
cout<<a[i];
flag = 1;
}
else if(dp[i][j] == dp[i-1][j])
output(i-1, j);
else
output(i, j-1);
}
int main()
{
acnt = 1, bcnt = 1;
while(scanf("%s",a[acnt++]) != EOF)
{
while(scanf("%s",a[acnt++]))
if(strcmp(a[acnt-1],"#") == 0)
break;
while(scanf("%s",b[bcnt++]))
if(strcmp(b[bcnt-1],"#") == 0)
break;
memset(dp ,0 ,sizeof(dp));
for(int i = 1; i < acnt-1; i++)
{
for( int j = 1; j < bcnt-1; j++)
{
if(strcmp(a[i], b[j]) == 0)
dp[i][j] = dp[i-1][j-1] + 1;
else
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
flag = false;
output( acnt-2, bcnt-2);
acnt = bcnt =1;
cout<<endl;
}
}