#include <bits/stdc++.h>
using namespace std;
string s1, s2, s3, s4;
int dp[101][101][101], lmt, sdp[101][101];
map<string, int> m;
vector<string> sv;
int gen(string xz) {
  for (int i = 0; i <= s3.size(); i++) sv.push_back(s3.substr(0, i));
  for (auto ix : sv) {
    string s = ix;
    for (int k = 'A'; k <= 'Z'; k++) {
      s.push_back(k);
      for (int j = 0; j < s.size(); j++) {
        int jj = 0, cnt = 0;
        bool br = 0;
        for (int i = 0; i + j < s.size() and jj < s3.size(); i++) {
          if (s[i + j] == s3[jj])
            jj++, cnt++;
          else {
            br = 1;
            break;
          }
        }
        if (!br)
          sdp[s.size() - 1][(int)s.back()] =
              max(cnt, sdp[s.size() - 1][(int)s.back()]);
      }
      if (sdp[s.size() - 1][(int)s.back()] == -1)
        sdp[s.size() - 1][(int)s.back()] = 0;
      s.pop_back();
    }
  }
  return 1;
}
bool printed = 0;
int lcs(int i, int j, int mi) {
  if (mi == s3.size()) return INT_MIN;
  if (i == s1.size() || j == s2.size()) return 0;
  if (dp[i][j][mi] != -1) return dp[i][j][mi];
  int x, y, z;
  x = y = z = INT_MIN;
  if (s1[i] == s2[j]) x = 1 + lcs(i + 1, j + 1, sdp[mi][(int)s1[i]]);
  y = lcs(i + 1, j, mi);
  z = lcs(i, j + 1, mi);
  return dp[i][j][mi] = max({x, y, z});
}
void print(int i, int j, int mi) {
  if (i == s1.size() || j == s2.size()) {
    return;
  }
  int re = lcs(i, j, mi);
  if (s1[i] == s2[j] and re == 1 + lcs(i + 1, j + 1, sdp[mi][(int)s1[i]])) {
    cout << s1[i];
    print(i + 1, j + 1, sdp[mi][(int)s1[i]]);
    return;
  }
  if (re == lcs(i + 1, j, mi)) {
    print(i + 1, j, mi);
    return;
  } else
    print(i, j + 1, mi);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  memset(dp, -1, sizeof dp);
  memset(sdp, -1, sizeof sdp);
  cin >> s1 >> s2 >> s3;
  s4 = s3;
  gen(s4);
  int ans = lcs(0, 0, 0);
  if (!ans) return cout << "0", 0;
  print(0, 0, 0);
}
