#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e2 + 5;
const int inf = 0x3f3f3f3f;
string s1, s2, v, f[N][N][N], ans;
int pi[N], len1, len2, lenv;
inline void update(string& a, string b) { a = (a.size() > b.size() ? a : b); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s1 >> s2 >> v;
  len1 = s1.length();
  len2 = s2.length();
  lenv = v.length();
  for (int i = 1, j = 0; i < lenv; i++) {
    while (j > 0 && v[i] != v[j]) j = pi[j - 1];
    if (v[i] == v[j]) pi[i] = ++j;
  }
  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; j++)
      for (int k = 0; k < lenv; k++) {
        if (s1[i - 1] == s2[j - 1]) {
          char tmp = s1[i - 1];
          int t = k;
          while (t > 0 && tmp != v[t]) t = pi[t - 1];
          if (tmp == v[t]) t++;
          update(f[i][j][t], f[i - 1][j - 1][k] + tmp);
        }
        update(f[i][j][k], f[i - 1][j][k]);
        update(f[i][j][k], f[i][j - 1][k]);
      }
  for (int i = 0; i < lenv; i++) update(ans, f[len1][len2][i]);
  if (ans.size() == 0)
    return puts("0"), 0;
  else
    cout << ans << endl;
  return 0;
}
