#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> kmp(string s) {
  long long n = s.size();
  vector<long long> kmp(n);
  vector<vector<long long>> nxt(n, vector<long long>(26));
  for (long long i = 1; i < n; i++) {
    long long j = kmp[i - 1];
    while (j and s[j] != s[i]) j = kmp[j - 1];
    if (s[j] == s[i]) j++;
    kmp[i] = j;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 26; j++) {
      long long k = i;
      while (k > 0 and s[k] != 'A' + j) k = kmp[k - 1];
      if (s[k] == 'A' + j) k++;
      nxt[i][j] = k;
    }
  }
  return nxt;
}
string s, t, v;
long long dp[102][102][102];
pair<pair<long long, long long>, long long> ptr[101][101][101];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> s >> t >> v;
  auto nxt = kmp(v);
  for (long long i = 0; i < 100; i++)
    for (long long j = 0; j < 100; j++)
      for (long long k = 0; k < 100; k++) dp[i][j][k] = -1000000000000000;
  dp[0][0][0] = 0;
  for (long long i = 0; i < (long long)s.size(); i++) {
    for (long long j = 0; j < (long long)t.size(); j++) {
      for (long long k = 0; k < (long long)v.size(); k++) {
        if (s[i] == t[j]) {
          if (dp[i + 1][j + 1][nxt[k][s[i] - 'A']] < dp[i][j][k] + 1) {
            ptr[i + 1][j + 1][nxt[k][s[i] - 'A']] = {{i, j}, k};
          }
          dp[i + 1][j + 1][nxt[k][s[i] - 'A']] =
              max(dp[i + 1][j + 1][nxt[k][s[i] - 'A']], dp[i][j][k] + 1);
        }
        if (dp[i + 1][j][k] < dp[i][j][k]) {
          ptr[i + 1][j][k] = {{i, j}, k};
        }
        if (dp[i][j + 1][k] < dp[i][j][k]) {
          ptr[i][j + 1][k] = {{i, j}, k};
        }
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
        dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
      }
    }
  }
  long long maxlen = 0, x, y, z;
  for (long long i = 1; i <= (long long)s.size(); i++)
    for (long long j = 1; j <= (long long)t.size(); j++)
      for (long long k = 0; k < (long long)v.size(); k++) {
        if (maxlen < dp[i][j][k]) {
          maxlen = dp[i][j][k];
          x = i, y = j, z = k;
        }
      }
  if (maxlen == 0) return cout << "0\n", 0;
  string ans = "";
  while (x and y) {
    if (ptr[x][y][z].first.first == x - 1 and
        ptr[x][y][z].first.second == y - 1) {
      z = ptr[x][y][z].second;
      x = x - 1, y = y - 1;
      assert(s[x] == t[y]);
      ans += s[x];
    } else {
      long long a = ptr[x][y][z].first.first, b = ptr[x][y][z].first.second,
                c = ptr[x][y][z].second;
      x = a, y = b, z = c;
    }
  }
  reverse(ans.begin(), ans.end());
  assert(ans.size() == maxlen);
  cout << ans << '\n';
}
