#include <bits/stdc++.h>
using namespace std;
int memo[110][110][110], back[110], asz, bsz, vsz;
string a, b, v;
void kmpPreprocess(void) {
  int i = 0, j = -1;
  back[0] = -1;
  while (i < vsz) {
    while (j >= 0 and v[i] != v[j]) {
      j = back[j];
    }
    i++;
    j++;
    back[i] = j;
  }
}
int lcs(int i, int j, int k) {
  if (k == vsz) {
    return -1000000000;
  }
  if (i == asz or j == bsz) {
    return 0;
  }
  if (memo[i][j][k] != -1) {
    return memo[i][j][k];
  }
  int ans = 0;
  if ((a[i] == b[j])) {
    int m = k;
    while (m >= 0 and a[i] != v[m]) {
      m = back[m];
    }
    ans = max(ans, 1 + lcs(i + 1, j + 1, m + 1));
  }
  ans = max(ans, lcs(i + 1, j, k));
  ans = max(ans, lcs(i, j + 1, k));
  memo[i][j][k] = ans;
  return ans;
}
void printPath(int i, int j, int k) {
  if (i == asz or j == bsz or k == vsz) {
    return;
  }
  if ((a[i] == b[j])) {
    int m = k;
    while (m >= 0 and a[i] != v[m]) {
      m = back[m];
    }
    if (memo[i][j][k] == 1 + lcs(i + 1, j + 1, m + 1)) {
      cout << a[i];
      printPath(i + 1, j + 1, m + 1);
      return;
    }
  }
  if (memo[i][j][k] == lcs(i + 1, j, k)) {
    printPath(i + 1, j, k);
  } else if (memo[i][j][k] == lcs(i, j + 1, k)) {
    printPath(i, j + 1, k);
  }
}
int main(void) {
  while (cin >> a >> b >> v) {
    asz = a.size();
    bsz = b.size();
    vsz = v.size();
    memset(memo, -1, sizeof(memo));
    kmpPreprocess();
    int ans = lcs(0, 0, 0);
    if (ans == 0) {
      cout << ans << endl;
    } else {
      printPath(0, 0, 0);
      cout << endl;
    }
  }
  return 0;
}
