#include <bits/stdc++.h>
using namespace std;
int n, m, z, dp[101][101][101], b[1001];
pair<int, int> p[101][101][101];
string s1, s2, vir, P;
int rec(int p1, int p2, int v) {
  if (v >= z) return -10000000;
  if (p1 == n || p2 == m) return 0;
  if (~dp[p1][p2][v]) return dp[p1][p2][v];
  int pt, ret = 0, be, v2 = v;
  be = 1;
  pt = v;
  ret = rec(p1 + 1, p2, v);
  int tmp = rec(p1, p2 + 1, v);
  if (ret < tmp) {
    ret = tmp;
    be = 2;
  }
  if (s1[p1] == s2[p2]) {
    while (v2 >= 0 && s1[p1] != P[v2]) v2 = b[v2];
    tmp = rec(p1 + 1, p2 + 1, v2 + 1) + 1;
    if (ret < tmp) {
      pt = v2 + 1;
      ret = tmp;
      be = 4;
    }
  }
  p[p1][p2][v] = make_pair(be, pt);
  return dp[p1][p2][v] = ret;
}
void kmpPreprocess() {
  int i = 0, j = -1;
  b[0] = -1, m = P.size();
  while (i < m) {
    while (j >= 0 && P[i] != P[j]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
int main() {
  cin >> s1 >> s2 >> vir;
  P = vir;
  kmpPreprocess();
  memset((dp), (-1), sizeof(dp));
  n = s1.size(), m = s2.size(), z = vir.size();
  int f = rec(0, 0, 0);
  if (f <= 0)
    cout << 0;
  else {
    int a = 0, b = 0, v = 0;
    while (a < n && b < m) {
      if (p[a][b][v].first == 4) {
        cout << s1[a];
        v = p[a][b][v].second;
        a++, b++;
      } else if (p[a][b][v].first == 1) {
        a++;
      } else if (p[a][b][v].first == 2)
        b++;
      else
        a++, b++;
    }
  }
  return 0;
}
