#include <bits/stdc++.h>
using namespace std;
int dp[105][105][105];
char a[105], b[105], c[105], tmp[105];
int n1, n2, n3, ans;
char f[105][105][105][105], res[105];
int main() {
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  scanf("%s", c + 1);
  n1 = strlen(a + 1);
  n2 = strlen(b + 1);
  n3 = strlen(c + 1);
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      for (int k = 0; k < n3; k++) {
        if (ans < dp[i][j][k]) {
          ans = dp[i][j][k];
          strcpy(res, f[i][j][k]);
        }
        if (i < n1 && dp[i + 1][j][k] < dp[i][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          strcpy(f[i + 1][j][k], f[i][j][k]);
        }
        if (j < n2 && dp[i][j + 1][k] < dp[i][j][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          strcpy(f[i][j + 1][k], f[i][j][k]);
        }
        if (i < n1 && j < n2) {
          if (a[i + 1] == b[j + 1]) {
            strcpy(tmp, f[i][j][k]);
            int len = dp[i][j][k] + 1;
            tmp[len - 1] = a[i + 1];
            tmp[len] = '\0';
            for (int l = min(len, n3); l >= 0; l--) {
              bool out = true;
              for (int p = 0; p < l; p++) {
                if (c[p + 1] != tmp[len - l + p]) {
                  out = false;
                  break;
                }
              }
              if (out) {
                if (len > dp[i + 1][j + 1][l]) {
                  dp[i + 1][j + 1][l] = len;
                  strcpy(f[i + 1][j + 1][l], tmp);
                }
                break;
              }
            }
          }
          if (dp[i + 1][j + 1][k] < dp[i][j][k]) {
            dp[i + 1][j + 1][k] = dp[i][j][k];
            strcpy(f[i + 1][j + 1][k], f[i][j][k]);
          }
        }
      }
    }
  }
  if (ans)
    puts(res);
  else
    puts("0");
  return 0;
}
