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 MIN = -1e4;
int n, m, k, d[101][101][101][2], lps[101];
string s1, s2, virus;
int dp(int i, int j, int KMP, int state) {
  if (KMP > k) return MIN;
  if (i > n || j > m) return 0;
  if (d[i][j][KMP][state] != -1) return d[i][j][KMP][state];
  int f = dp(i + 1, j, KMP, state), s = dp(i, j + 1, KMP, state);
  if (s1[i] == s2[j]) {
    int f1 = MIN;
    if (state == 1) {
      if (s1[i] == virus[KMP])
        f1 = dp(i + 1, j + 1, KMP + 1, 0) + 1;
      else if (KMP == 1)
        f1 = dp(i + 1, j + 1, 1, 0) + 1;
      else
        f1 = dp(i, j, lps[KMP - 1] + 1, 1);
      return d[i][j][KMP][state] = f1;
    }
    if (s1[i] == virus[KMP])
      f1 = dp(i + 1, j + 1, KMP + 1, 0) + 1;
    else if (KMP == 1)
      f1 = dp(i + 1, j + 1, 1, 0) + 1;
    else
      f1 = dp(i, j, lps[KMP - 1] + 1, 1);
    return d[i][j][KMP][state] = max(f1, max(s, f));
  }
  return d[i][j][KMP][state] = max(f, s);
}
void trace(int i, int j, int KMP, int state) {
  if (i > n || j > m) return;
  int f = dp(i + 1, j, KMP, state), s = dp(i, j + 1, KMP, state);
  if (s1[i] == s2[j]) {
    int f1 = MIN;
    if (state == 1) {
      if (s1[i] == virus[KMP]) {
        cout << s1[i];
        trace(i + 1, j + 1, KMP + 1, 0);
      } else if (KMP == 1) {
        cout << s1[i];
        trace(i + 1, j + 1, 1, 0);
      } else
        trace(i, j, lps[KMP - 1] + 1, 1);
      return;
    }
    if (s1[i] == virus[KMP])
      f1 = dp(i + 1, j + 1, KMP + 1, 0) + 1;
    else if (KMP == 1)
      f1 = dp(i + 1, j + 1, 1, 0) + 1;
    else
      f1 = dp(i, j, lps[KMP - 1] + 1, 1);
    if (dp(i, j, KMP, state) == f1) {
      if (s1[i] == virus[KMP]) {
        cout << s1[i];
        trace(i + 1, j + 1, KMP + 1, 0);
      } else if (KMP == 1) {
        cout << s1[i];
        trace(i + 1, j + 1, 1, 0);
      } else
        trace(i, j, lps[KMP - 1] + 1, 1);
      return;
    }
    if (dp(i, j, KMP, state) == f)
      trace(i + 1, j, KMP, state);
    else
      trace(i, j + 1, KMP, state);
    return;
  }
  if (dp(i, j, KMP, state) == f)
    trace(i + 1, j, KMP, state);
  else
    trace(i, j + 1, KMP, state);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s1 >> s2 >> virus;
  memset(d, -1, sizeof d);
  n = s1.size();
  m = s2.size();
  k = virus.size();
  s1 = " " + s1;
  s2 = " " + s2;
  virus = " " + virus;
  lps[0] = 0;
  int len = 1;
  for (int i = 2; i <= k; i++) {
    if (virus[i] == virus[len])
      lps[i] = len++;
    else if (len == 1)
      lps[len] = 0;
    else {
      len = lps[len - 1] + 1;
      i--;
    }
  }
  int ans = dp(1, 1, 1, 0);
  if (ans <= 0) {
    cout << 0;
    return 0;
  }
  trace(1, 1, 1, 0);
  return 0;
}