#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 100000000;
const long long infLL = 90000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
const int MX = 110;
int dp[MX][MX][MX], kmp[MX];
string s1, s2, virus;
int func(int i, int j, int l) {
  if (l == virus.size()) return -inf;
  if (i == s1.size() || j == s2.size()) return 0;
  int &ret = dp[i][j][l];
  if (ret != -1) return ret;
  ret = 0;
  if (s1[i] == s2[j]) {
    int lTemp = l;
    while (lTemp > 0 && virus[lTemp] != s1[i]) {
      lTemp = kmp[lTemp - 1];
    }
    if (s1[i] == virus[lTemp]) lTemp++;
    ret = max(ret, 1 + func(i + 1, j + 1, lTemp));
  }
  ret = max(ret, func(i + 1, j, l));
  ret = max(ret, func(i, j + 1, l));
  return ret;
}
void printAns(int i, int j, int l) {
  if (i == s1.size() || j == s2.size()) return;
  int ret = dp[i][j][l];
  if (s1[i] == s2[j]) {
    int lTemp = l;
    while (lTemp > 0 && virus[lTemp] != s1[i]) lTemp = kmp[lTemp - 1];
    if (s1[i] == virus[lTemp]) lTemp++;
    if (ret == 1 + func(i + 1, j + 1, lTemp)) {
      putchar(s1[i]);
      printAns(i + 1, j + 1, lTemp);
    } else if (ret == func(i + 1, j, l)) {
      printAns(i + 1, j, l);
    } else if (ret == func(i, j + 1, l)) {
      printAns(i, j + 1, l);
    }
  } else {
    if (ret == func(i + 1, j, l))
      printAns(i + 1, j, l);
    else if (ret == func(i, j + 1, l))
      printAns(i, j + 1, l);
  }
}
int main() {
  cin >> s1 >> s2 >> virus;
  kmp[0] = 0;
  for (int i = 1, k = 0; i < virus.size(); ++i) {
    ;
    while (k > 0 && virus[k] != virus[i]) k = kmp[k - 1];
    if (virus[k] == virus[i]) ++k;
    kmp[i] = k;
  }
  memset(dp, -1, sizeof(dp));
  if (func(0, 0, 0) == 0) {
    printf("0");
    return 0;
  }
  printAns(0, 0, 0);
  return 0;
}
