#include <bits/stdc++.h>
char s1[101], s2[101], v[101];
int m, n, l, AT[26][102], DT[110][110][110];
inline int max(int a, int b) { return a > b ? a : b; }
inline void make_table() {
  int i, j, k, kk;
  for (i = 0; i < l; i++) AT[v[i] - 'A'][i] = i + 1;
  for (i = 1; i < l; i++) {
    for (j = 'A'; j <= 'Z'; j++) {
      if (!AT[j - 'A'][i]) {
        for (k = i - 1; k >= 0; k--) {
          if (j == (int)v[k]) {
            for (kk = 1; kk <= k && v[i - kk] == v[k - kk]; kk++)
              ;
            if (kk > k) {
              AT[j - 'A'][i] = k + 1;
              break;
            }
          }
        }
      }
    }
  }
}
int solve(int a, int b, int c) {
  if (c == l) return DT[a][b][c] = -100;
  if (a == n || b == m) return DT[a][b][c] = 0;
  if (DT[a][b][c] == -1) {
    DT[a][b][c] = max(solve(a + 1, b, c), solve(a, b + 1, c));
    if (s1[a] == s2[b])
      DT[a][b][c] =
          max(DT[a][b][c], solve(a + 1, b + 1, AT[s1[a] - 'A'][c]) + 1);
  }
  return DT[a][b][c];
}
void prt(int a, int b, int c) {
  if (a == n || b == m) return;
  if (DT[a + 1][b][c] == DT[a][b][c])
    prt(a + 1, b, c);
  else if (DT[a][b + 1][c] == DT[a][b][c])
    prt(a, b + 1, c);
  else {
    printf("%c", s1[a]);
    prt(a + 1, b + 1, AT[s1[a] - 'A'][c]);
  }
}
int ans;
int main() {
  memset(DT, -1, sizeof(DT));
  scanf("%s%s%s", s1, s2, v);
  n = strlen(s1), m = strlen(s2), l = strlen(v);
  make_table();
  ans = solve(0, 0, 0);
  if (!ans)
    printf("%d\n", ans);
  else
    prt(0, 0, 0), puts("");
}
