#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 205;
int dp[maxn][maxn][maxn], ch[maxn][maxn];
bool vis[maxn][maxn][maxn];
int fail[maxn];
int x, y, n;
char s1[105], s2[105], vir[105];
void init() {
  fail[0] = fail[1] = 0;
  for (int i = 1; i < n; i++) {
    int j = fail[i];
    while (j != 0 and vir[i] != vir[j]) j = fail[j];
    fail[i + 1] = (vir[i] == vir[j] ? j + 1 : 0);
  }
}
void kmp() {
  init();
  for (int i = 0; i < n; i++) ch[i][vir[i] - 'A'] = i + 1;
  for (int i = 0; i < n; i++)
    for (int c = 0; c < 26; c++)
      if (ch[i][c] == 0) ch[i][c] = ch[fail[i]][c];
}
int dfs(int i, int j, int k) {
  if (vis[i][j][k]) return dp[i][j][k];
  vis[i][j][k] = true;
  if (k >= n) return dp[i][j][k] = -inf;
  if (i >= x or j >= y) return dp[i][j][k] = 0;
  dp[i][j][k] = max(dfs(i + 1, j, k), dfs(i, j + 1, k));
  if (s1[i] == s2[j])
    dp[i][j][k] = max(dp[i][j][k], dfs(i + 1, j + 1, ch[k][s1[i] - 'A']) + 1);
  return dp[i][j][k];
}
int main() {
  scanf("%s%s%s", s1, s2, vir);
  x = strlen(s1);
  y = strlen(s2);
  n = strlen(vir);
  kmp();
  if (dfs(0, 0, 0) != 0) {
    int i = 0, j = 0, k = 0;
    string ans;
    while (i < x and j < y) {
      if (dfs(i, j, k) == dfs(i + 1, j, k))
        i++;
      else if (dfs(i, j, k) == dfs(i, j + 1, k))
        j++;
      else {
        ans += s1[i];
        k = ch[k][s1[i] - 'A'];
        i++, j++;
      }
    }
    puts(ans.c_str());
  } else
    puts("0");
  return 0;
}
