#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 get_ans(int idx1, int idx2, int sub) {
  if (sub >= (int)s3.size()) return -INT_MAX;
  if (idx1 == (int)s1.size() || idx2 == (int)s2.size()) return 0;
  int &ret = dp[idx1][idx2][sub];
  if (ret != -1) return ret;
  ret = max(get_ans(idx1 + 1, idx2, sub), get_ans(idx1, idx2 + 1, sub));
  if (s1[idx1] == s2[idx2]) {
    if (s1[idx1] == s3[sub])
      ret = max(ret, get_ans(idx1 + 1, idx2 + 1, sub + 1) + 1);
    else {
      sub = m[{sub, s1[idx1]}];
      ret = max(ret, get_ans(idx1 + 1, idx2 + 1, sub) + 1);
    }
  }
  return ret;
}
void build(int idx1, int idx2, int sub) {
  if (idx1 == (int)s1.size() || idx2 == (int)s2.size()) return;
  int x1 = get_ans(idx1 + 1, idx2, sub), x2 = get_ans(idx1, idx2 + 1, sub);
  int x3 = -INT_MAX, mx;
  if (s1[idx1] == s2[idx2]) {
    if (s1[idx1] == s3[sub])
      x3 = get_ans(idx1 + 1, idx2 + 1, sub + 1);
    else
      x3 = get_ans(idx1 + 1, idx2 + 1, m[{sub, s1[idx1]}]);
  }
  mx = max(x1, max(x2, x3));
  if (mx == x3) {
    printf("%c", s1[idx1]);
    if (s1[idx1] == s3[sub])
      build(idx1 + 1, idx2 + 1, sub + 1);
    else
      build(idx1 + 1, idx2 + 1, m[{sub, s1[idx1]}]);
  } else if (mx == x1)
    build(idx1 + 1, idx2, sub);
  else
    build(idx1, idx2 + 1, 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 = get_ans(0, 0, 0);
  build(0, 0, 0);
  if (t == 0) puts("0");
  return 0;
}
