#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int N = 102, mod = 1000000007;
vector<int> compute_prefix(string s) {
  vector<int> pi(s.size(), -1);
  int k = -1;
  for (int i = 1; i < s.size(); i++) {
    while (k >= 0 && s[k + 1] != s[i]) k = pi[k];
    if (s[k + 1] == s[i]) k++;
    pi[i] = k;
  }
  return pi;
}
char s1[N], s2[N], s3[N];
vector<int> pi;
int n, m, k;
int mem[N][N][N];
int sol[N][N][N];
int dp(int i, int j, int mm) {
  if (mm == (int)pi.size() - 1) return -inf;
  if (i >= n || j >= m) return 0;
  int &ret = mem[i][j][mm + 1];
  if (ret != -1) return ret;
  int c1 = dp(i + 1, j, mm);
  int c2 = dp(i, j + 1, mm);
  ret = max(c1, c2);
  if (c1 > c2)
    sol[i][j][mm + 1] = -10;
  else
    sol[i][j][mm + 1] = -20;
  if (s1[i] == s2[j]) {
    int ma = mm;
    while (ma > -1 && s3[ma + 1] != s1[i]) ma = pi[ma];
    if (s3[ma + 1] == s1[i]) ma++;
    int c3 = dp(i + 1, j + 1, ma) + 1;
    if (c3 >= ret) {
      ret = c3;
      sol[i][j][mm + 1] = ma;
    }
  }
  return ret;
}
void build_sol(int i, int j, int mm) {
  if (mm == (int)pi.size() - 1) return;
  if (i >= n || j >= m) return;
  if (sol[i][j][mm + 1] == -10) {
    return build_sol(i + 1, j, mm);
  }
  if (sol[i][j][mm + 1] == -20) {
    return build_sol(i, j + 1, mm);
  }
  printf("%c", s1[i]);
  return build_sol(i + 1, j + 1, sol[i][j][mm + 1]);
}
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  scanf("%s", s3);
  n = strlen(s1);
  m = strlen(s2);
  k = strlen(s3);
  pi = compute_prefix(s3);
  memset(mem, -1, sizeof mem);
  int ANS = dp(0, 0, -1);
  if (ANS <= 0) {
    printf("0\n");
    return 0;
  }
  build_sol(0, 0, -1);
  return 0;
}
