#include <bits/stdc++.h>
using namespace std;
const int NMAX = 120;
int l1, l2, v, r, f[NMAX][NMAX][NMAX];
int P[NMAX], path[NMAX][NMAX][NMAX];
char S1[NMAX], S2[NMAX], virus[NMAX], result[NMAX];
void init() {
  int i, j = 0;
  memset(f, ~0u, sizeof(f));
  for (i = 0; i <= l1; i += 1) f[i][0][0] = 0;
  for (i = 0; i <= l2; i += 1) f[0][i][0] = 0;
  for (i = 2; i <= v; i += 1) {
    while (j && virus[j + 1] != virus[i]) j = P[j];
    if (virus[j + 1] == virus[i]) j += 1;
    P[i] = j;
  }
}
void rebuildAnswer(int i, int j, int k) {
  if (!i || !j) return;
  if (path[i][j][k] == -1)
    rebuildAnswer(i - 1, j, k);
  else if (path[i][j][k] == -2)
    rebuildAnswer(i, j - 1, k);
  else {
    rebuildAnswer(i - 1, j - 1, path[i][j][k]);
    result[r++] = S1[i];
  }
}
int main() {
  int i, j, k, p, q, answer;
  scanf("%s %s %s", S1 + 1, S2 + 1, virus + 1);
  l1 = strlen(S1 + 1);
  l2 = strlen(S2 + 1);
  v = strlen(virus + 1);
  init();
  for (i = 1; i <= l1; i += 1) {
    for (j = 1; j <= l2; j += 1) {
      for (k = 0; k < v; k += 1) {
        if (f[i - 1][j][k] >= 0 && f[i - 1][j][k] > f[i][j][k]) {
          f[i][j][k] = f[i - 1][j][k];
          path[i][j][k] = -1;
        }
        if (f[i][j - 1][k] >= 0 && f[i][j - 1][k] > f[i][j][k]) {
          f[i][j][k] = f[i][j - 1][k];
          path[i][j][k] = -2;
        }
        if (S1[i] == S2[j]) {
          for (p = v - 1; p >= 0; p -= 1) {
            if (f[i - 1][j - 1][p] < 0) continue;
            q = p;
            while (q && S1[i] != virus[q + 1]) q = P[q];
            if (S1[i] == virus[q + 1]) {
              if (q + 1 == k && f[i - 1][j - 1][p] + 1 > f[i][j][k]) {
                f[i][j][k] = f[i - 1][j - 1][p] + 1;
                path[i][j][k] = p;
              }
            } else if (q == k && f[i - 1][j - 1][p] + 1 > f[i][j][k]) {
              f[i][j][k] = f[i - 1][j - 1][p] + 1;
              path[i][j][k] = p;
            }
          }
        }
      }
    }
  }
  for (k = 0, answer = 0; k < v; k += 1) {
    if (f[l1][l2][k] > answer) {
      answer = f[l1][l2][k];
      memset(result, 0, sizeof(result));
      r = 0;
      rebuildAnswer(l1, l2, k);
    }
  }
  if (!answer)
    printf("0\n");
  else
    printf("%s\n", result);
  exit(0);
}
