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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class D {
    static char[] s1, s2, virus;
    static int[][][] dp;
    static int[][][] Trace;
    static int[] F;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        s1 = br.readLine().toCharArray();
        s2 = br.readLine().toCharArray();
        virus = br.readLine().toCharArray();

        dp = new int[s1.length][s2.length][virus.length];
        Trace = new int[s1.length][s2.length][virus.length];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[0].length; j++)
                for (int k = 0; k < dp[0][0].length; k++)
                    dp[i][j][k] = -1;

        buildFailureFunction(virus);

        int maxLength = solve(0, 0, 0);
        if (maxLength <= 0)
            System.out.println(0);
        else {
            String ans = findSolution(0, 0, 0);
            System.out.println(ans);
        }
    }

    private static String findSolution(int i, int j, int k) {
        if (i == s1.length || j == s2.length)
            return "";

        if (Trace[i][j][k] == 1) {
            if (s1[i] == virus[k])
                return s1[i] + findSolution(i + 1, j + 1, k + 1);
            else {
                int t = k;
                while (t > 0 && s1[i] != virus[t])
                    t = F[t];
                
                return s1[i] + findSolution(i + 1, j + 1, s1[i] == virus[t] ? t + 1 : t);
            }
        } else if (Trace[i][j][k] == 2)
            return findSolution(i + 1, j, k);
        else
            return findSolution(i, j + 1, k);
    }

    private static int solve(int i, int j, int k) {
        if (k == virus.length)
            return Integer.MIN_VALUE;

        if (i == s1.length || j == s2.length)
            return 0;

        if (dp[i][j][k] != -1)
            return dp[i][j][k];

        int x = Integer.MIN_VALUE;
        if (s1[i] == s2[j]) {
            if (s1[i] == virus[k])
                x = 1 + solve(i + 1, j + 1, k + 1);
            else {
                int t = k;
                while (t > 0 && s1[i] != virus[t])
                    t = F[t];

                x = 1 + solve(i + 1, j + 1, s1[i] == virus[t] ? t + 1 : t);
            }
        }

        int a = solve(i + 1, j, k);
        int b = solve(i, j + 1, k);

        int max = Math.max(a, Math.max(x, b));
        if (max == x)
            Trace[i][j][k] = 1;
        else if (max == a)
            Trace[i][j][k] = 2;

        return dp[i][j][k] = max;
    }

    private static void buildFailureFunction(char[] pattern) {
        int m = pattern.length;
        F = new int[m + 1];
        F[0] = F[1] = 0;

        for (int i = 2; i <= m; i++) {
            // j is the index of the largest next partial match
            // (the largest suffix/prefix) of the string under index i - 1
            int j = F[i - 1];
            while (true) {
                if (pattern[j] == pattern[i - 1]) {
                    F[i] = j + 1;
                    break;
                }

                if (j == 0) {
                    F[i] = 0;
                    break;
                }
                j = F[j];
            }

        }
    }

}