#include <bits/stdc++.h>
char s[109], t[109], v[109];
int h[109];
int n, m, l;
int f[109][109][109], g[109][109][109];
char res[109];
int main() {
  gets(s + 1);
  n = strlen(s + 1);
  gets(t + 1);
  m = strlen(t + 1);
  gets(v + 1);
  l = strlen(v + 1);
  for (int i = 2, k = 0; i <= l; i++) {
    while (k > 0 && v[k + 1] != v[i]) k = h[k];
    if (v[k + 1] == v[i]) k++;
    h[i] = k;
  }
  memset(f, -1, sizeof(f));
  f[0][0][0] = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= l; k++)
        if (f[i][j][k] >= 0) {
          if (f[i + 1][j][k] < f[i][j][k]) {
            f[i + 1][j][k] = f[i][j][k];
            g[i + 1][j][k] = ((i * 109) + j) * 109 + k;
          }
          if (f[i][j + 1][k] < f[i][j][k]) {
            f[i][j + 1][k] = f[i][j][k];
            g[i][j + 1][k] = ((i * 109) + j) * 109 + k;
          }
          if (s[i + 1] == t[j + 1]) {
            int K = k;
            while (K > 0 && v[K + 1] != s[i + 1]) K = h[K];
            if (v[K + 1] == s[i + 1]) K++;
            if (K < l)
              if (f[i + 1][j + 1][K] < f[i][j][k] + 1) {
                f[i + 1][j + 1][K] = f[i][j][k] + 1;
                g[i + 1][j + 1][K] = ((i * 109) + j) * 109 + k;
              }
          }
        }
  int I = n, J = m, K, mx = -1;
  for (int k = 0; k <= l; k++) {
    if (f[n][m][k] > mx) K = k, mx = f[n][m][k];
  }
  if (mx == 0) {
    puts("0");
    return 0;
  }
  res[mx] = 0;
  while (I) {
    int i = I, j = J, k = K;
    I = g[i][j][k] / 109 / 109;
    J = (g[i][j][k] / 109) % 109;
    K = g[i][j][k] % 109;
    if (f[i][j][k] != f[I][J][K]) res[--mx] = t[j];
  }
  puts(res);
}
