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;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
int n1, n2, v1;
string s1, s2, v;
int jump[200][30];
void get() {
  for (int i = 0; i < v1; i++) {
    for (int j = 0; j < 26; j++) {
      char temp = 'A' + j;
      int go = i + 1;
      while (go > 0) {
        int flag = false;
        if (go > 0 and v[go - 1] != temp) {
          go--;
          continue;
        }
        for (int k = 0; k < go - 1; k++) {
          if (v[go - 2 - k] != v[i - 1 - k]) {
            flag = true;
            break;
          }
        }
        if (flag == false) {
          break;
        }
        go--;
      }
      jump[i][j] = go;
    }
  }
}
int dp[101][101][101];
int from[101][101][101];
string solve() {
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      for (int k = 0; k <= v1; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i <= n1; i++) {
    for (int j = 0; j <= n2; j++) {
      for (int k = 0; k < v1; k++) {
        if (dp[i][j][k] == -1) {
          continue;
        }
        if (i < n1 and dp[i][j][k] > dp[i + 1][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          from[i + 1][j][k] = -1;
        }
        if (j < n2 and dp[i][j][k] > dp[i][j + 1][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          from[i][j + 1][k] = -2;
        }
        if (i < n1 and j < n2 and s1[i] == s2[j]) {
          int temp = jump[k][s1[i] - 'A'];
          if (temp < v1 and dp[i + 1][j + 1][temp] < (dp[i][j][k] + 1)) {
            dp[i + 1][j + 1][temp] = dp[i][j][k] + 1;
            from[i + 1][j + 1][temp] = k;
          }
        }
      }
    }
  }
  int mx = 0;
  int prev = 0;
  for (int i = 0; i <= v1; i++) {
    if (dp[n1][n2][i] > mx) {
      mx = dp[n1][n2][i];
      prev = i;
    }
  }
  if (mx == 0) {
    return "0";
  }
  string ans = "";
  for (int i = n1, j = n2; i > 0 and j > 0;) {
    int val = from[i][j][prev];
    if (val == -1) {
      i--;
    }
    if (val == -2) {
      j--;
    }
    if (val >= 0) {
      i--;
      j--;
      ans = s1[i] + ans;
      prev = val;
    }
  }
  return ans;
}
int main() {
  cin >> s1 >> s2 >> v;
  n1 = s1.size();
  n2 = s2.size();
  v1 = v.size();
  get();
  cout << solve() << "\n";
  return 0;
}