#include <bits/stdc++.h>
using namespace std;
string up, down, virus;
int uplen, dnlen, vilen;
string dp[101][101][101];
int par[101];
void KPM() {
  int k = 0;
  for (int i = 1; i < virus.size(); i++) {
    while (k > 0 && virus[i] != virus[k]) k = par[k - 1];
    if (virus[i] == virus[k]) k++;
    par[i] = k;
  }
  return;
}
string MM_max(string a, string b) {
  if (a.size() == b.size()) {
    if (a < b) return a;
    return b;
  }
  if (a.size() > b.size()) return a;
  return b;
}
string rec(int upind, int dnind, int virind) {
  if (upind == uplen || dnind == dnlen) {
    return "";
  }
  string &ret = dp[upind][dnind][virind];
  if (ret != "-1") return ret;
  ret = "";
  if (up[upind] == down[dnind]) {
    if (up[upind] == virus[virind]) {
      if (virind < vilen - 1)
        ret = MM_max(ret, up[upind] + rec(upind + 1, dnind + 1, virind + 1));
    } else {
      int k = virind;
      while (k > 0 && up[upind] != virus[k]) k = par[k - 1];
      if (up[upind] == virus[k]) k++;
      ret = MM_max(ret, up[upind] + rec(upind + 1, dnind + 1, k));
    }
  }
  {
    ret = MM_max(ret, rec(upind + 1, dnind, virind));
    ret = MM_max(ret, rec(upind, dnind + 1, virind));
  }
  return ret;
}
int main() {
  cin >> up >> down >> virus;
  uplen = (int)up.size();
  dnlen = (int)down.size();
  vilen = (int)virus.size();
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      for (int k = 0; k < 101; k++) dp[i][j][k] = "-1";
  KPM();
  string ans = rec(0, 0, 0);
  if (ans == "") ans = "0";
  cout << ans << endl;
  return 0;
}
