#include <bits/stdc++.h>
using namespace std;
long long int dp[105][105][105];
long long int opti[105][105][105];
long long int lps[105];
string s, s1, s2, ans;
long long int n, m, o;
long long int rec(long long int i, long long int j, long long int k) {
  if (k >= o) return -1e16;
  if (i >= n || j >= m) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  long long int an = -1e16, x = 0;
  if (s[i] == s1[j]) {
    long long int y = k;
    if (s2[k] != s[i]) {
      y--;
      y = max(y, 0ll);
      y = lps[y];
      while (y > 0) {
        if (s2[y] == s[i]) {
          y++;
          break;
        }
        y = lps[y - 1];
      }
      if (y == 0 && s2[y] == s[i]) y++;
    } else
      y++;
    x = rec(i + 1, j + 1, y) + 1;
    if (x > an) {
      opti[i][j][k] = 1;
      an = x;
    }
  }
  x = rec(i + 1, j, k);
  if (x > an) {
    opti[i][j][k] = 2;
    an = x;
  }
  x = rec(i, j + 1, k);
  if (x > an) {
    opti[i][j][k] = 3;
    an = x;
  }
  return dp[i][j][k] = an;
}
void computeLPSArray() {
  int len = 0;
  lps[0] = 0;
  int i = 1;
  while (i < o) {
    if (s2[i] == s2[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
}
int main() {
  for (int i = 0; i <= 104; i++)
    for (int j = 0; j <= 104; j++)
      for (int k = 0; k <= 104; k++) {
        dp[i][j][k] = -1;
        opti[i][j][k] = -1;
      }
  cin >> s >> s1 >> s2;
  n = s.length();
  m = s1.length();
  o = s2.length();
  computeLPSArray();
  long long int an = rec(0, 0, 0);
  if (an <= 0) return cout << "0" << '\n', 0;
  long long int i = 0, j = 0, k = 0;
  ans = "";
  while (opti[i][j][k] != -1) {
    if (opti[i][j][k] == 1) {
      ans.push_back(s[i]);
      long long int y = k;
      if (s2[k] != s[i]) {
        y--;
        y = max(y, 0ll);
        y = lps[y];
        while (y > 0) {
          if (s2[y] == s[i]) {
            y++;
            break;
          }
          y = lps[y - 1];
        }
        if (y == 0 && s2[y] == s[i]) y++;
      } else
        y++;
      k = y;
      i++, j++;
    } else if (opti[i][j][k] == 2)
      i++;
    else
      j++;
  }
  cout << ans << '\n';
  return 0;
}
