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 long long inf = 1e15;
const long long N = 105;
string S1, S2, S3;
long long n1, n2, n3, Point[26], Kmp[N], Next1[N][26], Next2[N][26],
    Dp[N][N][N];
pair<pair<long long, long long>, pair<long long, long long> > Pre[N][N][N];
vector<long long> Out;
void Input() {
  cin >> S1 >> S2 >> S3;
  n1 = S1.size(), n2 = S2.size(), n3 = S3.size();
  S1 = ' ' + S1, S2 = ' ' + S2, S3 = ' ' + S3;
}
void Build_Kmp() {
  long long Cur = 0;
  Kmp[1] = 0;
  for (long long i = 1; i < n3; ++i) {
    while (Cur && S3[i + 1] != S3[Cur + 1]) Cur = Kmp[Cur];
    if (S3[i + 1] == S3[Cur + 1]) Kmp[i + 1] = ++Cur;
  }
}
void Prepare() {
  for (long long j = 0; j <= 25; ++j) Point[j] = n1 + 1;
  for (long long i = n1; i >= 0; --i) {
    for (long long j = 0; j <= 25; ++j) Next1[i][j] = Point[j];
    if (i) Point[S1[i] - 'A'] = i;
  }
  for (long long j = 0; j <= 25; ++j) Point[j] = n2 + 1;
  for (long long i = n2; i >= 0; --i) {
    for (long long j = 0; j <= 25; ++j) Next2[i][j] = Point[j];
    if (i) Point[S2[i] - 'A'] = i;
  }
}
void Solve() {
  Build_Kmp();
  Prepare();
  memset(Dp, -1, sizeof Dp);
  Dp[0][0][0] = 0;
  long long Res = 0;
  pair<pair<long long, long long>, long long> Pos = {{0, 0}, 0};
  for (long long i = 0; i <= n1; ++i) {
    for (long long j = 0; j <= n2; ++j) {
      for (long long Cur = 0; Cur < n3; ++Cur) {
        if (Dp[i][j][Cur] == -1) continue;
        if (Dp[i][j][Cur] > Res) {
          Res = Dp[i][j][Cur];
          Pos = {{i, j}, Cur};
        }
        for (long long Dig = 0; Dig <= 25; ++Dig) {
          long long newCur = Cur;
          while (newCur && S3[newCur + 1] - 'A' != Dig) newCur = Kmp[newCur];
          if (S3[newCur + 1] - 'A' == Dig) newCur++;
          if (newCur == n3) continue;
          long long newi = Next1[i][Dig], newj = Next2[j][Dig];
          if (Dp[newi][newj][newCur] < Dp[i][j][Cur] + 1) {
            Dp[newi][newj][newCur] = Dp[i][j][Cur] + 1;
            Pre[newi][newj][newCur] = {{Dig, Cur}, {i, j}};
          }
        }
      }
    }
  }
  if (Res == 0) {
    cout << 0;
    return;
  }
  while (Pos.first.first && Pos.first.second) {
    long long i = Pos.first.first, j = Pos.first.second, Cur = Pos.second;
    Out.push_back(Pre[i][j][Cur].first.first);
    Pos.second = Pre[i][j][Cur].first.second;
    Pos.first.first = Pre[i][j][Cur].second.first;
    Pos.first.second = Pre[i][j][Cur].second.second;
  }
  reverse((Out).begin(), (Out).end());
  for (auto i : Out) cout << char(i + 'A');
}
int main() {
  if (fopen("trash.inp", "r"))
    freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Input();
  Solve();
}