#include <bits/stdc++.h>
using namespace std;
const int N = 100006 * 4;
vector<int> v[N];
struct node {
  int ch[N][26];
  int fail[N];
  int tot;
  int cnt[N];
  void init() {
    memset(ch[0], 0, sizeof ch[0]);
    tot = 0;
    fail[0] = cnt[0] = 0;
    tot++;
    v[0].clear();
  }
  void ins(char *str, int val) {
    int L = strlen(str);
    int rt = 0;
    for (int i = 0; i < L; i++) {
      int c = str[i] - 'A';
      if (!ch[rt][c]) {
        memset(ch[tot], 0, sizeof ch[tot]);
        ch[rt][c] = tot;
        fail[tot] = 0;
        cnt[tot] = 0;
        tot++;
        v[tot - 1].clear();
      }
      rt = ch[rt][c];
    }
    cnt[rt] = val;
  }
  void build() {
    queue<int> que;
    for (int i = 0; i < 26; i++)
      if (ch[0][i]) que.push(ch[0][i]), fail[ch[0][i]] = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = 0; i < 26; i++) {
        if (!ch[u][i]) {
          ch[u][i] = ch[fail[u]][i];
        } else {
          fail[ch[u][i]] = ch[fail[u]][i];
          que.push(ch[u][i]);
        }
      }
    }
  }
} ac;
char a[105];
char b[106];
char t[106];
string dp[105][106][106];
string maxx(string a, string b) {
  if (a.size() > b.size())
    return a;
  else
    return b;
}
struct LZ {
  int x, y, sta;
} lz[105][105][105];
int main() {
  int n;
  cin >> a + 1 >> b + 1 >> t + 1;
  int cc = strlen(t + 1);
  ac.init();
  ac.ins(t + 1, 1);
  int aa = strlen(a + 1);
  int bb = strlen(b + 1);
  ac.build();
  for (int i = 1; i <= aa; i++) {
    for (int j = 1; j <= bb; j++) {
      for (int sta = 0; sta < cc; sta++) {
        dp[i][j][sta] =
            maxx(dp[i][j][sta], maxx(dp[i - 1][j][sta], dp[i][j - 1][sta]));
        if (a[i] == b[j]) {
          dp[i][j][ac.ch[sta][a[i] - 'A']] = maxx(
              dp[i - 1][j - 1][sta] + a[i], dp[i][j][ac.ch[sta][a[i] - 'A']]);
        }
      }
    }
  }
  string ans;
  for (int i = 0; i < cc; i++) {
    ans = maxx(ans, dp[aa][bb][i]);
  }
  if (ans == "") {
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
}
