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.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve() {
        char s1[]=ns().toCharArray();
        char s2[]=ns().toCharArray();
        s3=ns().toCharArray();
        int n1=s1.length,n2=s2.length,n3=s3.length;
        int dp[][][]=new int[n1+1][n2+1][n3+1];
        int prev[][][]=new int[n1+1][n2+1][n3+1];

        for(int i1=0;i1<=n1;i1++) for(int i2=0;i2<=n2;i2++) for(int i3=1;i3<=n3;i3++) dp[i1][i2][i3]=-1;
        for(int i1=0;i1<=n1;i1++) for(int i2=0;i2<=n2;i2++) for(int i3=1;i3<=n3;i3++) prev[i1][i2][i3]=-1;


        computeLPS();

        for(int i1=1;i1<=n1;i1++){
            for(int i2=1;i2<=n2;i2++){
                if(s1[i1-1]==s2[i2-1]){
                    for(int k=0;k<n3;k++){
                        if(k==0){
                            if(s1[i1-1]==s3[k]) {
                                if(k+1<n3 && dp[i1-1][i2-1][k]!=-1) {
                                    dp[i1][i2][k + 1] = 1 + dp[i1 - 1][i2 - 1][k];
                                    prev[i1][i2][k+1]=k;
                                }
                            }else {
                                if(dp[i1-1][i2-1][0]!=-1 && 1+dp[i1-1][i2-1][0]>dp[i1][i2][0]) {
                                    dp[i1][i2][0] = 1 + dp[i1 - 1][i2 - 1][0];
                                    prev[i1][i2][0]=0;
                                }
                            }
                        }else {
                            if(s1[i1-1]==s3[k]){
                                if(k+1<n3 && dp[i1-1][i2-1][k]!=-1 && 1+dp[i1-1][i2-1][k]>dp[i1][i2][k+1]) {
                                    dp[i1][i2][k + 1] = 1 + dp[i1 - 1][i2 - 1][k];
                                    prev[i1][i2][k+1]=k;
                                }
                            }else {
                                if(dp[i1-1][i2-1][k]!=-1) {
                                    int j=lps[k-1];
                                    while(j>0 && s1[i1-1]!=s3[j]) j=lps[j-1];
                                    if(s1[i1-1]==s3[j]) j++;
                                    if(j<n3 && 1+dp[i1-1][i2-1][k]>dp[i1][i2][j]) {
                                        dp[i1][i2][j] = 1 + dp[i1 - 1][i2 - 1][k];
                                        prev[i1][i2][j] = k;
                                    }
                                }
                            }
                        }
                    }
                }
                    for(int k=0;k<n3;k++) {
                        if(Math.max(dp[i1-1][i2][k],dp[i1][i2-1][k])>dp[i1][i2][k]) {
                            dp[i1][i2][k] = Math.max(dp[i1 - 1][i2][k], dp[i1][i2 - 1][k]);
                            prev[i1][i2][k] = k;
                        }
                    }


            }
        }
        int ans=0;
        for(int i3=0;i3<n3;i3++) ans=Math.max(ans,dp[n1][n2][i3]);
        if(ans==0){
            pw.println(0);
            return;
        }
        int i1=n1,i2=n2;
        int i3=0;
        Stack<Character> stk=new Stack();
        for(i3=0;i3<n3;i3++){
            if(ans==dp[n1][n2][i3]) break;
        }
        int l=ans;
      // System.out.println(ans+" "+i3+" "+dp[7][7][0]);

        while(i1>0 && i2>0 && l>0){
            // pw.println(i3);

            if(s1[i1-1]==s2[i2-1] && dp[i1][i2][i3]==1+dp[i1-1][i2-1][prev[i1][i2][i3]]){
          //      System.out.println(i1+" "+i2+" "+i3);
                l--;
                stk.push(s1[i1-1]);
                i3=prev[i1][i2][i3];
                i1--;
                i2--;
            }else {
                if(dp[i1][i2][i3]==dp[i1-1][i2][prev[i1][i2][i3]]){
                    i3=prev[i1][i2][i3];
                    i1--;

                }else {
                    i3=prev[i1][i2][i3];
                    i2--;
                }


            }
        }

        if(stk.size()==0)
            pw.println(0);
        else {
            while(!stk.isEmpty()) pw.print(stk.pop());
        }
    }
    char s3[];
    int lps[];
    void computeLPS(){
        int n=s3.length;
        lps=new int[n];
        for(int i=1;i<n;i++){
            int j=lps[i-1];
            while(j>0 && s3[i]!=s3[j]){
                j=lps[j-1];
            }
            if(s3[i]==s3[j]) j++;
            lps[i]=j;
        }
    }



    long M= (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }
    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }

}