#include <bits/stdc++.h>
using namespace std;
struct eugin {
  int x, y, z;
  char v;
};
char s[3][110];
int l[3];
int f[110][110][110];
int p[110][26];
eugin path[110][110][110];
int check(int x, int y, int i) {
  if (s[0][i] != 'A' + y) return false;
  i--;
  x--;
  while (i >= 0) {
    if (s[0][i] != s[0][x]) return false;
    i--;
    x--;
  }
  return true;
}
int calc(int x, int y) {
  int ret = 0;
  for (int i = l[0]; i >= 1; i--)
    if (x >= i - 1) {
      if (check(x, y, i - 1)) {
        ret = i;
        break;
      }
    }
  return ret;
}
void init() {
  int i, j;
  for (i = 0; i < l[0]; i++)
    for (j = 0; j < 26; j++) p[i][j] = calc(i, j);
  memset(f, -1, sizeof(f));
  memset(path, -1, sizeof(path));
}
int F(int x, int y, int z) {
  if (z >= l[0]) return -22222222;
  if (f[x][y][z] != -1) return f[x][y][z];
  if (x >= l[1] || y >= l[2]) {
    f[x][y][z] = 0;
    return 0;
  }
  int ret = -22222222;
  eugin temp;
  int t = F(x + 1, y, z);
  if (t > ret) {
    ret = t;
    temp.x = x + 1;
    temp.y = y;
    temp.z = z;
    temp.v = -1;
  }
  t = F(x, y + 1, z);
  if (t > ret) {
    ret = t;
    temp.x = x;
    temp.y = y + 1;
    temp.z = z;
    temp.v = -1;
  }
  if (s[1][x] == s[2][y]) t = F(x + 1, y + 1, p[z][s[1][x] - 'A']) + 1;
  if (t > ret) {
    ret = t;
    temp.x = x + 1;
    temp.y = y + 1;
    temp.z = p[z][s[1][x] - 'A'];
    temp.v = s[1][x];
  }
  path[x][y][z] = temp;
  f[x][y][z] = ret;
  return ret;
}
int main() {
  int ans, i, x, y, z;
  char out[110];
  scanf("%s", s[1]);
  l[1] = strlen(s[1]);
  scanf("%s", s[2]);
  l[2] = strlen(s[2]);
  scanf("%s", s[0]);
  l[0] = strlen(s[0]);
  init();
  ans = F(0, 0, 0);
  if (ans == 0)
    printf("0\n");
  else {
    eugin t;
    t.x = t.y = t.z = i = 0;
    while (path[t.x][t.y][t.z].x != -1) {
      if (path[t.x][t.y][t.z].v > 0) {
        out[i] = path[t.x][t.y][t.z].v;
        i++;
      }
      x = path[t.x][t.y][t.z].x;
      y = path[t.x][t.y][t.z].y;
      z = path[t.x][t.y][t.z].z;
      t.x = x;
      t.y = y;
      t.z = z;
    }
    out[i] = 0;
    printf("%s\n", out);
  }
  return 0;
}
