#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5, alfa = 100;
string str1, str2, str3;
int b[N], autom[N][alfa], resp, posi, dp[N][N][N];
vector<char> vec;
void prekmp(string &s) {
  for (int i = 1; i < s.size(); i++) {
    int j = b[i - 1];
    while (j > 0 && s[i] != s[j]) j = b[j - 1];
    if (s[i] == s[j]) j++;
    b[i] = j;
  }
}
void automato(string &str) {
  autom[0][str[0] - 'A'] = 1;
  for (int i = 1; i <= str.size(); i++) {
    for (int c = 0; c < alfa; c++) {
      if (i < str.size() && str[i] == (char)(c + 'A'))
        autom[i][c] = i + 1;
      else
        autom[i][c] = autom[b[i - 1]][c];
    }
  }
}
int LCS(int i, int j, int pos) {
  if (i == 0 || j == 0) return dp[i][j][pos] = 0;
  if (dp[i][j][pos] != -1) return dp[i][j][pos];
  if (str1[i - 1] == str2[j - 1]) {
    for (int p = 0; p < str3.size(); p++)
      if (autom[p][str1[i - 1] - 'A'] == pos)
        dp[i][j][pos] = max(dp[i][j][pos], LCS(i - 1, j - 1, p) + 1);
  }
  dp[i][j][pos] =
      max(dp[i][j][pos], max(LCS(i, j - 1, pos), LCS(i - 1, j, pos)));
  return dp[i][j][pos];
}
void build(int i, int j, int pos) {
  if (i == 0 || j == 0) return;
  if (str1[i - 1] == str2[j - 1]) {
    for (int p = 0; p < str3.size(); p++)
      if (autom[p][str1[i - 1] - 'A'] == pos &&
          dp[i][j][pos] == dp[i - 1][j - 1][p] + 1) {
        vec.push_back(str1[i - 1]), build(i - 1, j - 1, p);
        return;
      }
  }
  if (dp[i][j][pos] == dp[i][j - 1][pos]) {
    build(i, j - 1, pos);
    return;
  }
  if (dp[i][j][pos] == dp[i - 1][j][pos]) {
    build(i - 1, j, pos);
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> str1 >> str2 >> str3;
  memset(dp, -1, sizeof(dp)), prekmp(str3), automato(str3);
  for (int i = 0; i < str3.size(); i++)
    if (resp < LCS(str1.size(), str2.size(), i))
      posi = i, resp = LCS(str1.size(), str2.size(), i);
  build(str1.size(), str2.size(), posi);
  if (!resp)
    cout << resp << "\n";
  else {
    for (int i = vec.size() - 1; i >= 0; i--) cout << vec[i];
    cout << "\n";
  }
}
