#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
struct Trpl {
  int i, j, k;
  Trpl() {}
  Trpl(int _i, int _j, int _k) : i(_i), j(_j), k(_k) {}
};
char s[MAX_N + 4], t[MAX_N + 4], v[MAX_N + 4], w[MAX_N + 4];
int vt[MAX_N][26];
int dp[MAX_N + 1][MAX_N + 1][MAX_N];
Trpl ps[MAX_N + 1][MAX_N + 1][MAX_N];
int main() {
  scanf("%s%s%s", s, t, v);
  int sn = strlen(s), tn = strlen(t), vn = strlen(v);
  for (int i = 0; i < vn; i++) {
    for (int j = 0; j < 26; j++) {
      w[i] = 'A' + j;
      for (int k = 0, l = i + 1; k <= i; k++, l--)
        if (!strncmp(v, w + k, l)) {
          vt[i][j] = l;
          break;
        }
    }
    w[i] = v[i];
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  ps[0][0][0] = Trpl(-1, -1, -1);
  for (int i = 0; i <= sn; i++)
    for (int j = 0; j <= tn; j++)
      for (int k = 0; k < vn; k++) {
        if (i < sn && j < tn && s[i] == t[j]) {
          int d1 = dp[i][j][k] + 1;
          int k1 = vt[k][s[i] - 'A'];
          if (k1 < vn && dp[i + 1][j + 1][k1] < d1) {
            dp[i + 1][j + 1][k1] = d1;
            ps[i + 1][j + 1][k1] = Trpl(i, j, k);
          }
        }
        if (i < sn && dp[i + 1][j][k] < dp[i][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          ps[i + 1][j][k] = Trpl(i, j, k);
        }
        if (j < tn && dp[i][j + 1][k] < dp[i][j][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          ps[i][j + 1][k] = Trpl(i, j, k);
        }
      }
  int maxd = -1, maxk = -1;
  for (int k = 0; k < vn; k++)
    if (maxd < dp[sn][tn][k]) maxd = dp[sn][tn][k], maxk = k;
  if (maxd == 0)
    puts("0");
  else {
    int l = 0;
    for (int i = sn, j = tn, k = maxk; i >= 0;) {
      Trpl p = ps[i][j][k];
      if (p.i < 0) break;
      if (p.i < i && p.j < j) w[l++] = s[p.i];
      i = p.i, j = p.j, k = p.k;
    }
    for (int i = l - 1; i >= 0; i--) putchar(w[i]);
    putchar('\n');
  }
  return 0;
}
