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;
string s1, s2, virus, as1[110], as2[110], dp[110][110][110];
map<string, int> mapa;
int contador = 1;
void limpiara(string &a, string &b, bool rep) {
  string c = a;
  string d = b;
  string primero = "";
  for (int i = 0; i < c.size(); i++) {
    for (int j = 0; j < d.size(); j++) {
      if (c[i] == d[j]) {
        primero = primero + c[i];
        break;
      }
    }
  }
  a = primero;
  if (rep == true) {
    limpiara(b, a, false);
  }
}
bool tienevirus(string a, string virus) {
  if (a.size() < virus.size()) {
    return false;
  }
  string temp = "";
  for (int i = 0; i < virus.size(); i++) {
    temp += a[i];
  }
  for (int i = virus.size(); i < a.size(); i++) {
    if (temp == virus) {
      return true;
    }
    temp.erase(temp.begin(), temp.begin() + 1);
    temp += a[i];
  }
  if (temp == virus) {
    return true;
  }
  return false;
}
string LCD(string a, string b, string &virus, int k) {
  if (a[a.size() - 1] == b[b.size() - 1]) {
    string r = dp[a.size() - 1][b.size() - 1][k] + a[a.size() - 1];
    string temp1 = dp[a.size() - 1][b.size() - 1][k];
    if (!tienevirus(r, virus)) {
      return r;
    }
    int contador2 = contador;
    for (int i = contador2; i < contador2 + virus.size(); i++) {
      int x = i - contador2;
      string temp2 = r;
      temp2.erase(temp2.end() - (x + 1));
      if (mapa[temp2] < 1) {
        if (tienevirus(temp2, virus)) {
          dp[a.size()][b.size()][contador] = "";
        } else {
          dp[a.size()][b.size()][contador] = temp2;
        }
        contador++;
        mapa[temp2]++;
      }
    }
    r.erase(r.end() - 1);
    return r;
  } else {
    string aux1 = dp[a.size() - 1][b.size()][k];
    string aux2 = dp[a.size()][b.size() - 1][k];
    if (aux1.size() >= aux2.size()) {
      return aux1;
    } else {
      return aux2;
    }
  }
}
int main() {
  while (cin >> s1 >> s2 >> virus) {
    limpiara(s1, s2, true);
    for (int i = 0; i < 110; i++) {
      for (int j = 0; j < 110; j++) {
        for (int k = 0; k < 110; k++) {
          dp[i][j][k] = "";
        }
      }
    }
    for (int i = 1; i <= s1.size(); i++) {
      as1[i] = as1[i - 1] + s1[i - 1];
    }
    for (int i = 1; i <= s2.size(); i++) {
      as2[i] = as2[i - 1] + s2[i - 1];
    }
    for (int k = 1; k < 110; k++) {
      for (int i = 1; i <= s1.size(); i++) {
        for (int j = 1; j <= s2.size(); j++) {
          if (dp[i][j][k] == "") {
            dp[i][j][k] = LCD(as1[i], as2[j], virus, k);
          }
        }
      }
    }
    string r = dp[s1.size()][s2.size()][0];
    for (int i = 0; i < 110; i++) {
      for (int j = 0; j < 110; j++) {
        for (int k = 0; k < 110; k++) {
          string r2 = dp[i][j][k];
          if (r2.size() > r.size()) {
            r = r2;
          }
        }
      }
    }
    if (r == "") {
      cout << "0" << endl;
    } else {
      cout << r << endl;
    }
  }
  return 0;
}