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;
const int N = 102;
int d[N][N][N];
pair<int, pair<int, int> > sol[N][N][N];
char solChar[N][N][N];
int pre[N];
string s1, s2, virus;
void prefix(string s) {
  pre[1] = 0;
  for (int i = 2; i < s.size(); ++i) {
    int k = pre[i - 1];
    while (s[k + 1] != s[i] && k) {
      k = pre[k];
    }
    if (s[k + 1] == s[i]) {
      pre[i] = k + 1;
    }
  }
}
string change(string s) {
  string sol;
  sol.push_back(' ');
  for (int i = 0; i < s.size(); ++i) {
    sol.push_back(s[i]);
  }
  return sol;
}
int main() {
  cin >> s1 >> s2 >> virus;
  s1 = change(s1);
  s2 = change(s2);
  virus = change(virus);
  prefix(virus);
  int n = s1.size() - 1;
  int m = s2.size() - 1;
  int t = virus.size() - 1;
  s1.push_back('0');
  s2.push_back('1');
  d[0][0][0] = 1;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int k = 0; k <= t; ++k) {
        if (s1[i + 1] == s2[j + 1]) {
          int p = k;
          while (p && virus[p + 1] != s1[i + 1]) {
            p = pre[p];
          }
          int match = p;
          if (virus[p + 1] == s1[i + 1]) {
            ++match;
          }
          if (match < t) {
            if (d[i + 1][j + 1][match] < d[i][j][k] + 1) {
              solChar[i + 1][j + 1][match] = s1[i + 1];
              d[i + 1][j + 1][match] = d[i][j][k] + 1;
              sol[i + 1][j + 1][match] = make_pair(i, make_pair(j, k));
            }
          }
          if (d[i + 1][j + 1][k] < d[i][j][k]) {
            solChar[i + 1][j + 1][k] = 0;
            d[i + 1][j + 1][k] = d[i][j][k];
            sol[i + 1][j + 1][k] = make_pair(i, make_pair(j, k));
          }
        } else {
          if (d[i + 1][j][k] < d[i][j][k]) {
            solChar[i + 1][j][k] = 0;
            d[i + 1][j][k] = d[i][j][k];
            sol[i + 1][j][k] = make_pair(i, make_pair(j, k));
          }
          if (d[i][j + 1][k] < d[i][j][k]) {
            solChar[i][j + 1][k] = 0;
            d[i][j + 1][k] = d[i][j][k];
            sol[i][j + 1][k] = make_pair(i, make_pair(j, k));
          }
        }
      }
    }
  }
  string solString;
  int max = 0;
  int k;
  for (int i = 0; i <= t - 1; ++i) {
    if (d[n][m][i] > max) {
      max = d[n][m][i];
      k = i;
    }
  }
  int i = n;
  int j = m;
  while (i && j && d[i][j][k]) {
    if (solChar[i][j][k] > 0) {
      solString.push_back(solChar[i][j][k]);
    }
    int ii = sol[i][j][k].first;
    int jj = sol[i][j][k].second.first;
    int kk = sol[i][j][k].second.second;
    i = ii;
    j = jj;
    k = kk;
  }
  if (solString.size()) {
    for (int i = solString.size() - 1; i >= 0; --i) {
      cout << solString[i];
    }
  } else {
    cout << 0 << '\n';
  }
  cout << '\n';
  return 0;
}