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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

    static class BLuckyCommonSubsequence {
        char[] str1;
        char[] str2;
        char[] virus;
        long[][][] dp;
        int[] lps;
        PrintWriter pp;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            str1 = in.scanString().toCharArray();
            str2 = in.scanString().toCharArray();
            virus = in.scanString().toCharArray();
            this.pp = out;

            dp = new long[str1.length + 5][str2.length + 5][virus.length + 5];


            for (int i = 0; i < str1.length + 5; i++) {
                for (int j = 0; j < str2.length + 5; j++) {
                    for (int k = 0; k < virus.length + 5; k++) {
                        dp[i][j][k] = -1;
                    }
                }
            }

            lps = CodeX.prefix_function(virus);


            long ans = findit(0, 0, 0);


            if (ans != 0) {
                print(0, 0, 0);
            } else {
                out.println(0);
            }


        }

        long findit(int i, int j, int k) {
            if (k == virus.length) return dp[i][j][k] = Integer.MIN_VALUE;
            if (i == str1.length) return dp[i][j][k] = 0;
            if (j == str2.length) return dp[i][j][k] = 0;
            if (dp[i][j][k] != -1) return dp[i][j][k];


            if (str1[i] == str2[j]) {

                dp[i][j][k] = Math.max(dp[i][j][k], findit(i + 1, j + 1, k));


                if (str1[i] == virus[k]) {
                    dp[i][j][k] = Math.max(dp[i][j][k], 1 + findit(i + 1, j + 1, k + 1));
                } else {
                    if (k == 0) {
                        dp[i][j][k] = Math.max(dp[i][j][k], 1 + findit(i + 1, j + 1, k));
                    } else {

                        int index = -1;
                        for (int ii = k - 1; ii >= 0; ii--) {
                            if (str1[i] == virus[lps[ii]]) {
                                index = lps[ii];
                                break;
                            }
                        }
                        if (index == -1) {
                            dp[i][j][k] = Math.max(dp[i][j][k], 1 + findit(i + 1, j + 1, 0));
                        } else {
                            dp[i][j][k] = Math.max(dp[i][j][k], 1 + findit(i + 1, j + 1, index + 1));
                        }


                    }
                }
            } else {
                dp[i][j][k] = Math.max(dp[i][j][k], findit(i + 1, j, k));
                dp[i][j][k] = Math.max(dp[i][j][k], findit(i, j + 1, k));
            }

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

        void print(int i, int j, int k) {

            if (i == str1.length) return;
            if (j == str2.length) return;
            if (str1[i] == str2[j]) {


                if (findit(i + 1, j + 1, k) == dp[i][j][k]) {
                    print(i + 1, j + 1, k);
                    return;
                }


                if (str1[i] == virus[k]) {
                    if (1 + findit(i + 1, j + 1, k + 1) == dp[i][j][k]) {
                        pp.print(str1[i]);
                        print(i + 1, j + 1, k + 1);
                        return;
                    }
                } else {
                    if (k == 0) {
                        if (1 + findit(i + 1, j + 1, k) == dp[i][j][k]) {
                            pp.print(str1[i]);
                            print(i + 1, j + 1, k);
                            return;
                        }
                    } else {


                        int index = -1;
                        for (int ii = k - 1; ii >= 0; ii--) {
                            if (str1[i] == virus[lps[ii]]) {
                                index = lps[ii];
                                break;
                            }
                        }
                        if (index == -1) {

                            if (1 + findit(i + 1, j + 1, 0) == dp[i][j][k]) {
                                pp.print(str1[i]);
                                print(i + 1, j + 1, 0);
                                return;
                            }

                        } else {

                            if (1 + findit(i + 1, j + 1, index + 1) == dp[i][j][k]) {
                                pp.print(str1[i]);
                                print(i + 1, j + 1, index + 1);
                                return;
                            }
                        }


                    }
                }
            } else {

                if (dp[i][j][k] == findit(i + 1, j, k)) {
                    print(i + 1, j, k);
                    return;
                }

                if (dp[i][j][k] == findit(i, j + 1, k)) {
                    print(i, j + 1, k);
                    return;
                }


            }

            return;

        }

    }

    static class CodeX {
        public static int[] prefix_function(char[] s) {
            int n = s.length;
            int[] pi = new int[n];
            for (int i = 1; i < n; i++) {
                int j = pi[i - 1];
                while (j > 0 && s[i] != s[j]) j = pi[j - 1];
                if (s[i] == s[j]) j++;
                pi[i] = j;
            }
            return pi;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public String scanString() {
            int c = scan();
            while (isWhiteSpace(c)) c = scan();
            StringBuilder RESULT = new StringBuilder();
            do {
                RESULT.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return RESULT.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}