#include <bits/stdc++.h>
using namespace std;
string s1, s2, v;
vector<int> pre;
vector<int> kmp(string s) {
  int len = s.size();
  vector<int> p(len);
  int x = 0;
  for (int i = 1; i < len; i++) {
    x = p[i - 1];
    while (x && s[i] != s[x]) x = p[x - 1];
    if (s[i] == s[x]) x++;
    p[i] = x;
  }
  return p;
}
int dp[110][110][110];
pair<int, int> dir[110][110][110];
int f(int i, int j, int k) {
  if (k >= v.size()) return -10000;
  if (i == s1.size() || j == s2.size()) return 0;
  if (dp[i][j][k] != -1) return dp[i][j][k];
  int r1 = f(i + 1, j, k);
  int r2 = f(i, j + 1, k);
  int dr = 0;
  int lv = k;
  if (r1 > r2) {
    dr = 1;
  } else
    dr = 2;
  r1 = max(r1, r2);
  int x = k;
  if (s1[i] == s2[j]) {
    if (x) x == pre[k - 1];
    while (x && s1[i] != v[x]) x = pre[x - 1];
    if (s1[i] == v[x]) x++;
    r2 = f(i + 1, j + 1, x) + 1;
    if (r2 > r1) {
      dr = 3;
      r1 = r2;
      lv = x;
    }
  }
  dir[i][j][k] = make_pair(dr, lv);
  return dp[i][j][k] = r1;
}
int main() {
  while (cin >> s1 >> s2 >> v) {
    pre = kmp(v);
    memset(dp, -1, sizeof(dp));
    int len = f(0, 0, 0);
    int x = 0, y = 0, z = 0;
    if (!len)
      cout << "0";
    else
      while (len) {
        if (dir[x][y][z].first == 1) {
          z = dir[x][y][z].second;
          x++;
        } else if (dir[x][y][z].first == 2) {
          z = dir[x][y][z].second;
          y++;
        } else {
          cout << s1[x];
          z = dir[x][y][z].second;
          len--;
          x++;
          y++;
        }
      }
    cout << endl;
  }
  return 0;
}
