#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int Next[N];
int dp[N][N][N];
struct node {
  int i, j, k;
  node() {}
  node(int a, int b, int c) : i(a), j(b), k(c) {}
};
node flag[N][N][N];
char s1[N], s2[N], virus[N], re[N];
void Next1() {
  int len, i = 1, j = 0;
  len = strlen(virus + 1);
  while (i < len) {
    if (j == 0 || virus[i] == virus[j]) {
      i++;
      j++;
      Next[i] = j;
    } else
      j = Next[j];
  }
}
int main() {
  scanf("%s%s%s", s1 + 1, s2 + 1, virus + 1);
  Next1();
  int len1 = strlen(s1 + 1), len2 = strlen(s2 + 1);
  int len_virus = strlen(virus + 1), id, tmp;
  s1[len1 + 1] = '1';
  s2[len2 + 1] = '2';
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 0; i <= len1; i++)
    for (int j = 0; j <= len2; j++)
      for (int k = 0; k < len_virus; k++)
        if (dp[i][j][k] != -1) {
          if (s1[i + 1] == s2[j + 1]) {
            tmp = k + 1;
            while (tmp) {
              if (virus[tmp] == s1[i + 1]) break;
              tmp = Next[tmp];
            }
            if (dp[i + 1][j + 1][tmp] <= dp[i][j][k] + 1) {
              dp[i + 1][j + 1][tmp] = dp[i][j][k] + 1;
              flag[i + 1][j + 1][tmp] = node(i, j, k);
            }
          }
          if (dp[i + 1][j][k] <= dp[i][j][k]) {
            dp[i + 1][j][k] = dp[i][j][k];
            flag[i + 1][j][k] = node(i, j, k);
          }
          if (dp[i][j + 1][k] <= dp[i][j][k]) {
            dp[i][j + 1][k] = dp[i][j][k];
            flag[i][j + 1][k] = node(i, j, k);
          }
        }
  id = 0;
  for (int i = 1; i < len_virus; i++)
    if (dp[len1][len2][i] > dp[len1][len2][id]) id = i;
  int x, y, ans = 102;
  re[ans] = 0;
  if (dp[len1][len2][id] <= 0) {
    printf("0\n");
    return 0;
  }
  while (dp[len1][len2][id]) {
    x = flag[len1][len2][id].i;
    y = flag[len1][len2][id].j;
    if (len1 - x + len2 - y == 2) {
      re[--ans] = s1[len1];
      id = flag[len1][len2][id].k;
      len1 = x, len2 = y;
    } else {
      id = flag[len1][len2][id].k;
      len1 = x, len2 = y;
    }
  }
  printf("%s\n", re + ans);
  return 0;
}
