#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 2e2 + 20, mod = 1e9 + 7, inf = 1e18, dlt = 12250,
                    maxm = 2e6;
int poww(long long a, int k) {
  if (!k) return 1;
  if (k == 1) return a;
  long long r = poww(a, k / 2);
  return (((r * r) % mod) * poww(a, k & 1)) % mod;
}
int f[N];
pair<string, int> dp[N][N];
int func(string s, string t) {
  int n = s.size(), m = t.size();
  string w = t + '#' + s;
  int k = 0, ans = 0;
  for (int i = 1; i < m + n + 1; i++) {
    while (k && w[i] != w[k]) k = f[k - 1];
    k += (w[i] == w[k]);
    f[i] = k;
    ans = max(ans, k);
  }
  return ans;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  string s, t, v;
  cin >> s >> t >> v;
  int d1, d2, d3;
  d1 = s.size(), d2 = t.size(), d3 = v.size();
  int ans = 0;
  string out;
  for (int o = 0; o < d3; o++) {
    for (int i = 0; i < d1; i++) {
      if (!i) {
        if (s[i] == t[0] && (o || s[i] != v[0])) dp[i][0] = make_pair(s[0], 1);
        if ((dp[i][0].first).size() > ans) {
          ans = (dp[i][0].first).size();
          out = dp[i][0].first;
        }
        continue;
      }
      dp[i][0] = dp[i - 1][0];
      if (s[i] == t[0]) {
        if (s[i] != v[0]) dp[i][0] = make_pair(s[i], 0);
        if (o && dp[i][0].first == "") dp[i][0] = make_pair(s[i], 1);
      }
      if (ans < (dp[i][0].first).size()) {
        ans = (dp[i][0].first).size();
        out = dp[i][0].first;
      }
    }
    for (int i = 1; i < d2; i++) {
      dp[0][i] = dp[0][i - 1];
      if (s[0] == t[i]) {
        if (s[0] != v[0]) dp[0][i] = make_pair(s[0], 0);
        if (o && dp[0][i].first == "") dp[0][i] = make_pair(s[0], 1);
      }
      if (ans < (dp[0][i].first).size()) {
        ans = (dp[0][i].first).size();
        out = dp[0][i].first;
      }
    }
    for (int i = 1; i < d1; i++) {
      for (int j = 1; j < d2; j++) {
        dp[i][j] = dp[i - 1][j];
        if ((dp[i][j].first).size() < (dp[i][j - 1].first).size())
          dp[i][j] = dp[i][j - 1];
        if ((dp[i][j].first).size() == (dp[i][j - 1].first).size() &&
            dp[i][j].second > dp[i][j - 1].second)
          dp[i][j] = dp[i][j - 1];
        if ((dp[i][j].first).size() > ans) {
          out = dp[i][j].first;
          ans = out.size();
        }
        if (s[i] == t[j]) {
          int mx = func(dp[i - 1][j - 1].first + s[i], v);
          if (mx > o ||
              (dp[i - 1][j - 1].first).size() + 1 < (dp[i][j].first).size() ||
              ((dp[i - 1][j - 1].first).size() + 1 == (dp[i][j].first).size() &&
               mx >= dp[i][j].second))
            continue;
          dp[i][j] = make_pair(dp[i - 1][j - 1].first + s[i], mx);
        }
        if ((dp[i][j].first).size() > ans) {
          out = dp[i][j].first;
          ans = out.size();
        }
      }
    }
  }
  if (!ans)
    cout << 0;
  else
    cout << out;
  return 0;
}
