#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
inline T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
template <class T>
T gcd(T a, T b) {
  return (b == (T)0 ? a : gcd(b, a % b));
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T mathround(T x) {
  long long i64x = (long long)x;
  if (x < i64x + 0.5) return (T)i64x;
  return (T)i64x + 1;
}
template <class T>
bool isprime(T x) {
  int till = (T)sqrt(x + .0);
  if (x <= 1) return 0;
  if (x == 2) return 1;
  if (x % 2 == 0) return 0;
  for (int i = 3; i <= till; i += 2)
    if (x % i == 0) return 0;
  return 1;
}
const int LRG = (int)1e9;
struct tpl {
  int i, j, h;
  tpl(int _i = 0, int _j = 0, int _h = 0) {
    i = _i;
    j = _j;
    h = _h;
  }
};
string a;
int lna;
string b;
int lnb;
string v;
int lnv;
int dp[105][105][105];
tpl pr[105][105][105];
int F[105];
void build_failure_function() {
  F[0] = F[1] = 0;
  for (int i = 2; i <= lnv; i++) {
    int j = F[i - 1];
    while (1) {
      if (v[i - 1] == v[j]) {
        F[i] = j + 1;
        break;
      } else if (j > 0) {
        j = F[j];
      } else {
        F[i] = 0;
        break;
      }
    }
  }
}
int main() {
  cin >> a;
  lna = a.length();
  cin >> b;
  lnb = b.length();
  cin >> v;
  lnv = v.length();
  build_failure_function();
  for (int i = 0; i < 105; i++)
    for (int j = 0; j < 105; j++)
      for (int h = 0; h < 105; h++) dp[i][j][h] = -LRG;
  for (int i = 0; i <= lna; i++) dp[i][0][0] = 0;
  for (int i = 0; i <= lnb; i++) dp[0][i][0] = 0;
  for (int i = 1; i <= lna; i++) {
    for (int j = 1; j <= lnb; j++) {
      for (int h = 0; h < lnv; h++) {
        if (dp[i][j][h] < dp[i - 1][j][h]) {
          dp[i][j][h] = dp[i - 1][j][h];
          pr[i][j][h] = tpl(i - 1, j, h);
        }
        if (dp[i][j][h] < dp[i][j - 1][h]) {
          dp[i][j][h] = dp[i][j - 1][h];
          pr[i][j][h] = tpl(i, j - 1, h);
        }
        if (dp[i][j][h] < dp[i - 1][j - 1][h]) {
          dp[i][j][h] = dp[i - 1][j - 1][h];
          pr[i][j][h] = tpl(i - 1, j - 1, h);
        }
        if (a[i - 1] == b[j - 1]) {
          int tmp = h;
          while (tmp > 0 && a[i - 1] != v[tmp]) tmp = F[tmp];
          if (a[i - 1] == v[tmp]) tmp++;
          if (tmp < lnv && dp[i][j][tmp] < dp[i - 1][j - 1][h] + 1) {
            dp[i][j][tmp] = dp[i - 1][j - 1][h] + 1;
            pr[i][j][tmp] = tpl(i - 1, j - 1, h);
          }
        }
      }
    }
  }
  int x = lna;
  int y = lnb;
  int z = max_element(dp[lna][lnb], dp[lna][lnb] + 105) - dp[lna][lnb];
  string res = "";
  while (x > 0 && y > 0) {
    int pri = pr[x][y][z].i;
    int prj = pr[x][y][z].j;
    int prh = pr[x][y][z].h;
    if (pri == x - 1 && prj == y - 1) res += a[pri];
    x = pri;
    y = prj;
    z = prh;
  }
  reverse(res.begin(), res.end());
  if (res == "")
    cout << 0;
  else
    cout << res;
  return EXIT_SUCCESS;
}
