#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
};
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); };
char x[105], y[105], virus[105];
int p[105], dp[105][105][105], xlen, ylen, vlen;
void prefix(char* ss) {
  int len = strlen(ss);
  int j = 0;
  for (int i = 1; i < len; i++) {
    while (j > 0 && ss[j] != ss[i]) j = p[j - 1];
    if (ss[i] == ss[j]) ++j;
    p[i] = j;
  }
}
int calc(int i, int j, int k) {
  if (i == xlen || j == ylen || k == vlen) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int f1 = 0, f2 = 0, f3 = 0, tmp = k;
  f1 = calc(i + 1, j, k);
  f2 = calc(i, j + 1, k);
  if (x[i] == y[j]) {
    while (tmp > 0 && x[i] != virus[tmp]) tmp = p[tmp - 1];
    if (x[i] == virus[tmp]) ++tmp;
    if (tmp < vlen) f3 = calc(i + 1, j + 1, tmp) + 1;
  }
  dp[i][j][k] = max(f1, max(f2, f3));
  return dp[i][j][k];
}
int ans;
void print(int i, int j, int k) {
  if (i == xlen || j == ylen || k >= vlen) return;
  int tmp = k;
  if (dp[i][j][k] == dp[i + 1][j][k])
    print(i + 1, j, k);
  else if (dp[i][j][k] == dp[i][j + 1][k])
    print(i, j + 1, k);
  else {
    if (x[i] == y[j]) {
      printf("%c", x[i]);
      while (tmp > 0 && x[i] != virus[tmp]) tmp = p[tmp - 1];
      if (x[i] == virus[tmp]) ++tmp;
      if (tmp < vlen && dp[i][j][k] == dp[i + 1][j + 1][tmp] + 1) {
        print(i + 1, j + 1, tmp);
        return;
      }
    }
  }
}
int main() {
  scanf("%s %s %s", x, y, virus);
  xlen = strlen(x), ylen = strlen(y), vlen = strlen(virus);
  prefix(virus);
  memset(dp, -1, sizeof(dp));
  ans = calc(0, 0, 0);
  if (ans)
    print(0, 0, 0);
  else
    printf("0\n");
  return 0;
}
