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 NMAX = 120;
int l1, l2, v, r, f[NMAX][NMAX][NMAX];
int P[NMAX], path[NMAX][NMAX][NMAX];
char S1[NMAX], S2[NMAX], virus[NMAX], result[NMAX];
void init() {
  int i, j = 0;
  memset(f, ~0u, sizeof(f));
  for (i = 0; i <= l1; i += 1) f[i][0][0] = 0;
  for (i = 0; i <= l2; i += 1) f[0][i][0] = 0;
  for (i = 2; i <= v; i += 1) {
    while (j && virus[j + 1] != virus[i]) j = P[j];
    if (virus[j + 1] == virus[i]) j += 1;
    P[i] = j;
  }
}
void rebuildAnswer(int i, int j, int k) {
  if (!i || !j) return;
  if (path[i][j][k] == -1)
    rebuildAnswer(i - 1, j, k);
  else if (path[i][j][k] == -2)
    rebuildAnswer(i, j - 1, k);
  else {
    rebuildAnswer(i - 1, j - 1, path[i][j][k]);
    result[r++] = S1[i];
  }
}
int main() {
  int i, j, k, p, q, answer;
  scanf("%s %s %s", S1 + 1, S2 + 1, virus + 1);
  l1 = strlen(S1 + 1);
  l2 = strlen(S2 + 1);
  v = strlen(virus + 1);
  init();
  for (i = 1; i <= l1; i += 1) {
    for (j = 1; j <= l2; j += 1) {
      for (k = 0; k < v; k += 1) {
        if (f[i - 1][j][k] >= 0 && f[i - 1][j][k] > f[i][j][k]) {
          f[i][j][k] = f[i - 1][j][k];
          path[i][j][k] = -1;
        }
        if (f[i][j - 1][k] >= 0 && f[i][j - 1][k] > f[i][j][k]) {
          f[i][j][k] = f[i][j - 1][k];
          path[i][j][k] = -2;
        }
        if (S1[i] == S2[j]) {
          for (p = v - 1; p >= 0; p -= 1) {
            if (f[i - 1][j - 1][p] < 0) continue;
            q = p;
            while (q && S1[i] != virus[q + 1]) q = P[q];
            if (S1[i] == virus[q + 1]) {
              if (q + 1 == k && f[i - 1][j - 1][p] + 1 > f[i][j][k]) {
                f[i][j][k] = f[i - 1][j - 1][p] + 1;
                path[i][j][k] = p;
              }
            } else if (q == k && f[i - 1][j - 1][p] + 1 > f[i][j][k]) {
              f[i][j][k] = f[i - 1][j - 1][p] + 1;
              path[i][j][k] = p;
            }
          }
        }
      }
    }
  }
  for (k = 0, answer = 0; k < v; k += 1) {
    if (f[l1][l2][k] > answer) {
      answer = f[l1][l2][k];
      memset(result, 0, sizeof(result));
      r = 0;
      rebuildAnswer(l1, l2, k);
    }
  }
  if (!answer)
    printf("0\n");
  else
    printf("%s\n", result);
  exit(0);
}