#include <bits/stdc++.h>
using namespace std;
int l1, l2, l3, dp[105][105][105];
char s1[105], s2[105], s3[105];
int dfs(int n1, int n2, int n3) {
  int ret = -1000000000;
  if (n3 == l3) return dp[n1][n2][n3] = -1000000000;
  if (n1 > l1 || n2 > l2) return dp[n1][n2][n3] = 0;
  if (~dp[n1][n2][n3]) return dp[n1][n2][n3];
  if (s1[n1] == s2[n2]) {
    if (s3[n3 + 1] == s1[n1]) {
      ret = max(dfs(n1 + 1, n2 + 1, n3 + 1) + 1, ret);
      if (s3[1] == s1[n1]) {
        int res = dfs(n1 + 1, n2 + 1, 1) + 1;
        ret = min(ret, res);
      }
    } else {
      int go = (s1[n1] == s3[1]);
      ret = max(dfs(n1 + 1, n2 + 1, go) + 1, ret);
    }
  }
  ret = max(ret, max(dfs(n1 + 1, n2, n3), dfs(n1, n2 + 1, n3)));
  return dp[n1][n2][n3] = ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%s %s %s", s1 + 1, s2 + 1, s3 + 1);
  l1 = strlen(s1 + 1);
  l2 = strlen(s2 + 1);
  l3 = strlen(s3 + 1);
  dfs(1, 1, 0);
  int n1 = 1, n2 = 1, n3 = 0;
  while (n1 <= l1 && n2 <= l2) {
    if (s1[n1] == s2[n2]) {
      if (s3[n3 + 1] == s1[n1]) {
        if (dp[n1][n2][n3] == dp[n1 + 1][n2 + 1][n3 + 1] + 1) {
          printf("%c", s1[n1]);
          n1++;
          n2++;
          n3++;
          continue;
        }
        if (s3[1] == s1[n1]) {
          if (dp[n1][n2][n3] == dp[n1 + 1][n2 + 1][1]) {
            printf("%c", s1[n1]);
            n1++;
            n2++;
            n3 = 1;
            continue;
          }
        }
      } else {
        int go = (s1[n1] == s3[1]);
        if (dp[n1][n2][n3] == dp[n1 + 1][n2 + 1][go] + 1) {
          printf("%c", s1[n1]);
          n1++;
          n2++;
          n3 = go;
          continue;
        }
      }
    }
    if (dp[n1][n2][n3] == dp[n1 + 1][n2][n3]) {
      n1++;
      continue;
    }
    if (dp[n1][n2][n3] == dp[n1][n2 + 1][n3]) {
      n2++;
      continue;
    }
  }
  if (!dp[1][1][0]) printf("0");
}
