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 Problem1 {
	static char [] s1,s2,virus;
	static int s1L,s2L,vL;
	static int [][] [] dp;
	static int NINF=-(int)1e6;
	static StringBuilder ans;
	static int [] fail;
	static PrintWriter pw;
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		pw=new PrintWriter(System.out);
		s1=bf.readLine().toCharArray();
		s1L=s1.length;
		s2=bf.readLine().toCharArray();
		s2L=s2.length;
		virus=bf.readLine().toCharArray();
		vL=virus.length;
		fail = FailFunction2(new String(virus));
		dp=new int [s1L+10] [s2L+10] [vL+10];
		ans=new StringBuilder();
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[i].length; j++) {
				Arrays.fill(dp[i][j],-1);
			}
		}
		int anss=dp(0,0,0);
		//System.out.println(anss);
		if(anss <= 0)
			pw.println("0");
		else{
			LCSPrint(0, 0, 0);
			pw.println(ans.toString());
		}

		pw.flush();
		pw.close();
		
	}
	static void LCSPrint(int i, int j,int v) {
		if (i >= s1L || j >= s2L || v>= vL)
			return;
		int optimal = dp(i, j ,v);
		int sol1=Integer.MAX_VALUE;
		int oldV = v;
		if(s1[i]==s2[j] ) {
			if(s1[i]!= virus[v] && v> 0 && s1[i] != virus[fail[v]]){
					v=0;//nbtdy nmatch mn awl wi gded
			}
			else if(s1[i]!= virus[v] && v> 0 && s1[i] == virus[fail[v]]){
				v=fail[v]+1;
			}
			else if(s1[i]== virus[v]){
				v++;
			}
			else{//it didnt match now and it wont match any prefix so start mn el awl
				v=0;
			}
            sol1 = dp(i+1,j+1,v) + 1;
        }
		int sol2 = dp(i + 1, j,oldV);
		int sol3 = dp(i, j + 1,oldV);
		
		if (optimal == sol1) {
			ans.append(s1[i]);
			LCSPrint(i + 1, j + 1,v);
		} else if (optimal == sol2)
			LCSPrint(i + 1, j,oldV);
		else
			LCSPrint(i, j + 1,oldV);
	}
	static int dp(int i , int j ,int v){
		if(v == vL)
			return NINF;
		if(i == s1L || j == s2L)
			return 0;
		if(dp[i][j][v] != -1)
			return dp[i][j][v];
		int max=Integer.MIN_VALUE;
		int oldV=v;
		if(s1[i]==s2[j] ) {
			if(s1[i]!= virus[v] && v> 0 && s1[i] != virus[fail[v]]){
					v=0;//nbtdy nmatch mn awl wi gded
			}
			else if(s1[i]!= virus[v] && v> 0 && s1[i] == virus[fail[v]]){
				v=fail[v]+1;
			}
			else if(s1[i]== virus[v]){
				v++;
			}
			else{//it didnt match now and it wont match any prefix so start mn el awl
				v=0;
				
			}
            max = dp(i+1,j+1,v) + 1;
        }
        
		
		int max2=dp(i+1,j,oldV);
		int max3=dp(i,j+1,oldV);
		
		return dp[i][j][oldV]=Math.max(max, Math.max(max2, max3));
	
	}
	public static int[] FailFunction2(String s) {
		int n = s.length();
		int F[] = new int[n + 1];
		int i = 0, j = -1;
		F[i] = j;
		while (i < n) {
			while (j >= 0 && s.charAt(i) != s.charAt(j))
				j = F[j];
			i++;
			j++;
			F[i] = j;
		}
		return F;
	}

}