#include <bits/stdc++.h>
using namespace std;
const int N = 200, M = 26, INF = 1e15;
long long n, m, w, tnod = 1, f[N], nxt[N][M + 4], virnod;
string s, t, vir;
pair<long long, string> ans, dp[N][N][N];
queue<long long> q;
void insertt() {
  long long ind = 0;
  for (char c : vir) {
    if (nxt[ind][c - 'A'] == 0) nxt[ind][c - 'A'] = tnod++;
    ind = nxt[ind][c - 'A'];
  }
  virnod = ind;
}
void aho() {
  long long x;
  for (int i = 0; i < M; i++)
    if (nxt[0][i]) q.push(nxt[0][i]);
  while (!q.empty()) {
    x = q.front(), q.pop();
    for (int i = 0; i < 26; i++) {
      if (nxt[x][i] != 0) {
        f[nxt[x][i]] = nxt[f[x]][i];
        q.push(nxt[x][i]);
      } else
        nxt[x][i] = nxt[f[x]][i];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> s >> t >> vir;
  n = s.size(), m = t.size(), w = vir.size();
  insertt();
  aho();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        for (int l = 0; l < tnod; l++) {
          if (nxt[l][s[i - 1] - 'A'] == virnod || l == virnod) continue;
          if (dp[i - 1][j - 1][l].first >=
              dp[i][j][nxt[l][s[i - 1] - 'A']].first) {
            dp[i][j][nxt[l][s[i - 1] - 'A']].first =
                dp[i - 1][j - 1][l].first + 1;
            dp[i][j][nxt[l][s[i - 1] - 'A']].second =
                dp[i - 1][j - 1][l].second + s[i - 1];
          }
        }
      }
      for (int l = 0; l < tnod; l++) {
        if (l == virnod) continue;
        if (dp[i][j - 1][l].first > dp[i][j][l].first)
          dp[i][j][l] = dp[i][j - 1][l];
        if (dp[i - 1][j][l].first > dp[i][j][l].first)
          dp[i][j][l] = dp[i - 1][j][l];
      }
    }
  }
  ans = {-INF, ""};
  for (int i = 0; i < tnod; i++)
    if (i != virnod) ans = max(ans, dp[n][m][i]);
  if (ans.first == 0) cout << 0;
  if (ans.first != 0) cout << ans.second;
  return 0;
}
