#include <bits/stdc++.h>
using namespace std;
struct KMP {
  static const int MAXC = 26;
  int n;
  string s;
  vector<int> prefix;
  vector<vector<int>> nextState;
  KMP(string s) : s(s) {
    n = s.size();
    prefix.resize(n);
    nextState = vector<vector<int>>(n + 1, vector<int>(MAXC));
    calcPrefix();
    calcNextState();
  }
  void calcPrefix() {
    for (int i = 1; i < n; i++) {
      int k = prefix[i - 1];
      while (k && s[i] != s[k]) {
        k = prefix[k - 1];
      }
      if (s[i] == s[k]) {
        k++;
      }
      prefix[i] = k;
    }
  }
  void calcNextState() {
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < MAXC; j++) {
        char x = j + 'A';
        if (i == n || (i && x != s[i])) {
          nextState[i][j] = nextState[prefix[i - 1]][j];
        } else {
          nextState[i][j] = i + (x == s[i]);
        }
      }
    }
  }
};
int d[105][105][105];
struct Trace {
  int i, j, k;
} trace[105][105][105];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string s, t, virus;
  cin >> s >> t >> virus;
  KMP kmp(virus);
  int n = s.size(), m = t.size();
  auto relax = [&](int i, int j, int k) {
    if (d[i][j][k] < d[i][j + 1][k]) {
      d[i][j][k] = d[i][j + 1][k];
      trace[i][j][k] = {i, j + 1, k};
    }
    if (d[i][j][k] < d[i + 1][j][k]) {
      d[i][j][k] = d[i + 1][j][k];
      trace[i][j][k] = {i + 1, j, k};
    }
    int nxt = kmp.nextState[k][s[i] - 'A'];
    if (s[i] == t[j] && nxt < virus.size()) {
      if (d[i][j][k] < d[i + 1][j + 1][nxt] + 1) {
        d[i][j][k] = d[i + 1][j + 1][nxt] + 1;
        trace[i][j][k] = {i + 1, j + 1, nxt};
      }
    }
  };
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      for (int k = 0; k < virus.size(); k++) {
        relax(i, j, k);
      }
    }
  }
  Trace state;
  int res = 0;
  for (int k = 0; k < virus.size(); k++) {
    if (res < d[0][0][k]) {
      res = d[0][0][k];
      state = {0, 0, k};
    }
  }
  if (!res)
    cout << 0;
  else {
    string ans;
    while (1) {
      auto newState = trace[state.i][state.j][state.k];
      if (newState.i > state.i && newState.j > state.j) {
        ans += s[state.i];
      }
      if (newState.i < state.i || newState.j < state.j) break;
      state = newState;
    }
    cout << ans;
  }
  return 0;
}
