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;
string s1, s2, v;
vector<vector<vector<pair<int, pair<int, int> > > > > dp;
int lsub(string ss) {
  int res = 0;
  for (int i = 1; i <= min(v.size(), ss.size()); i++) {
    if (v.substr(0, i) == ss.substr(ss.size() - i, i)) {
      res = i;
    }
  }
  return res;
}
pair<int, pair<int, int> > sol(int i, int j, int o) {
  if (o == v.size()) return make_pair(0, make_pair(0, 0));
  if (i >= s1.size() || j >= s2.size()) return make_pair(0, make_pair(0, 0));
  if (dp[i][j][o].first != -1) return dp[i][j][o];
  if (s1[i] == s2[j]) {
    if (s1[i] == v[o]) {
      if (o < v.size() - 1 &&
          1 + sol(i + 1, j + 1, o + 1).first >= sol(i + 1, j + 1, o).first) {
        dp[i][j][o] =
            make_pair(1 + sol(i + 1, j + 1, o + 1).first, make_pair(1, o + 1));
      } else {
        dp[i][j][o] = make_pair(sol(i + 1, j + 1, o).first, make_pair(2, o));
      }
    } else {
      int r = lsub(v.substr(0, o) + s1[i]);
      dp[i][j][o] = make_pair(1 + sol(i + 1, j + 1, r).first, make_pair(3, r));
    }
  } else {
    if (sol(i, j + 1, o).first >= sol(i + 1, j, o).first) {
      dp[i][j][o] = make_pair(sol(i, j + 1, o).first, make_pair(4, o));
    } else {
      dp[i][j][o] = make_pair(sol(i + 1, j, o).first, make_pair(5, o));
    }
  }
  return dp[i][j][o];
}
int main() {
  cin >> s1 >> s2 >> v;
  string res = "";
  dp = vector<vector<vector<pair<int, pair<int, int> > > > >(
      s1.size(),
      vector<vector<pair<int, pair<int, int> > > >(
          s2.size(), vector<pair<int, pair<int, int> > >(
                         v.size(), make_pair(-1, make_pair(-1, -1)))));
  sol(0, 0, 0);
  int a = 0, b = 0, c = 0;
  while (true) {
    if (a >= s1.size() || b >= s2.size() || c >= v.size()) break;
    if (dp[a][b][c].second.first == 1) {
      res += s1[a];
      a++;
      b++;
      c++;
    } else if (dp[a][b][c].second.first == 2) {
      a++;
      b++;
    } else if (dp[a][b][c].second.first == 3) {
      res += s1[a];
      c = dp[a][b][c].second.second;
      a++;
      b++;
    } else if (dp[a][b][c].second.first == 4) {
      b++;
    } else if (dp[a][b][c].second.first == 5) {
      a++;
    }
  }
  if (res.size() == 0)
    cout << 0 << endl;
  else
    cout << res << endl;
}