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.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    static char [] s,t,virus;
    static int [][][] dp;
    static int [][][] choice;
    static StringBuilder sol;
    static int [] p;
    
    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;
        
        s = in.readLine().toCharArray();
        t = in.readLine().toCharArray();
        virus = in.readLine().toCharArray();
        
        dp = new int[s.length+1][t.length+1][virus.length+1];
        choice = new int[s.length+1][t.length+1][virus.length+1];
        sol = new StringBuilder();
        
        for(int i=0; i<=s.length; i++)
            for(int j=0; j<=t.length; j++)
                Arrays.fill(dp[i][j],-1);

        p = new int[virus.length];
        for(int i=1,k=0; i<virus.length; i++) {
            while(k>0 && virus[k]!=virus[i])
                k = p[k-1];
            if(virus[k]==virus[i])
                p[i] = ++k;
            else p[i] = k;
        }

        int v = calc(0,0,0);

        if(v==0) {
            System.out.println("0");
            return;
        }

        findSol(0,0,0);

        System.out.println(sol);
    }

    static int calc(int i,int j,int k) {
        if(k==virus.length) 
            return -(int)1e9;
        if(i==s.length || j==t.length)
            return 0;

        if(dp[i][j][k]!=-1)
            return dp[i][j][k];

        int c3 = 0;

        if(s[i]==t[j] && !(s[i]==virus[k] && k==virus.length-1)) {
            boolean f = (virus[k]!=s[i] && k>0);
            int nk = (virus[k]==s[i] ? k+1 : (k>0 ? p[k-1] : 0));
            if(f && virus[nk]==s[i]) nk++;
            else if(f) nk = 0;

            c3 = calc(i+1,j+1,nk) + 1;
        }
        
        if(s[i]==t[j] && s[i]==virus[k] && k==virus.length-1) c3 = -(int)1e9;
        
        int c1 = calc(i+1,j,k),c2 = calc(i,j+1,k);
        int mx = max(c3,max(c1,c2));
        choice[i][j][k] = (c1==mx ? 1 : (c2==mx ? 2 : 0));
        
        return dp[i][j][k] = max(c3,max(c1,c2));
    }
    
    static void findSol(int i,int j,int k) {
        if(k==virus.length || i==s.length || j==t.length)
            return;
        
        if(choice[i][j][k]==0) {
            sol.append(s[i]);
            
         //   System.out.println(i+" , "+j+" "+s[i]+" - "+t[j]);
            boolean f = (virus[k]!=s[i] && k>0 ? true : false);
            int nk = (virus[k]==s[i] ? k+1 : (k>0 ? p[k-1] : 0));
            if(f && virus[nk]==s[i]) nk++;
            else if(f) nk = 0;
            
            findSol(i+1,j+1,nk);
            return;
        } 
        
        if(choice[i][j][k]==1) {
            findSol(i+1,j,k);
            return;
        }
        
        if(choice[i][j][k]==2) {
            findSol(i,j+1,k);
            return;
        }
    }
}