#include <bits/stdc++.h>
using namespace std;
template <class T>
T _abs(T n) {
  return (n < 0 ? -n : n);
}
template <class T>
T _max(T a, T b) {
  return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T sq(T x) {
  return x * x;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int dp[110][110][110], cn[110][26];
bool vis[110][110][110];
char s1[110], s2[110], vir[110];
int dfs(int p, int q, int r) {
  if (!vir[r]) return -10000;
  if (!s1[p] || !s2[q]) return 0;
  if (vis[p][q][r]) return dp[p][q][r];
  vis[p][q][r] = 1;
  int a = 0;
  if (s1[p] == s2[q]) {
    a = max(a, dfs(p + 1, q + 1, cn[r][s1[p] - 'A']) + 1);
  }
  a = max(a, dfs(p + 1, q, r));
  a = max(a, dfs(p, q + 1, r));
  return dp[p][q][r] = a;
}
string dfs2(int p, int q, int r) {
  if (!s1[p] || !s2[q]) return "";
  if (s1[p] == s2[q]) {
    if (dp[p][q][r] == (dfs(p + 1, q + 1, cn[r][s1[p] - 'A']) + 1)) {
      string second = dfs2(p + 1, q + 1, cn[r][s1[p] - 'A']);
      return string("") + (s1[p]) + second;
    }
  }
  if (dp[p][q][r] == dfs(p + 1, q, r)) return dfs2(p + 1, q, r);
  if (dp[p][q][r] == dfs(p, q + 1, r)) return dfs2(p, q + 1, r);
  assert(0);
}
int main() {
  cin >> s1 >> s2 >> vir;
  int i, j, k;
  for (i = 0; vir[i]; i++) {
    for (j = i; j >= 0; j--)
      if (!cn[i][vir[j] - 'A']) {
        for (k = 1; k <= j && vir[j - k] == vir[i - k]; k++)
          ;
        if (k == j + 1) cn[i][vir[j] - 'A'] = j + 1;
      }
  }
  if (dfs(0, 0, 0))
    cout << dfs2(0, 0, 0) << '\n';
  else
    cout << 0 << '\n';
  return 0;
}
