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 = 101;
string s, t, v;
int x, y, z, dp[N][N][N], pi[N];
vector<int> par[N][N][N];
void preset() {
  memset(dp, -1, sizeof(dp));
  cin >> s >> t >> v;
  x = s.length(), y = t.length(), z = v.length();
  for (int i = 1; i < z; ++i) {
    int j = pi[i - 1];
    while (j > 0 && v[i] != v[j]) j = pi[j - 1];
    pi[i] = j + (v[i] == v[j]);
  }
}
void bfs() {
  queue<vector<int>> q;
  q.push(vector<int>({0, 0, 0}));
  dp[0][0][0] = 0;
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    int i = now[0], j = now[1], k = now[2];
    if (i < x && j < y && k < z) {
      if (s[i] == t[j]) {
        if (s[i] == v[k]) {
          if (dp[i + 1][j + 1][k + 1] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][k + 1] = dp[i][j][k] + 1;
            par[i + 1][j + 1][k + 1] = {i, j, k};
            q.push({i + 1, j + 1, k + 1});
          }
        } else {
          int back = (k > 0 ? pi[k - 1] : 0);
          while (back > 0 && v[back] != s[i]) back = pi[back - 1];
          back += (v[back] == s[i]);
          if (dp[i + 1][j + 1][back] < dp[i][j][k] + 1) {
            dp[i + 1][j + 1][back] = dp[i][j][k] + 1;
            par[i + 1][j + 1][back] = {i, j, k};
            q.push({i + 1, j + 1, back});
          }
        }
      }
    }
    if (i + 1 <= x && dp[i + 1][j][k] < dp[i][j][k]) {
      dp[i + 1][j][k] = dp[i][j][k], par[i + 1][j][k] = {i, j, k};
      q.push({i + 1, j, k});
    }
    if (j + 1 <= y && dp[i][j + 1][k] < dp[i][j][k]) {
      dp[i][j + 1][k] = dp[i][j][k], par[i][j + 1][k] = {i, j, k};
      q.push({i, j + 1, k});
    }
  }
}
signed main() {
  preset();
  bfs();
  string ans;
  int i = x, j = y, k = max_element(dp[x][y], dp[x][y] + z) - dp[x][y];
  if (dp[i][j][k] <= 0) cout << 0, exit(0);
  while (!par[i][j][k].empty()) {
    if (par[i][j][k][0] + 1 == i && par[i][j][k][1] + 1 == j) ans += s[i - 1];
    tie(i, j, k) = {par[i][j][k][0], par[i][j][k][1], par[i][j][k][2]};
  }
  reverse(begin(ans), end(ans));
  cout << ans;
}