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 maxn = 110;
char a[maxn], b[maxn], c[maxn];
int dp[maxn][maxn][maxn];
int Next[maxn][30], f[maxn];
const int maxnode = 110;
const int sigma_size = 26;
struct AC {
  int ch[maxnode][sigma_size];
  int f[maxnode];
  int sz;
  void init() {
    sz = 1;
    memset(ch[0], 0, sizeof(ch[0]));
  }
  int idx(char ch) { return ch - 'A'; }
  void insert(char *s) {
    int u = 0;
    for (int i = 0; s[i]; i++) {
      int c = idx(s[i]);
      if (ch[u][c] == 0) {
        memset(ch[sz], 0, sizeof(ch[sz]));
        ch[u][c] = sz++;
      }
      u = ch[u][c];
    }
  }
  void getFail() {
    queue<int> q;
    f[0] = 0;
    for (int c = 0; c < sigma_size; c++) {
      int u = ch[0][c];
      if (u) {
        f[u] = 0;
        q.push(u);
      }
    }
    while (!q.empty()) {
      int r = q.front();
      q.pop();
      for (int c = 0; c < sigma_size; c++) {
        int u = ch[r][c];
        if (!u) {
          ch[r][c] = ch[f[r]][c];
          continue;
        }
        q.push(u);
        int v = f[r];
        while (v && !ch[v][c]) v = f[v];
        f[u] = ch[v][c];
      }
    }
  }
} ac;
pair<int, int> pa[maxn][maxn][maxn];
int fk[maxn][maxn][maxn];
int main() {
  scanf("%s%s%s", a, b, c);
  int lena = strlen(a);
  int lenb = strlen(b);
  int lenc = strlen(c);
  ac.init();
  ac.insert(c);
  ac.getFail();
  memset(dp, 0, sizeof dp);
  memset(pa, -1, sizeof pa);
  for (int i = 0; i < lena; i++)
    for (int j = 0; j < lenb; j++)
      for (int k = 0; k < lenc; k++) {
        if (a[i] == b[j]) {
          int c = a[i] - 'A';
          if (dp[i + 1][j + 1][ac.ch[k][c]] < dp[i][j][k] + 1) {
            pa[i + 1][j + 1][ac.ch[k][c]] = pair<int, int>(i, j);
            fk[i + 1][j + 1][ac.ch[k][c]] = k;
            dp[i + 1][j + 1][ac.ch[k][c]] = dp[i][j][k] + 1;
          }
        }
        if (dp[i + 1][j + 1][k] < max(dp[i][j + 1][k], dp[i + 1][j][k])) {
          dp[i + 1][j + 1][k] = max(dp[i][j + 1][k], dp[i + 1][j][k]);
          if (dp[i][j + 1][k] > dp[i + 1][j][k]) {
            pa[i + 1][j + 1][k] = pair<int, int>(i, j + 1);
          } else
            pa[i + 1][j + 1][k] = pair<int, int>(i + 1, j);
        }
      }
  int ans = 0;
  int k;
  for (int i = 0; i < lenc; i++) {
    if (dp[lena][lenb][i] > ans) {
      ans = dp[lena][lenb][i];
      k = i;
    }
  }
  if (!ans) {
    printf("%d\n", ans);
  } else {
    int x = lena, y = lenb;
    string str = "";
    while (x != -1 && y != -1) {
      pair<int, int> last = pa[x][y][k];
      int nx = last.first;
      int ny = last.second;
      if (nx == -1 || ny == -1) break;
      if (nx == x - 1 && ny == y - 1) {
        str += a[x - 1];
        k = fk[x][y][k];
        x = nx, y = ny;
      } else {
        x = nx, y = ny;
      }
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
  }
  return 0;
}