#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;
template <typename T>
void check(T& a, const T& b) {
  if (a >= b) {
    a %= b;
  }
}
template <typename T>
T gcd(T u, T v) {
  if (u == v) return u;
  if (u == 0) return v;
  if (v == 0) return u;
  if (~u & 1) {
    if (v & 1)
      return gcd(u >> 1, v);
    else
      return gcd(u >> 1, v >> 1) << 1;
  }
  if (~v & 1) return gcd(u, v >> 1);
  if (u > v) return gcd((u - v) >> 1, v);
  return gcd((v - u) >> 1, u);
}
LL mulmod(LL a, LL b, const LL& m) {
  LL q = (LL)(((LD)a * (LD)b) / (LD)m);
  LL r = a * b - q * m;
  if (r > m) r %= m;
  if (r < 0) r += m;
  return r;
}
template <typename T, typename S>
T expo(T e, S n) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = x * p;
    p = p * p;
    n >>= 1;
  }
  return x;
}
template <typename T>
T powerL(T e, T n, const T& m) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = mulmod(x, p, m);
    p = mulmod(p, p, m);
    n >>= 1;
  }
  return x;
}
const int N = (int)110;
int dp[N][N][N], n, m, l;
vi take[N][N][N];
string s1, s2, v;
vi PI;
vector<int> kmp(string& KMP) {
  int KMPN = (int)KMP.size();
  int q = -1;
  vector<int> pi(KMPN);
  pi[0] = -1;
  for (int i = 1; i < KMPN; i++) {
    while (q >= 0 && KMP[i] != KMP[q + 1]) q = pi[q];
    if (KMP[i] == KMP[q + 1]) q++;
    pi[i] = q;
  }
  return pi;
}
int solve(int i, int j, int k) {
  if (k >= l - 1) return -(int)1e9;
  if (i >= n || j >= m) return 0;
  int& ans = dp[i][j][(k == -1 ? 102 : k)];
  auto& _ans = take[i][j][(k == -1 ? 102 : k)];
  if (ans != -1) return ans;
  if (s1[i] == s2[j]) {
    int tk = k;
    while (k >= 0 && s1[i] != v[k + 1]) k = PI[k];
    if (s1[i] == v[k + 1]) k++;
    ans = 1 + solve(i + 1, j + 1, k);
    _ans = {i + 1, j + 1, k};
    k = tk;
    int x = solve(i + 1, j, k), y = solve(i, j + 1, k);
    if (x > ans) {
      ans = x;
      _ans = {i + 1, j, k};
    }
    if (y > ans) {
      ans = y;
      _ans = {i, j + 1, k};
    }
    return ans;
  }
  int x = solve(i + 1, j, k), y = solve(i, j + 1, k);
  ans = x;
  _ans = {i + 1, j, k};
  if (y > ans) {
    ans = y;
    _ans = {i, j + 1, k};
  }
  return ans;
}
void gen(int i, int j, int k, string& Gen) {
  if (i >= n || j >= m) return;
  vi& ans = take[i][j][(k == -1 ? 102 : k)];
  if (ans[0] == i + 1 && ans[1] == j + 1) Gen += s1[i];
  gen(ans[0], ans[1], ans[2], Gen);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cerr.tie(NULL);
  ;
  memset(dp, -1, sizeof dp);
  cin >> s1 >> s2 >> v;
  PI = kmp(v);
  n = (int)s1.size(), m = (int)s2.size(), l = (int)v.size();
  int ans = solve(0, 0, -1);
  if (ans <= 0) {
    cout << 0 << '\n';
    return 0;
  }
  string Gen = "";
  gen(0, 0, -1, Gen);
  cout << Gen << '\n';
  return 0;
}
