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>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 111;
string sa, sb, r;
int dp[maxn][maxn][maxn];
int go[maxn][26];
int pre[maxn];
void start() {
  memset(go, 0, sizeof(go));
  memset(pre, 0, sizeof(pre));
  int now, c;
  for (int i = 1; i < r.length(); i++) {
    c = r[i] - 'A';
    go[i - 1][c] = i;
  }
  int temp;
  for (int now = 1; now < r.length(); now++) {
    c = r[now + 1] - 'A';
    for (int x = 0; x < 26; x++) {
      if (x != c) {
        temp = pre[now];
        go[now][x] = go[temp][x];
      }
    }
    pre[now + 1] = go[pre[now]][r[now + 1] - 'A'];
  }
  memset(dp, 0, sizeof(dp));
  for (int x = 0; x < sa.length(); x++) {
    for (int y = 0; y < sb.length(); y++) {
      for (int k = 0; k + 1 < r.length(); k++) {
        if (x + 1 < sa.length()) {
          dp[x + 1][y][k] = max(dp[x + 1][y][k], dp[x][y][k]);
        }
        if (y + 1 < sb.length()) {
          dp[x][y + 1][k] = max(dp[x][y + 1][k], dp[x][y][k]);
        }
        int to;
        if (x + 1 < sa.length() && y + 1 < sb.length()) {
          if (sa[x + 1] == sb[y + 1]) {
            to = go[k][sa[x + 1] - 'A'];
            if (to + 1 != r.length()) {
              dp[x + 1][y + 1][go[k][sa[x + 1] - 'A']] = max(
                  dp[x + 1][y + 1][go[k][sa[x + 1] - 'A']], dp[x][y][k] + 1);
            }
          }
        }
      }
    }
  }
}
string ans = "";
void gao(int x, int y, int k) {
  if (x == 0 || y == 0) return;
  if (sa[x] == sb[y]) {
    for (int i = 0; i < r.length(); i++) {
      if (go[i][sa[x] - 'A'] == k) {
        if (dp[x - 1][y - 1][i] == dp[x][y][k] - 1) {
          ans += sa[x];
          gao(x - 1, y - 1, i);
          return;
        }
      }
    }
    if (dp[x - 1][y][k] == dp[x][y][k]) {
      gao(x - 1, y, k);
    } else {
      gao(x, y - 1, k);
    }
  } else {
    if (dp[x - 1][y][k] == dp[x][y][k]) {
      gao(x - 1, y, k);
    } else {
      gao(x, y - 1, k);
    }
  }
}
int main() {
  while (cin >> sa >> sb >> r) {
    sa = " " + sa;
    sb = " " + sb;
    r = " " + r;
    start();
    int x, y, kk;
    int temp = 0;
    for (int i = 1; i < sa.length(); i++) {
      for (int j = 1; j < sb.length(); j++) {
        for (int k = 0; k < r.length(); k++) {
          if (dp[i][j][k] > temp) {
            temp = dp[i][j][k];
            x = i;
            y = j;
            kk = k;
          }
        }
      }
    }
    if (temp == 0) {
      cout << 0 << endl;
      continue;
    }
    gao(x, y, kk);
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
  return 0;
}