/*
	Name: Prathamesh Shendarkar
	My Motto: IS TO NEVER GIVE UP
	My Belief: If you are not able to solve a particular question don't copy and paste a solution, 
			  no one is going to look into your account and tell you that, oh my look he has solved so many questions, 
			  remeber you are cheating on yourself, Just try to solve that question after some time or some days, 
			  or look upon a solution and check for the intiution or approach they have used, 
			  But never mug up there solution. 
			  Go for Learning don't copy plz.
*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ll long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define loop(x,n) for(ll i=x;i<n;i++)
#define loopa(x,n) for(ll j=x;j<n;j++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}

ll exp(ll x,ll y){ 
	ll res=1;
	x=x%mod;
	while(y>0) 
	{ 
		if(y&1) 
			res=(res*x)%mod; 
		y = y>>1;
		x=(x*x)%mod; 
	} 
	return res; 
} 

using namespace std;

ll check_prime(ll n){
	for(ll i = 2;i<=ceil(sqrt(n));i++){
		if(n%i == 0){
			return 0;
		}
	}
	return 1;
}

bool check_princi(vector<ll> v){
	ll n = v.size();
	for(ll i = 1;i<n - 1;i++){
		if(v[i - 1] + v[i + 1] < v[i]){
			return false;
		}
	}
	return true;
}

int main(){
    fastio;
    
    // So the problem is about longest common subsequence from atcoder.jp
    // So the strategy is simple, what we do is, first check the first character with the first character of other string
    // If there is match we update our answer
    // iF THERE IS NO MATCH then , we update first character of first string and compare with first character of second string
    // and we update first character of second string and compare with first character of first string
    // It follows recursion and there are many overlapping cases, so we need to use memoization to store all values
    // We will use dynamic approach to store values and update our answer
    // Our dp array will be 2d array
    string s,d;
	cin >> s >> d;
	int n = s.size();
	int m = d.size();
	
	vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
	
	
	for(ll i = 0;i <= n;i++){
		dp[0][i] = 0;
	}
	for(ll i = 0;i <= m;i++){
		dp[i][0] = 0;
	}
	
	for(ll i = 1;i <= m;i++){
		for(ll j = 1;j<=n;j++){
			if(d[i - 1] == s[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			
//			cout << dp[i][j] << " ";
		}
		cout << "\n";
	}
	
	string t;
	ll i = m, j = n;
	while(i >= 1 && j >= 1){
		if(dp[i][j] == dp[i - 1][j])
			i--;
		else if(dp[i][j] == dp[i][j - 1])
			j--;
		else if(dp[i][j] == (1 + dp[i - 1][j - 1])){
			t += d[i - 1];
			i--;
			j--;	
		}
	}
	reverse(t.begin(),t.end());
	cout << t << "\n";
}


/* <--SOME IMPORTANT CONCEPTS-->
  #1.
  ascii value for A-Z 065-096
  ascii value for a-z 097-122
  conversion:  lower=upper+32
  
  #2.
  converting a number to string:
  
  step:1 include the following class:
          #include<sstream>
  step:2  ostringstream st;
  
  step 3: st<<num
  
  step 4: string s=st.str();
  
  #3 
  converting a string to number
  
  step:1 include the following class:
          #include<sstream>
  
  step:2  stringstream val(s); //s is the string
  
  step:3  int y=0;
  
  step 4: val>>y;
  
  now y is the numeric form of the string

#4
  
  sorting in descending order
  
  sort(arr, arr+n, greater<int>());
 #5
  
  to convert a char to numeric
  (the character is c)
   c-'0'

 #6
  
  for(int &x:a)
  cin>>x;
  for(int &x:b)
  cout<<x<<" ";

#7    [bitwise left shift] 
       1<<n=pow(2,n)

#8
        [bitwise right shift]

         n>>k=n/pow(2,k)

#9
 clock_t start, end; 
  start = clock(); 
fun();
end = clock(); 

double time_taken 
        = double(end - start) 
          / double(CLOCKS_PER_SEC); 

cout << "Execution time: " << time_taken 
         << " secs";


*/




Measured memory_bytes: 35584