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 JAVA):

Solution:
import java.io.*;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

/**
 * 346B
 * θ(|x|*|y|*|p| + |alphabet|*|p|) time
 * θ(|x|*|y|*|p| + |alphabet|*|p|) space
 *
 * @author artyom
 */
public class _346B implements Runnable {
    private BufferedReader in;

    private String solve() throws IOException {
        String ans = find(nextToken(), nextToken(), nextToken());
        return ans.isEmpty() ? "0" : ans;
    }

    /**
     * O(|x|*|y|*|p| + |alphabet|*|p|).
     *
     * @return a LCS of x and y excluding p as a substring
     */
    private static String find(String x, String y, String p) {
        int n = x.length(), m = y.length(), r = p.length();

        // Preprocessing
        int[] kmp = computePrefixFunction(p);
        int[][] sigma = new int[r][26];
        sigma[0][p.charAt(0) - 'A'] = 1;
        for (int t = 1; t < r; t++) {
            for (int a = 0; a < 26; a++) {
                if (a == p.charAt(t) - 'A') {
                    sigma[t][a] = t + 1;
                } else {
                    sigma[t][a] = sigma[kmp[t]][a];
                }
            }
        }

        // Evaluation
        int[][][] dp = new int[n + 1][m + 1][r + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                for (int k = 0; k <= r; k++) {
                    dp[i][j][k] = Math.max(dp[i - 1][j][k], dp[i][j - 1][k]);
                }
                if (x.charAt(i - 1) == y.charAt(j - 1)) {
                    for (int k = 0; k < r; k++) {
                        int t = sigma[k][x.charAt(i - 1) - 'A'];
                        dp[i][j][t] = Math.max(dp[i][j][t], 1 + dp[i - 1][j - 1][k]);
                    }
                }
            }
        }
        int max = dp[n][m][0], k = 0;
        for (int i = 1; i < r; i++) {
            if (dp[n][m][i] > max) {
                max = dp[n][m][i];
                k = i;
            }
        }

        // Backtracking
        Deque<Character> stack = new LinkedList<>();
        int i = n, j = m;
        while (i > 0 && j > 0) {
            if (x.charAt(i - 1) == y.charAt(j - 1)) {
                if (dp[i][j][k] > dp[i - 1][j - 1][k]) {
                    k = maxSigma(dp[i - 1][j - 1], r, x.charAt(i - 1) - 'A', k, sigma);
                    stack.push(x.charAt(i - 1));
                }
                i--;
                j--;
            } else if (dp[i - 1][j][k] > dp[i][j - 1][k]) {
                i--;
            } else {
                j--;
            }
        }

        StringBuilder out = new StringBuilder();
        for (Character ch : stack) {
            out.append(ch);
        }
        return out.toString();
    }

    private static int[] computePrefixFunction(String p) {
        int r = p.length();
        int[] kmp = new int[r + 1];
        kmp[0] = -1;
        for (int i = 2; i <= r; i++) {
            char x = p.charAt(i - 1);
            int k = kmp[i - 1];
            while (k >= 0 && p.charAt(k) != x) {
                k = kmp[k];
            }
            kmp[i] = k + 1;
        }
        return kmp;
    }

    private static int maxSigma(int[] vals, int r, int c, int k, int[][] lmb) {
        int max = -1, maxIndex = -1;
        for (int t = 0; t < r; t++) {
            if (lmb[t][c] == k) {
                if (vals[t] > max) {
                    max = vals[t];
                    maxIndex = t;
                }
            }
        }
        return maxIndex;
    }

    //--------------------------------------------------------------
    public static void main(String[] args) {
        new _346B().run();
    }

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            System.out.print(solve());
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    private String nextToken() throws IOException {
        return in.readLine();
    }
}