#include <bits/stdc++.h>
using namespace std;
int next1[305][30], next2[305][30], next3[305][30];
int dp[110][110][30], nA, nB, nC;
string A, B, C;
int func(int a, int b, int c) {
  if (dp[a][b][c] != -1) return dp[a][b][c];
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    int a2 = next1[a][i];
    int b2 = next2[b][i];
    int c2 = next3[c][i];
    if (a2 != -1 && b2 != -1 && c2 != -1) ans = max(ans, func(a2, b2, c2) + 1);
  }
  return dp[a][b][c] = ans;
}
int search(string s) {
  for (int i = s.size(); i >= 0; i--) {
    bool match = true;
    for (int j = 0; j < i; j++)
      if (s[s.size() - i + j] != C[j]) match = false;
    if (match) {
      if (i == nC)
        return -1;
      else
        return i;
    }
  }
}
string construct(int a, int b, int c) {
  if (dp[a][b][c] == 0) return "";
  for (int i = 0; i < 26; i++) {
    int a2 = next1[a][i];
    int b2 = next2[b][i];
    int c2 = next3[c][i];
    if (a2 != -1 && b2 != -1 && c2 != -1)
      if (dp[a][b][c] == dp[a2][b2][c2] + 1)
        return (char)('A' + i) + construct(a2, b2, c2);
  }
}
int main() {
  cin >> A >> B >> C;
  nA = A.size(), nB = B.size(), nC = C.size();
  memset(next1, -1, sizeof(next1));
  for (int i = nA - 1; i >= 0; i--)
    for (int j = 0; j < 26; j++)
      if (A[i] == 'A' + j)
        next1[i][j] = i + 1;
      else
        next1[i][j] = next1[i + 1][j];
  memset(next2, -1, sizeof(next2));
  for (int i = nB - 1; i >= 0; i--)
    for (int j = 0; j < 26; j++)
      if (B[i] == 'A' + j)
        next2[i][j] = i + 1;
      else
        next2[i][j] = next2[i + 1][j];
  memset(next3, -1, sizeof(next3));
  for (int i = 0; i < nC; i++)
    for (int j = 0; j < 26; j++)
      next3[i][j] = search(C.substr(0, i) + (char)('A' + j));
  memset(dp, -1, sizeof(dp));
  int ans = func(0, 0, 0);
  if (ans == 0)
    cout << 0 << endl;
  else
    cout << construct(0, 0, 0) << endl;
  return 0;
}
