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

public class problem5_1 {
	
    static int n1,n2,m;
    static char [] a,b,virus;
    static int [] f;
    static int [][][] dp,ans;
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                               //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;
        
        a = in.readLine().toCharArray();
        b = in.readLine().toCharArray();
        virus = in.readLine().toCharArray();
        n1 = a.length;
        n2 = b.length;
        m = virus.length;
        
        fail();
        
        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);
        
        if(res==0) System.out.println("0");
        else System.out.println(buildSol(0,0,0));
    }
        
    static String buildSol(int i,int j,int k) {
        //System.out.println(i+" , "+j+" , "+k);
        if(i==n1 || j==n2)
            return "";
        
        if(ans[i][j][k]==-2)  return buildSol(i+1,j,k);
        else if(ans[i][j][k]==-1) return buildSol(i,j+1,k);
        
        return a[i]+buildSol(i+1,j+1,ans[i][j][k]);
    }
    
    static int calc(int i,int j,int k) {
        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),c2 = calc(i,j+1,k),c3=0;
        int x=-1;
        
        if(a[i]==b[j]) {
          x = add(i,k);
          if(x!=-1) c3 = calc(i+1,j+1,x)+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) {
        while(l>0 && a[i]!=virus[l])
            l = f[l-1];
        if(a[i]==virus[l])
            l++;
        if(l==virus.length) {
            return -1;
        }
        return l;
    }
    
    static void fail() {
        f = new int[m];
        int l = 0;
        for(int i=1; i<m; i++) {
            while(l>0 && virus[i]!=virus[l])
                l = f[l-1];
            if(virus[i]==virus[l])
                l++;
            f[i] = l;
        }
    }
}