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
import javafx.util.*;

import javax.print.DocFlavor;
import java.io.*;
import java.util.*;
import java.util.zip.CheckedOutputStream;

import static java.lang.Math.*;
import static java.util.Arrays.*;


public class Main{


    void run(){
        Locale.setDefault(Locale.US);
        boolean my;
        try {
            my = System.getProperty("MY_LOCAL") != null;
        } catch (Exception e) {
            my = false;
        }
        try{
            err = System.err;
            if( my ){
                sc  = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//                sc  = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt")));
                out = new PrintWriter   (new FileWriter("output.txt"));
            }
            else {
                sc  = new FastScanner( new BufferedReader(new InputStreamReader(System.in)) );
                out = new PrintWriter( new OutputStreamWriter(System.out));
            }
//            out = new PrintWriter(new OutputStreamWriter(System.out));
        }catch(Exception e){
            MLE();
        }
        if( my )
            tBeg = System.currentTimeMillis();
        solve();
        if( my )
            err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        exit(0);
    }

    void exit( int val ){
        err.flush();
        out.flush();
        System.exit(val);
    }

    double tBeg;
    FastScanner sc;
    PrintWriter out;
    PrintStream err;

    class FastScanner{

        StringTokenizer st;
        BufferedReader br;

        FastScanner( BufferedReader _br ){
            br = _br;
        }

        String readLine(){
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        String next(){
            while( st==null || !st.hasMoreElements() )
                st = new StringTokenizer(readLine());
            return st.nextToken();
        }

        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
        double nextDouble(){ return Double.parseDouble(next()); }
    }

    void MLE(){
        int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];
    }

    void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//        }, "Lolka", 256_000_000L ).run();
    }

    ////////////////////////////////////////////////////////////////


    final int inf = (int)1e8;
    String s1, s2, virus;
    int[][][] dp;
    StringBuilder ans;
    int[] suf;
    int[][] go;

    void solve(){
        s1 = sc.next();
        s2 = sc.next();
        virus = sc.next();

        dp  = new int[s1.length()][s2.length()][virus.length()];
        for (int[][] a : dp)
        for (int[] b : a)
            fill( b, -1 );

        suf = new int[virus.length()];
        fill( suf, -1 );
        for (int i = 1; i < virus.length(); i++) {
            int p = suf[i-1];
            while( p !=-1 && virus.charAt(p+1) != virus.charAt(i) )
                p = suf[p];
            if( virus.charAt(p+1) == virus.charAt(i) )
                suf[i] = p + 1;
        }

        go = new int[virus.length()][255];
        for (int[] v : go) fill( v, inf );
        for (int i = 0; i < virus.length(); i++)
        for (int ch = 0; ch < go[i].length; ch++)
                go[i][ch] = go(i,ch);

        err.println( "getDp(0,0,0): " + getDp(0,0,0) );
        if( getDp(0,0,0) == 0 )
            out.println( "0" );
        else{
            f(0,0,0);
            out.println();
        }
    }

    private int go(int i, int ch) {
//        err.printf( "%d %c: \n", i, (char)ch );
        if( i+1 < virus.length() && virus.charAt(i+1) == ch )
            return i + 1;
        if( i == -1 ) return -1;
        if( go[i][ch] != inf ) return go[i][ch];
        return go[i][ch] = go(suf[i],ch);
    }

    private int getDp(int i, int j, int k) {
        if( k == virus.length() ) return -inf;
        if( s1.length() <= i ) return 0;
        if( s2.length() <= j ) return 0;

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

        int ans = 0;
        ans = max( ans, getDp(i + 1, j, k));
        ans = max( ans, getDp(i,j+1,k) );
        if( s1.charAt(i) == s2.charAt(j) ){
            int newK;
            if( k == 0 )
                newK = virus.charAt(0) == s1.charAt(i)? 0:-1;
            else
                newK = go[k-1][s1.charAt(i)];
            ++newK;
            ans = max( ans, getDp(i+1,j+1,newK) + 1 );
        }
        return dp[i][j][k] = ans;
    }


    private void f(int i, int j, int k) {
        err.printf( "%d %d %d\n", i,j,k );
        if( s1.length() <= i ) return ;
        if( s2.length() <= j ) return ;
        if( k == virus.length() ) MLE();

        int ans = getDp(i,j,k);
        if( ans == getDp(i + 1, j, k) ){
            f( i+1, j, k );
            return;
        }
        if( ans == getDp(i, j + 1, k) ){
            f( i, j+1, k );
            return;
        }
        if( s1.charAt(i) == s2.charAt(j) ){
            int newK;
            if( k == 0 )
                newK = virus.charAt(0) == s1.charAt(i)? 0:-1;
            else
                newK = go[k-1][s1.charAt(i)];
            ++newK;
            ans = max( ans, getDp(i+1,j+1,newK) + 1 );
            if( ans == getDp(i+1,j+1,newK) + 1 ){
                out.print( s1.charAt(i) );
                f(i+1,j+1,newK);
                return;
            }
        }
        MLE();
    }

}
