#include <bits/stdc++.h>
using namespace std;
int n, m, l;
char a[105], b[105], c[105];
int ne[105];
inline void init() {
  gets(a + 1);
  gets(b + 1);
  gets(c + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  l = strlen(c + 1);
  ne[1] = 0;
  for (int i = 2; i <= l; ++i) {
    int j = ne[i - 1];
    for (; j && c[i] != c[j + 1]; j = ne[j])
      ;
    ne[i] = c[i] == c[j + 1] ? j + 1 : 0;
  }
}
struct dpval {
  int len, c, pi, pj, pk;
  inline friend bool operator>(const dpval &a, const dpval &b) {
    return a.len > b.len;
  }
} dp[105][105][105];
inline void upd(dpval &x, const dpval &v) {
  if (v > x) x = v;
}
char ans[105];
inline void solve() {
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      for (int k = 0; k < l; ++k) dp[i][j][k].len = -1;
  dp[0][0][0].len = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      for (int k = 0; k < l; ++k) {
        dpval &f = dp[i][j][k];
        if (f.len == -1) continue;
        if (i < n) upd(dp[i + 1][j][k], f);
        if (j < m) upd(dp[i][j + 1][k], f);
        if (i == n || j == m || a[i + 1] != b[j + 1]) continue;
        const dpval g = (dpval){f.len + 1, a[i + 1], i, j, k};
        if (a[i + 1] == c[k + 1])
          upd(dp[i + 1][j + 1][k + 1], g);
        else {
          int t = k;
          for (; t && c[t + 1] != g.c; t = ne[t])
            ;
          t = c[t + 1] == g.c ? t + 1 : 0;
          upd(dp[i + 1][j + 1][t], g);
        }
      }
  dpval f = (dpval){0, 0, 0, 0, 0};
  for (int i = 0; i < l; ++i) upd(f, dp[n][m][i]);
  if (!f.len)
    puts("0");
  else {
    for (; f.len; f = dp[f.pi][f.pj][f.pk]) ans[f.len] = f.c;
    puts(ans + 1);
  }
}
int main() {
  init();
  solve();
  return 0;
}
