#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void RD(char *s) { scanf("%s", s); }
void RD(char &s) { scanf("%c", &s); }
void RD(string &s) { cin >> s; }
void PR(int x) { printf("%d\n", x); }
void PR(int x, int y) { printf("%d %d\n", x, y); }
void PR(long long x) { printf("%I64d\n", x); }
void PR(char x) { printf("%c\n", x); }
void PR(char *x) { printf("%s\n", x); }
void PR(string x) { cout << x << endl; }
const long long inf = 1;
const long long mod = 1LL;
int par[110];
void pre_process(string &pat) {
  int i, k, n;
  n = (int)pat.size();
  k = 0;
  par[0] = 0;
  for (i = 1; i < n; i++) {
    while (k > 0 && pat[i] != pat[k]) k = par[k - 1];
    if (pat[i] == pat[k]) k++;
    par[i] = k;
  }
  return;
}
int dp[110][110][110], len1, len2, M;
string s1, s2, virus;
int solve(int indx1, int indx2, int match) {
  if (match == M) return -1000;
  if (indx1 == len1 || indx2 == len2) return 0;
  int &ret = dp[indx1][indx2][match];
  if (~ret) return ret;
  ret = solve(indx1 + 1, indx2, match);
  ret = max(ret, solve(indx1, indx2 + 1, match));
  if (s1[indx1] == s2[indx2]) {
    while (match) {
      if (s1[indx1] == virus[match]) break;
      match = par[match - 1];
    }
    if (s1[indx1] == virus[match])
      ret = max(ret, 1 + solve(indx1 + 1, indx2 + 1, match + 1));
    else
      ret = max(ret, 1 + solve(indx1 + 1, indx2 + 1, match));
  }
  return ret;
}
void path(int indx1, int indx2, int match) {
  if (indx1 == len1 || indx2 == len2) {
    printf("\n");
    return;
  }
  int k = dp[indx1][indx2][match];
  if (k <= 0) {
    printf("\n");
    return;
  } else if (k == dp[indx1 + 1][indx2][match])
    return path(indx1 + 1, indx2, match);
  else if (k == dp[indx1][indx2 + 1][match])
    return path(indx1, indx2 + 1, match);
  else {
    printf("%c", s1[indx1]);
    while (match) {
      if (s1[indx1] == virus[match]) break;
      match = par[match - 1];
    }
    if (s1[indx1] == virus[match])
      return path(indx1 + 1, indx2 + 1, match + 1);
    else
      return path(indx1 + 1, indx2 + 1, match);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  while (cin >> s1 >> s2 >> virus) {
    len1 = (int)s1.size();
    len2 = (int)s2.size();
    M = (int)virus.size();
    memset(dp, -1, sizeof(dp));
    pre_process(virus);
    k = solve(0, 0, 0);
    if (!k)
      PR(k);
    else
      path(0, 0, 0);
  }
  return 0;
}
