#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
string s1, s2, v;
int dp[101][101][101], pre[101][101][101];
void prt(int a, int b, int c) {
  if (a == 0 or b == 0) return;
  int x = pre[a][b][c];
  if (x == 0) {
    prt(a - 1, b - 1, c);
  } else if (x == 1) {
    prt(a - 1, b - 1, c - 1);
    cout << s1[a - 1];
  } else if (x == 2) {
    prt(a - 1, b, c);
  } else if (x == 3) {
    prt(a, b - 1, c);
  } else if (x < 0) {
    x = -x - 1;
    prt(a - 1, b - 1, x);
    cout << s1[a - 1];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> s1 >> s2 >> v;
  int n, m, k;
  n = s1.size();
  m = s2.size();
  k = v.size();
  int lps[k];
  int p = 0, q2 = 1;
  lps[0] = 0;
  while (q2 < k) {
    if (v[p] == v[q2])
      lps[q2++] = ++p;
    else if (p == 0)
      lps[q2++] = 0;
    else
      p = lps[p - 1];
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      for (int l = 0; l < k; l++) {
        if (i < l or j < l) continue;
        if (l == 0) {
          if (s1[i - 1] == s2[j - 1]) {
            char q = s1[i - 1];
            int x = dp[i - 1][j - 1][0], z = 0;
            for (int f = 0; f < k; f++) {
              int y = dp[i - 1][j - 1][f];
              int p = f;
              while (p >= 0) {
                if (q == v[p]) break;
                if (p == 0) {
                  if (1 + y > x) z = -1 - f;
                  x = max(x, 1 + y);
                  break;
                }
                p = lps[p - 1];
              }
            }
            dp[i][j][0] = x;
            pre[i][j][0] = z;
          } else {
            if (dp[i - 1][j][l] > dp[i][j - 1][l])
              pre[i][j][l] = 2;
            else
              pre[i][j][l] = 3;
            dp[i][j][l] = max(dp[i - 1][j][l], dp[i][j - 1][l]);
          }
        } else {
          if (s1[i - 1] == s2[j - 1]) {
            char q = s1[i - 1];
            int x = dp[i - 1][j - 1][l], z = 0;
            for (int f = l - 1; f < k; f++) {
              if (q != v[l - 1]) break;
              int y = dp[i - 1][j - 1][f];
              int p = f;
              while (p >= l - 1) {
                if (q == v[p] and p > l - 1) break;
                if (p == l - 1) {
                  if (1 + y > x) z = -1 - f;
                  x = max(x, 1 + y);
                  break;
                }
                p = lps[p - 1];
              }
            }
            dp[i][j][l] = x;
            pre[i][j][l] = z;
          } else {
            if (dp[i - 1][j][l] > dp[i][j - 1][l])
              pre[i][j][l] = 2;
            else
              pre[i][j][l] = 3;
            dp[i][j][l] = max(dp[i - 1][j][l], dp[i][j - 1][l]);
          }
        }
      }
    }
  }
  int maxx = -1, crt = 0;
  for (int i = 0; i < k; i++)
    if (dp[n][m][i] > maxx) {
      crt = i;
      maxx = dp[n][m][i];
    }
  if (dp[n][m][crt] == 0)
    cout << 0;
  else
    prt(n, m, crt);
  cout << endl;
}
