#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void Print() { cout << endl; }
template <typename T1, typename... T>
void Print(const T1 &t1, const T &...t) {
  cout << t1 << " ";
  Print(t...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class Iterator>
ostream &output_cantainer(ostream &os, Iterator first, Iterator last,
                          bool space = true) {
  if (space) {
    for (Iterator it = first; it != last; it++) {
      os << (*it) << ' ';
    }
    os << endl;
  } else
    for (Iterator it = first; it != last; it++) {
      os << (*it) << endl;
    }
  return os;
}
const int N = 105;
char s1[N], s2[N], v[N];
int dp[N][N][N], ptr[N][N][N];
bool pick[N][N][N];
int m, n, l, p[N];
void process() {
  int last = 0;
  for (int i = 2; i <= l; i++) {
    while (last > 0 && v[i] != v[last + 1]) last = p[last];
    if (v[i] == v[last + 1]) p[i] = ++last;
  }
}
string output(int i, int j, int k) {
  if (i == 0 || j == 0) return "";
  if (!pick[i][j][k]) {
    if (dp[i - 1][j][k] >= dp[i][j - 1][k]) return output(i - 1, j, k);
    return output(i, j - 1, k);
  }
  return output(i - 1, j - 1, ptr[i][j][k]) + string(1, s1[i]);
}
int main() {
  cin >> (s1 + 1) >> (s2 + 1) >> (v + 1);
  m = strlen(s1 + 1);
  n = strlen(s2 + 1);
  l = strlen(v + 1);
  process();
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (s1[i] == s2[j]) {
        for (int k = 0; k < l; k++) {
          int t = k;
          while (t > 0 && v[t + 1] != s1[i]) t = p[t];
          if (v[t + 1] == s1[i]) {
            if (dp[i - 1][j - 1][k] + 1 > dp[i][j][t + 1])
              dp[i][j][t + 1] = dp[i - 1][j - 1][k] + 1, ptr[i][j][t + 1] = k,
                           pick[i][j][t + 1] = true;
          } else if (dp[i - 1][j - 1][k] + 1 > dp[i][j][0])
            dp[i][j][0] = dp[i - 1][j - 1][k] + 1, ptr[i][j][0] = k,
            pick[i][j][0] = true;
        }
      }
      for (int k = 0; k < l; k++)
        if (dp[i][j - 1][k] > dp[i][j][k] || dp[i - 1][j][k] > dp[i][j][k])
          dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k]),
          pick[i][j][k] = false;
    }
  }
  int wh = 0;
  for (int i = 1; i < l; i++)
    if (dp[m][n][i] > dp[m][n][wh]) wh = i;
  if (dp[m][n][wh] == 0)
    cout << 0 << endl;
  else
    cout << output(m, n, wh) << endl;
}
