#include <bits/stdc++.h>
using namespace std;
string s[3];
int l[3];
int a[101][101][101];
int d[101][101][101];
int e[101][26];
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;
  if (go(x + 1, y, z) > r) {
    r = go(x + 1, y, z);
    d[x][y][z] = 1;
  }
  if (go(x, y + 1, z) > r) {
    r = go(x, y + 1, z);
    d[x][y][z] = 2;
  }
  if (s[0][x] == s[1][y]) {
    int c = e[z][s[0][x] - 'A'];
    if (go(x + 1, y + 1, c) + 1 > r) {
      r = go(x + 1, y + 1, c) + 1;
      d[x][y][z] = 200 + c;
    }
  }
  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 (d[x][y][z] == 1)
    go1(x + 1, y, z);
  else if (d[x][y][z] == 2)
    go1(x, y + 1, z);
  else if (d[x][y][z] >= 200) {
    printf("%c", s[0][x]);
    go1(x + 1, y + 1, d[x][y][z] - 200);
  }
}
int main() {
  for (int i = 0; i < 3; i++) {
    getline(cin, s[i]);
    l[i] = s[i].length();
  }
  for (int i = 0; i < l[2]; i++) {
    for (int j = 0; j < 26; j++) {
      string b = s[2].substr(0, i) + string(1, 'A' + j);
      int c = 0;
      for (int k = 1; k <= b.length(); k++) {
        if (b.substr(b.length() - k, k) == s[2].substr(0, k)) c = k;
      }
      e[i][j] = c;
    }
  }
  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;
}
