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.StringTokenizer;

public class Subsequence {
    FastScanner in;
    PrintStream out = System.out;

    private static final char FIRST = 'A';
    private static final char LAST = 'Z';
    private static final int NO_VALUE = Integer.MIN_VALUE / 2;

    public void solve() throws IOException {
        String a = in.next();
        String b = in.next();
        String s = in.next();

        int[][] transitions = automataTransition(s);

        int[][][] longest = new int[a.length() + 1][b.length() + 1][s.length()];
        int[][][] previ = new int[a.length() + 1][b.length() + 1][s.length()];
        int[][][] prevj = new int[a.length() + 1][b.length() + 1][s.length()];
        int[][][] prevk = new int[a.length() + 1][b.length() + 1][s.length()];

        for (int i = 0; i < a.length(); i++) {
            for (int j = 0; j < b.length(); j++) {
                for (int k = 0; k < s.length(); k++) {
                    longest[i][j][k] = NO_VALUE;
                    if (k == 0 && (j == 0 || i == 0)) {
                        longest[i][j][k] = 0;
                    }
                }
            }
        }

        for (int i = 0; i <= a.length(); i++) {
            for (int j = 0; j <= b.length(); j++) {
                for (int k = 0; k < s.length(); k++) {
                    int current = longest[i][j][k];

                    if (i < a.length() && longest[i + 1][j][k] < current) {
                        longest[i + 1][j][k] = current;
                        previ[i + 1][j][k] = i;
                        prevj[i + 1][j][k] = j;
                        prevk[i + 1][j][k] = k;
                    }

                    if (j < b.length() && longest[i][j + 1][k] < current) {
                        longest[i][j + 1][k] = current;
                        previ[i][j + 1][k] = i;
                        prevj[i][j + 1][k] = j;
                        prevk[i][j + 1][k] = k;
                    }

                    if (i < a.length() && j < b.length() && a.charAt(i) == b.charAt(j)) {
                        char ch = a.charAt(i);
                        int futLen = transitions[k][ch - 'A'];
                        if (futLen < s.length()) {
                            if (longest[i + 1][j + 1][futLen] < current + 1) {
                                longest[i + 1][j + 1][futLen] = current + 1;
                                previ[i + 1][j + 1][futLen] = i;
                                prevj[i + 1][j + 1][futLen] = j;
                                prevk[i + 1][j + 1][futLen] = k;
                            }
                        }
                    }
                }
            }
        }

        int[] lastRow = longest[a.length()][b.length()];
        int endLen = 0;
        for (int k = 0; k < s.length(); k++) {
            if (lastRow[k] > lastRow[endLen]) {
                endLen = k;
            }
        }

        StringBuilder res = new StringBuilder();
        int curi = a.length();
        int curj = b.length();
        while (curi > 0 || curj > 0) {
            int movei = previ[curi][curj][endLen];
            int movej = prevj[curi][curj][endLen];
            int moveLen = prevk[curi][curj][endLen];
            if (longest[curi][curj][endLen] == longest[movei][movej][moveLen] + 1) {
                res.append(a.charAt(movei));
            }
            curi = movei;
            curj = movej;
            endLen = moveLen;
        }
        String ans = res.reverse().toString();
        out.print(ans.isEmpty() ? "0" : ans);
    }

    /**
     * Poor man's kmp
     */
    int[][] automataTransition(String s) {
        int[][] res = new int[s.length()][LAST - FIRST + 1];

        for (int i = 0; i < res.length; i++) {
            String sub = s.substring(0, i);
            for (char ch = FIRST; ch <= LAST; ch++) {
                String con = sub + ch;
                for (int sufStart = 0; sufStart < s.length(); sufStart++) {
                    String prefix = s.substring(0, s.length() - sufStart);
                    if (con.endsWith(prefix)) {
                        res[i][ch - FIRST] = prefix.length();
                        break;
                    }
                }
            }
        }
        return res;
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            solve();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
    }

    public static void main(String[] arg) {
        new Subsequence().run();
    }
}