#include <bits/stdc++.h>
char s1[105];
char s2[105];
char virus[105];
int fail[105];
int dp[105][105][105];
int seq[105][105][105][3];
int print[105][105][105];
int n, m, p;
int solve(int pos1, int pos2, int pos3) {
  if (pos3 >= p) {
    return -0x3f3f3f3f;
  }
  if (pos1 >= n || pos2 >= m) {
    return 0;
  }
  if (seq[pos1][pos2][pos3][0] != -1) {
    return dp[pos1][pos2][pos3];
  }
  int aux, aux2, aux3;
  int way1, way2, way3;
  aux = aux2 = aux3 = -0x3f3f3f3f;
  way1 = way2 = way3 = 0;
  if (s1[pos1] == s2[pos2]) {
    if (s1[pos1] == virus[pos3]) {
      print[pos1][pos2][pos3] = 1;
      aux = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
      way1 = pos1 + 1;
      way2 = pos2 + 1;
      way3 = pos3 + 1;
    } else {
      way1 = pos1;
      way2 = pos2;
      if (pos3 != 0) {
        if (virus[fail[pos3 - 1]] == s1[pos1]) {
          aux = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1] + 1);
          print[pos1][pos2][pos3] = 1;
          way1++;
          way2++;
          way3 = fail[pos3 - 1] + 1;
        } else {
          aux = solve(pos1, pos2, fail[pos3 - 1]);
          way3 = fail[pos3 - 1];
        }
      } else {
        aux = 1 + solve(pos1 + 1, pos2 + 1, 0);
        print[pos1][pos2][0] = 1;
        way1++;
        way2++;
        way3 = 0;
      }
    }
  }
  dp[pos1][pos2][pos3] = aux;
  seq[pos1][pos2][pos3][0] = way1;
  seq[pos1][pos2][pos3][1] = way2;
  seq[pos1][pos2][pos3][2] = way3;
  aux2 = solve(pos1 + 1, pos2, pos3);
  aux3 = solve(pos1, pos2 + 1, pos3);
  if (aux2 > dp[pos1][pos2][pos3]) {
    dp[pos1][pos2][pos3] = aux2;
    print[pos1][pos2][pos3] = 0;
    seq[pos1][pos2][pos3][0] = pos1 + 1;
    seq[pos1][pos2][pos3][1] = pos2;
    seq[pos1][pos2][pos3][2] = pos3;
  }
  if (aux3 > dp[pos1][pos2][pos3]) {
    dp[pos1][pos2][pos3] = aux3;
    print[pos1][pos2][pos3] = 0;
    seq[pos1][pos2][pos3][0] = pos1;
    seq[pos1][pos2][pos3][1] = pos2 + 1;
    seq[pos1][pos2][pos3][2] = pos3;
  }
  return dp[pos1][pos2][pos3];
}
void build_fail(void) {
  int len;
  int i;
  fail[0] = 0;
  i = 1;
  len = 0;
  while (i < p) {
    if (virus[i] == virus[len]) {
      len++;
      fail[i++] = len;
    } else {
      if (len != 0) {
        len = fail[len - 1];
      } else {
        fail[i++] = 0;
      }
    }
  }
  return;
}
int main(void) {
  int i, j, k;
  int res;
  int w1, w2, w3;
  scanf(" %s %s %s", s1, s2, virus);
  n = strlen(s1);
  m = strlen(s2);
  p = strlen(virus);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (k = 0; k < p; k++) {
        seq[i][j][k][0] = -1;
        print[i][j][k] = 0;
      }
    }
  }
  build_fail();
  res = solve(0, 0, 0);
  if (res) {
    i = 0;
    j = 0;
    k = 0;
    while (i != n && j != m) {
      if (print[i][j][k]) {
        printf("%c", s1[i]);
      }
      w1 = seq[i][j][k][0];
      w2 = seq[i][j][k][1];
      w3 = seq[i][j][k][2];
      i = w1;
      j = w2;
      k = w3;
    }
    printf("\n");
  } else {
    printf("0\n");
  }
  return 0;
}
