#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("03")
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return b / gcd(a, b) * a; }
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, -1, 1, 1, 1, -1, -1};
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};
const int mx = 1e2 + 5;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
string s, t, v;
int pos[mx][mx];
int dp[mx][mx][mx];
void calc() {
  for (int i = 0; i < v.size(); i++)
    for (char c = 'A'; c <= 'Z'; c++) {
      string ss = v.substr(0, i) + c;
      for (int k = 0; k <= i + 1; k++)
        if (v.substr(0, k) == ss.substr(i - k + 1, k)) pos[i][c] = k;
    }
}
int fun1(int i, int j, int k) {
  if (k == v.size()) return -inf;
  if (i == s.size() || j == t.size()) return 0;
  int &ans = dp[i][j][k];
  if (~ans) return ans;
  ans = max(fun1(i + 1, j, k), fun1(i, j + 1, k));
  if (s[i] == t[j]) ans = max(ans, 1 + fun1(i + 1, j + 1, pos[k][s[i]]));
  return ans;
}
void fun2(int i, int j, int k) {
  if (k == v.size()) return;
  if (i == s.size() || j == t.size()) return;
  int &ans = dp[i][j][k];
  if (ans == fun1(i + 1, j, k))
    fun2(i + 1, j, k);
  else if (ans == fun1(i, j + 1, k))
    fun2(i, j + 1, k);
  else if (s[i] == t[j] && ans == 1 + fun1(i + 1, j + 1, pos[k][s[i]])) {
    cout << s[i];
    fun2(i + 1, j + 1, pos[k][s[i]]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> s >> t >> v;
  calc();
  memset(dp, -1, sizeof dp);
  if (fun1(0, 0, 0))
    fun2(0, 0, 0);
  else
    cout << "0";
  cout << "\n";
  return 0;
}
