#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
char s1[maxn], s2[maxn], v[maxn];
int l1, l2, lv;
int dp[maxn][maxn][maxn], Next[maxn];
int pre[maxn][maxn][maxn][3], Len = 0, p, depth;
string ans;
void dfs(int i, int j, int k) {
  if (pre[i][j][k][0] == i - 1 && pre[i][j][k][1] == j - 1) depth++;
  if (depth < Len) {
    dfs(pre[i][j][k][0], pre[i][j][k][1], pre[i][j][k][2]);
  }
  if (pre[i][j][k][0] == i - 1 && pre[i][j][k][1] == j - 1) ans += s1[i];
}
void getNext() {
  int q, k;
  Next[0] = 0;
  for (q = 1, k = 0; q < lv; q++) {
    while (k && v[k] != v[q]) {
      k = Next[k - 1];
    }
    if (v[k] == v[q]) {
      k++;
    }
    Next[q] = k;
  }
}
void update(int i, int j, int k, int ii, int jj, int kk, int com) {
  if (dp[ii][jj][kk] == -1) return;
  if (dp[i][j][k] == -1 ||
      (dp[i][j][k] != -1 && dp[i][j][k] < dp[ii][jj][kk] + com)) {
    dp[i][j][k] = dp[ii][jj][kk] + com;
    pre[i][j][k][0] = ii;
    pre[i][j][k][1] = jj;
    pre[i][j][k][2] = kk;
  }
}
int main() {
  scanf("%s%s%s", s1 + 1, s2 + 1, v);
  l1 = strlen(s1 + 1);
  l2 = strlen(s2 + 1);
  lv = strlen(v);
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= l1; i++) {
    for (int j = 0; j <= l2; j++) {
      dp[i][j][0] = 0;
    }
  }
  getNext();
  for (int i = 1; i <= l1; i++) {
    for (int j = 1; j <= l2; j++) {
      for (int k = 0; k < lv; k++) {
        update(i, j, k, i - 1, j, k, 0);
        update(i, j, k, i, j - 1, k, 0);
      }
      if (s1[i] == s2[j]) {
        for (int k = 0; k < lv; k++) {
          int tmp;
          if (s1[i] == v[k]) {
            tmp = k + 1;
          } else {
            tmp = (k == 0 ? 0 : Next[k - 1]);
            while (tmp && s1[i] != v[tmp]) tmp = Next[tmp - 1];
            tmp = (v[tmp] == s1[i] ? tmp + 1 : 0);
          }
          update(i, j, tmp, i - 1, j - 1, k, 1);
        }
      }
    }
  }
  for (int i = 0; i < lv; i++) {
    if (Len < dp[l1][l2][i]) {
      Len = dp[l1][l2][p = i];
    }
  }
  if (!Len) {
    printf("0\n");
  } else {
    depth = 0;
    ans = "";
    dfs(l1, l2, p);
    cout << ans << endl;
  }
}
