#include <bits/stdc++.h>
using namespace std;
inline int Min(int a, int b) { return (a < b ? a : b); }
inline int Max(int a, int b) { return (a > b ? a : b); }
char S1[105];
char S2[105];
char C[105];
int DP[105][105][105];
bool vis[105][105][105];
int sigPos[105][105 * 3];
int M;
bool checa(int pos, int i, int x) {
  if (C[pos] != x) return false;
  for (int j = pos - 1; j >= 0; j--) {
    i--;
    if (C[j] != C[i]) return false;
  }
  return true;
}
int busca(int pos, int pos2, int pos3) {
  if (!C[pos3]) return -987654321;
  if (S1[pos] == 0 || S2[pos2] == 0) return 0;
  if (vis[pos][pos2][pos3]) return DP[pos][pos2][pos3];
  vis[pos][pos2][pos3] = true;
  if (S1[pos] == S2[pos2])
    DP[pos][pos2][pos3] = busca(pos + 1, pos2 + 1, sigPos[pos3][S1[pos]]) + 1;
  return DP[pos][pos2][pos3] =
             Max(DP[pos][pos2][pos3],
                 Max(busca(pos + 1, pos2, pos3), busca(pos, pos2 + 1, pos3)));
}
void recon(int pos, int pos2, int pos3) {
  if (!C[pos3]) return;
  if (S1[pos] == 0 || S2[pos2] == 0) return;
  if (S1[pos] == S2[pos2] &&
      DP[pos][pos2][pos3] ==
          busca(pos + 1, pos2 + 1, sigPos[pos3][S1[pos]]) + 1) {
    printf("%c", S1[pos]);
    recon(pos + 1, pos2 + 1, sigPos[pos3][S1[pos]]);
  } else if (DP[pos][pos2][pos3] == busca(pos + 1, pos2, pos3)) {
    recon(pos + 1, pos2, pos3);
  } else {
    recon(pos, pos2 + 1, pos3);
  }
}
int main() {
  scanf("%s %s %s", S1, S2, C);
  for (M = 0; C[M]; M++)
    ;
  for (int i = 0; C[i]; i++) {
    for (int j = 'A'; j <= 'Z'; j++) {
      int k = i;
      for (; k >= 0; k--) {
        if (checa(k, i, j)) {
          sigPos[i][j] = k + 1;
          break;
        }
      }
    }
  }
  if (busca(0, 0, 0) == 0)
    printf("0\n");
  else
    recon(0, 0, 0);
  return 0;
}
