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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
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 {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] a = in.next().toCharArray();
        char[] b = in.next().toCharArray();

        char[] v = in.next().toCharArray();
        String s = new String(v);
        int[] next2 = new int[s.length()];
        next2[0] = -1;
        for (int i = 1; i < s.length(); ++i) {
            int to = next2[i - 1];
            while (to != -1 && v[to + 1] != v[i]) {
                to = next2[to];
            }
            next2[i] = to;
            if (v[to + 1] == v[i]) ++next2[i];
        }

        int[][] next = new int[v.length][26];
        for (int i = 0; i < v.length; ++i) {
            for (int j = 0; j < 26; ++j) {
                if (i == 0) {
                    if (j == v[i] - 'A') {
                        next[i][j] = 1;
                    } else {
                        next[i][j] = 0;
                    }
                    continue;
                }

                if (j == v[i] - 'A') {
                    next[i][j] = i + 1;
                } else {
                    next[i][j] = next[next2[i - 1] + 1][j];
                }
            }
        }

        int[][][] dp = new int[a.length + 1][b.length + 1][v.length];
        int[][][] prev = new int[a.length + 1][b.length + 1][v.length];
        for (int i = 0; i <= a.length; ++i) {
            for (int j = 0; j <= b.length; ++j) {
                for (int k = 0; k < v.length; ++k) {
                    if (i + 1 <= a.length) {
                        if (dp[i + 1][j][k] < dp[i][j][k]) {
                            dp[i + 1][j][k] = dp[i][j][k];
                            prev[i + 1][j][k] = 1;
                        }
                    }
                    if (j + 1 <= b.length) {
                        if (dp[i][j + 1][k] < dp[i][j][k]) {
                            dp[i][j + 1][k] = dp[i][j][k];
                            prev[i][j + 1][k] = 2;
                        }
                    }
                    if (i + 1 <= a.length && j + 1 <= b.length && a[i] == b[j]) {
                        int nextK = next[k][a[i] - 'A'];
                        if (nextK < v.length) {
                            if (dp[i + 1][j + 1][nextK] < dp[i][j][k] + 1) {
                                dp[i + 1][j + 1][nextK] = dp[i][j][k] + 1;
                                prev[i + 1][j + 1][nextK] = 100 + k;
                            }
                        }
                    }
                }
            }
        }

        int where = 0;
        for (int i = 0; i < v.length; ++i) {
            if (dp[a.length][b.length][i] > dp[a.length][b.length][where]) {
                where = i;
            }
        }

        if (dp[a.length][b.length][where] == 0) {
            out.println(0);
            return;
        }

        String result = "";
        int i = a.length, j = b.length, k = where;
        while (dp[i][j][k] > 0) {
            if (prev[i][j][k] == 1) {
                --i;
            } else if (prev[i][j][k] == 2) {
                --j;
            } else {
                result = a[i - 1] + result;
                k = prev[i][j][k] - 100;
                --i; --j;
            }
        }

        out.println(result);
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (Exception e) {
                throw new UnknownError();
            }
        }
        return tokenizer.nextToken();
    }

    }