#include <bits/stdc++.h>
using namespace std;
int n, n1, n2;
string s1, s2, s;
pair<int, string> dp[100][100][100];
int lps[100];
int func(int k, char ch) {
  if (k == 0) {
    return 0;
  }
  int len = lps[k - 1];
  while (true) {
    if (s[len] == ch) {
      return len + 1;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        return 0;
      }
    }
  }
}
void make_lps() {
  int len = 0;
  int i = 1;
  lps[0] = 0;
  while (i < n) {
    if (s[len] == s[i]) {
      lps[i] = len + 1;
      len++;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
}
int g = 0;
pair<int, string> rec(int i, int j, int k) {
  if (i == n1 || j == n2) {
    return make_pair(0, "");
  }
  if (dp[i][j][k].first != -1) {
    return dp[i][j][k];
  }
  int mx = 0, t;
  string a = "";
  if (rec(i, j + 1, k).first > mx) {
    mx = rec(i, j + 1, k).first;
    a = rec(i, j + 1, k).second;
  }
  if (rec(i + 1, j, k).first > mx) {
    mx = rec(i + 1, j, k).first;
    a = rec(i + 1, j, k).second;
  }
  if (s1[i] == s2[j]) {
    if (s1[i] != s[k]) {
      t = func(k, s1[i]);
      if (1 + rec(i + 1, j + 1, t).first > mx) {
        mx = 1 + rec(i + 1, j + 1, t).first;
        a = s1[i] + rec(i + 1, j + 1, t).second;
      }
    } else {
      if (k != n - 1 && 1 + rec(i + 1, j + 1, k + 1).first > mx) {
        mx = 1 + rec(i + 1, j + 1, k + 1).first;
        a = s1[i] + rec(i + 1, j + 1, k + 1).second;
      }
    }
  }
  return dp[i][j][k] = make_pair(mx, a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, k;
  pair<int, string> pr;
  cin >> s1 >> s2 >> s;
  n = s.length();
  n1 = s1.length();
  n2 = s2.length();
  make_lps();
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      for (k = 0; k < 100; k++) {
        dp[i][j][k] = make_pair(-1, "");
      }
    }
  }
  pr = rec(0, 0, 0);
  if (pr.first) {
    cout << pr.second;
  } else {
    cout << "0";
  }
  return 0;
}
