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

public class History {
	static int d[][][] = new int[102][102][102];
	static int p[][][] = new int[102][102][102];
	static String s1, s2, virus;
	
	public static String restore(int i, int j, int k) {
		String result = "";
		if (i > 0 && d[i - 1][j][k] == d[i][j][k]) {
			return restore(i - 1, j, k) + result;
		}
		if (j > 0 && d[i][j - 1][k] == d[i][j][k]) {
			return restore(i, j - 1, k) + result;
		}
		if (i > 0 && j > 0 && s1.charAt(i - 1) == s2.charAt(j - 1) && 
				p[i][j][k] != -1 && d[i - 1][j - 1][p[i][j][k]] == d[i][j][k] - 1) {
			return restore(i - 1, j - 1, p[i][j][k]) + s1.charAt(i - 1) + result;
		}
		
		return result;
	}
	
	public static void main(String[] args) {
		
		InputReader in = new InputReader(System.in);
		s1 = in.next();
		s2 = in.next();
		virus = in.next();
		
		int n = (int) virus.length();
		int pi[] = new int[102];
		for (int i = 0; i < n; i++) {
			pi[i] = 0;
		}
		for (int i=1; i<n; ++i) {
			int j = pi[i-1];
			while (j > 0 && virus.charAt(i) != virus.charAt(j))
				j = pi[j-1];
			if (virus.charAt(i) == virus.charAt(j))  ++j;
			pi[i] = j;
		}
		
		String s = virus + "#";
		
		int aut[][] = new int[102][256];
		for (int i = 0; i < 102; i++) {
			for (int j = 0; j < 256; j++) {
				aut[i][j] = 0;
			}
		}
		
		for (int i=0; i<n; ++i)
			for (char c=0; c< 256; ++c)
				if (i > 0 && c != s.charAt(i))
					aut[i][c] = aut[pi[i-1]][c];
				else
					aut[i][c] = i + (c == s.charAt(i) ? 1 : 0);		
		
		
		for (int i = 0; i < 102; i++)
			for (int j = 0; j < 102; j++)
				for (int k = 0; k < 102; k++) {
					d[i][j][k] = p[i][j][k] = -1;
				}
		
		d[0][0][0] = 0;
		
		for (int i = 0; i <= s1.length(); i++)
			for (int j = 0; j <= s2.length(); j++)
				for (int k = 0; k < virus.length(); k++) {
					if (i < s1.length()) {
						d[i + 1][j][k] = Math.max(d[i + 1][j][k], d[i][j][k]); 
					}
					if (j < s2.length()) {
						d[i][j + 1][k] = Math.max(d[i][j + 1][k], d[i][j][k]);
					}
					if (i == s1.length() || j == s2.length()) {
						continue;
					}
					if (s1.charAt(i) == s2.charAt(j)) {
						int to = aut[k][s1.charAt(i)];
						
						if (d[i][j][k] + 1 > d[i + 1][j + 1][to]) {
							d[i + 1][j + 1][to] = d[i][j][k] + 1;
							p[i + 1][j + 1][to] = k;
						}
					}
				}		
		
		
		String result = "";
		for (int k = 0; k < virus.length(); k++) {
			String cur = restore(s1.length(), s2.length(), k);
			if (cur.length() > result.length()) {
				result = cur;
			}
		}
		
		if (result.length() == 0) {
			System.out.println("0");
		}
		else {
			System.out.println(result);
		}
	}
}

class InputReader {
    public BufferedReader reader;
    public 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 (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
    	return Long.parseLong(next());
    };
}