#include <bits/stdc++.h>
using namespace std;
const int nmax = 101;
const int oo = 1000000000;
string a, b, c;
int n, m, p;
int F[nmax][nmax][nmax];
int T[nmax][nmax][nmax];
int ne[nmax];
int ans;
int cs_luu;
char kq[nmax];
int buoc1() {
  ne[1] = 0;
  ne[0] = 0;
  int j = 0;
  for (int i = 2; i <= p; i++) {
    while (j > 0 && (c[i - 1] != c[j])) j = ne[j];
    if (c[i - 1] == c[j]) j++;
    ne[i] = j;
  }
  return 0;
}
int cs[nmax];
int buoc2() {
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      if (a[i - 1] != b[j - 1]) {
        for (int k = 0; k <= p - 1; k++) {
          F[i][j][k] = max(F[i][j - 1][k], F[i - 1][j][k]);
          T[i][j][k] = -1;
        }
      } else {
        for (int k = 0; k <= p - 1; k++) {
          F[i][j][k] = max(F[i][j - 1][k], F[i - 1][j][k]);
          T[i][j][k] = -1;
        }
        char kt = a[i - 1];
        for (int k = 0; k <= p; k++) cs[k] = 0;
        for (int k = 1; k <= p; k++)
          if (c[k - 1] == kt)
            cs[k - 1] = k;
          else {
            cs[k - 1] = cs[ne[k - 1]];
          }
        for (int k = 0; k <= p - 1; k++) {
          F[i][j][cs[k]] = max(F[i][j][cs[k]], F[i - 1][j - 1][k] + 1);
          if (F[i][j][cs[k]] == F[i - 1][j - 1][k] + 1) {
            T[i][j][cs[k]] = k;
          }
        }
      }
    }
  return 0;
}
int buoc3() {
  ans = 0;
  cs_luu = 0;
  for (int k = 0; k <= p - 1; k++)
    if (F[m][n][k] > ans) {
      ans = F[m][n][k];
      cs_luu = k;
    }
  return 0;
}
int buoc4() {
  int i = m;
  int j = n;
  int k = cs_luu;
  for (int xx = 1; xx <= ans; xx++) {
    while (0 != 1) {
      if (T[i][j][k] == -1) {
        if (F[i - 1][j][k] > F[i][j - 1][k])
          i--;
        else
          j--;
      } else {
        int k1 = T[i][j][k];
        kq[xx] = a[i - 1];
        i--;
        j--;
        k = k1;
        break;
      }
    }
  }
  for (int i = ans; i >= 2; i--) cout << kq[i];
  cout << kq[1] << endl;
  return 0;
}
int main() {
  getline(cin, a);
  getline(cin, b);
  getline(cin, c);
  m = a.length();
  n = b.length();
  p = c.length();
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= p; k++) F[i][j][k] = T[i][j][k] = -oo;
    }
  for (int i = 0; i <= m; i++) F[i][0][0] = 0;
  for (int j = 0; j <= n; j++) F[0][j][0] = 0;
  F[0][0][0] = 0;
  ans = 0;
  buoc1();
  buoc2();
  buoc3();
  if (ans == 0)
    cout << 0 << endl;
  else
    buoc4();
  return 0;
}
