#include <bits/stdc++.h>
using namespace std;
string s[3];
int l[3];
int a[101][101][101];
int go(int x, int y, int z) {
  if (a[x][y][z] != -1) return a[x][y][z];
  if (z == l[2]) return -1e9;
  if (x == l[0] || y == l[1]) return 0;
  int &r = a[x][y][z];
  r = 0;
  r = max(r, go(x + 1, y, z));
  r = max(r, go(x, y + 1, z));
  if (s[0][x] == s[1][y]) {
    string b = s[2].substr(0, z) + s[0].substr(x, 1);
    int c = 0;
    for (int i = 1; i <= b.length(); i++) {
      if (b.substr(b.length() - i, i) == s[2].substr(0, i)) c = i;
    }
    r = max(r, go(x + 1, y + 1, c) + 1);
  }
  return r;
}
void go1(int x, int y, int z) {
  if (x == l[0] || y == l[1] || z == l[2] || a[x][y][z] == -1) return;
  if (a[x][y][z] == a[x + 1][y][z])
    go1(x + 1, y, z);
  else if (a[x][y][z] == a[x][y + 1][z])
    go1(x, y + 1, z);
  else if (a[x][y][z] > 0) {
    string b = s[2].substr(0, z) + s[0].substr(x, 1);
    int c = 0;
    for (int i = 1; i <= b.length(); i++) {
      if (b.substr(b.length() - i, i) == s[2].substr(0, i)) c = i;
    }
    printf("%c", s[0][x]);
    go1(x + 1, y + 1, c);
  }
}
int main() {
  for (int i = 0; i < 3; i++) {
    getline(cin, s[i]);
    l[i] = s[i].length();
  }
  memset(a, -1, sizeof(a));
  go(0, 0, 0);
  if (a[0][0][0] == 0) {
    printf("0\n");
    return 0;
  }
  go1(0, 0, 0);
  printf("\n");
  return 0;
}
