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>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
using namespace std;
char s1[MAXN], s2[MAXN], v[MAXN];
int dp[MAXN][MAXN][MAXN], a[MAXN][26], lcp[MAXN];
tuple<int, int, int> par[MAXN][MAXN][MAXN];
void kmp(int n) {
  for (int i = 1; i < n; i++) {
    int k = lcp[i - 1];
    while (k && v[i] != v[k]) {
      k = lcp[k - 1];
    }
    if (v[i] == v[k]) k++;
    lcp[i] = k;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      if (i && j != v[i] - 'A')
        a[i][j] = a[lcp[i - 1]][j];
      else
        a[i][j] = i + (j == v[i] - 'A');
    }
  }
}
int main() {
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXN; k++) {
        par[i][j][k] = make_tuple(-1, -1, -1);
        dp[i][j][k] = 0;
      }
  scanf("%s %s %s", s1, s2, v);
  int n = strlen(s1), m = strlen(s2), l = strlen(v), ans = 0;
  kmp(l);
  tuple<int, int, int> p = make_tuple(-1, -1, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        bool flag = (s1[i] == s2[j]);
        int cur = s1[i] - 'A';
        int next = a[k][cur];
        if (flag && next < l) {
          if (dp[i + 1][j + 1][next] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][next] = dp[i][j][k] + 1;
            par[i + 1][j + 1][next] = make_tuple(i, j, k);
          }
        }
        if (dp[i][j][k] > dp[i + 1][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          par[i + 1][j][k] = par[i][j][k];
        }
        if (dp[i][j][k] > dp[i][j + 1][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          par[i][j + 1][k] = par[i][j][k];
        }
      }
    }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k < l; k++)
        if (ans < dp[i][j][k]) {
          ans = dp[i][j][k];
          p = par[i][j][k];
        }
  string res = "";
  do {
    if (p == make_tuple(-1, -1, -1)) break;
    res += s1[get<0>(p)];
    p = par[get<0>(p)][get<1>(p)][get<2>(p)];
    if (p == make_tuple(-1, -1, -1)) break;
  } while (1);
  reverse(res.begin(), res.end());
  if (res == "")
    printf("0\n");
  else
    cout << res << endl;
  return 0;
}