#include <bits/stdc++.h>
using namespace std;
string s1, s2, v;
vector<vector<vector<pair<int, pair<int, int> > > > > dp;
int lsub(string ss) {
  int res = 0;
  for (int i = 1; i <= min(v.size(), ss.size()); i++) {
    if (v.substr(0, i) == ss.substr(ss.size() - i, i)) {
      res = i;
    }
  }
  return res;
}
pair<int, pair<int, int> > sol(int i, int j, int o) {
  if (o == v.size()) return make_pair(0, make_pair(0, 0));
  if (i >= s1.size() || j >= s2.size()) return make_pair(0, make_pair(0, 0));
  if (dp[i][j][o].first != -1) return dp[i][j][o];
  if (s1[i] == s2[j]) {
    if (s1[i] == v[o]) {
      if (o < v.size() - 1 &&
          1 + sol(i + 1, j + 1, o + 1).first >= sol(i + 1, j + 1, o).first) {
        dp[i][j][o] =
            make_pair(1 + sol(i + 1, j + 1, o + 1).first, make_pair(1, o + 1));
      } else {
        dp[i][j][o] = make_pair(sol(i + 1, j + 1, o).first, make_pair(2, o));
      }
    } else {
      int r = lsub(v.substr(0, o) + s1[i]);
      dp[i][j][o] = make_pair(1 + sol(i + 1, j + 1, r).first, make_pair(3, r));
    }
  } else {
    if (sol(i, j + 1, o).first >= sol(i + 1, j, o).first) {
      dp[i][j][o] = make_pair(sol(i, j + 1, o).first, make_pair(4, o));
    } else {
      dp[i][j][o] = make_pair(sol(i + 1, j, o).first, make_pair(5, o));
    }
  }
  return dp[i][j][o];
}
int main() {
  cin >> s1 >> s2 >> v;
  string res = "";
  dp = vector<vector<vector<pair<int, pair<int, int> > > > >(
      s1.size(),
      vector<vector<pair<int, pair<int, int> > > >(
          s2.size(), vector<pair<int, pair<int, int> > >(
                         v.size(), make_pair(-1, make_pair(-1, -1)))));
  sol(0, 0, 0);
  int a = 0, b = 0, c = 0;
  while (true) {
    if (a >= s1.size() || b >= s2.size() || c >= v.size()) break;
    if (dp[a][b][c].second.first == 1) {
      res += s1[a];
      a++;
      b++;
      c++;
    } else if (dp[a][b][c].second.first == 2) {
      a++;
      b++;
    } else if (dp[a][b][c].second.first == 3) {
      res += s1[a];
      c = dp[a][b][c].second.second;
      a++;
      b++;
    } else if (dp[a][b][c].second.first == 4) {
      b++;
    } else if (dp[a][b][c].second.first == 5) {
      a++;
    }
  }
  if (res.size() == 0)
    cout << 0 << endl;
  else
    cout << res << endl;
}
