#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = 1e9 + 10;
char a[maxn], b[maxn], c[maxn];
int dp[120][120][120];
int an, bn, cn;
int f[maxn];
void getFail(char *c, int n) {
  f[n] = f[n - 1] = n;
  for (int i = n - 1; i > 1; i--) {
    int j = f[i];
    while (j != n && c[i] != c[j]) j = f[j];
    f[i - 1] = c[i] == c[j] ? j - 1 : n;
  }
}
int dfs(int i, int j, int k) {
  int &res = dp[i][j][k];
  if (~res) return res;
  if (k == 0) return res = -INF;
  if (i < 1 || j < 1) return res = 0;
  res = 0;
  if (a[i] == b[j]) {
    int kt = k;
    while (kt != cn && a[i] != c[kt]) kt = f[kt];
    int tmp = 0;
    if (a[i] == c[kt])
      tmp = dfs(i - 1, j - 1, kt - 1) + 1;
    else
      tmp = dfs(i - 1, j - 1, kt) + 1;
    res = max(tmp, max(dfs(i - 1, j, k), dfs(i, j - 1, k)));
  } else
    res = max(dfs(i - 1, j, k), dfs(i, j - 1, k));
  return res;
}
void Print(int i, int j, int k) {
  int res = dp[i][j][k];
  if (i < 1 || j < 1) return;
  if (a[i] == b[j]) {
    int x = dp[i - 1][j][k], y = dp[i][j - 1][k];
    int kt = k;
    while (kt != cn && a[i] != c[kt]) kt = f[kt];
    int tmp = 0;
    if (a[i] == c[kt])
      tmp = dp[i - 1][j - 1][kt - 1] + 1;
    else
      tmp = dp[i - 1][j - 1][kt] + 1;
    if (res == tmp) {
      if (a[i] == c[kt])
        Print(i - 1, j - 1, kt - 1);
      else
        Print(i - 1, j - 1, kt);
      printf("%c", a[i]);
    } else {
      if (tmp == x)
        Print(i - 1, j, k);
      else
        Print(i, j - 1, k);
    }
  } else {
    if (res == dp[i - 1][j][k])
      Print(i - 1, j, k);
    else
      Print(i, j - 1, k);
  }
}
int main() {
  while (cin >> (a + 1) >> (b + 1) >> (c + 1)) {
    an = strlen(a + 1);
    bn = strlen(b + 1);
    cn = strlen(c + 1);
    memset(dp, -1, sizeof(dp));
    getFail(c, cn);
    int res = dfs(an, bn, cn);
    if (res == 0)
      printf("0");
    else
      Print(an, bn, cn);
    puts("");
  }
  return 0;
}
