#include <bits/stdc++.h>
using namespace std;
const int MAX_L = 110;
int An, Bn, Pn, Ansn;
char Ptr[MAX_L], A[MAX_L], B[MAX_L], Ans[MAX_L];
int P[MAX_L], F[MAX_L][MAX_L][MAX_L];
struct Triple {
  int i, j, k;
} G[MAX_L][MAX_L][MAX_L];
void GetP() {
  int i, j;
  for (P[1] = j = 0, i = 2; i <= Pn; i++) {
    while (j != 0 && Ptr[j + 1] != Ptr[i]) j = P[j];
    if (Ptr[j + 1] == Ptr[i]) j++;
    P[i] = j;
  }
}
void Construct(int i, int j, int k) {
  if (!F[i][j][k]) return;
  Triple g = G[i][j][k];
  if (g.i + 1 == i && g.j + 1 == j) Ans[++Ansn] = A[i];
  Construct(g.i, g.j, g.k);
}
inline void Main() {
  scanf("%s%s%s", A + 1, B + 1, Ptr + 1);
  An = strlen(A + 1), Bn = strlen(B + 1), Pn = strlen(Ptr + 1);
  GetP();
  for (int i = 0; i <= An; i++)
    for (int j = 0; j <= Bn; j++)
      for (int k = 0; k < Pn; k++) {
        int f = F[i][j][k];
        if (f > F[i + 1][j][k])
          F[i + 1][j][k] = f, G[i + 1][j][k] = (Triple){i, j, k};
        if (f > F[i][j + 1][k])
          F[i][j + 1][k] = f, G[i][j + 1][k] = (Triple){i, j, k};
        if (A[i + 1] == B[j + 1]) {
          char c = A[i + 1];
          if (c == Ptr[k + 1]) {
            if (f + 1 > F[i + 1][j + 1][k + 1])
              F[i + 1][j + 1][k + 1] = f + 1,
                                  G[i + 1][j + 1][k + 1] = (Triple){i, j, k};
          } else {
            int nxt = k;
            while (nxt != 0 && Ptr[nxt + 1] != c) nxt = P[nxt];
            if (Ptr[nxt + 1] == c) nxt++;
            if (f + 1 > F[i + 1][j + 1][nxt])
              F[i + 1][j + 1][nxt] = f + 1,
                           G[i + 1][j + 1][nxt] = (Triple){i, j, k};
          }
        }
      }
  int ans = -1, bestk = -1;
  for (int k = 0; k < Pn; k++)
    if (F[An][Bn][k] > ans) ans = F[An][Bn][k], bestk = k;
  assert(~ans), assert(~bestk);
  if (!ans)
    puts("0");
  else {
    Construct(An, Bn, bestk);
    for (int i = Ansn; i >= 1; i--) putchar(Ans[i]);
    puts("");
  }
}
int main() {
  Main();
  return 0;
}
