#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 109;
const int inf = 0x3f3f3f3f;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
char s1[N], s2[N], s0[N];
int fail[N], l1, l2, l0;
void getFail(char s[], int fail[]) {
  fail[0] = -1;
  for (int i = 1, j = -1; s[i]; i++) {
    while (j != -1 && s[j + 1] != s[i]) j = fail[j];
    if (s[j + 1] == s[i]) j++;
    fail[i] = j;
  }
}
int dp[N][N][N];
int dfs(int a, int b, int c) {
  if (c == l0) return -inf;
  if (a == l1 || b == l2) return 0;
  int &ret = dp[a][b][c];
  if (ret + 1) return ret;
  ret = 0;
  if (s1[a] == s2[b]) {
    if (s0[c] == s1[a])
      ret = max(ret, dfs(a + 1, b + 1, c + 1) + 1);
    else {
      int id = c - 1;
      while (id != -1 && s0[id + 1] != s1[a]) id = fail[id];
      if (s0[id + 1] == s1[a]) id++;
      ret = max(ret, dfs(a + 1, b + 1, id + 1) + 1);
    }
  }
  ret = max(ret, dfs(a + 1, b, c));
  ret = max(ret, dfs(a, b + 1, c));
  return ret;
}
void print(int a, int b, int c) {
  if (a == l1 || b == l2 || c == l0) {
    puts("");
    return;
  }
  int ret = dfs(a, b, c);
  if (s1[a] == s2[b]) {
    int temp = -1;
    int id = c - 1;
    if (s0[c] == s1[a])
      temp = dfs(a + 1, b + 1, c + 1) + 1, id = c + 1;
    else {
      while (id != -1 && s0[id + 1] != s1[a]) id = fail[id];
      if (s0[id + 1] == s1[a]) id++;
      temp = dfs(a + 1, b + 1, id + 1) + 1;
      id++;
    }
    if (temp == ret) {
      printf("%c", s1[a]);
      print(a + 1, b + 1, id);
      return;
    }
  }
  if (ret == dfs(a + 1, b, c)) {
    print(a + 1, b, c);
    return;
  }
  if (ret == dfs(a, b + 1, c)) {
    print(a, b + 1, c);
    return;
  }
  return;
}
int main() {
  scanf("%s%s%s", s1, s2, s0);
  l1 = strlen(s1);
  l2 = strlen(s2);
  l0 = strlen(s0);
  memset(dp, -1, sizeof(dp));
  getFail(s0, fail);
  if (dfs(0, 0, 0))
    print(0, 0, 0);
  else
    puts("0");
  return 0;
}
