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.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 *
 * Total complexity : O(NlogN)
 *
 * @author pttrung
 */
public class D {

    public static String a, b, v;
    public static int[][][] dp;
    public static int[] back;

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        a = in.next();
        b = in.next();
        v = in.next();
        dp = new int[a.length() + 1][b.length() + 1][v.length()];
        for (int[][] val : dp) {
            for (int[] temp : val) {
                Arrays.fill(temp, -1);
            }
        }
        back = new int[v.length() + 1];
        KMP();

        int val = cal(0, 0, 0);
        //  System.out.println(val);
        int i = 0;
        int j = 0;
        int k = 0;
        StringBuilder builder = new StringBuilder();
        while (i < a.length() && j < b.length()) {
            int next = k;
            while (next >= 0 && a.charAt(i) != v.charAt(next)) {
                next = back[next];
                //System.out.println("Next " + next);
            }
            next++;
            if (a.charAt(i) == b.charAt(j) && next < v.length() && dp[i][j][k] == dp[i + 1][j + 1][next]) {
                builder.append(a.charAt(i));
                i++;
                j++;
                k = next;
            } else if (dp[i + 1][j][k] + 1 == dp[i][j][k]) {
                i++;
            } else if (dp[i][j + 1][k] + 1 == dp[i][j][k]) {
                j++;
            } else {
                i++;
                j++;
            }

        }
        if (builder.length() > 0) {
            out.println(builder.toString());
        }else{
            out.println(0);
        }


        out.close();
    }

    public static int cal(int i, int j, int k) {
        if (k >= v.length()) {
            return Integer.MAX_VALUE / 2;
        }
        if (i == a.length() || j == b.length()) {
            if (i == a.length()) {
                dp[i][j][k] = b.length() - j + 1;
                return b.length() - j + 1;
            } else {
                dp[i][j][k] = a.length() - i + 1;
                return a.length() - i + 1;
            }
        }
        if (dp[i][j][k] != -1) {
            return dp[i][j][k];
        }
        int result = Integer.MAX_VALUE / 2;
        if (a.charAt(i) == b.charAt(j)) {
            int next = k;
            while (next >= 0 && a.charAt(i) != v.charAt(next)) {
                next = back[next];
                //System.out.println("Next " + next);
            }
            next++;
            result = Math.min(result, cal(i + 1, j + 1, next));
        }
        result = Math.min(result, 1 + cal(i + 1, j, k));
        result = Math.min(result, 1 + cal(i, j + 1, k));
        result = Math.min(result, 2 + cal(i + 1, j + 1, k));
        dp[i][j][k] = result;
        return result;

    }

    public static void KMP() {
        int i = 0, j = -1;
        back[i] = j;
        while (i < v.length()) {
            while (j >= 0 && v.charAt(i) != v.charAt(j)) {
                j = back[j];
            }
            j++;
            i++;
            back[i] = j;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}