#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e2 + 10;
long long qpow(long long x, long long y, long long MOD) {
  long long a = 1;
  while (y) {
    if (y & 1) a = a * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return a;
}
struct node {
  int x, y, l;
  char ch;
} path[N][N][N];
int dp[N][N][N];
char s[N], t[N], vs[N];
int nxt[N];
void get_nxt(char s[], int m) {
  nxt[0] = -1;
  int i = 0, j = -1;
  while (i < m) {
    while (j != -1 && s[i] != s[j]) j = nxt[j];
    nxt[++i] = ++j;
  }
}
int main() {
  scanf("%s%s%s", s + 1, t + 1, vs);
  int n = strlen(s + 1), m = strlen(t + 1), len = strlen(vs);
  get_nxt(vs, len);
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = int(0); i <= int(n); ++i)
    for (int j = int(0); j <= int(m); ++j) {
      for (int k = int(0); k <= int(len - 1); ++k) {
        if (i && dp[i - 1][j][k] > dp[i][j][k]) {
          dp[i][j][k] = dp[i - 1][j][k];
          path[i][j][k] = path[i - 1][j][k];
        }
        if (j && dp[i][j - 1][k] > dp[i][j][k]) {
          dp[i][j][k] = dp[i][j - 1][k];
          path[i][j][k] = path[i][j - 1][k];
        }
      }
      if (s[i] == t[j] && i && j) {
        for (int k = int(0); k <= int(len - 1); ++k) {
          if (dp[i - 1][j - 1][k] != -1) {
            int nk = k;
            while (nk != -1 && vs[nk] != s[i]) nk = nxt[nk];
            if (dp[i - 1][j - 1][k] + 1 > dp[i][j][nk + 1]) {
              dp[i][j][nk + 1] = dp[i - 1][j - 1][k] + 1;
              path[i][j][nk + 1] = {i - 1, j - 1, k, s[i]};
            }
          }
        }
      }
    }
  int ans = -inf;
  for (int i = int(0); i <= int(len - 1); ++i) ans = max(ans, dp[n][m][i]);
  if (ans <= 0) {
    puts("0");
    return 0;
  }
  vector<char> vec;
  for (int i = int(0); i <= int(len - 1); ++i) {
    if (dp[n][m][i] == ans) {
      int x = n, y = m, c = i;
      while (1) {
        vec.push_back(path[x][y][c].ch);
        if ((int)vec.size() == ans) break;
        int xx = path[x][y][c].x, yy = path[x][y][c].y, cc = path[x][y][c].l;
        x = xx, y = yy, c = cc;
      }
      break;
    }
  }
  for (int i = vec.size() - 1; i >= 0; --i) {
    printf("%c", vec[i]);
  }
  return 0;
}
