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<vector<int> > > ans;
string s1, s2, virus;
vector<vector<int> > goTo;
vector<vector<vector<pair<pair<int, int>, int> > > > go;
bool check(string &s, int p1, int p2) {
  while (p2 >= 0) {
    if (s[p1] != s[p2]) {
      return false;
    }
    --p1;
    --p2;
  }
  return true;
}
void input_data(void) {
  cin >> skipws >> s1;
  cin >> skipws >> s2;
  cin >> skipws >> virus;
  ans.clear();
  goTo.assign(virus.size() + 1, vector<int>(26, 0));
  for (int i = 0; i <= virus.size(); ++i) {
    for (int c = 0; c < 26; ++c) {
      char cur = c + 'A';
      int j = i;
      while (j >= 0) {
        if ((j != virus.size() && cur == virus[j]) &&
            check(virus, i - 1, j - 1)) {
          break;
        }
        --j;
      }
      goTo[i][c] = j + 1;
    }
  }
}
string proc(int i, int j, int k) {
  if (i == 0 || j == 0) {
    return string();
  }
  pair<pair<int, int>, int> toGo = go[i][j][k];
  string res = proc(toGo.first.first, toGo.first.second, toGo.second);
  if (ans[i][j][k] ==
      ans[toGo.first.first][toGo.first.second][toGo.second] + 1) {
    res += s1[i - 1];
  }
  return res;
}
void calc(void) {
  int l1 = s1.size();
  int l2 = s2.size();
  int lv = virus.size();
  ans.assign(l1 + 1, vector<vector<int> >(l2 + 1, vector<int>(lv + 1, 0)));
  go.assign(l1 + 1, vector<vector<pair<pair<int, int>, int> > >(
                        l2 + 1, vector<pair<pair<int, int>, int> >(
                                    lv + 1, make_pair(make_pair(-1, -1), -1))));
  for (int i = 0; i <= l1; ++i) {
    for (int j = 0; j <= l2; ++j) {
      for (int k = 0; k < lv; ++k) {
        if (i != l1) {
          ans[i + 1][j][k] = max(ans[i + 1][j][k], ans[i][j][k]);
          if (ans[i + 1][j][k] == ans[i][j][k]) {
            go[i + 1][j][k] = make_pair(make_pair(i, j), k);
          }
        }
        if (j != l2) {
          ans[i][j + 1][k] = max(ans[i][j + 1][k], ans[i][j][k]);
          if (ans[i][j + 1][k] == ans[i][j][k]) {
            go[i][j + 1][k] = make_pair(make_pair(i, j), k);
          }
        }
        if (i != l1 && j != l2 && s1[i] == s2[j]) {
          int nxt = goTo[k][s1[i] - 'A'];
          ans[i + 1][j + 1][nxt] =
              max(ans[i + 1][j + 1][nxt], ans[i][j][k] + 1);
          if (ans[i + 1][j + 1][nxt] == ans[i][j][k] + 1) {
            go[i + 1][j + 1][nxt] = make_pair(make_pair(i, j), k);
          }
        }
      }
    }
  }
  int res = 0;
  int opt = -1;
  for (int i = 0; i < lv; ++i) {
    if (ans[l1][l2][i] > res) {
      res = ans[l1][l2][i];
      opt = i;
    }
  }
  if (opt == -1) {
    cout << "0"
         << "\n";
  } else {
    string res = proc(l1, l2, opt);
    cout << res << "\n";
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  input_data();
  calc();
  return 0;
}