#include <bits/stdc++.h>
using namespace std;
string s1, s2, virus;
pair<int, int> dp[105][105][105];
int l1, l2, lvirus;
string ans = "";
int pi[105];
void pf(string s) {
  memset(pi, 0, sizeof(pi));
  int n = (int)s.length();
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
}
int main() {
  cin >> s1 >> s2 >> virus;
  l1 = s1.length();
  l2 = s2.length();
  lvirus = virus.length();
  int i, j, k;
  for (i = 1; i <= l1; i++) {
    for (j = 1; j <= l2; j++) {
      for (k = 0; k < lvirus; k++) {
        if (dp[i][j][k].first <= dp[i - 1][j][k].first) {
          dp[i][j][k].first = dp[i - 1][j][k].first;
          dp[i][j][k].second = 1;
        }
        if (dp[i][j][k].first <= dp[i][j - 1][k].first) {
          dp[i][j][k].first = dp[i][j - 1][k].first;
          dp[i][j][k].second = 2;
        }
        if (s1[i - 1] == s2[j - 1]) {
          if (k != 0 && s1[i - 1] == virus[k - 1]) {
            if (dp[i][j][k].first < dp[i - 1][j - 1][k - 1].first + 1) {
              dp[i][j][k].first = dp[i - 1][j - 1][k - 1].first + 1;
              dp[i][j][k].second = 3;
            }
          }
          int z = k;
          if (s1[i - 1] != virus[z]) {
            char c = virus[z];
            virus[z] = s1[i - 1];
            pf(virus);
            int v = pi[z];
            if (dp[i][j][v].first < dp[i - 1][j - 1][z].first + 1) {
              dp[i][j][v].first = dp[i - 1][j - 1][z].first + 1;
              dp[i][j][v].second = 10 + z;
            }
            virus[z] = c;
          }
        }
      }
    }
  }
  int mx = 0, cur = -1;
  for (i = 0; i < lvirus; i++) {
    if (mx <= dp[l1][l2][i].first) {
      cur = i;
      mx = dp[l1][l2][i].first;
    }
  }
  if (mx == 0) {
    cout << 0;
    return 0;
  }
  i = l1;
  j = l2;
  while (i != 0 && j != 0) {
    if (dp[i][j][cur].second == 1) {
      i--;
      continue;
    }
    if (dp[i][j][cur].second == 2) {
      j--;
      continue;
    }
    if (dp[i][j][cur].second == 3) {
      ans = s1[i - 1] + ans;
      i--;
      j--;
      cur--;
      continue;
    }
    ans = s1[i - 1] + ans;
    cur = dp[i][j][cur].second - 10;
    i--;
    j--;
  }
  cout << ans;
  return 0;
}
