#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.first << ',' << P.second << ')';
}
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
vector<long long> getPrefix(string str) {
  long long n = str.length();
  vector<long long> pi(n, 0);
  for (long long i = 1; i < n; ++i) {
    long long j = pi[i - 1];
    while (j > 0 && str[i] != str[j]) {
      j = pi[j - 1];
    }
    if (str[i] == str[j]) {
      ++j;
    }
    pi[i] = j;
  }
  return pi;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s1, s2, virus;
  cin >> s1 >> s2 >> virus;
  long long n = s1.length();
  long long m = s2.length();
  long long k = virus.length();
  string f[n + 5][m + 5][k + 5];
  for (long long i = 0; i < n + 5; ++i) {
    for (long long j = 0; j < m + 5; ++j) {
      for (long long t = 0; t < k + 5; ++t) {
        f[i][j][t] = "";
      }
    }
  }
  vector<long long> vec = getPrefix(virus);
  for (long long ix1 = 1; ix1 <= n; ++ix1) {
    for (long long ix2 = 1; ix2 <= m; ++ix2) {
      for (long long elen = 0; elen < virus.length(); ++elen) {
        string tmp1 = f[ix1][ix2 - 1][elen];
        string tmp2 = f[ix1 - 1][ix2][elen];
        f[ix1][ix2][elen] = (tmp1.length() > tmp2.length()) ? tmp1 : tmp2;
      }
      char c1 = s1[ix1 - 1], c2 = s2[ix2 - 1];
      if (c1 == c2) {
        for (long long pelen = 0; pelen < virus.length(); ++pelen) {
          long long tplen = pelen;
          while (tplen > 0 && (virus[tplen] != c1)) {
            tplen = vec[tplen - 1];
          }
          if (virus[tplen] == c1) {
            ++tplen;
          }
          string poss = f[ix1 - 1][ix2 - 1][pelen] + c1;
          if (tplen != virus.length() &&
              (poss.length() > f[ix1][ix2][tplen].length())) {
            f[ix1][ix2][tplen] = poss;
          }
        }
      }
    }
  }
  string ans = "";
  for (long long elen = 0; elen < virus.length(); ++elen) {
    if (ans.length() < f[n][m][elen].length()) {
      ans = f[n][m][elen];
    }
  }
  if (ans != "") {
    cout << ans;
  } else {
    cout << 0;
  }
}
