#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b & 1) return a * power(a, b - 1);
  long long int temp = power(a, b / 2);
  return temp * temp;
}
bool mycompare(long long int a, long long int b) { return a > b; }
int reset[101];
string s1, s2, lucky;
int l1, l2, l3;
int dp[101][101][101];
void buildtable() {
  reset[0] = -1;
  int i = 0, j = -1;
  while (i < l3) {
    while (j >= 0 && lucky[i] != lucky[j]) j = reset[j];
    j++;
    i++;
    reset[i] = j;
  }
  return;
}
int kmp(int j, char c) {
  while (j >= 0 && lucky[j] != c) j = reset[j];
  j++;
  return j;
}
int helper(int i, int j, int k) {
  ;
  if (k == l3) return INT_MIN + 1;
  if (i == l1 || j == l2) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int ans = 0;
  if (s1[i] == s2[j]) {
    int temp = kmp(k, s1[i]);
    ans = max(ans, 1 + helper(i + 1, j + 1, temp));
  }
  int op1 = helper(i + 1, j, k);
  int op2 = helper(i, j + 1, k);
  return dp[i][j][k] = max(ans, max(op1, op2));
}
bool flag = false;
void construct(int i, int j, int k) {
  if (i == l1 || j == l2) return;
  int ans = helper(i, j, k);
  if (ans == helper(i + 1, j, k)) {
    construct(i + 1, j, k);
    return;
  }
  if (ans == helper(i, j + 1, k)) {
    construct(i, j + 1, k);
    return;
  }
  cout << s1[i];
  flag = true;
  construct(i + 1, j + 1, kmp(k, s1[i]));
  return;
}
void solve() {
  cin >> s1 >> s2 >> lucky;
  l1 = s1.size();
  ;
  l2 = s2.size();
  ;
  l3 = lucky.size();
  ;
  buildtable();
  memset(dp, -1, sizeof dp);
  int ans = helper(0, 0, 0);
  if (!ans)
    cout << '0';
  else
    construct(0, 0, 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int test = 1;
  while (test--) {
    solve();
  }
}
