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>
char s1[105];
char s2[105];
char virus[105];
int fail[105];
int dp[105][105][105];
int seq[105][105][105][3];
int print[105][105][105];
int n, m, p;
int solve(int pos1, int pos2, int pos3) {
  if (pos3 >= p) {
    return -0x3f3f3f3f;
  }
  if (pos1 >= n || pos2 >= m) {
    return 0;
  }
  if (seq[pos1][pos2][pos3][0] != -1) {
    return dp[pos1][pos2][pos3];
  }
  int aux, aux2, aux3;
  int way1, way2, way3;
  aux = aux2 = aux3 = -0x3f3f3f3f;
  way1 = way2 = way3 = 0;
  if (s1[pos1] == s2[pos2]) {
    if (s1[pos1] == virus[pos3]) {
      print[pos1][pos2][pos3] = 1;
      aux = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
      way1 = pos1 + 1;
      way2 = pos2 + 1;
      way3 = pos3 + 1;
    } else {
      way1 = pos1;
      way2 = pos2;
      if (pos3 != 0) {
        if (virus[fail[pos3 - 1]] == s1[pos1]) {
          aux = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1] + 1);
          print[pos1][pos2][pos3] = 1;
          way1++;
          way2++;
          way3 = fail[pos3 - 1] + 1;
        } else {
          aux = solve(pos1, pos2, fail[pos3 - 1]);
          way3 = fail[pos3 - 1];
        }
      } else {
        aux = 1 + solve(pos1 + 1, pos2 + 1, 0);
        print[pos1][pos2][0] = 1;
        way1++;
        way2++;
        way3 = 0;
      }
    }
  }
  dp[pos1][pos2][pos3] = aux;
  seq[pos1][pos2][pos3][0] = way1;
  seq[pos1][pos2][pos3][1] = way2;
  seq[pos1][pos2][pos3][2] = way3;
  aux2 = solve(pos1 + 1, pos2, pos3);
  aux3 = solve(pos1, pos2 + 1, pos3);
  if (aux2 > dp[pos1][pos2][pos3]) {
    dp[pos1][pos2][pos3] = aux2;
    print[pos1][pos2][pos3] = 0;
    seq[pos1][pos2][pos3][0] = pos1 + 1;
    seq[pos1][pos2][pos3][1] = pos2;
    seq[pos1][pos2][pos3][2] = pos3;
  }
  if (aux3 > dp[pos1][pos2][pos3]) {
    dp[pos1][pos2][pos3] = aux3;
    print[pos1][pos2][pos3] = 0;
    seq[pos1][pos2][pos3][0] = pos1;
    seq[pos1][pos2][pos3][1] = pos2 + 1;
    seq[pos1][pos2][pos3][2] = pos3;
  }
  return dp[pos1][pos2][pos3];
}
void build_fail(void) {
  int len;
  int i;
  fail[0] = 0;
  i = 1;
  len = 0;
  while (i < p) {
    if (virus[i] == virus[len]) {
      len++;
      fail[i++] = len;
    } else {
      if (len != 0) {
        len = fail[len - 1];
      } else {
        fail[i++] = 0;
      }
    }
  }
  return;
}
int main(void) {
  int i, j, k;
  int res;
  int w1, w2, w3;
  scanf(" %s %s %s", s1, s2, virus);
  n = strlen(s1);
  m = strlen(s2);
  p = strlen(virus);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (k = 0; k < p; k++) {
        seq[i][j][k][0] = -1;
        print[i][j][k] = 0;
      }
    }
  }
  build_fail();
  res = solve(0, 0, 0);
  if (res) {
    i = 0;
    j = 0;
    k = 0;
    while (i != n && j != m) {
      if (print[i][j][k]) {
        printf("%c", s1[i]);
      }
      w1 = seq[i][j][k][0];
      w2 = seq[i][j][k][1];
      w3 = seq[i][j][k][2];
      i = w1;
      j = w2;
      k = w3;
    }
    printf("\n");
  } else {
    printf("0\n");
  }
  return 0;
}