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.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

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

class TaskB {
    private static final int INF = 100000000;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] A = in.nextString().toCharArray();
        char[] B = in.nextString().toCharArray();
        char[] V = in.nextString().toCharArray();

        int N = A.length;
        int M = B.length;
        int K = V.length;

        int[] pr = new int[K];
        pr[0] = -1;
        int pos = -1;
        for(int i = 1; i < K; i++) {
            while(pos >= 0 && V[i] != V[pos + 1])
                pos = pr[pos];
            if(V[i] == V[pos + 1])
                pos++;
            pr[i] = pos;
        }

        int[][] go = new int[K][26];
        for(int i = 0; i < K; i++)
            for(char c = 'A'; c <= 'Z'; c++) {
                int nk = i;
                while(nk >= 0 && (nk + 1 == K || V[nk + 1] != c))
                    nk = pr[nk];
                if(nk + 1 != K && V[nk + 1] == c)
                    nk++;
                go[i][c - 'A'] = nk;
            }

//        for(int i = 0; i < K; i++) {
//            for(int j = 0; j < 2; j++)
//                System.out.print(go[i][j] + " ");
//            System.out.println();
//        }


        int[][][] dp = new int[N + 1][M + 1][K + 1];
        State[][][] from = new State[N + 1][M + 1][K + 1];


        for(int i = 0; i < N; i++)
            for(int j = 0; j < M; j++) {
//                dp[i][j][0] = 0;
                for(int k = 0; k < K; k++) {
                    dp[i][j][k] = -INF;
                }
            }
        dp[0][0][0] = 0;

        for(int i = 0; i < N; i++)
            for(int j = 0; j < M; j++)
                for(int k = 0; k < K; k++) {
                    State now = new State(i, j, k);

                    if(A[i] == B[j]) {
                        int nk = k;
                        if(A[i] == V[k])
                            nk++;
                        else {
                            if(k == 0) {
                                nk = 0;
                            }
                            else
                                nk = go[k - 1][ A[i] - 'A' ] + 1;
                        }

                        if(dp[i][j][k] + 1 > dp[i + 1][j + 1][nk]) {
                            dp[i + 1][j + 1][nk] = dp[i][j][k] + 1;
                            from[i + 1][j + 1][nk] = now;
                        }
                    }
                    if(dp[i][j][k] > dp[i + 1][j][k]) {
                        dp[i + 1][j][k] = dp[i][j][k];
                        from[i + 1][j][k] = now;
                    }
                    if(dp[i][j][k] > dp[i][j + 1][k]) {
                        dp[i][j + 1][k] = dp[i][j][k];
                        from[i][j + 1][k] = now;
                    }
                }

        int imax = -1;
        int jmax = -1;
        int kmax = -1;
        int vmax = 0;
        for(int i = 0; i <= N; i++)
            for(int j = 0; j <= M; j++)
                for(int k = 0; k < K; k++)
                    if(dp[i][j][k] > vmax) {
                        vmax = dp[i][j][k];
                        imax = i;
                        jmax = j;
                        kmax = k;
                    }

        if(vmax == 0) {
            out.println(0);
            return;
        }

        StringBuilder sb = new StringBuilder();
        int i = imax;
        int j = jmax;
        int k = kmax;
//        System.out.println(new State(i, j, k) + " " + dp[i][j][k]);
        while(i > 0 || j > 0 || k > 0) {
            if(from[i][j][k] == null)
                break;

            State next = from[i][j][k];
            if(next.i == i - 1 && next.j == j - 1) {
                sb.append(A[i - 1]);
//                System.out.print("=> ");
            }

            i = next.i;
            j = next.j;
            k = next.k;
//            System.out.println(next + " " + dp[i][j][k]);
        }

        sb.reverse();
        out.println(sb.toString());
    }

    private class State {
        public int i;
        public int j;
        public int k;

        private State(int i, int j, int k) {
            this.i = i;
            this.j = j;
            this.k = k;
        }

        public String toString() {
            return "State{" + i + " " + j + " " + k + "}";
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }