#include <bits/stdc++.h>
char S1[121], S2[121], V[121];
int D[121][121][121], F[121], rx[121][121][121], ry[121][121][121],
    rz[121][121][121], rpl[121][121][121], ansn = 0;
char ans[121];
void inst(int x, int y, int z, int i, int j, int k, int pl) {
  D[x][y][z] = D[i][j][k] + pl;
  rx[x][y][z] = i;
  ry[x][y][z] = j;
  rz[x][y][z] = k;
  rpl[x][y][z] = pl;
}
int main() {
  int n, m, k, i, j, p;
  scanf("%s%s%s", S1 + 1, S2 + 1, V + 1);
  n = strlen(S1 + 1), m = strlen(S2 + 1), k = strlen(V + 1);
  for (i = 2; i <= k; i++) {
    int now = F[i - 1];
    while (1) {
      if (V[now + 1] == V[i]) {
        F[i] = now + 1;
        break;
      }
      if (now == 0) break;
      now = F[now];
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      for (p = 0; p <= k; p++) {
        if (D[i][j - 1][p] > D[i - 1][j][p])
          inst(i, j, p, i, j - 1, p, 0);
        else
          inst(i, j, p, i - 1, j, p, 0);
      }
      if (S1[i] == S2[j]) {
        for (p = 0; p < k; p++) {
          if (p && !D[i - 1][j - 1][p]) continue;
          int now = p;
          while (1) {
            if (S1[i] == V[now + 1]) {
              now++;
              break;
            }
            if (now == 0) break;
            now = F[now];
          }
          if (D[i][j][now] < D[i - 1][j - 1][p] + 1)
            inst(i, j, now, i - 1, j - 1, p, 1);
        }
      }
    }
  int mx = 0, nx, ny, nz;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      for (p = 0; p < k; p++) {
        if (mx < D[i][j][p]) mx = D[i][j][p], nx = i, ny = j, nz = p;
      }
  if (mx == 0) {
    printf("0");
    return 0;
  }
  while (nx > 0 && ny > 0) {
    int x, y, z;
    x = rx[nx][ny][nz];
    y = ry[nx][ny][nz];
    z = rz[nx][ny][nz];
    if (rpl[nx][ny][nz]) ans[ansn++] = S1[nx];
    nx = x;
    ny = y;
    nz = z;
  }
  for (i = ansn - 1; i >= 0; i--) printf("%c", ans[i]);
  return 0;
}
