#include <bits/stdc++.h>
using namespace std;
int N, M;
string s1, s2, v;
int memo[108][108][108];
int N_s1, N_s2, N_v;
vector<int> P;
void Cal() {
  memset(memo, -1, sizeof memo);
  P.push_back(0);
  for (int i = 1, k = 0; v[i]; i++) {
    while (k && v[i] != v[k]) k = P[k - 1];
    if (v[i] == v[k]) k++;
    P.push_back(k);
  }
}
int res(int index_s1, int index_s2, int index_v) {
  if (index_v >= N_v) return -123;
  if (index_s1 >= N_s1 || index_s2 >= N_s2) return 0;
  if (memo[index_s1][index_s2][index_v] != -1)
    return memo[index_s1][index_s2][index_v];
  int &ret = memo[index_s1][index_s2][index_v];
  int X = 0;
  if (s1[index_s1] == s2[index_s2]) {
    int k = index_v;
    while (k && s1[index_s1] != v[k]) k = P[k - 1];
    if (s1[index_s1] == v[k]) k++;
    if (v[k]) X = 1 + res(index_s1 + 1, index_s2 + 1, k);
  }
  return ret = max(0, max(X, max(res(index_s1 + 1, index_s2, index_v),
                                 res(index_s1, index_s2 + 1, index_v))));
}
string mm = "";
void solve(int index_s1, int index_s2, int index_v) {
  if (index_s1 >= N_s1 || index_s2 >= N_s2) return;
  int to = memo[index_s1][index_s2][index_v];
  if (s1[index_s1] == s2[index_s2]) {
    int k = index_v;
    while (k && s1[index_s1] != v[k]) k = P[k - 1];
    if (s1[index_s1] == v[k]) k++;
    if (to == 1 + res(index_s1 + 1, index_s2 + 1, k)) {
      mm += s1[index_s1];
      solve(index_s1 + 1, index_s2 + 1, k);
      return;
    }
  }
  if (to == res(index_s1 + 1, index_s2, index_v))
    solve(index_s1 + 1, index_s2, index_v);
  else
    solve(index_s1, index_s2 + 1, index_v);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s1 >> s2 >> v;
  Cal();
  N_s1 = s1.size(), N_s2 = s2.size(), N_v = v.size();
  if (!res(0, 0, 0)) {
    cout << 0;
    return 0;
  }
  solve(0, 0, 0);
  cout << mm;
}
