#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
int dp[102][102][102];
string s1, s2, v;
int n, m, r;
string patt;
int pi[105];
void Process() {
  int j = -1;
  pi[0] = -1;
  for (int i = 1; i < r; i++) {
    while (j >= 0 && patt[i - 1] != patt[j]) j = pi[j];
    pi[i] = ++j;
  }
}
int prvidx(int x, int y) {
  while (y >= 0 && s1[x] != v[y]) y = pi[y];
  return y;
}
int calc(int i, int j, int k) {
  if (k == r) return -1e5;
  if (i == n || j == m) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int ret = max(calc(i + 1, j, k), calc(i, j + 1, k));
  if (s1[i] == s2[j]) {
    ret = max(ret, 1 + calc(i + 1, j + 1, prvidx(i, k) + 1));
  }
  return dp[i][j][k] = ret;
}
string ans = "";
void go(int rest, int i, int j, int k) {
  if (rest == 0) return;
  int t1 = calc(i + 1, j, k);
  int t2 = calc(i, j + 1, k);
  int t3 = -1e5;
  if (s1[i] == s2[j]) t3 = 1 + calc(i + 1, j + 1, prvidx(i, k) + 1);
  int ret = max(t1, max(t2, t3));
  if (ret == t1) {
    go(rest, i + 1, j, k);
  } else if (ret == t2) {
    go(rest, i, j + 1, k);
  } else if (ret == t3) {
    ans += s1[i];
    go(rest - 1, i + 1, j + 1, prvidx(i, k) + 1);
  }
}
int main() {
  int test, cases = 1;
  cin >> s1 >> s2 >> v;
  memset(dp, -1, sizeof(dp));
  n = s1.size();
  m = s2.size();
  r = v.size();
  patt = v;
  Process();
  int out = calc(0, 0, 0);
  if (!out)
    cout << 0 << "\n";
  else {
    go(out, 0, 0, 0);
    cout << ans << "\n";
  }
  return 0;
}
