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.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author aalexand
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public static int[] prefixFunction(CharSequence s) {
        int[] prefix = new int[s.length()];
        for (int i = 1, l = 0; i < prefix.length; i++) {
            do {
                if (s.charAt(i) == s.charAt(l)) {
                    l++;
                    break;
                } else if (l > 0) l = prefix[l-1];
            } while (l > 0);
            prefix[i] = l;
        }
        return prefix;
    }

    public static int[][] makeAutomata(CharSequence s) {
        int[] pf = prefixFunction(s);
        int[][] ret = new int[s.length()+1][26];
        ret[0][s.charAt(0)-'A'] = 1;
        for (int i = 1; i <= s.length(); ++i) {
            System.arraycopy(ret[pf[i-1]], 0, ret[i], 0, 26);
            if (i < s.length()) {
                ret[i][s.charAt(i)-'A'] = i+1;
            }
        }
        return ret;
    }
    private static final int pack(int i, int j, int k) {
        return 0x10000000 | (i << 16) | (j << 8) | k;
    }
    private static final boolean isPacked(int v) {
        return (v & 0x10000000) != 0;
    }
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        String s1 = in.next();
        int n1 = s1.length();
        String s2 = in.next();
        int n2 = s2.length();
        String virus = in.next();
        int nv = virus.length();

        int[][] paut = makeAutomata(virus);
        int[][][] dp = new int[n1+1][n2+1][nv+1];
        for (int[][] i : dp) for (int[] j : i) Arrays.fill(j, -1);
        int[][][] prev = new int[n1+1][n2+1][nv+1];
        for (int i = 0; i <= n1; i++) {
            for (int j = 0; j <= n2; j++) {
                for (int k = 0; k < nv; k++) {
                    if (dp[i][j][k] == -1)
                        if (i == 0 || j == 0) dp[i][j][k] = 0;
                        else continue;
                    if (i < n1 && j < n2 && s1.charAt(i) == s2.charAt(j)) {
                        int a = paut[k][s1.charAt(i)-'A'];
                        if (dp[i][j][k]+1 > dp[i+1][j+1][a]) {
                            dp[i+1][j+1][a] = dp[i][j][k]+1;
                            prev[i+1][j+1][a] = pack(i, j, k);
                        }
                        if (dp[i][j][k] > dp[i + 1][j + 1][k]) {
                            dp[i+1][j+1][k] = dp[i][j][k];
                            prev[i+1][j+1][k] = prev[i][j][k];
                        }
                    } else {
                        if (j < n2 && dp[i][j][k] > dp[i][j+1][k]) {
                            dp[i][j+1][k] = dp[i][j][k];
                            prev[i][j+1][k] = pack(i, j, k);
                        }
                        if (i < n1 && dp[i][j][k] > dp[i+1][j][k]) {
                            dp[i+1][j][k] = dp[i][j][k];
                            prev[i+1][j][k] = pack(i, j, k);
                        }
                    }
                }
            }
        }

        int lenMax = 0, iMax = 0, jMax = 0, kMax = 0;
        for (int i = 0; i <= n1; i++)
            for (int j = 0; j <= n2; j++)
                for (int k = 0; k < nv; k++) {
                    if (dp[i][j][k] > lenMax) {
                        iMax = i; jMax = j; kMax = k;
                        lenMax = dp[i][j][k];
                    }
                }
        StringBuffer ret = new StringBuffer();
        int i = iMax, j = jMax, k = kMax;
        while (isPacked(prev[i][j][k])) {
            int p = prev[i][j][k];
            i = (p >> 16) & 0xff;
            j = (p >> 8) & 0xff;
            k = p & 0xff;
            if (i < n1 && j < n2 && s1.charAt(i) == s2.charAt(j)) {
                ret.append(s1.charAt(i));
            }
        }

        if (ret.length() == 0) {
            out.println(0);
        } else {
            out.println(ret.reverse().toString());
        }
    }
}