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;
int dr[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
const int MAX = 1e2 + 7;
const int MOD = 1e9 + 7;
string s1, s2, virus;
int mem[MAX][MAX][MAX];
vector<int> Z;
int Z_table[26][MAX];
void Z_Algrothim() {
  for (int len = 0; len < virus.length(); ++len) {
    for (int k = 0; k < 26; ++k) {
      string temp = virus + '@' + virus.substr(0, len) + char('A' + k);
      int n = temp.length();
      Z.resize(n);
      Z.assign(n, 0);
      Z[0] = n;
      for (int i = 1, L = 0, R = 0; i < n; i++) {
        if (i <= R) Z[i] = min(Z[i - L], R - i + 1);
        while (i + Z[i] < n && temp[Z[i]] == temp[i + Z[i]]) Z[i]++;
        if (i + Z[i] - 1 > R) L = i, R = i + Z[i] - 1;
      }
      for (int i = virus.length() + 1; i < temp.length(); ++i) {
        if (Z[i] == temp.length() - i) {
          Z_table[k][len] = max(Z[i], Z_table[k][len]);
          break;
        }
      }
    }
  }
}
int LCS(int i, int j, int k) {
  if (i == s1.length() || j == s2.length()) return mem[i][j][k] = 0;
  if (mem[i][j][k] != -1) return mem[i][j][k];
  mem[i][j][k] = 0;
  if (s1[i] == s2[j]) {
    if (virus[k] == s1[i]) {
      if (k + 1 == virus.length())
        ;
      else
        mem[i][j][k] = max(LCS(i + 1, j + 1, k + 1) + 1, mem[i][j][k]);
    } else {
      mem[i][j][k] =
          max(LCS(i + 1, j + 1, Z_table[s1[i] - 'A'][k]) + 1, mem[i][j][k]);
    }
    return mem[i][j][k] = max(LCS(i + 1, j + 1, k), mem[i][j][k]);
  }
  return mem[i][j][k] = max(LCS(i + 1, j, k), LCS(i, j + 1, k));
}
string print_LCS() {
  memset(mem, -1, sizeof mem);
  cin >> s1 >> s2 >> virus;
  Z_Algrothim();
  LCS(0, 0, 0);
  int i = 0, j = 0, k = 0;
  string ans;
  while (i < s1.length() && j < s2.length()) {
    if (s1[i] == s2[j]) {
      if (!(mem[i + 1][j + 1][k] > mem[i + 1][j + 1][k + 1] &&
            mem[i + 1][j + 1][k] >
                mem[i + 1][j + 1][Z_table[s1[i] - 'A'][k]])) {
        if (virus[k] == s1[i]) {
          if (k + 1 != virus.length()) {
            ans += s1[i];
            i++, j++, k++;
          } else
            break;
        } else {
          ans += s1[i];
          i++, j++;
          k = Z_table[s1[i - 1] - 'A'][k];
        }
      } else
        i++, j++;
    } else if (mem[i + 1][j][k] > mem[i][j + 1][k])
      i++;
    else
      j++;
  }
  if (ans.length() != 0) return ans;
  return "0";
}
int main() { cout << print_LCS() << "\n"; }