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 N = 100 + 10;
string s1, s2, virus;
struct KnuthMorrisPratt {
  int link[N];
  int skip[N][26];
  void clear() {
    memset(link, 0, sizeof link);
    memset(skip, 0, sizeof skip);
  }
  KnuthMorrisPratt() { clear(); }
  KnuthMorrisPratt(string S) {
    clear();
    for (int i = int(2); i < int(S.size()); i++) {
      link[i] = link[i - 1];
      while (link[i] > 0 && S[link[i] + 1] != S[i]) link[i] = link[link[i]];
      if (S[link[i] + 1] == S[i]) link[i]++;
    }
    for (int c = int(0); c < int(26); c++)
      skip[0][c] = 0, skip[(int)S.size() - 1][c] = -1;
    skip[0][S[1] - 'A'] = 1;
    for (int i = int(1); i < int((int)S.size() - 1); i++) {
      for (int c = int(0); c < int(26); c++)
        if (S[i + 1] - 'A' == c)
          skip[i][c] = i + 1;
        else
          skip[i][c] = skip[link[i]][c];
    }
  }
} kmp;
int dp[N][N][N];
struct Data {
  int x, y, z;
  char c;
} trace[N][N][N];
bool maximize(int &a, int b) {
  if (a > b) return 0;
  a = b;
  return 1;
}
void solve() {
  dp[0][0][0] = 1;
  for (int i = int(0); i < int(s1.size()); i++)
    for (int j = int(0); j < int(s2.size()); j++)
      for (int k = int(0); k < int(virus.size() - 1); k++) {
        if (dp[i][j][k] == 0) continue;
        bool f1 = (i + 1 < s1.size());
        bool f2 = (j + 1 < s2.size());
        if (f1 && f2 && s1[i + 1] == s2[j + 1])
          if (maximize(dp[i + 1][j + 1][kmp.skip[k][s1[i + 1] - 'A']],
                       dp[i][j][k] + 1))
            trace[i + 1][j + 1][kmp.skip[k][s1[i + 1] - 'A']] = {i, j, k,
                                                                 s1[i + 1]};
        if (f1)
          if (maximize(dp[i + 1][j][k], dp[i][j][k]))
            trace[i + 1][j][k] = {i, j, k, '\0'};
        if (f2)
          if (maximize(dp[i][j + 1][k], dp[i][j][k]))
            trace[i][j + 1][k] = {i, j, k, '\0'};
      }
  int bestMatch = 0;
  int x = s1.size() - 1, y = s2.size() - 1;
  for (int i = int(1); i < int(virus.size() - 1); i++)
    if (dp[x][y][i] > dp[x][y][bestMatch]) bestMatch = i;
  string result = "";
  bool flag = 1;
  while (x > 0 && y > 0) {
    Data pre = trace[x][y][bestMatch];
    if (pre.c != '\0') result = pre.c + result;
    x = pre.x, y = pre.y, bestMatch = pre.z;
  }
  if (result.empty()) result = "0";
  cout << result << '\n';
}
int main() {
  cin >> s1 >> s2 >> virus;
  s1 = " " + s1;
  s2 = " " + s2;
  virus = " " + virus;
  kmp = KnuthMorrisPratt(virus);
  solve();
}