#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
using namespace std;
char s1[MAXN], s2[MAXN], v[MAXN];
int dp[MAXN][MAXN][MAXN], a[MAXN][26], lcp[MAXN];
tuple<int, int, int> par[MAXN][MAXN][MAXN];
void kmp(int n) {
  for (int i = 1; i < n; i++) {
    int k = lcp[i - 1];
    while (k && v[i] != v[k]) {
      k = lcp[k - 1];
    }
    if (v[i] == v[k]) k++;
    lcp[i] = k;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      if (i && j != v[i] - 'A')
        a[i][j] = a[lcp[i - 1]][j];
      else
        a[i][j] = i + (j == v[i] - 'A');
    }
  }
}
int main() {
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXN; k++) {
        par[i][j][k] = make_tuple(-1, -1, -1);
        dp[i][j][k] = 0;
      }
  scanf("%s %s %s", s1, s2, v);
  int n = strlen(s1), m = strlen(s2), l = strlen(v), ans = 0;
  kmp(l);
  tuple<int, int, int> p = make_tuple(-1, -1, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        bool flag = (s1[i] == s2[j]);
        int cur = s1[i] - 'A';
        int next = a[k][cur];
        if (flag && next < l) {
          if (dp[i + 1][j + 1][next] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][next] = dp[i][j][k] + 1;
            par[i + 1][j + 1][next] = make_tuple(i, j, k);
          }
        }
        if (dp[i][j][k] > dp[i + 1][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          par[i + 1][j][k] = par[i][j][k];
        }
        if (dp[i][j][k] > dp[i][j + 1][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          par[i][j + 1][k] = par[i][j][k];
        }
      }
    }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k < l; k++)
        if (ans < dp[i][j][k]) {
          ans = dp[i][j][k];
          p = par[i][j][k];
        }
  string res = "";
  do {
    if (p == make_tuple(-1, -1, -1)) break;
    res += s1[get<0>(p)];
    p = par[get<0>(p)][get<1>(p)][get<2>(p)];
    if (p == make_tuple(-1, -1, -1)) break;
  } while (1);
  reverse(res.begin(), res.end());
  if (res == "")
    printf("0\n");
  else
    cout << res << endl;
  return 0;
}
