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, s3;
vector<int> chars[30];
int dp[109][109][109];
map<pair<int, char>, int> m;
int longestsubsequence(int idx1, int idx2, int sub) {
  if (sub >= (int)s3.size()) return -INT_MAX;
  if (idx1 >= (int)s1.size() || idx2 >= (int)s2.size() + 1) return 0;
  int t = 0;
  if (idx2 >= 0 && dp[idx1][idx2][sub] >= 0) return dp[idx1][idx2][sub];
  auto v = chars[s1[idx1] - 'A'];
  auto idx22 = upper_bound(v.begin(), v.end(), idx2) - v.begin();
  if (idx22 < (int)v.size()) {
    if (s1[idx1] == s3[sub])
      t = longestsubsequence(idx1 + 1, v[idx22], sub + 1) + 1;
    else {
      t = longestsubsequence(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]) + 1;
    }
  }
  t = max(t, longestsubsequence(idx1 + 1, idx2, sub));
  if (idx1 >= 0 && idx2 >= 0) dp[idx1][idx2][sub] = t;
  return t;
}
void build(int idx1, int idx2, int sub) {
  if (idx1 >= (int)s1.size() || idx2 >= (int)s2.size()) return;
  int t = longestsubsequence(idx1 + 1, idx2, sub);
  auto v = chars[s1[idx1] - 'A'];
  auto idx22 = upper_bound(v.begin(), v.end(), idx2) - v.begin();
  int T = -INT_MAX;
  if (idx22 < (int)v.size()) {
    if (s1[idx1] == s3[sub])
      T = longestsubsequence(idx1 + 1, v[idx22], sub + 1) + 1;
    else {
      T = longestsubsequence(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]) + 1;
    }
    if (T >= t) {
      cout << s1[idx1];
      if (s1[idx1] == s3[sub])
        build(idx1 + 1, v[idx22], sub + 1);
      else {
        build(idx1 + 1, v[idx22], m[{sub, s1[idx1]}]);
      }
    }
  }
  if (t > T) build(idx1 + 1, idx2, sub);
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> s1 >> s2 >> s3;
  for (int i = 0; i < (int)s3.size(); ++i) {
    for (char c = 'A'; c <= 'Z'; ++c) {
      for (int k = 0; k <= i; ++k) {
        int idx1 = k - 1, idx2 = i;
        if (c == s3[k]) {
          while (idx1 >= 0 && s3[idx1] == s3[idx2]) idx1--, idx2--;
          if (idx1 == -1) {
            if (m.count({i + 1, c}))
              m[{i + 1, c}] = max(m[{i + 1, c}], k + 1);
            else
              m[{i + 1, c}] = k + 1;
          }
        }
      }
    }
  }
  for (int i = 0; i < (int)s2.size(); ++i) chars[s2[i] - 'A'].push_back(i);
  int t = longestsubsequence(0, -1, 0);
  if (t > 0)
    build(0, -1, 0);
  else
    cout << 0 << endl;
  return 0;
}