#include <bits/stdc++.h>
using namespace std;
const int N = 101;
string s, t, v;
int x, y, z, dp[N][N][N], pi[N];
vector<int> par[N][N][N];
void preset() {
  memset(dp, -1, sizeof(dp));
  cin >> s >> t >> v;
  x = s.length(), y = t.length(), z = v.length();
  for (int i = 1; i < z; ++i) {
    int j = pi[i - 1];
    while (j > 0 && v[i] != v[j]) j = pi[j - 1];
    pi[i] = j + (v[i] == v[j]);
  }
}
void bfs() {
  queue<vector<int>> q;
  q.push(vector<int>({0, 0, 0}));
  dp[0][0][0] = 0;
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    int i = now[0], j = now[1], k = now[2];
    if (i < x && j < y && k < z) {
      if (s[i] == t[j]) {
        if (s[i] == v[k]) {
          if (dp[i + 1][j + 1][k + 1] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][k + 1] = dp[i][j][k] + 1;
            par[i + 1][j + 1][k + 1] = {i, j, k};
            q.push({i + 1, j + 1, k + 1});
          }
        } else {
          int back = (k > 0 ? pi[k - 1] : 0);
          while (back > 0 && v[back] != s[i]) back = pi[back - 1];
          back += (v[back] == s[i]);
          if (dp[i + 1][j + 1][back] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][back] = dp[i][j][k] + 1;
            par[i + 1][j + 1][back] = {i, j, k};
            q.push({i + 1, j + 1, back});
          }
        }
      }
    }
    if (i + 1 <= x && dp[i + 1][j][k] < dp[i][j][k]) {
      dp[i + 1][j][k] = dp[i][j][k], par[i + 1][j][k] = {i, j, k};
      q.push({i + 1, j, k});
    }
    if (j + 1 <= y && dp[i][j + 1][k] < dp[i][j][k]) {
      dp[i][j + 1][k] = dp[i][j][k], par[i][j + 1][k] = {i, j, k};
      q.push({i, j + 1, k});
    }
  }
}
signed main() {
  preset();
  bfs();
  string ans;
  int i = x, j = y, k = max_element(dp[x][y], dp[x][y] + z) - dp[x][y];
  if (dp[i][j][k] <= 0) cout << 0, exit(0);
  while (!par[i][j][k].empty()) {
    if (par[i][j][k][0] + 1 == i && par[i][j][k][1] + 1 == j) ans += s[i - 1];
    tie(i, j, k) = {par[i][j][k][0], par[i][j][k][1], par[i][j][k][2]};
  }
  reverse(begin(ans), end(ans));
  cout << ans;
}
