Problem: In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.

You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

Input

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. 

If there is no valid common subsequence, output 0.

Examples

Input

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ


Output

ORZ


Input

AA
A
A


Output

0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> kmp(string s) {
  long long n = s.size();
  vector<long long> kmp(n);
  vector<vector<long long>> nxt(n, vector<long long>(26));
  for (long long i = 1; i < n; i++) {
    long long j = kmp[i - 1];
    while (j and s[j] != s[i]) j = kmp[j - 1];
    if (s[j] == s[i]) j++;
    kmp[i] = j;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 26; j++) {
      long long k = i;
      while (k > 0 and s[k] != 'A' + j) k = kmp[k - 1];
      if (s[k] == 'A' + j) k++;
      nxt[i][j] = k;
    }
  }
  return nxt;
}
string s, t, v;
long long dp[102][102][102];
pair<pair<long long, long long>, long long> ptr[101][101][101];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> s >> t >> v;
  auto nxt = kmp(v);
  for (long long i = 0; i < 100; i++)
    for (long long j = 0; j < 100; j++)
      for (long long k = 0; k < 100; k++) dp[i][j][k] = -1000000000000000;
  dp[0][0][0] = 0;
  for (long long i = 0; i < (long long)s.size(); i++) {
    for (long long j = 0; j < (long long)t.size(); j++) {
      for (long long k = 0; k < (long long)v.size(); k++) {
        if (s[i] == t[j]) {
          if (dp[i + 1][j + 1][nxt[k][s[i] - 'A']] < dp[i][j][k] + 1) {
            ptr[i + 1][j + 1][nxt[k][s[i] - 'A']] = {{i, j}, k};
          }
          dp[i + 1][j + 1][nxt[k][s[i] - 'A']] =
              max(dp[i + 1][j + 1][nxt[k][s[i] - 'A']], dp[i][j][k] + 1);
        }
        if (dp[i + 1][j][k] < dp[i][j][k]) {
          ptr[i + 1][j][k] = {{i, j}, k};
        }
        if (dp[i][j + 1][k] < dp[i][j][k]) {
          ptr[i][j + 1][k] = {{i, j}, k};
        }
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
        dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
      }
    }
  }
  long long maxlen = 0, x, y, z;
  for (long long i = 1; i <= (long long)s.size(); i++)
    for (long long j = 1; j <= (long long)t.size(); j++)
      for (long long k = 0; k < (long long)v.size(); k++) {
        if (maxlen < dp[i][j][k]) {
          maxlen = dp[i][j][k];
          x = i, y = j, z = k;
        }
      }
  if (maxlen == 0) return cout << "0\n", 0;
  string ans = "";
  while (x and y) {
    if (ptr[x][y][z].first.first == x - 1 and
        ptr[x][y][z].first.second == y - 1) {
      z = ptr[x][y][z].second;
      x = x - 1, y = y - 1;
      assert(s[x] == t[y]);
      ans += s[x];
    } else {
      long long a = ptr[x][y][z].first.first, b = ptr[x][y][z].first.second,
                c = ptr[x][y][z].second;
      x = a, y = b, z = c;
    }
  }
  reverse(ans.begin(), ans.end());
  assert(ans.size() == maxlen);
  cout << ans << '\n';
}