#include <bits/stdc++.h>
using namespace std;
template <typename _Tp>
bool maximize(_Tp &__a, _Tp __b) {
  if (__a < __b) {
    __a = __b;
    return true;
  }
  return false;
}
template <typename _Tp>
bool minimize(_Tp &__a, _Tp __b) {
  if (__a > __b) {
    __a = __b;
    return true;
  }
  return false;
}
const int siz = 1e2 + 2;
const int SIZ = 1e6 + 2;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const long long MAXX = 1e18;
const string file = "3";
int n, m, l;
string a, b, c;
int nxt[siz][26];
int f[siz][siz][siz];
bool g[siz][siz][siz];
int dp(int pos_a, int pos_b, int pos_c) {
  if (pos_a == n + 1 || pos_b == m + 1) {
    return 0;
  }
  int &res = f[pos_a][pos_b][pos_c];
  bool &cal = g[pos_a][pos_b][pos_c];
  if (cal) {
    return res;
  }
  res = max(dp(pos_a + 1, pos_b, pos_c), dp(pos_a, pos_b + 1, pos_c));
  if (a[pos_a] == b[pos_b]) {
    if (nxt[pos_c][a[pos_a] - 'A'] != l + 1) {
      maximize(res, dp(pos_a + 1, pos_b + 1, nxt[pos_c][a[pos_a] - 'A']) + 1);
    }
  }
  cal = true;
  return res;
}
void trace(int pos_a, int pos_b, int pos_c) {
  if (pos_a == n + 1 || pos_b == m + 1) {
    return;
  }
  int res = dp(pos_a, pos_b, pos_c);
  if (res == dp(pos_a + 1, pos_b, pos_c)) {
    trace(pos_a + 1, pos_b, pos_c);
    return;
  } else if (res == dp(pos_a, pos_b + 1, pos_c)) {
    trace(pos_a, pos_b + 1, pos_c);
    return;
  }
  if (a[pos_a] == b[pos_b]) {
    if (nxt[pos_c][a[pos_a] - 'A'] != l + 1) {
      if (res == dp(pos_a + 1, pos_b + 1, nxt[pos_c][a[pos_a] - 'A']) + 1) {
        cout << a[pos_a];
        trace(pos_a + 1, pos_b + 1, nxt[pos_c][a[pos_a] - 'A']);
        return;
      }
    }
  }
  assert(0);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> c;
  n = (int)(a).size();
  a = ' ' + a;
  m = (int)(b).size();
  b = ' ' + b;
  l = (int)(c).size();
  c = ' ' + c;
  for (int i = (int)(1); i <= (int)(l); i++) {
    char org = c[i];
    for (int chr = (int)('A'); chr <= (int)('Z'); chr++) {
      c[i] = chr;
      int pos = 1;
      for (int len = (int)(1); len <= (int)(i - 1); len++) {
        if (c.substr(1, len) == c.substr(i - len + 1, len)) {
          pos = len + 1;
        }
      }
      nxt[i][chr - 'A'] = pos;
    }
    c[i] = org;
    nxt[i][c[i] - 'A'] = i + 1;
  }
  if (dp(1, 1, 1) == 0) {
    return cout << 0 << "\n", 0;
  }
  trace(1, 1, 1);
  cout << "\n";
  return 0;
}
