#include <bits/stdc++.h>
const int N = 100 + 10;
int dp[N][N][N];
int pre[N][N][N][3];
char s1[N], s2[N], vir[N];
int next[N];
char ans[N];
void makeNext(int n) {
  next[0] = -1;
  int i = 0, j = -1;
  while (i < n) {
    if (j == -1 || vir[i] == vir[j]) {
      i++;
      j++;
      next[i] = j;
    } else
      j = next[j];
  }
}
void DP(int x, int y, int z, int x1, int y1, int z1, int val) {
  if (dp[x][y][z] < dp[x1][y1][z1] + val) {
    dp[x][y][z] = dp[x1][y1][z1] + val;
    pre[x][y][z][0] = x1;
    pre[x][y][z][1] = y1;
    pre[x][y][z][2] = z1;
  }
}
int main() {
  int i, j, k;
  scanf("%s%s%s", s1, s2, vir);
  int len1 = strlen(s1);
  int len2 = strlen(s2);
  int len3 = strlen(vir);
  memset(dp, 0, sizeof(dp));
  memset(pre, -1, sizeof(pre));
  makeNext(len3);
  for (i = 0; i <= len1; ++i)
    for (j = 0; j <= len2; ++j) {
      for (k = 0; k < len3; ++k) {
        DP(i + 1, j, k, i, j, k, 0);
        DP(i, j + 1, k, i, j, k, 0);
        if (dp[i][j][k] >= 0 && s1[i] == s2[j]) {
          if (s1[i] == vir[k]) {
            DP(i + 1, j + 1, k + 1, i, j, k, 1);
          } else {
            int p = next[k];
            while (p != -1 && s1[i] != vir[p]) p = next[p];
            if (p == -1) p = 0;
            DP(i + 1, j + 1, p + (s1[i] == vir[p]), i, j, k, 1);
          }
        }
      }
    }
  int z;
  int Max = -1;
  for (k = 0; k < len3; ++k)
    if (Max < dp[len1][len2][k]) {
      Max = dp[len1][len2][k];
      z = k;
    }
  if (Max <= 0)
    printf("0\n");
  else {
    int tMax = Max;
    int x = len1, y = len2;
    while (pre[x][y][z][0] != -1) {
      int xx = pre[x][y][z][0];
      int yy = pre[x][y][z][1];
      int zz = pre[x][y][z][2];
      if (x - xx == 1 && y - yy == 1 && s1[x - 1] == s2[y - 1])
        ans[Max--] = s1[x - 1];
      x = xx;
      y = yy;
      z = zz;
    }
    for (i = 1; i <= tMax; ++i) printf("%c", ans[i]);
    printf("\n");
  }
}
