#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int INF = (int)2e9 + 5;
string toUpperCase(string s) {
  string res = "";
  for (int i = 0; i < s.length(); i++) res += toupper(s[i]);
  return res;
}
string toLowerCase(string s) {
  string res = "";
  for (int i = 0; i < s.length(); i++) res += tolower(s[i]);
  return res;
}
int A[N][26];
int p[N];
string s1, s2;
string s;
int dp[N][N][N];
int calc(int i, int j, int k) {
  if (dp[i][j][k] != -1) return dp[i][j][k];
  if (i >= s1.length() || j >= s2.length()) return dp[i][j][k] = 0;
  dp[i][j][k] = 0;
  if (s1[i] == s2[j] && A[k][s1[i] - 'a'] < s.length() - 1)
    dp[i][j][k] = max(dp[i][j][k], 1 + calc(i + 1, j + 1, A[k][s1[i] - 'a']));
  dp[i][j][k] = max(dp[i][j][k], calc(i + 1, j, k));
  dp[i][j][k] = max(dp[i][j][k], calc(i, j + 1, k));
  return dp[i][j][k];
}
string ans;
void restore(int i, int j, int k) {
  if (i >= s1.length() || j >= s2.length()) return;
  if (k + 1 >= s.length()) return;
  if (s1[i] == s2[j] && A[k][s1[i] - 'a'] < s.length() - 1 &&
      calc(i, j, k) == 1 + calc(i + 1, j + 1, A[k][s1[i] - 'a'])) {
    ans += s1[i];
    restore(i + 1, j + 1, A[k][s1[i] - 'a']);
    return;
  }
  if (calc(i, j, k) == calc(i + 1, j, k)) {
    restore(i + 1, j, k);
    return;
  }
  if (calc(i, j, k) == calc(i, j + 1, k)) {
    restore(i, j + 1, k);
    return;
  }
}
int main() {
  cin >> s1 >> s2;
  s1 = toLowerCase(s1);
  s2 = toLowerCase(s2);
  cin >> s;
  s = toLowerCase(s);
  s += '#';
  p[0] = 0;
  for (int i = 1; i < s.length(); i++) {
    int j = p[i - 1];
    while (j > 0 && s[j] != s[i]) {
      j = p[j - 1];
    }
    if (s[i] == s[j]) j++;
    p[i] = j;
  }
  for (int j = 0; j < s.length(); j++) {
    for (int c = 0; c < 26; c++) {
      if (j > 0 && s[j] - 'a' != c) {
        A[j][c] = A[p[j - 1]][c];
      } else {
        A[j][c] = j + (s[j] - 'a' == c);
      }
    }
  }
  memset(dp, -1, sizeof dp);
  restore(0, 0, 0);
  if (ans == s.substr(0, s.length() - 1)) ans = "";
  if (ans.empty()) {
    cout << 0;
  } else
    cout << toUpperCase(ans);
}
