#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
const int N = 150;
string A, B, V;
int dp[N][N][N], len1, len2, len3;
int fail[N];
int fun(int i, int j, int k) {
  if (i == len1 or j == len2 or k == len3) {
    if (k != len3) return 0;
    return -1111;
  }
  int &mami = dp[i][j][k];
  if (mami != -1) return mami;
  int ans = -1111;
  ans = max(fun(i + 1, j, k), fun(i, j + 1, k));
  if (A[i] == B[j]) {
    int temp = k;
    while (temp >= 1) {
      if (A[i] == V[temp]) {
        break;
      } else {
        temp = fail[temp];
      }
    }
    if (A[i] == V[temp])
      temp++;
    else
      temp = 0;
    ans = max(ans, 1 + fun(i + 1, j + 1, temp));
  }
  return mami = ans;
}
void sol(int i, int j, int k) {
  if (i == len1 or j == len2 or k == len3) return;
  int ans1 = fun(i + 1, j, k);
  int ans3 = fun(i, j + 1, k);
  int ans2 = -1111;
  int temp = k;
  if (A[i] == B[j]) {
    while (temp >= 1) {
      if (A[i] == V[temp]) {
        break;
      } else {
        temp = fail[temp];
      }
    }
    if (A[i] == V[temp])
      temp++;
    else
      temp = 0;
    ans2 = 1 + fun(i + 1, j + 1, temp);
  }
  if (ans2 > ans1 && ans2 > ans3) {
    printf("%c", A[i]);
    sol(i + 1, j + 1, temp);
  } else {
    if (ans1 > ans3)
      sol(i + 1, j, k);
    else
      sol(i, j + 1, k);
  }
  return;
}
void pref_fun() {
  fail[0] = -1;
  fail[1] = 0;
  for (int i = 2; i <= len3; i++) {
    int j = fail[i - 1];
    while (j >= 0 && V[i - 1] != V[j]) j = fail[j];
    fail[i] = ++j;
  }
}
void solve() {
  cin >> A >> B >> V;
  len1 = A.size(), len2 = B.size(), len3 = V.size();
  memset(dp, -1, sizeof dp);
  pref_fun();
  int ans = fun(0, 0, 0);
  if (ans > 0)
    sol(0, 0, 0);
  else
    printf("0\n");
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
