#include <bits/stdc++.h>
using namespace std;
void run() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
string a, b, v;
int mem[105][105][105], f[105];
int solve(int p1, int p2, int p3) {
  if (p3 == v.size())
    return mem[p1][p2][p3] = -INT_MAX;
  else if (p1 == a.size() || p2 == b.size())
    return mem[p1][p2][p3] = 0;
  int &ret = mem[p1][p2][p3];
  int np3 = p3;
  if (ret != -1) return ret;
  ret = -INT_MAX;
  if (a[p1] == b[p2]) {
    while (p3 > 0 && a[p1] != v[p3]) p3 = f[p3 - 1];
    if (a[p1] == v[p3]) p3++;
    ret = solve(p1 + 1, p2 + 1, p3) + 1;
  }
  p3 = np3;
  ret = max(ret, solve(p1 + 1, p2, p3));
  ret = max(ret, solve(p1, p2 + 1, p3));
  return ret;
}
void build(int p1, int p2, int p3) {
  while (1) {
    if (p1 == a.size() || p2 == b.size()) break;
    int take = -INT_MAX, l1 = -INT_MAX, l2 = -INT_MAX;
    int np3 = p3;
    if (a[p1] == b[p2]) {
      while (p3 > 0 && a[p1] != v[p3]) p3 = f[p3 - 1];
      if (a[p1] == v[p3]) p3++;
      take = mem[p1 + 1][p2 + 1][p3] + 1;
    }
    l1 = mem[p1 + 1][p2][np3];
    l2 = mem[p1][p2 + 1][np3];
    if (take == mem[p1][p2][np3]) {
      cout << a[p1];
      p1++;
      p2++;
    } else if (l1 == mem[p1][p2][np3]) {
      p1++;
      p3 = np3;
    } else {
      p2++;
      p3 = np3;
    }
  }
  return;
}
void fail(string tmp) {
  f[0] = 0;
  int k = 0;
  for (int i = 1; i < tmp.size(); i++) {
    while (k > 0 && tmp[k] != tmp[i]) k = f[k - 1];
    if (tmp[k] == tmp[i])
      f[i] = ++k;
    else if (tmp[k] != tmp[i])
      f[i] = k;
  }
}
int main() {
  run();
  cin >> a >> b >> v;
  for (int i = 0; i <= a.size(); i++)
    for (int j = 0; j <= b.size(); j++)
      for (int k = 0; k <= v.size(); k++) mem[i][j][k] = -1;
  fail(v);
  int ans = solve(0, 0, 0);
  if (ans > 0)
    build(0, 0, 0);
  else
    cout << 0 << endl;
  return 0;
}
