#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
string s1, s2, s3;
int p[222];
int f[111][111][111];
int path[111][111][111][3];
char show[111][111][111];
int n, m;
void update(int i, int j, int k, int oi, int oj, int ok, char p, int now) {
  if (f[i][j][k] >= now) return;
  f[i][j][k] = now;
  path[i][j][k][0] = oi;
  path[i][j][k][1] = oj;
  path[i][j][k][2] = ok;
  show[i][j][k] = p;
}
void print(int i, int j, int k) {
  if (i == 0 && j == 0) return;
  print(path[i][j][k][0], path[i][j][k][1], path[i][j][k][2]);
  if (show[i][j][k] != ' ') cout << show[i][j][k];
}
int main() {
  cin >> s1 >> s2 >> s3;
  m = s3.size();
  int j = 0;
  p[1] = 0;
  for (int i = 2; i <= m; ++i) {
    while (j && s3[j] != s3[i - 1]) j = p[j];
    if (s3[j] == s3[i - 1]) ++j;
    p[i] = j;
  }
  memset(f, -1, sizeof(f));
  f[0][0][0] = 0;
  for (int i = 0; i <= s1.size(); ++i)
    for (int j = 0; j <= s2.size(); ++j)
      for (int k = 0; k < m; ++k) {
        if (f[i][j][k] == -1) continue;
        if (i < s1.size() && j < s2.size() && s1[i] == s2[j]) {
          int l = k;
          while (l && s3[l] != s1[i]) l = p[l];
          if (s3[l] == s1[i]) ++l;
          if (l != m) update(i + 1, j + 1, l, i, j, k, s1[i], f[i][j][k] + 1);
        }
        update(i + 1, j, k, i, j, k, ' ', f[i][j][k]);
        update(i, j + 1, k, i, j, k, ' ', f[i][j][k]);
        update(i + 1, j + 1, k, i, j, k, ' ', f[i][j][k]);
      }
  int ans = 0;
  for (int i = 0; i < m; ++i) ans = max(ans, f[s1.size()][s2.size()][i]);
  if (!ans) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < m; ++i)
    if (f[s1.size()][s2.size()][i] == ans) {
      print(s1.size(), s2.size(), i);
      return 0;
    }
}
