#include <bits/stdc++.h>
enum { LEFT, RIGHT, BOTH };
const int INF = INT_MAX >> 1;
std::string virus, s1, s2;
std::vector<int> failure;
int solution[105][105][105];
bool solved[105][105][105];
int next[105][105][105];
void fill_failure(void) {
  int candidate, pos;
  failure.clear();
  failure.resize(virus.size());
  pos = 2;
  candidate = 0;
  failure[1] = 0;
  failure[0] = -1;
  while (pos < virus.size()) {
    if (virus[pos - 1] == virus[candidate]) {
      failure[pos++] = ++candidate;
    } else if (candidate > 0) {
      candidate = failure[candidate];
    } else {
      failure[pos++] = 0;
    }
  }
}
int longest_match(const int pos_s1, const int pos_s2, const int pos_v) {
  int aux;
  int& step = next[pos_s1][pos_s2][pos_v];
  bool& seen = solved[pos_s1][pos_s2][pos_v];
  int& best = solution[pos_s1][pos_s2][pos_v];
  if (seen++) {
    return best;
  }
  if (pos_v == virus.size()) {
    return best = -INF;
  }
  if (pos_s1 == s1.size() || pos_s2 == s2.size()) {
    return best = 0;
  }
  best = -INF;
  if (s1[pos_s1] == s2[pos_s2]) {
    aux = pos_v;
    while (aux != -1 && virus[aux] != s1[pos_s1]) {
      aux = failure[aux];
    }
    if ((aux = 1 + longest_match(pos_s1 + 1, pos_s2 + 1, aux + 1)) > best) {
      best = aux;
      step = BOTH;
    }
  }
  if ((aux = longest_match(pos_s1 + 1, pos_s2, pos_v)) > best) {
    best = aux;
    step = LEFT;
  }
  if ((aux = longest_match(pos_s1, pos_s2 + 1, pos_v)) > best) {
    best = aux;
    step = RIGHT;
  }
  return best;
}
int main(void) {
  int pos_s1, pos_s2, pos_v, best;
  std::string result;
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);
  std::cin >> s1 >> s2 >> virus;
  fill_failure();
  best = longest_match(0, 0, 0);
  if (best <= 0) {
    std::cout << 0 << std::endl;
  } else {
    pos_s1 = pos_s2 = pos_v = 0;
    while (pos_s1 != s1.size() && pos_s2 != s2.size()) {
      if (next[pos_s1][pos_s2][pos_v] == LEFT) {
        ++pos_s1;
      } else if (next[pos_s1][pos_s2][pos_v] == RIGHT) {
        ++pos_s2;
      } else {
        result += s1[pos_s1];
        while (pos_v != -1 && virus[pos_v] != s1[pos_s1]) {
          pos_v = failure[pos_v];
        }
        ++pos_v;
        ++pos_s1;
        ++pos_s2;
      }
    }
    std::cout << result << std::endl;
  }
  return 0;
}
