#include <bits/stdc++.h>
using namespace std;
int p[102][102][102], d[102][102][102], prf[102];
char s1[102], s2[102], s3[102];
bool mex(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  } else
    return false;
}
void init() {
  scanf("%s %s %s", s1, s2, s3);
  prf[0] = -1;
  prf[1] = 0;
  for (int i = 1; s3[i]; i++) {
    int cur = prf[i];
    while (cur >= 0 && s3[cur] != s3[i]) cur = prf[cur];
    cur++;
    prf[i + 1] = cur;
  }
}
int dp(int a, int b, int c) {
  if (s3[c] == 0) return -3;
  if (s1[a] == 0 || s2[b] == 0) return 0;
  int &ans = d[a][b][c];
  int &par = p[a][b][c];
  if (ans) return ans - 1000;
  if (mex(ans, dp(a + 1, b, c))) {
    par = 3;
  }
  if (mex(ans, dp(a, b + 1, c))) {
    par = 2;
  }
  if (s1[a] == s2[b]) {
    int f = c;
    while (f >= 0 && s3[f] != s1[a]) {
      f = prf[f];
    }
    f++;
    if (mex(ans, dp(a + 1, b + 1, f) + 1)) {
      par = 1;
    }
  }
  ans += 1000;
  return ans - 1000;
}
void rec(int a, int b, int c) {
  while (true) {
    switch (p[a][b][c]) {
      case 1: {
        printf("%c", s1[a]);
        while (c >= 0 && s1[a] != s3[c]) c = prf[c];
        a++;
        b++;
        c++;
      } break;
      case 2: {
        b++;
      } break;
      case 3: {
        a++;
      } break;
      default:
        return;
        break;
    }
  }
}
void solve() {
  int ans = dp(0, 0, 0);
  if (ans)
    rec(0, 0, 0);
  else
    printf("0");
}
int main() {
  init();
  solve();
  return 0;
}
