#include <bits/stdc++.h>
using namespace std;
char s1[1000], s2[1000], v[1000], s[1000];
int d[200][200][200];
int p[200][200][200][3];
int pp[1000];
int main() {
  int i, j, k, l1, l2, l, tmp, ans, bk, ti, tj, tk, m;
  scanf("%s%s%s", s1, s2, v);
  l1 = strlen(s1);
  l2 = strlen(s2);
  l = strlen(v);
  pp[0] = 0;
  pp[1] = 0;
  i = 0;
  j = 1;
  while (1) {
    if (j == l) break;
    pp[j] = i;
    while ((i > 0) && (v[i] != v[j])) i = pp[i];
    if (v[i] == v[j]) {
      i++;
      j++;
    } else
      j++;
  }
  memset(d, -1, sizeof(d));
  d[0][0][0] = 0;
  for (i = 0; i <= l1; i++)
    for (j = 0; j <= l2; j++)
      for (k = 0; k < l; k++)
        if (d[i][j][k] != -1) {
          if (i < l1)
            if (d[i][j][k] > d[i + 1][j][k]) {
              d[i + 1][j][k] = d[i][j][k];
              p[i + 1][j][k][0] = i;
              p[i + 1][j][k][1] = j;
              p[i + 1][j][k][2] = k;
            }
          if (j < l2)
            if (d[i][j][k] > d[i][j + 1][k]) {
              d[i][j + 1][k] = d[i][j][k];
              p[i][j + 1][k][0] = i;
              p[i][j + 1][k][1] = j;
              p[i][j + 1][k][2] = k;
            }
          if ((i < l1) && (j < l2) && (s1[i] == s2[j])) {
            tmp = k;
            while ((tmp > 0) && (v[tmp] != s1[i])) tmp = pp[tmp];
            if (v[tmp] == s1[i]) tmp++;
            if (tmp < l) {
              if (d[i][j][k] + 1 > d[i + 1][j + 1][tmp]) {
                d[i + 1][j + 1][tmp] = d[i][j][k] + 1;
                p[i + 1][j + 1][tmp][0] = i;
                p[i + 1][j + 1][tmp][1] = j;
                p[i + 1][j + 1][tmp][2] = k;
              }
            }
          }
        }
  ans = -1;
  for (k = 0; k < l; k++)
    if (d[l1][l2][k] > ans) {
      ans = d[l1][l2][k];
      bk = k;
    }
  if (ans == 0)
    printf("0\n");
  else {
    m = 0;
    ti = l1;
    tj = l2;
    tk = bk;
    while ((ti != 0) || (tj != 0)) {
      i = p[ti][tj][tk][0];
      j = p[ti][tj][tk][1];
      k = p[ti][tj][tk][2];
      if ((i < ti) && (j < tj)) {
        s[m] = s1[i];
        m++;
      }
      ti = i;
      tj = j;
      tk = k;
    }
    s[m] = '\0';
    reverse(s, s + m);
    printf("%s\n", s);
  }
}
