#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
string s1, s2, virus;
int dp[101][101][101];
int b[101];
void lps() {
  int i = 0, j = -1;
  b[0] = -1;
  int m = virus.length();
  while (i < m) {
    while (j >= 0 && virus[i] != virus[j]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
int solve(int id1, int id2, int len) {
  if (len == virus.length()) {
    return -(long long)1e6 + 2;
  }
  if (id1 == s1.length()) return 0;
  if (id2 == s2.length()) return 0;
  if (dp[id1][id2][len] != -1) return dp[id1][id2][len];
  int ans = -(long long)1e6 + 2;
  ans = max(ans, solve(id1 + 1, id2 + 1, len));
  if (s1[id1] == s2[id2]) {
    if (s1[id1] == virus[len])
      ans = max(ans, 1 + solve(id1 + 1, id2 + 1, len + 1));
    else {
      int j = len;
      while (j >= 0 && s1[id1] != virus[j]) j = b[j];
      ans = max(ans, 1 + solve(id1 + 1, id2 + 1, j + 1));
    }
  } else {
    ans = max(ans, solve(id1 + 1, id2, len));
    ans = max(ans, solve(id1, id2 + 1, len));
  }
  return dp[id1][id2][len] = ans;
}
void print(int id1, int id2, int len) {
  if (len == virus.length()) return;
  if (id1 == s1.length() || id2 == s2.length()) return;
  if (dp[id1][id2][len] == solve(id1 + 1, id2 + 1, len)) {
    print(id1 + 1, id2 + 1, len);
    return;
  }
  if (s1[id1] == s2[id2]) {
    if (s1[id1] == virus[len]) {
      if (dp[id1][id2][len] == 1 + solve(id1 + 1, id2 + 1, len + 1)) {
        cout << s1[id1];
        print(id1 + 1, id2 + 1, len + 1);
      }
    } else {
      int j = len;
      while (j >= 0 && s1[id1] != virus[j]) j = b[j];
      if (dp[id1][id2][len] == 1 + solve(id1 + 1, id2 + 1, j + 1)) {
        cout << s1[id1];
        print(id1 + 1, id2 + 1, j + 1);
      }
    }
  } else {
    if (dp[id1][id2][len] == solve(id1 + 1, id2, len))
      print(id1 + 1, id2, len);
    else if (dp[id1][id2][len] == solve(id1, id2 + 1, len))
      print(id1, id2 + 1, len);
  }
}
int main() {
  cin >> s1 >> s2 >> virus;
  memset(dp, -1, sizeof dp);
  lps();
  int ans = solve(0, 0, 0);
  if (ans < 0) ans = 0;
  if (ans == 0) {
    cout << 0;
    return 0;
  }
  print(0, 0, 0);
}
