#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
char str1[N], str2[N], virus[N];
int n, m, k;
int F[N];
int dp[N][N][N];
void build() {
  F[0] = 0;
  int l = 0;
  for (int i = 1; i < k; ++i) {
    while (l && virus[l] != virus[i]) l = F[l - 1];
    if (virus[l] == virus[i]) ++l;
    F[i] = l;
  }
}
int calc(int i, int j, int p) {
  if (p == k) return -1e9;
  int &ret = dp[i][j][p];
  if (ret != -1) return ret;
  ret = 0;
  if (i == n || j == m) return 0;
  if (str1[i] == str2[j]) {
    int np = p;
    while (np && virus[np] != str1[i]) np = F[np - 1];
    if (str1[i] == virus[np]) ++np;
    ret = max(ret, 1 + calc(i + 1, j + 1, np));
  }
  return ret = max(ret, max(calc(i + 1, j, p), calc(i, j + 1, p)));
}
string res = "";
void calc(int i, int j, int p, int ans) {
  if (ans == 0) return;
  if (i == n || j == m) return;
  if (str1[i] == str2[j]) {
    int np = p;
    while (np && virus[np] != str1[i]) np = F[np - 1];
    if (str1[i] == virus[np]) ++np;
    if (np != k && dp[i + 1][j + 1][np] + 1 == ans) {
      res += str1[i];
      calc(i + 1, j + 1, np, ans - 1);
      return;
    }
  }
  if (dp[i + 1][j][p] == ans)
    calc(i + 1, j, p, ans);
  else
    calc(i, j + 1, p, ans);
}
int main(int argc, char *argv[]) {
  scanf("%s", str1);
  scanf("%s", str2);
  scanf("%s", virus);
  n = strlen(str1);
  m = strlen(str2);
  k = strlen(virus);
  memset(dp, -1, sizeof dp);
  build();
  int ans = calc(0, 0, 0);
  if (ans == 0) {
    puts("0");
    return 0;
  }
  calc(0, 0, 0, ans);
  printf("%s\n", res.c_str());
  return 0;
}
