#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char a[105];
char b[105];
char c[105];
int dp2[105][26];
int go[105][105][105];
int dp[105][105][105];
bool mark[105][105][105];
int g(int last, char cc) {
  char s[105];
  for (int i = 1; i <= last; i++) s[i] = c[i];
  s[last + 1] = cc;
  for (int t = last; t >= 1; t--) {
    bool ok = true;
    for (int i = last + 1, j = t; j >= 1 && ok; i--, j--)
      if (s[i] != c[j]) ok = false;
    if (!ok) continue;
    return t;
  }
  return 0;
}
int f(int x, int y, int z) {
  if (z == k) return -1;
  if (x == n + 1 || y == m + 1) return 0;
  if (mark[x][y][z]) return dp[x][y][z];
  dp[x][y][z] = -1;
  mark[x][y][z] = true;
  int tmp;
  if (a[x] == b[y]) {
    int ok = (a[x] == c[z + 1]);
    int tmp2 = 0;
    if (ok)
      tmp = f(x + 1, y + 1, z + 1);
    else {
      tmp2 = dp2[z][a[x] - 'A'];
      tmp = f(x + 1, y + 1, tmp2);
    }
    tmp++;
    if (tmp && tmp > dp[x][y][z]) {
      dp[x][y][z] = tmp;
      go[x][y][z] = -tmp2;
    }
  }
  tmp = f(x + 1, y, z);
  if (tmp > dp[x][y][z]) {
    dp[x][y][z] = tmp;
    go[x][y][z] = 1;
  }
  tmp = f(x, y + 1, z);
  if (tmp > dp[x][y][z]) {
    dp[x][y][z] = tmp;
    go[x][y][z] = 2;
  }
  return dp[x][y][z];
}
int main() {
  scanf("%s%s%s", a + 1, b + 1, c + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  k = strlen(c + 1);
  for (int i = 0; i < k; i++)
    for (int j = 0; j < 26; j++) dp2[i][j] = g(i, j + 'A');
  int tmp = f(1, 1, 0);
  if (tmp <= 0) {
    printf("0\n");
    exit(0);
  }
  int x = 1, y = 1, z = 0;
  while (x != n + 1 && y != m + 1) {
    if (go[x][y][z] == 1)
      x++;
    else if (go[x][y][z] == 2)
      y++;
    else {
      printf("%c", a[x]);
      if (a[x] == c[z + 1])
        z++;
      else
        z = -go[x][y][z];
      x++, y++;
    }
  }
  printf("\n");
  return 0;
}
