#include <bits/stdc++.h>
using namespace std;
const int MAX = 105, inf = 0x3f3f3f3f;
int f[MAX][MAX][MAX], KMP[MAX], tr[MAX][MAX][MAX];
pair<int, int> dp[MAX][MAX][MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s1, s2, S;
  cin >> s1;
  cin >> s2;
  cin >> S;
  int n, m, l;
  n = s1.size();
  m = s2.size();
  l = S.size();
  s1 = ' ' + s1;
  s2 = ' ' + s2;
  S = ' ' + S;
  KMP[1] = 0;
  for (int i = 2, j = 0; i <= l; i++) {
    while (j > 0 && S[i] != S[j + 1]) j = KMP[j];
    if (S[j + 1] == S[i]) j++;
    KMP[i] = j;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      f[i][j][0] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k < l; k++) {
        f[i][j][k] = max(f[i - 1][j][k], f[i][j - 1][k]);
        if (f[i][j][k] == f[i - 1][j][k]) {
          dp[i][j][k] = dp[i - 1][j][k];
          tr[i][j][k] = k;
        }
        if (f[i][j][k] == f[i][j - 1][k]) {
          dp[i][j][k] = dp[i][j - 1][k];
          tr[i][j][k] = k;
        }
      }
      if (s1[i] == s2[j]) {
        for (int k = 0; k < l; k++) {
          int u = k;
          while (u > 0 && s1[i] != S[u + 1]) u = KMP[u];
          if (S[u + 1] == s1[i]) u++;
          if (u != l) {
            if (f[i][j][u] < f[i - 1][j - 1][k] + 1) {
              f[i][j][u] = f[i - 1][j - 1][k] + 1;
              dp[i][j][u] = pair<int, int>(i, j);
              tr[i][j][u] = k;
            }
          }
        }
      }
    }
  }
  int res = 0, kr;
  for (int i = 0; i < l; i++) {
    if (f[n][m][i] > res) {
      res = f[n][m][i];
      kr = i;
    }
  }
  if (res == 0) {
    cout << 0;
    return 0;
  }
  string ans;
  int u = dp[n][m][kr].first, v = dp[n][m][kr].second;
  ans = s1[u];
  kr = tr[u][v][kr];
  u--;
  v--;
  while (--res) {
    pair<int, int> ne = dp[u][v][kr];
    u = ne.first;
    v = ne.second;
    kr = tr[u][v][kr];
    ans = s1[u] + ans;
    u--;
    v--;
  }
  cout << ans;
}
