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 java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char s1[]=in.readString().toCharArray();
        char s2[]=in.readString().toCharArray();
        char pattern[]=in.readString().toCharArray();
        final int n1=s1.length, n2=s2.length, m=pattern.length;
        final int oo=Integer.MAX_VALUE/2;
        int pi[]=new int[m], q=-1;
        pi[0]=q;
        for( int i=1; i<m; i++ ) {
            while( q>=0 && pattern[i]!=pattern[q+1] ) q=pi[q];
            if( pattern[i]==pattern[q+1] ) {
                q++;
            }
            pi[i]=q;
        }
        int dyn[][][]=new int[n1+1][n2+1][m+1];
        int answer[][][]=new int[n1+1][n2+1][m+1];
        dyn[n1][n2][m]=-oo;
        for( int i=0; i<n1; i++ ) dyn[i][n2][m]=-oo;
        for( int j=0; j<n2; j++ ) dyn[n1][j][m]=-oo;
        for( int i=n1-1, a, b; i>=0; i-- ) {
            for( int j=n2-1; j>=0; j-- ) {
                dyn[i][j][m]=-oo;
                for (int k = 0; k < m; k++) {
                    dyn[i][j][k]=dyn[i+1][j+1][k];
                    answer[i][j][k]=0;
                    if( s1[i]==s2[j] ) {
                        q=k-1;
                        while( q>=0 && pattern[q+1]!=s1[i] ) q=pi[q];
                        if( pattern[q+1]==s1[i] ) q++;
                        if( 1+dyn[i+1][j+1][q+1]> dyn[i][j][k]) {
                            dyn[i][j][k]=1+dyn[i+1][j+1][q+1];
                            answer[i][j][k]=1;
                        }
                    } else {
                        a=dyn[i+1][j][k];
                        b=dyn[i][j+1][k];
                        if( a>dyn[i][j][k] ) {
                            dyn[i][j][k]=a;
                            answer[i][j][k]=2;
                        }
                        if( b>dyn[i][j][k] ) {
                            dyn[i][j][k]=b;
                            answer[i][j][k]=3;
                        }
                    }
                }
            }
        }
        if( dyn[0][0][0]==0 ) {
            out.printLine(0);
            return;
        }
        int i=0, j=0, k=0;
        while( i<n1 && j<n2 ) {
            if( answer[i][j][k]==0 ) {
                i++; j++;
            } else if( answer[i][j][k]==1 ) {
                q=k-1;
                while( q>=0 && pattern[q+1]!=s1[i] ) q=pi[q];
                if( pattern[q+1]==s1[i] ) q++;
                out.print( s1[i] );
                i++; j++; k=q+1;
            } else if( answer[i][j][k]==2 ) {
                i++;
            } else {
                j++;
            }

        }
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print( objects );
        writer.println();
    }

    public void close() {
        writer.close();
    }
}

