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.util.Arrays;
import java.util.Scanner;

public class problem5_1 {
	
    static int [] f;
    static int [][][] dp,ans;
    
    public static void solve(String dna1, String dna2, String bacteriaDNA) {
    	char [] a,b,bacteria;
    	a = dna1.toCharArray();
    	b = dna2.toCharArray();
    	bacteria = bacteriaDNA.toCharArray();
        int n1 = a.length;
        int n2 = b.length;
        int m = bacteria.length;
        f = new int[m];
        int l = 0;
        for(int i=1; i<m; i++) {
            while(l>0 && bacteria[i]!=bacteria[l])
                l = f[l-1];
            if(bacteria[i]==bacteria[l])
                l++;
            f[i] = l;
        }
        dp = new int[n1][n2][m];
        ans = new int[n1][n2][m];
        for(int i=0; i<n1; i++)
            for(int j=0; j<n2; j++)
                Arrays.fill(dp[i][j], -1);
        
        int res = calc(0,0,0, a, b, bacteria);      
        if(res==0) System.out.println("0");
        else System.out.println(rec(0,0,0, a, b, bacteria));
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);    
        String dna1 = in.nextLine();
        String dna2 = in.nextLine();
        String bacteria = in.nextLine();
        solve(dna1, dna2, bacteria);
        in.close();
    }
        
    static String rec(int i, int j, int k, char [] a, char[] b, char[] bacteria) {
    	int n1 = a.length;
        int n2 = b.length;
        
    	if(i==n1 || j==n2)
            return "";
        
        if(ans[i][j][k]==-2)  return rec(i+1,j,k, a, b, bacteria);
        else if(ans[i][j][k]==-1) return rec(i,j+1,k, a, b, bacteria);
        return a[i]+rec(i+1,j+1,ans[i][j][k], a, b, bacteria);
    }
    
    static int calc(int i,int j,int k, char [] a, char[] b, char[] bacteria) {
    	int n1 = a.length;
        int n2 = b.length;
    	if(i==n1 || j==n2)
            return 0;
        
        if(dp[i][j][k]!=-1)
            return dp[i][j][k];
        
        int c1= calc(i+1,j,k, a, b, bacteria),c2 = calc(i,j+1,k, a,b,bacteria),c3=0;
        int x=-1;
        
        if(a[i]==b[j]) {
          x = add(i,k,a,b,bacteria);
          if(x!=-1) c3 = calc(i+1,j+1,x, a, b, bacteria)+1;
          else c3 = -5;
        } 
        
        if(c1>=c2 && c1>=c3) 
            ans[i][j][k] = -2;
        else if(c2>=c1 && c2>=c3)
            ans[i][j][k] = -1;
        else ans[i][j][k] = x;
        
        return dp[i][j][k] = Math.max(c1,Math.max(c2,c3));
    }
    
    static int add(int i,int l, char [] a, char[] b, char[] bacteria) {
        while(l>0 && a[i]!=bacteria[l])
            l = f[l-1];
        if(a[i]==bacteria[l])
            l++;
        if(l==bacteria.length) {
            return -1;
        }
        return l;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}