#include <bits/stdc++.h>
using namespace std;
int N, M, K, p[105][26], f[105][105][105], g[105][105][105][3];
char A[105], B[105], C[105], s[105];
void init() {
  scanf("%s%s%s", A + 1, B + 1, C + 1), N = strlen(A + 1), M = strlen(B + 1),
                                        K = strlen(C + 1);
  for (int i = 0; i < K; i++)
    for (int j = 0; j < 26; j++) {
      for (int k = i + 1; k; k--)
        if (C[k] == j + 65) {
          bool ok = 1;
          for (int l = k; ok && l > 1; l--)
            if (C[l - 1] != C[i - (k - l)]) ok = 0;
          if (ok) {
            p[i][j] = k;
            break;
          }
        }
    }
}
inline void up(int i, int j, int k, int ii, int jj, int kk, int d) {
  if (f[i][j][k] + d > f[ii][jj][kk])
    f[ii][jj][kk] = f[i][j][k] + d, g[ii][jj][kk][0] = i, g[ii][jj][kk][1] = j,
    g[ii][jj][kk][2] = k;
}
void doit() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      for (int k = 0; k < K; k++) {
        up(i - 1, j, k, i, j, k, 0), up(i, j - 1, k, i, j, k, 0);
        if (A[i] == B[j]) up(i - 1, j - 1, k, i, j, p[k][A[i] - 65], 1);
      }
  int t, m = 0, n = 0;
  for (int i = 0; i < K; i++)
    if (f[N][M][i] > m) t = i, m = f[N][M][i];
  if (!m) {
    puts("0");
    return;
  }
  for (int i = N, j = M, k = t; i || j;) {
    int ii = g[i][j][k][0], jj = g[i][j][k][1], kk = g[i][j][k][2];
    if (f[i][j][k] == f[ii][jj][kk] + 1) s[++n] = A[i];
    i = ii, j = jj, k = kk;
  }
  for (int i = n; i; i--) putchar(s[i]);
  puts("");
}
int main() {
  init();
  doit();
  return 0;
}
