#include <bits/stdc++.h>
using namespace std;
const int maxn = 310;
const int oo = 1e9;
string s1, s2;
string virus;
int aut[maxn][31];
int memo[maxn][maxn][maxn];
int id(const char &ch) { return ch - 'A'; }
int solve(int i, int j, int k) {
  if (k == (int)virus.size()) {
    return -oo;
  }
  if (i == (int)s1.size()) {
    return 0;
  }
  if (j == (int)s2.size()) {
    return 0;
  }
  int &on = memo[i][j][k];
  if (on == -1) {
    on = max(solve(i + 1, j, k), solve(i, j + 1, k));
    if (s1[i] == s2[j]) {
      on = max(on, solve(i + 1, j + 1, aut[k][id(s1[i])]) + 1);
    }
  }
  return on;
}
void pre(const string &s) {
  for (int i = 0; i < 26; i++) {
    aut[0][i] = 0;
  }
  int brd = 0;
  aut[0][id(s[0])] = 1;
  for (int i = 1; i <= (int)s.size(); i++) {
    for (int j = 0; j < 26; j++) {
      aut[i][j] = aut[brd][j];
    }
    if (i < (int)s.size()) {
      aut[i][id(s[i])] = i + 1;
      brd = aut[brd][id(s[i])];
    }
  }
}
vector<char> ans;
bool dfs(int i, int j, int k, int sz) {
  int &on = memo[i][j][k];
  if (sz + 1 == solve(0, 0, 0) && s1[i] == s2[j]) {
    if (!((s1[i] == virus[k]) && k + 1 == (int)virus.size())) {
      ans.push_back(s1[i]);
      return true;
    }
  }
  if (memo[i + 1][j][k] == memo[i][j][k]) {
    if (dfs(i + 1, j, k, sz)) {
      return true;
    }
  }
  if (memo[i][j + 1][k] == memo[i][j][k]) {
    if (dfs(i, j + 1, k, sz)) {
      return true;
    }
  }
  if (s1[i] == s2[j]) {
    if (memo[i + 1][j + 1][aut[k][id(s1[i])]] == memo[i][j][k] - 1) {
      if (dfs(i + 1, j + 1, aut[k][id(s1[i])], sz + 1)) {
        ans.push_back(s1[i]);
        return true;
      }
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s1 >> s2 >> virus;
  pre(virus);
  memset(memo, -1, sizeof memo);
  if (solve(0, 0, 0)) {
    dfs(0, 0, 0, 0);
    reverse(ans.begin(), ans.end());
    for (auto &c : ans) {
      cout << c;
    }
    cout << '\n';
  } else {
    cout << 0 << '\n';
  }
  return 0;
}
