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;
char s1[110], s2[110], v[110];
int l1, l2, l3, go[110][110];
int f(int x, char y) {
  string s = "";
  for (int i = 0; i <= x; i++) s += v[i];
  s += y;
  for (int i = l3; i > 0; i--) {
    int st2 = (int)s.length() - i;
    if (st2 < 0) continue;
    bool ok = 1;
    for (int j = 1; j <= i; j++)
      if (v[j - 1] != s[st2 + j - 1]) {
        ok = 0;
        break;
      }
    if (ok == 1) return i;
  }
  return 0;
}
int dp[110][110][110], zz[110][110][110];
pair<int, int> fr[110][110][110];
int nxt1[110][110], nxt2[110][110];
int main() {
  cin >> s1 >> s2 >> v;
  l1 = strlen(s1);
  l2 = strlen(s2);
  l3 = strlen(v);
  for (int i = 1; i < l3; i++)
    for (int j = 'A'; j <= 'Z'; j++) {
      go[i][j] = f(i - 1, j);
    }
  go[0][v[0]] = 1;
  for (int i = 'A'; i <= 'Z'; i++) nxt1[l1 - 1][i] = -1, nxt2[l2 - 1][i] = -1;
  for (int i = l1 - 2; i >= 0; i--)
    for (char j = 'A'; j <= 'Z'; j++) {
      nxt1[i][j] = nxt1[i + 1][j];
      if (s1[i + 1] == j) nxt1[i][j] = i + 1;
    }
  for (int i = l2 - 2; i >= 0; i--)
    for (char j = 'A'; j <= 'Z'; j++) {
      nxt2[i][j] = nxt2[i + 1][j];
      if (s2[i + 1] == j) nxt2[i][j] = i + 1;
    }
  for (int i = 0; i < l1; i++)
    for (int j = 0; j < l2; j++)
      if (s1[i] == s2[j]) {
        if (s1[i] == v[0])
          dp[i][j][0] = -100000, dp[i][j][1] = 1;
        else
          dp[i][j][1] = -100000, dp[i][j][0] = 1;
      }
  for (int i = 0; i < l1; i++) {
    for (int j = 0; j < l2; j++) {
      if (s1[i] != s2[j]) continue;
      for (int z = 0; z < l3; z++)
        for (char e = 'A'; e <= 'Z'; e++) {
          int to1 = nxt1[i][e], to2 = nxt2[j][e], pos;
          pos = go[z][e];
          if (pos == l3) continue;
          if (to1 == -1 || to2 == -1) continue;
          if (dp[to1][to2][pos] < dp[i][j][z] + 1) {
            dp[to1][to2][pos] = dp[i][j][z] + 1;
            fr[to1][to2][pos] = make_pair(i, j);
            zz[to1][to2][pos] = z;
          }
        }
    }
  }
  int mxans = 0, wh1, wh2, wh3;
  for (int i = 0; i < l1; i++)
    for (int j = 0; j < l2; j++)
      for (int z = 0; z < l3; z++) {
        if (dp[i][j][z] > mxans) {
          mxans = dp[i][j][z];
          wh1 = i;
          wh2 = j;
          wh3 = z;
        }
      }
  if (mxans == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<char> ans;
  for (int i = 1; i <= mxans; i++) {
    ans.push_back(s1[wh1]);
    int nwh1, nwh2, nwh3;
    nwh1 = fr[wh1][wh2][wh3].first;
    nwh2 = fr[wh1][wh2][wh3].second;
    nwh3 = zz[wh1][wh2][wh3];
    wh1 = nwh1;
    wh2 = nwh2;
    wh3 = nwh3;
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i];
  cout << endl;
  return 0;
}