#include <bits/stdc++.h>
using namespace std;
string s1, s2, s3;
vector<int> chars[30];
int dp[109][109][109];
map<pair<int, char>, int> m;
int longestsubsequence(int idx1, int idx2, int sub) {
  if (sub >= (int)s3.size()) return -INT_MAX;
  if (idx1 >= (int)s1.size() || idx2 >= (int)s2.size() + 1) return 0;
  int t = 0;
  if (idx2 >= 0 && dp[idx1][idx2][sub] >= 0) return dp[idx1][idx2][sub];
  auto v = chars[s1[idx1] - 'A'];
  auto idx22 = upper_bound(v.begin(), v.end(), idx2) - v.begin();
  if (idx22 < (int)v.size()) {
    if (s1[idx1] == s3[sub])
      t = longestsubsequence(idx1 + 1, v[idx22], sub + 1) + 1;
    else {
      t = longestsubsequence(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]) + 1;
    }
  }
  t = max(t, longestsubsequence(idx1 + 1, idx2, sub));
  if (idx1 >= 0 && idx2 >= 0) dp[idx1][idx2][sub] = t;
  return t;
}
void build(int idx1, int idx2, int sub) {
  if (idx1 >= (int)s1.size() || idx2 >= (int)s2.size()) return;
  int t = longestsubsequence(idx1 + 1, idx2, sub);
  auto v = chars[s1[idx1] - 'A'];
  auto idx22 = upper_bound(v.begin(), v.end(), idx2) - v.begin();
  int T = -INT_MAX;
  if (idx22 < (int)v.size()) {
    if (s1[idx1] == s3[sub])
      T = longestsubsequence(idx1 + 1, v[idx22], sub + 1) + 1;
    else {
      T = longestsubsequence(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]) + 1;
    }
    if (T >= t) {
      cout << s1[idx1];
      if (s1[idx1] == s3[sub])
        build(idx1 + 1, v[idx22], sub + 1);
      else {
        build(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]);
      }
    }
  }
  if (t > T) build(idx1 + 1, idx2, sub);
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> s1 >> s2 >> s3;
  for (int i = 0; i < (int)s3.size(); ++i) {
    for (char c = 'A'; c <= 'Z'; ++c) {
      for (int k = 0; k <= i; ++k) {
        int idx1 = k - 1, idx2 = i;
        if (c == s3[k]) {
          while (idx1 >= 0 && s3[idx1] == s3[idx2]) idx1--, idx2--;
          if (idx1 == -1) {
            if (m.count({i + 1, c}))
              m[{i + 1, c}] = max(m[{i + 1, c}], k + 1);
            else
              m[{i + 1, c}] = k + 1;
          }
        }
      }
    }
  }
  for (int i = 0; i < (int)s2.size(); ++i) chars[s2[i] - 'A'].push_back(i);
  int t = longestsubsequence(0, -1, 0);
  if (t > 0)
    build(0, -1, 0);
  else
    cout << 0 << endl;
  return 0;
}
