#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
string s, ss, t;
int func[200][30];
int dp[200][200][200];
inline int go(int pos1, int pos2, int state) {
  if (state == (int)t.size()) return -inf;
  if (pos1 == (int)s.size() || pos2 == (int)ss.size()) return 0;
  int &ret = dp[pos1][pos2][state];
  if (ret != -1) return ret;
  ret = max(go(pos1 + 1, pos2, state), go(pos1, pos2 + 1, state));
  if (s[pos1] == ss[pos2])
    ret = max(ret, go(pos1 + 1, pos2 + 1, func[state][s[pos1] - 'A']) + 1);
  return ret = max(ret, 0);
}
inline void print(int pos1, int pos2, int state) {
  if (pos1 == (int)s.size() || pos2 == (int)ss.size()) return;
  int &ret = dp[pos1][pos2][state];
  if (ret == 0) return;
  if (go(pos1 + 1, pos2, state) == ret) {
    print(pos1 + 1, pos2, state);
    return;
  } else if (go(pos1, pos2 + 1, state) == ret) {
    print(pos1, pos2 + 1, state);
    return;
  }
  cout << s[pos1];
  print(pos1 + 1, pos2 + 1, func[state][s[pos1] - 'A']);
}
int main() {
  cin >> s >> ss >> t;
  func[0][t[0] - 'A'] = 1;
  for (int x = 0, j = 1; j < t.size(); j++) {
    for (char c = 'A'; c <= 'Z'; c++) func[j][c - 'A'] = func[x][c - 'A'];
    func[j][t[j] - 'A'] = j + 1;
    x = func[x][t[j] - 'A'];
  }
  memset(dp, -1, sizeof dp);
  int temp = go(0, 0, 0);
  if (temp == 0)
    cout << 0 << endl;
  else {
    print(0, 0, 0);
    cout << endl;
  }
  return 0;
}
