#include <bits/stdc++.h>
using namespace std;
const int CHR = 30;
struct node {
  int nxt[CHR];
  node() { memset(nxt, 0, sizeof(nxt)); }
};
node T[209];
int fl[209];
int nw;
int val[209];
void init() {
  memset(T, 0, sizeof(T));
  memset(fl, 0, sizeof(fl));
  memset(val, 0, sizeof(val));
  T[1] = node();
  nw = 1;
}
void Ins(string s, int ln, int vl) {
  int p = 1;
  for (int i = 0; i < ln; i++) {
    int k = s[i] - 'A';
    if (T[p].nxt[k] == 0) {
      T[p].nxt[k] = (++nw);
      T[nw] = node();
    }
    p = T[p].nxt[k];
  }
  val[p] += vl;
}
void fail_bfs() {
  queue<int> Q;
  Q.push(1);
  for (int i = 0; i < CHR; i++) T[0].nxt[i] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < CHR; i++) {
      int v = T[u].nxt[i];
      if (v == 0) {
        T[u].nxt[i] = T[fl[u]].nxt[i];
        continue;
      }
      fl[v] = T[fl[u]].nxt[i];
      Q.push(v);
    }
  }
}
string vrs, a, b;
int la, lb, lv;
int dp[209][209][209];
int go(int i, int j, int id) {
  if (i == la || j == lb) return 0;
  int &ret = dp[i][j][id];
  if (ret != -1) return ret;
  ret = 0;
  int op1 = go(i + 1, j, id);
  int op2 = go(i, j + 1, id);
  int op3 = 0;
  if (a[i] == b[j]) {
    int cst = 0, nid = T[id].nxt[a[i] - 'A'];
    int tmp = nid;
    while (tmp) cst += val[tmp], tmp = fl[tmp];
    if (!cst) op3 = 1 + go(i + 1, j + 1, nid);
  }
  ret = max(ret, max(max(op1, op2), op3));
  return ret;
}
void po(int i, int j, int id) {
  if (i == la || j == lb) return;
  int &ret = dp[i][j][id];
  if (ret == go(i + 1, j, id)) {
    po(i + 1, j, id);
    return;
  } else if (ret == go(i, j + 1, id)) {
    po(i, j + 1, id);
    return;
  } else if (a[i] == b[j]) {
    int cst = 0, nid = T[id].nxt[a[i] - 'A'];
    int tmp = nid;
    while (tmp) cst += val[tmp], tmp = fl[tmp];
    if (!cst) {
      if (ret = 1 + go(i + 1, j + 1, nid)) {
        cout << a[i];
        po(i + 1, j + 1, nid);
        return;
      }
    }
  }
  return;
}
int main() {
  int i, j, k;
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> a >> b >> vrs;
  init();
  la = a.size();
  lb = b.size();
  lv = vrs.size();
  Ins(vrs, lv, 2);
  fail_bfs();
  memset(dp, -1, sizeof(dp));
  int ans = go(0, 0, 1);
  if (ans == 0)
    cout << 0 << endl;
  else
    po(0, 0, 1), cout << endl;
  ;
  return 0;
}
