#include <bits/stdc++.h>
using namespace std;
string a, b, v;
int mem[105][105][105];
int las[105][26];
string s;
int get(int ind, char ch) {
  if (las[ind][ch - 'A'] != -1) return las[ind][ch - 'A'];
  las[ind][ch - 'A'] = 0;
  for (int i = 1; i <= ind + 1; i++) {
    string z = v.substr(0, i);
    string m = v.substr(ind - i + 1, i - 1) + ch;
    if (z == m) las[ind][ch - 'A'] = i;
  }
  return las[ind][ch - 'A'];
}
int go(int x, int y, int z) {
  if (z == v.size()) return -(1 << 30);
  if (x == a.size() || y == b.size()) return 0;
  if (mem[x][y][z] != -1) return mem[x][y][z];
  mem[x][y][z] = 0;
  mem[x][y][z] = max(go(x + 1, y, z), go(x, y + 1, z));
  if (a[x] == b[y]) {
    if (v[z] == a[x])
      mem[x][y][z] = max(mem[x][y][z], 1 + go(x + 1, y + 1, z + 1));
    else
      mem[x][y][z] = max(mem[x][y][z], 1 + go(x + 1, y + 1, get(z, a[x])));
  }
  return mem[x][y][z];
}
void build(int x, int y, int z) {
  if (z == v.size() || x == a.size() || y == b.size()) return;
  if (mem[x][y][z] == 0) return;
  if (mem[x][y][z] == go(x + 1, y, z)) {
    build(x + 1, y, z);
    return;
  }
  if (mem[x][y][z] == go(x, y + 1, z)) {
    build(x, y + 1, z);
    return;
  }
  if (a[x] == b[y]) {
    if (v[z] == a[x] && mem[x][y][z] == 1 + go(x + 1, y + 1, z + 1)) {
      s += a[x];
      build(x + 1, y + 1, z + 1);
      return;
    } else if (v[z] != a[x] &&
               mem[x][y][z] == 1 + go(x + 1, y + 1, get(z, a[x]))) {
      s += a[x];
      build(x + 1, y + 1, get(z, a[x]));
      return;
    }
  }
}
int main() {
  cin >> a >> b >> v;
  memset(mem, -1, sizeof mem);
  memset(las, -1, sizeof las);
  go(0, 0, 0);
  build(0, 0, 0);
  if (s.size() == 0)
    cout << 0 << endl;
  else
    cout << s << endl;
}
