#include <bits/stdc++.h>
using namespace std;
string s, t, pp;
int b[105], len1, len2, len3, dp[105][105][105], pizza;
bool done[105][105][105];
inline void preprocess() {
  int i = 0, j = -1;
  b[i] = j;
  while (i < len3) {
    while (j >= 0 && pp.at(i) != pp.at(j)) j = b[j];
    j++, i++;
    b[i] = j;
  }
}
int f(int p, int q, int r) {
  if (r == len3) return -(1 << 30);
  ;
  if (p == len1 || q == len2) return 0;
  if (done[p][q][r]) {
    return dp[p][q][r];
  }
  done[p][q][r] = 1;
  int ans = max(f(p + 1, q, r), f(p, q + 1, r));
  if (s.at(p) == t.at(q)) {
    if (s.at(p) == pp.at(r)) {
      ans = max(ans, 1 + f(p + 1, q + 1, r + 1));
    } else {
      int rr = r;
      while (rr >= 0 && pp.at(rr) != s.at(p)) rr = b[rr];
      rr++;
      ans = max(ans, 1 + f(p + 1, q + 1, rr));
    }
  }
  return dp[p][q][r] = ans;
}
void print(int p, int q, int r) {
  if (p == len1 || q == len2 || r == len3) return;
  if (dp[p][q][r] == dp[p + 1][q][r]) {
    print(p + 1, q, r);
  } else if (dp[p][q][r] == dp[p][q + 1][r]) {
    print(p, q + 1, r);
  } else if (s.at(p) == t.at(q)) {
    if (s.at(p) == pp.at(r)) {
      printf("%c", s.at(p));
      print(p + 1, q + 1, r + 1);
    } else {
      printf("%c", s.at(p));
      int rr = r;
      while (rr >= 0 && pp.at(rr) != s.at(p)) rr = b[rr];
      rr++;
      print(p + 1, q + 1, rr);
    }
  }
  return;
}
int main() {
  cin >> s >> t >> pp;
  len3 = pp.length();
  len1 = s.length();
  len2 = t.length();
  preprocess();
  pizza = f(0, 0, 0);
  if (pizza) {
    print(0, 0, 0);
    printf("\n");
  } else {
    printf("0\n");
  }
  return 0;
}
