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:
/**
 * Created by Aminul on 4/3/2018.
 */

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

import static java.lang.Math.*;

public class CF346B {
    static int lps[], next[][];
    static char a[], b[], v[];

    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        a = in.nextCharArray();
        b = in.nextCharArray();
        v = in.nextCharArray();

        n = a.length;
        m = b.length;
        l = v.length;

        //lps = lps(v);
        next = redundantKMP(v);

        dp = new int[n + 1][m + 1][l + 1];
        for (int p[][] : dp) for (int q[] : p) Arrays.fill(q, -1);

        int len = solve(0, 0, 0);
        if (len == 0) pw.println(0);
        else printPath(0, 0, 0);

        pw.close();
    }

    static int n, m, l, dp[][][];

    static int solve(int x, int y, int z) {
        if (x == n || y == m) return 0;
        if (dp[x][y][z] != -1) return dp[x][y][z];
        int max = 0;
        if (a[x] == b[y]) {
            int q = getNext(z, a[x]);
            if (q == l) max = solve(x + 1, y + 1, z);
            else max = 1 + solve(x + 1, y + 1, q);
        }
        int max2 = solve(x + 1, y, z);
        int max3 = solve(x, y + 1, z);
        return dp[x][y][z] = max(max, max(max2, max3));
    }


    static void printPath(int x, int y, int z) {
        if (x == n || y == m) {
            System.out.println();
            return;
        }
        int max = solve(x, y, z);
        if (max == solve(x + 1, y, z)) {
            printPath(x + 1, y, z);
        } else if (max == solve(x, y + 1, z)) {
            printPath(x, y + 1, z);
        } else {
            int q = getNext(z, a[x]);
            if (q == l) printPath(x + 1, y + 1, z);
            else {
                System.out.print(a[x]);
                printPath(x + 1, y + 1, q);
            }
        }
    }
    
    static int getNext(int pos, char c) {
        if (v[pos] == c) return ++pos;
        return next[pos][c - 'A'];
    }

    public static int[][] redundantKMP(char[] s) {
        int n = s.length;
        final int W = 26;
        int[][] dp = new int[n][W];
        int[] kmp = new int[n + 1];
        kmp[0] = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < W; j++) {
                if (kmp[i] == -1) {
                    dp[i][j] = 0;
                } else if (j == s[kmp[i]] - 'A') {
                    dp[i][j] = kmp[i] + 1;
                } else {
                    dp[i][j] = dp[kmp[i]][j];
                }
            }
            kmp[i + 1] = dp[i][s[i] - 'A'];
        }
        return dp;
    }

    static int[] lps(char[] s) {
        int n = s.length, k = 0, lps[] = new int[n];
        for (int i = 1; i < n; i++) {
            while (k > 0 && s[k] != s[i]) k = lps[k - 1];
            if (s[k] == s[i]) k++;
            lps[i] = k;
        }
        return lps;
    }


    static int kmp(char[] text, char[] pat) {
        int tlen = text.length, plen = pat.length;
        int[] lps = lps(pat);
        int q = 0;
        int i, res = 0;
        for (i = 0; i < tlen; i++) {
            while (q > 0 && pat[q] != text[i]) q = lps[q - 1];
            if (pat[q] == text[i]) q++;
            if (q == plen) {
                res++;
                q = lps[q - 1];
            }
        }
        return res;
    }


    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;
        static final int ints[] = new int[128];

        public FastReader(InputStream is) {
            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

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


        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        private char buff[] = new char[105];

        public char[] nextCharArray() {
            int b = skip(), p = 0;
            while (!(isSpaceChar(b))) {
                buff[p++] = (char) b;
                b = readByte();
            }
            return Arrays.copyOf(buff, p);
        }
    }
}