#include <bits/stdc++.h>
using namespace std;
int pi[110], aut[110][26], len;
char s[110];
string A, B;
void init() {
  len = strlen(s);
  for (int i = 1; i < len; ++i) {
    int j = pi[i - 1];
    while (j > 0 and s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  for (int i = 0; i < len; ++i)
    for (int c = 0; c < 26; ++c) {
      int j = i;
      while (j > 0 and s[j] != char(c + 'A')) j = pi[j - 1];
      if (s[j] == char(c + 'A')) ++j;
      aut[i][c] = j;
    }
}
int DP[110][110][110];
int solve(int i, int j, int k) {
  int &res = DP[i][j][k];
  if (res != -1) return res;
  res = 0;
  if (i == A.size() or j == B.size()) return res;
  res = max(res, solve(i + 1, j, k));
  res = max(res, solve(i, j + 1, k));
  if (A[i] == B[j] and aut[k][A[i] - 'A'] != len)
    res = max(res, 1 + solve(i + 1, j + 1, aut[k][A[i] - 'A']));
  return res;
}
string findString(int i, int j, int k) {
  if (i == A.size() or j == B.size()) return string("");
  int a = solve(i + 1, j, k), b = solve(i, j + 1, k), c = -1;
  if (A[i] == B[j] and aut[k][A[i] - 'A'] != len)
    c = 1 + solve(i + 1, j + 1, aut[k][A[i] - 'A']);
  if (a >= b and a >= c) return findString(i + 1, j, k);
  if (b >= a and b >= c) return findString(i, j + 1, k);
  return A[i] + findString(i + 1, j + 1, aut[k][A[i] - 'A']);
}
int main() {
  cin >> A >> B >> s;
  init();
  memset(DP, -1, sizeof DP);
  int res = solve(0, 0, 0);
  if (res == 0)
    cout << 0;
  else
    cout << findString(0, 0, 0);
}
