#include <bits/stdc++.h>
using namespace std;
string s1, s2, virus;
string dp[110][110][110];
bool marked[110][110][110];
int d2[110][30];
bool canGo[110][110];
string maxi(string a, string b) {
  if (a.length() > b.length())
    return a;
  else
    return b;
}
string maxLength(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return "";
  if (marked[i][j][k]) return dp[i][j][k];
  marked[i][j][k] = true;
  dp[i][j][k] = maxi(maxLength(i - 1, j, k), maxLength(i, j - 1, k));
  if (s1[i] == s2[j])
    if (s1[i] == virus[k]) {
      if (k != 0)
        dp[i][j][k] = maxi(dp[i][j][k], maxLength(i - 1, j - 1, k - 1) + s1[i]);
    } else
      dp[i][j][k] = maxi(dp[i][j][k],
                         maxLength(i - 1, j - 1, d2[k][s1[i] - 'A']) + s1[i]);
  return dp[i][j][k];
}
int main() {
  memset(marked, false, sizeof marked);
  cin >> s1 >> s2 >> virus;
  canGo[virus.length()][virus.length()] = true;
  for (int i = 0; i < virus.length(); i++) {
    canGo[virus.length()][i] = true;
    for (int j = 0; j < virus.length(); j++) {
      int t1 = i, t2 = j;
      while (t1 < virus.length() && t2 < virus.length())
        if (virus[t1] != virus[t2])
          break;
        else
          t1++, t2++;
      if (t1 == virus.length())
        canGo[i][j] = true;
      else
        canGo[i][j] = false;
    }
  }
  for (int i = 0; i < virus.length(); i++)
    for (int j = 0; j < 26; j++) {
      d2[i][j] = virus.length() - 1;
      for (int k = i; k < virus.length(); k++) {
        if ((virus[k] == char(j + 'A')) && canGo[k + 1][i + 1]) {
          d2[i][j] = k - 1;
          break;
        }
      }
    }
  string s = maxLength(s1.length() - 1, s2.length() - 1, virus.length() - 1);
  if (s == "")
    cout << 0 << endl;
  else
    cout << s << endl;
}
