#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
long long sqr(long long n) { return n * n; }
double LOG(long long a, long long b) { return (log(a) / log(b)); }
long long GCD(long long a, long long b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (!b) ? a : GCD(b, a % b);
}
long long LCM(long long a, long long b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a * (b / GCD(a, b)));
}
long long BigMod(long long B, long long P, long long M) {
  if (!P) return 1;
  if (!(P % 2)) return sqr(BigMod(B, P / 2, M)) % M;
  return (B % M) * (BigMod(B, P - 1, M)) % M;
}
int par[205];
int dp[105][105][105];
string s1, s2, vir;
string ans;
int rec(int x, int y, int z) {
  if (z == (int)vir.size()) return -(1 << 30);
  if (x == (int)s1.size() || y == (int)s2.size()) return 0;
  int &ret = dp[x][y][z];
  if (ret != -1) return ret;
  ret = rec(x + 1, y, z);
  ret = max(ret, rec(x, y + 1, z));
  if (s1[x] == s2[y]) {
    int k = z;
    while (k > 0 && s1[x] != vir[k]) k = par[k - 1];
    if (s1[x] == vir[k]) k++;
    ret = max(ret, rec(x + 1, y + 1, k) + 1);
  }
  return ret;
}
void prec(int x, int y, int z) {
  if (z == (int)vir.size()) return;
  if (x == (int)s1.size() || y == (int)s2.size()) return;
  int &ret = dp[x][y][z];
  if (ret == rec(x + 1, y, z)) return prec(x + 1, y, z);
  if (ret == rec(x, y + 1, z)) return prec(x, y + 1, z);
  if (s1[x] == s2[y]) {
    int k = z;
    while (k > 0 && s1[x] != vir[k]) k = par[k - 1];
    if (s1[x] == vir[k]) k++;
    if (ret == rec(x + 1, y + 1, k) + 1) {
      ans += s1[x];
      return prec(x + 1, y + 1, k);
    }
  }
  return;
}
int main(void) {
  cin >> s1 >> s2 >> vir;
  memset(par, 0, sizeof(par));
  int k = 0;
  string cur = vir;
  for (int i = 1; i < (int)cur.size(); i++) {
    while (k > 0 && cur[i] != cur[k]) k = par[k - 1];
    if (cur[i] == cur[k]) k++;
    par[i] = k;
  }
  memset(dp, -1, sizeof(dp));
  int res = rec(0, 0, 0);
  if (!res) {
    deb(res);
    return 0;
  }
  ans = "";
  prec(0, 0, 0);
  deb(ans);
  return 0;
}
