#include <bits/stdc++.h>
using namespace std;
int nxt[105];
void get_next(char *S, int *next) {
  int j = -1, m = strlen(S);
  next[0] = -1;
  for (int i = 1; i < m; i++) {
    while (~j && S[j + 1] != S[i]) j = next[j];
    if (S[j + 1] == S[i]) j++;
    next[i] = j;
  }
}
char S[2][105];
char vi[105];
string dp[105][105][105];
void calc(string &a, string b) {
  if (a.size() < b.size()) a = b;
}
int main() {
  scanf("%s%s%s", &S[0], &S[1], vi);
  get_next(vi, nxt);
  int n = strlen(S[0]), m = strlen(S[1]), l = strlen(vi);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        calc(dp[i + 1][j + 1][k + 1], dp[i][j + 1][k + 1]);
        calc(dp[i + 1][j + 1][k + 1], dp[i + 1][j][k + 1]);
        if (S[0][i] == S[1][j]) {
          int x = k - 1;
          while (~x && S[0][i] != vi[x + 1]) x = nxt[x];
          if (S[0][i] == vi[x + 1]) x++;
          if (x + 1 < l)
            calc(dp[i + 1][j + 1][x + 2], dp[i][j][k + 1] + S[0][i]);
        }
      }
    }
  }
  string ans = "";
  for (int i = 1; i <= l; i++) calc(ans, dp[n][m][i]);
  if (ans.size() == 0)
    puts("0");
  else
    cout << ans << endl;
  return 0;
}
