#include <bits/stdc++.h>
using namespace std;
int f[200][200][200];
string s1, s2;
string v;
int pi[200][200][200];
int pj[200][200][200];
int pk[200][200][200];
int p[200];
void pre() {
  int i, j;
  p[1] = 0;
  p[0] = 0;
  for (i = 2; i <= v.size(); i++) {
    j = p[i - 1];
    while (j > 0 && v[i - 1] != v[j]) j = p[j];
    if (v[i - 1] == v[j]) j = j + 1;
    p[i] = j;
  }
}
void print(int x, int y, int l) {
  if ((x == 0) || (y == 0)) return;
  int px = pi[x][y][l];
  int py = pj[x][y][l];
  int pl = pk[x][y][l];
  print(px, py, pl);
  if (f[px][py][pl] + 1 == f[x][y][l]) {
    printf("%c", s1[x - 1]);
  }
}
int main() {
  while (cin >> s1 >> s2 >> v) {
    pre();
    memset(f, 0, sizeof(f));
    int n1 = s1.size();
    int n2 = s2.size();
    int n = v.size();
    for (int i = 0; i <= n1; ++i) {
      for (int j = 0; j <= n2; ++j) {
        for (int k = 0; k < n; ++k) {
          if (f[i][j][k] < k) continue;
          if (i < n1 && f[i][j][k] > f[i + 1][j][k]) {
            f[i + 1][j][k] = max(f[i + 1][j][k], f[i][j][k]);
            pi[i + 1][j][k] = i;
            pj[i + 1][j][k] = j;
            pk[i + 1][j][k] = k;
          }
          if (j < n2 && f[i][j][k] > f[i][j + 1][k]) {
            f[i][j + 1][k] = max(f[i][j + 1][k], f[i][j][k]);
            pi[i][j + 1][k] = i;
            pj[i][j + 1][k] = j;
            pk[i][j + 1][k] = k;
          }
          if (i < n1 && j < n2 && f[i][j][k] > f[i + 1][j + 1][k]) {
            f[i + 1][j + 1][k] = max(f[i + 1][j + 1][k], f[i][j][k]);
            pi[i + 1][j + 1][k] = i;
            pj[i + 1][j + 1][k] = j;
            pk[i + 1][j + 1][k] = k;
          }
          if (i >= n1 || j >= n2) continue;
          if (s1[i] == s2[j]) {
            if (s1[i] == v[k]) {
              if (k < n - 1) {
                if (f[i][j][k] + 1 > f[i + 1][j + 1][k + 1]) {
                  f[i + 1][j + 1][k + 1] =
                      max(f[i + 1][j + 1][k + 1], f[i][j][k] + 1);
                  pi[i + 1][j + 1][k + 1] = i;
                  pj[i + 1][j + 1][k + 1] = j;
                  pk[i + 1][j + 1][k + 1] = k;
                }
              }
            } else {
              int pos = p[k];
              while (pos > 0 && (v[pos] != s1[i])) pos = p[pos];
              if (pos > 0)
                pos++;
              else if (v[pos] == s1[i])
                pos++;
              if (f[i][j][k] + 1 > f[i + 1][j + 1][pos]) {
                f[i + 1][j + 1][pos] =
                    max(f[i + 1][j + 1][pos], f[i][j][k] + 1);
                pi[i + 1][j + 1][pos] = i;
                pj[i + 1][j + 1][pos] = j;
                pk[i + 1][j + 1][pos] = k;
              }
            }
          }
        }
      }
    }
    int ans = 0;
    int p = -1;
    for (int i = 0; i < n; ++i) {
      if (f[n1][n2][i] > ans) {
        ans = f[n1][n2][i];
        p = i;
      }
    }
    if (ans == 0)
      puts("0");
    else {
      print(n1, n2, p);
      puts("");
    }
  }
  return 0;
}
