#include <bits/stdc++.h>
using namespace std;
template <class _T>
_T MAX(_T p1, _T p2) {
  return (p1 > p2) ? p1 : p2;
}
template <class _T>
_T MIN(_T p1, _T p2) {
  return (p1 < p2) ? p1 : p2;
}
template <class _Tv>
inline string join(const _Tv &v, string sep = " ") {
  ostringstream s;
  for (__typeof__((v).begin()) it = (v).begin(); it != (v).end(); ++it) {
    if (it != v.begin()) s << sep;
    s << *it;
  };
  return s.str();
}
void update(string &p1, const string &p2) {
  if (p1.size() < p2.size()) p1 = p2;
}
int strlap(const string &s1, const string &s2) {
  int l = MIN(s1.size(), s2.size());
  for (int i = l; i > 0; --i) {
    if (s1.substr(s1.size() - i, i) == s2.substr(0, i)) return i;
  }
  return 0;
}
string dp[101][101][101];
string lcs_ng(const string &s1, const string &s2, const string &ng) {
  int n1 = s1.size(), n2 = s2.size(), n3 = ng.size();
  for (int i = 1; i < n1 + 1; i++) {
    for (int j = (0); j < ((0) + (n2 + 1)); ++j) {
      if (i == 0 || j == 0) continue;
      for (int k = (0); k < ((0) + (n3)); ++k) {
        update(dp[k][i][j], dp[k][i][j - 1]);
        update(dp[k][i][j], dp[k][i - 1][j]);
        if (dp[k][i - 1][j - 1].size() < k) break;
        if (s1[i - 1] == s2[j - 1]) {
          string ts = dp[k][i - 1][j - 1] + s1[i - 1];
          int m = strlap(ts, ng);
          if (ng.size() != m) {
            update(dp[m][i][j], ts);
          }
        }
      }
    };
    for (int k = (0); k < ((0) + (n3 + 1)); ++k) {
      ;
      for (int j = (0); j < ((0) + (n2 + 1)); ++j)
        ;
      ;
    }
  }
  string ret;
  for (int k = (0); k < ((0) + (n3)); ++k) {
    ;
    if (ret.size() < dp[k][n1][n2].size()) ret = dp[k][n1][n2];
  }
  return ret;
}
int main() {
  do {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
  } while (0);
  string s1, s2, v;
  cin >> s1 >> s2 >> v;
  string ret = lcs_ng(s1, s2, v);
  if (ret.size() == 0) ret = "0";
  cout << ret << endl;
  ;
  return 0;
}
