#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int dp[111][111][111], dp2[111][111], n, m, k, p[111];
bool calced[111][111][111], calced2[111][111];
string second, t, v;
bool ok = false;
int calc(int i, int j, int first) {
  if (first >= k) return -int(2e9);
  if (i == n || j == m) return 0;
  if (calced[i][j][first]) return dp[i][j][first];
  calced[i][j][first] = true;
  int &res = dp[i][j][first];
  res = 0;
  if (second[i] == t[j]) {
    int q = first;
    while (q > 0 && v[q] != second[i]) q = p[q - 1];
    if (v[q] == second[i]) q++;
    res = max(res, calc(i + 1, j + 1, q) + 1);
  }
  res = max(res, max(calc(i + 1, j, first), calc(i, j + 1, first)));
  return res;
}
void restore(int i, int j, int first, int r) {
  if (i == n || j == m || r == 0) return;
  if (second[i] == t[j]) {
    int q = first;
    while (q > 0 && v[q] != second[i]) q = p[q - 1];
    if (v[q] == second[i]) q++;
    if (calc(i + 1, j + 1, q) + 1 == r) {
      cout << second[i];
      ok = true;
      restore(i + 1, j + 1, q, r - 1);
      return;
    }
  }
  if (calc(i + 1, j, first) == r)
    restore(i + 1, j, first, r);
  else
    restore(i, j + 1, first, r);
}
int main() {
  cin >> second >> t >> v;
  n = int((second).size());
  m = int((t).size());
  k = int((v).size());
  for (int i = 1; i < k; ++i) {
    int j = p[i - 1];
    while (j > 0 && v[i] != v[j]) j = p[j - 1];
    if (v[i] == v[j]) j++;
    p[i] = j;
  }
  int r = calc(0, 0, 0);
  restore(0, 0, 0, r);
  if (!ok) puts("0");
  return 0;
}
