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 = 105;
int Next[N];
int dp[N][N][N];
struct node {
  int i, j, k;
  node() {}
  node(int a, int b, int c) : i(a), j(b), k(c) {}
};
node flag[N][N][N];
char s1[N], s2[N], virus[N], re[N];
void Next1() {
  int len, i = 1, j = 0;
  len = strlen(virus + 1);
  while (i < len) {
    if (j == 0 || virus[i] == virus[j]) {
      i++;
      j++;
      Next[i] = j;
    } else
      j = Next[j];
  }
}
int main() {
  scanf("%s%s%s", s1 + 1, s2 + 1, virus + 1);
  Next1();
  int len1 = strlen(s1 + 1), len2 = strlen(s2 + 1);
  int len_virus = strlen(virus + 1), id, tmp;
  s1[len1 + 1] = '1';
  s2[len2 + 1] = '2';
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 0; i <= len1; i++)
    for (int j = 0; j <= len2; j++)
      for (int k = 0; k < len_virus; k++)
        if (dp[i][j][k] != -1) {
          if (s1[i + 1] == s2[j + 1]) {
            tmp = k + 1;
            while (tmp) {
              if (virus[tmp] == s1[i + 1]) break;
              tmp = Next[tmp];
            }
            if (dp[i + 1][j + 1][tmp] <= dp[i][j][k] + 1) {
              dp[i + 1][j + 1][tmp] = dp[i][j][k] + 1;
              flag[i + 1][j + 1][tmp] = node(i, j, k);
            }
          }
          if (dp[i + 1][j][k] <= dp[i][j][k]) {
            dp[i + 1][j][k] = dp[i][j][k];
            flag[i + 1][j][k] = node(i, j, k);
          }
          if (dp[i][j + 1][k] <= dp[i][j][k]) {
            dp[i][j + 1][k] = dp[i][j][k];
            flag[i][j + 1][k] = node(i, j, k);
          }
        }
  id = 0;
  for (int i = 1; i < len_virus; i++)
    if (dp[len1][len2][i] > dp[len1][len2][id]) id = i;
  int x, y, ans = 102;
  re[ans] = 0;
  if (dp[len1][len2][id] <= 0) {
    printf("0\n");
    return 0;
  }
  while (dp[len1][len2][id]) {
    x = flag[len1][len2][id].i;
    y = flag[len1][len2][id].j;
    if (len1 - x + len2 - y == 2) {
      re[--ans] = s1[len1];
      id = flag[len1][len2][id].k;
      len1 = x, len2 = y;
    } else {
      id = flag[len1][len2][id].k;
      len1 = x, len2 = y;
    }
  }
  printf("%s\n", re + ans);
  return 0;
}