#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int dp[N][N][N];
int lps[N];
string a, b, v;
int n, m, len;
void kmppreprocess(string s) {
  lps[0] = -1;
  int i = 0;
  int j = -1;
  int n = s.size();
  while (i < n) {
    while (j >= 0 && s[i] != s[j]) j = lps[j];
    i++;
    j++;
    lps[i] = j;
  }
}
int search(char ch, int pos, string s) {
  while (pos >= 0 && ch != s[pos]) pos = lps[pos];
  pos++;
  return pos;
}
int rec(int x, int y, int z) {
  if (z == len) return -1000000007;
  if (x == n && y == m) return 0;
  if (x > n || y > m) return -1000000007;
  if (dp[x][y][z] != -1) return dp[x][y][z];
  int ans = -1000000007;
  ans = max(ans, rec(x + 1, y, z));
  ans = max(ans, rec(x, y + 1, z));
  if (a[x] == b[y]) {
    ans = max(ans, 1 + rec(x + 1, y + 1, search(a[x], z, v)));
  }
  return dp[x][y][z] = ans;
}
string solve(int x, int y, int z) {
  if (x == n && y == m) return "";
  if (rec(x + 1, y, z) == rec(x, y, z))
    return solve(x + 1, y, z);
  else if (rec(x, y + 1, z) == rec(x, y, z))
    return solve(x, y + 1, z);
  else
    return a[x] + solve(x + 1, y + 1, search(a[x], z, v));
}
int main() {
  cin >> a >> b >> v;
  n = a.size();
  m = b.size();
  len = v.size();
  kmppreprocess(v);
  memset(dp, -1, sizeof(dp));
  int ans = rec(0, 0, 0);
  if (ans <= 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << solve(0, 0, 0) << endl;
}
