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 get_ans(int idx1, int idx2, int sub) {
  if (sub >= (int)s3.size()) return -INT_MAX;
  if (idx1 == (int)s1.size() || idx2 == (int)s2.size()) return 0;
  int &ret = dp[idx1][idx2][sub];
  if (ret != -1) return ret;
  ret = max(get_ans(idx1 + 1, idx2, sub), get_ans(idx1, idx2 + 1, sub));
  if (s1[idx1] == s2[idx2]) {
    if (s1[idx1] == s3[sub])
      ret = max(ret, get_ans(idx1 + 1, idx2 + 1, sub + 1) + 1);
    else {
      sub = m[{sub, s1[idx1]}];
      ret = max(ret, get_ans(idx1 + 1, idx2 + 1, sub) + 1);
    }
  }
  return ret;
}
void build(int idx1, int idx2, int sub) {
  if (idx1 == (int)s1.size() || idx2 == (int)s2.size()) return;
  int x1 = get_ans(idx1 + 1, idx2, sub), x2 = get_ans(idx1, idx2 + 1, sub);
  int x3 = -INT_MAX, mx;
  if (s1[idx1] == s2[idx2]) {
    if (s1[idx1] == s3[sub])
      x3 = get_ans(idx1 + 1, idx2 + 1, sub + 1);
    else
      x3 = get_ans(idx1 + 1, idx2 + 1, m[{sub, s1[idx1]}]);
  }
  mx = max(x1, max(x2, x3));
  if (mx == x3) {
    printf("%c", s1[idx1]);
    if (s1[idx1] == s3[sub])
      build(idx1 + 1, idx2 + 1, sub + 1);
    else
      build(idx1 + 1, idx2 + 1, m[{sub, s1[idx1]}]);
  } else if (mx == x1)
    build(idx1 + 1, idx2, sub);
  else
    build(idx1, idx2 + 1, 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 = get_ans(0, 0, 0);
  build(0, 0, 0);
  if (t == 0) puts("0");
  return 0;
}