#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
const int mod = 1e9 + 7;
const int base = 67;
const int INF = 1e9 + 7;
string s1, s2, virus;
void Input() { cin >> s1 >> s2 >> virus; }
int memo[MAXN][MAXN][MAXN];
int f[MAXN];
int Pow[MAXN];
int calc(int id, char x) {
  if (virus[id] == x) return id + 1;
  int suff = (1LL * f[id - 1] * base % mod + x - 'A' + 1) % mod;
  for (int i = id - 1; i >= 1; i--) {
    int l = id - i + 1;
    int save =
        ((suff - 1LL * f[l - 1] * Pow[id - l + 1] % mod) % mod + mod) % mod;
    if (save == f[i]) return i + 1;
  }
  return 1;
}
int solve(int i, int j, int k) {
  if (k == (int)virus.size()) return -INF;
  if (i == (int)s1.size() || j == (int)s2.size()) return 0;
  if (memo[i][j][k] != -1) return memo[i][j][k];
  int cur = -INF;
  if (s1[i] == s2[j]) {
    int pos = calc(k, s1[i]);
    cur = max(cur, solve(i + 1, j + 1, pos) + 1);
  }
  cur = max(cur, solve(i + 1, j, k));
  cur = max(cur, solve(i, j + 1, k));
  return memo[i][j][k] = cur;
}
void Trace(int i, int j, int k) {
  if (i == (int)s1.size() || j == (int)s2.size()) return;
  if (solve(i, j, k) == solve(i + 1, j, k)) {
    Trace(i + 1, j, k);
    return;
  }
  if (solve(i, j, k) == solve(i, j + 1, k)) {
    Trace(i, j + 1, k);
    return;
  }
  if (s1[i] == s2[j]) {
    cout << s1[i];
    int pos = calc(k, s1[i]);
    if (s1[i] != virus[k])
      Trace(i + 1, j + 1, pos);
    else
      Trace(i + 1, j + 1, pos);
  }
}
void Init() {
  Pow[0] = 1;
  for (int i = 1; i <= 100; i++) Pow[i] = 1LL * Pow[i - 1] * base % mod;
  s1 = " " + s1;
  s2 = " " + s2;
  virus = " " + virus;
  for (int i = 1; i < (int)virus.size(); i++)
    f[i] = (1LL * f[i - 1] * base % mod + virus[i] - 'A' + 1) % mod;
  memset(memo, -1, sizeof memo);
}
void Output() {
  int ans = max(0, solve(1, 1, 1));
  if (ans == 0)
    cout << 0;
  else
    Trace(1, 1, 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Input();
  Init();
  Output();
  return 0;
}
