#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
struct p {
  int x, y, z;
} pre[105][105][105], e;
char a[105];
char b[105];
char c[105];
int dp[105][105][105];
int nex[105];
void get_next(const char P[], int nex[]) {
  int q, k;
  int m = strlen(P);
  nex[0] = 0;
  for (q = 1, k = 0; q < m; ++q) {
    while (k > 0 && P[q] != P[k]) {
      k = nex[k - 1];
    }
    if (P[q] == P[k]) {
      k++;
    }
    nex[q] = k;
  }
  return;
}
void dfs(p t) {
  int x, y, z;
  x = t.x, y = t.y, z = t.z;
  if (x == 0 && y == 0 && z == 0) return;
  p q = pre[x][y][z];
  int i = q.x, j = q.y, k = q.z;
  dfs(q);
  if (dp[i][j][k] + 1 == dp[x][y][z]) printf("%c", a[i]);
}
int main() {
  scanf("%s%s%s", a, b, c);
  get_next(c, nex);
  memset(dp, 0, sizeof dp);
  int n = strlen(a), m = strlen(b), q = strlen(c);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) dp[i][j][0] = 0;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      for (int k = 0; k < q; k++) {
        if (dp[i + 1][j][k] < dp[i][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          pre[i + 1][j][k].x = i;
          pre[i + 1][j][k].y = j;
          pre[i + 1][j][k].z = k;
        }
        if (dp[i][j + 1][k] < dp[i][j][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          pre[i][j + 1][k].x = i;
          pre[i][j + 1][k].y = j;
          pre[i][j + 1][k].z = k;
        }
        if (a[i] == b[j]) {
          int w = k;
          while (w > 0 && a[i] != c[w]) w = nex[w - 1];
          if (a[i] == c[w])
            w++;
          else
            w = 0;
          if (dp[i + 1][j + 1][w] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][w] = dp[i][j][k] + 1;
            pre[i + 1][j + 1][w].x = i;
            pre[i + 1][j + 1][w].y = j;
            pre[i + 1][j + 1][w].z = k;
          }
        }
      }
    }
  }
  int ma = 0;
  for (int k = 0; k < q; k++) {
    if (dp[n][m][k] > ma) {
      ma = dp[n][m][k];
      e.x = n;
      e.y = m;
      e.z = k;
    }
  }
  if (ma == 0) return 0 * printf("0\n");
  dfs(e);
  return 0;
}
