#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << endl;
}
const long long N = 110;
string a, b, v;
long long n, m, s;
long long f[N];
long long dp[N][N][N];
long long get(long long l, char c) {
  while (l > 0 && v[l] != c) {
    l = f[l - 1];
  }
  if (v[l] == c) l++;
  return l;
}
long long solve(long long i, long long j, long long k) {
  if (i == n || j == m) return 0;
  long long &res = dp[i][j][k];
  if (res != -1) return res;
  res = solve(i + 1, j, k);
  res = max(res, solve(i, j + 1, k));
  if (a[i] == b[j]) {
    long long kk = get(k, a[i]);
    if (kk < s) {
      res = max(res, solve(i + 1, j + 1, kk) + 1);
    }
  }
  return res;
}
void print(long long i, long long j, long long k) {
  if (i == n || j == m) return;
  if (solve(i + 1, j, k) == solve(i, j, k)) return print(i + 1, j, k);
  if (solve(i, j + 1, k) == solve(i, j, k)) return print(i, j + 1, k);
  putchar(a[i]);
  return print(i + 1, j + 1, get(k, a[i]));
}
void oblivious() {
  cin >> a >> b >> v;
  long long l = 0;
  n = a.length();
  m = b.length();
  s = v.length();
  for (long long i = 1; i < n; i++) {
    f[i] = l = get(l, v[i]);
  }
  memset(dp, -1, sizeof(dp));
  if (solve(0, 0, 0)) {
    print(0, 0, 0);
  } else {
    cout << 0 << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    oblivious();
  }
  return 0;
}
