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


public class LuckyCommonSubsequence {
	static PrintWriter out = new PrintWriter(System.out);

	static int n, m, o, dp[][][], kmp[];
	static String s1, s2, v;
	static final int INF = (int) 1e9;
	
	public static int rec(int i, int j, int k) {
		if(k == o)
			return -INF;
		if(i == n || j == m)
			return 0;
		
		if(dp[i][j][k] != -1)
			return dp[i][j][k];
		
		int ans1, ans2, ans3, ans4;
		ans1 = ans2 = ans3 = ans4 = -INF;
		if(s1.charAt(i) == s2.charAt(j)) {
			int temp = k;
			while(temp > 0 && s1.charAt(i) != v.charAt(temp)) temp = kmp[temp - 1];
			if(s1.charAt(i) == v.charAt(temp))
				ans2 = rec(i + 1, j + 1, temp + 1) + 1;
			else
				ans2 = rec(i + 1, j + 1, 0) + 1;
		}
		ans3 = rec(i + 1, j, k);
		ans4 = rec(i, j + 1, k);
		
		return dp[i][j][k] = Math.max(Math.max(ans1, ans2), Math.max(ans3, ans4));
	}
	
	static void build(int i, int j, int k)
	{
		if(i == n || j == m)
			return;
		
		if(s1.charAt(i) == s2.charAt(j)) {
			int ans2 = INF;
			int temp = k;
			while(temp > 0 && s1.charAt(i) != v.charAt(temp)) temp = kmp[temp - 1];
			if(s1.charAt(i) == v.charAt(temp)){
				ans2 = rec(i + 1, j + 1, temp + 1) + 1;
				if(ans2 == rec(i, j, k)) {
					out.print(s1.charAt(i));
					build(i + 1, j + 1, temp + 1);
					return;
				}
			}
			else{
				ans2 = rec(i + 1, j + 1, 0) + 1;
				if(ans2 == rec(i, j, k)) {
					out.print(s1.charAt(i));
					build(i + 1, j + 1, 0);
					return;
				}
			}
		}
		int ans3 = rec(i + 1, j, k);
		if(ans3 == rec(i, j, k)) {
			build(i + 1, j, k);
			return;
		}
		int ans4 = rec(i, j + 1, k);
		if(ans4 == rec(i, j, k)) {
			build(i, j + 1, k);
			return;
		}
	}
	
	public static int[] kmp(String s) {
		int[] res = new int[s.length()];
		for (int i = 1, j = 0; i < s.length(); i++) {
			while(j > 0 && s.charAt(i) != s.charAt(j)) j = res[j - 1];
			if(s.charAt(i) == s.charAt(j)) {
				res[i] = ++j;
			}
			else {
				res[i] = j;
			}
		}
		
		return res;
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		s1 = in.readLine();
		s2 = in.readLine();
		v = in.readLine();
		kmp = kmp(v);
		n = s1.length();
		m = s2.length();
		o = v.length();
		
		dp = new int[n][m][o];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}
//System.out.println(Arrays.toString(kmp));
		int len = rec(0, 0, 0);
//System.out.println(len);
		if(len > 0) {
			build(0, 0, 0);
			out.flush();
			out.close();
		}
		else {
			System.out.println(0);
		}
	}
}