#include <bits/stdc++.h>
using namespace std;
int dp[102][102][102];
int lps[102];
string s1, s2, virus;
string ans = "";
void countLps() {
  int i = 1, len = 0;
  lps[0] = 0;
  int N = virus.size();
  while (i < N) {
    if (virus[i] == virus[len]) {
      lps[i++] = ++len;
    } else {
      if (len != 0)
        len = lps[len - 1];
      else
        lps[i++] = 0;
    }
  }
}
int solve(int i, int j, int k) {
  if (k == virus.size()) return -1e9;
  if (i == s1.size()) return 0;
  if (j == s2.size()) return 0;
  int& ret = dp[i][j][k];
  if (ret != -1) return ret;
  ret = max(solve(i + 1, j, k), solve(i, j + 1, k));
  if (s1[i] == s2[j] && s1[i] == virus[k])
    ret = max(solve(i + 1, j + 1, k + 1) + 1, ret);
  if (s1[i] == s2[j] && s1[i] != virus[k]) {
    int where = k;
    while (where > 0 && virus[where] != s1[i]) where = lps[where - 1];
    if (virus[where] == s1[i])
      ret = max(solve(i + 1, j + 1, where + 1) + 1, ret);
    else
      ret = max(solve(i + 1, j + 1, where) + 1, ret);
  }
  return ret;
}
void path(int i, int j, int k) {
  if (k == virus.size()) return;
  if (i == s1.size()) return;
  if (j == s2.size()) return;
  int sol1 = solve(i + 1, j, k);
  int sol2 = solve(i, j + 1, k);
  int sol3 = -1;
  int sol4 = -1;
  int sol5 = -1;
  int real = solve(i, j, k);
  int where = k;
  while (where > 0 && virus[where] != s1[i]) where = lps[where - 1];
  if (s1[i] == s2[j] && s1[i] == virus[k])
    sol3 = solve(i + 1, j + 1, k + 1) + 1;
  if (s1[i] == s2[j] && s1[i] != virus[k]) {
    if (virus[where] == s1[i])
      sol4 = solve(i + 1, j + 1, where + 1) + 1;
    else
      sol5 = solve(i + 1, j + 1, where) + 1;
  }
  if (real == sol1) {
    path(i + 1, j, k);
  } else if (real == sol2) {
    path(i, j + 1, k);
  } else if (real == sol3) {
    ans += s1[i];
    path(i + 1, j + 1, k + 1);
  } else {
    ans += s1[i];
    if (virus[where] == s1[i])
      path(i + 1, j + 1, where + 1);
    else
      path(i + 1, j + 1, where);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> s1 >> s2 >> virus;
  countLps();
  memset(dp, -1, sizeof dp);
  if (solve(0, 0, 0) == 0) {
    cout << 0;
  } else {
    path(0, 0, 0);
    cout << ans;
  }
  return 0;
}
