#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 1e2 + 5;
string s1, s2, virus, final, glo_tmp;
int n, m, l, dp[N][N][N];
pair<int, pair<int, int>> where[N][N][N];
ll base = 1e9 + 7;
ull pw2[N];
void init_base() {
  pw2[0] = 1;
  for (int i = 1; i < N; i++) {
    pw2[i] = pw2[i - 1] * base;
  }
}
struct SingleHash {
  vector<ull> pre2;
  SingleHash() {}
  SingleHash(const string& s) { make(s); }
  void make(string s = "") {
    int n = s.size();
    pre2 = vector<ull>(n + 5u, 0);
    for (int i = 1; i <= n; i++) {
      pre2[i] = pre2[i - 1] + s[i] * pw2[i - 1];
    }
  }
  inline ull operator()(const int pos, const int len) const {
    int l = pos;
    int r = pos + len - 1;
    ull h2 = pre2[r] - pre2[l - 1];
    h2 *= pw2[N - r];
    return h2;
  }
} hash1;
int solve(int i, int j, int k) {
  if (k >= l) return -1e9;
  if (i >= n or j >= m) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int ans = -1e9;
  if (s1[i] == s2[j]) {
    bool f = false;
    if (s1[i] == virus[k]) f = true;
    int nk = 0;
    if (!f or f) {
      string tmp = "";
      tmp += '#';
      for (int r = 0; r < k; r++) tmp += virus[r];
      tmp += s1[i];
      tmp += '#';
      SingleHash hash2(tmp);
      for (int r = 1; r <= k + 1; r++) {
        if (hash1(1, r) == hash2(k + 1 - r + 1, r)) {
          nk = r;
        }
      }
    }
    int x = solve(i + 1, j + 1, (nk)) + 1;
    if (x > ans) {
      ans = x;
      where[i][j][k] = {i + 1, {j + 1, (nk)}};
    }
  }
  int y = solve(i + 1, j, k);
  if (y > ans) {
    ans = y;
    where[i][j][k] = {i + 1, {j, k}};
  }
  int z = solve(i, j + 1, k);
  if (z > ans) {
    ans = z;
    where[i][j][k] = {i, {j + 1, k}};
  }
  return dp[i][j][k] = ans;
}
void back_track(int i, int j, int k) {
  if (k >= l) return;
  if (i >= n or j >= m) return;
  pair<int, pair<int, int>> p = make_pair(0, make_pair(0, 0));
  if (where[i][j][k] == p) return;
  p = where[i][j][k];
  if (p.first == i + 1 and p.second.first == j + 1) final += s1[i];
  back_track(p.first, p.second.first, p.second.second);
}
void code() {
  cin >> s1 >> s2 >> virus;
  n = s1.size(), m = s2.size(), l = virus.size();
  init_base();
  glo_tmp = '#' + virus + '#';
  hash1.make(glo_tmp);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        where[i][j][k] = make_pair(0, make_pair(0, 0));
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  int ans = solve(0, 0, 0);
  if (ans == 0) {
    cout << ans << "\n";
  } else {
    back_track(0, 0, 0);
    cout << final << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t-- > 0) {
    code();
  }
}
