#include <bits/stdc++.h>
using namespace std;
string s1, s2, v;
int dp[101][101][101];
string ans[101][101][101];
int t[101][26];
int main() {
  cin >> s1 >> s2 >> v;
  int mx = 0;
  string javab = "";
  for (int i = 0; i < v.size(); i++)
    for (int j = 0; j < 26; j++) {
      string tmp = v.substr(0, i);
      tmp += 'A' + j;
      t[i][j] = 0;
      for (int k = 0; k < tmp.size(); k++)
        if (v.substr(0, k + 1) == tmp.substr(tmp.size() - k - 1))
          t[i][j] = k + 1;
    }
  for (int i = 0; i < s1.size(); i++) {
    for (int j = 0; j < s2.size(); j++) {
      for (int k = 0; k < v.size(); k++) {
        if (i > 0) {
          dp[i][j][k] = dp[i - 1][j][k];
          ans[i][j][k] = ans[i - 1][j][k];
        }
        if (j > 0 && dp[i][j - 1][k] > dp[i][j][k]) {
          dp[i][j][k] = dp[i][j - 1][k];
          ans[i][j][k] = ans[i][j - 1][k];
        }
        if (s1[i] == s2[j]) {
          if (k == 0) {
            if (i == 0 || j == 0) {
              if (s1[i] != v[0]) {
                dp[i][j][k] = 1;
                ans[i][j][k] = s1[i];
              }
            } else {
              for (int l = 0; l < v.size(); l++) {
                if (t[l][s1[i] - 'A'] == 0) {
                  if (dp[i - 1][j - 1][l] + 1 > dp[i][j][0]) {
                    dp[i][j][0] = dp[i - 1][j - 1][l] + 1;
                    ans[i][j][0] = ans[i - 1][j - 1][l] + s1[i];
                  }
                }
              }
            }
          } else {
            if (i == 0 || j == 0) {
              if (k == 1 && s1[i] == v[0]) {
                dp[i][j][k] = 1;
                ans[i][j][k] = s1[i];
              }
            } else {
              for (int l = 0; l < v.size(); l++) {
                if (t[l][s1[i] - 'A'] == k) {
                  if (dp[i - 1][j - 1][l] + 1 > dp[i][j][k]) {
                    dp[i][j][k] = dp[i - 1][j - 1][l] + 1;
                    ans[i][j][k] = ans[i - 1][j - 1][l] + s1[i];
                  }
                }
              }
            }
          }
        }
        if (dp[i][j][k] > mx) {
          mx = dp[i][j][k];
          javab = ans[i][j][k];
        }
      }
    }
  }
  if (mx > 0)
    cout << javab << endl;
  else
    cout << 0 << endl;
  return 0;
}
