#include <bits/stdc++.h>
using namespace std;
string A, B, V;
vector<int> T(V.size() + 1);
int mem[110][110][110];
pair<pair<int, int>, int> nex[110][110][110];
int dp(int ia, int ib, int iv) {
  if (iv == V.size()) return -1000000000;
  if (ia == A.size() || ib == B.size()) return 0;
  if (mem[ia][ib][iv] != -1) return mem[ia][ib][iv];
  int w = -1000000000;
  if (A[ia] == B[ib]) {
    int niv = iv;
    while (niv >= 0 && V[niv] != B[ib]) niv = T[niv];
    niv++;
    int t = dp(ia + 1, ib + 1, niv) + 1;
    if (t > w) {
      nex[ia][ib][iv] =
          pair<pair<int, int>, int>(pair<int, int>(ia + 1, ib + 1), niv);
      w = t;
    }
  }
  {
    int t = dp(ia + 1, ib, iv);
    if (t > w) {
      nex[ia][ib][iv] =
          pair<pair<int, int>, int>(pair<int, int>(ia + 1, ib), iv);
      w = t;
    }
  }
  {
    int t = dp(ia, ib + 1, iv);
    if (t > w) {
      nex[ia][ib][iv] =
          pair<pair<int, int>, int>(pair<int, int>(ia, ib + 1), iv);
      w = t;
    }
  }
  return mem[ia][ib][iv] = w;
}
int main() {
  cin >> A >> B >> V;
  {
    int i = 0, j = -1;
    T[i] = j;
    while (i < V.size()) {
      while (j >= 0 && V[i] != V[j]) j = T[j];
      i++;
      j++;
      T[i] = j;
    }
  }
  memset(mem, -1, sizeof(mem));
  int t = dp(0, 0, 0);
  if (t == 0) {
    cout << t << endl;
  } else {
    int ia = 0, ib = 0, iv = 0;
    string s = "";
    int cnt = 0;
    while (iv < V.size() && ia < A.size() && ib < B.size()) {
      pair<pair<int, int>, int> n = nex[ia][ib][iv];
      if (n.first.first == ia + 1 && n.first.second == ib + 1) {
        s += A[ia];
      }
      ia = n.first.first;
      ib = n.first.second;
      iv = n.second;
    }
    cout << s << endl;
  }
}
