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:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dipankar12
 */
import java.io.*;
import java.util.*;
public class r201b {
    static String s1,s2,virus;
    static int lps[];
    static String dp[][][];
    void callps(String virus)
    {
        int n=virus.length();
        int i=1,j=0;
        while(i<n)
        {
            if(virus.charAt(i)==virus.charAt(j))
            {
                lps[i]=j+1;
                i++;
                j++;
            }
            if(i<n&&virus.charAt(i)!=virus.charAt(j))
            {
                if(j==0)
                {
                    lps[i]=0;
                    i++;
                }
                else
                    j=lps[j-1];
            }
        }
    }
    public StringBuilder rec(int i,int j,int pos){
		if(i>=s1.length() || j >= s2.length() || pos >= virus.length())
			return new StringBuilder("");

		if(!dp[i][j][pos].equals("0"))
			return new StringBuilder(dp[i][j][pos]);

		StringBuilder ans1 = new StringBuilder("");
		StringBuilder ans2 = new StringBuilder("");

		if(s1.charAt(i) == s2.charAt(j)){
			if(s1.charAt(i) == virus.charAt(pos)){
				if(pos == virus.length()-1){
					ans1 = rec(i+1,j+1,pos);
				}
				else{
					ans1 = rec(i+1,j+1,pos+1).append(s1.charAt(i));
					ans2 = rec(i+1,j+1,pos);
				}	
			}
			else{
				// if(pos != 0)
				// System.out.println(pos+" "+lps[pos-1]);
				if(pos == 0)
					ans1 = rec(i+1,j+1,0).append(s1.charAt(i));
				else{
					if(virus.charAt(lps[pos-1]) == s1.charAt(i)){
						//System.out.println("baal");
						ans1 = rec(i+1,j+1,lps[pos-1]+1).append(s1.charAt(i));
					}
					else ans1 = rec(i+1,j+1,0).append(s1.charAt(i));
				}
				ans2 = rec(i+1,j+1,pos);
			}
		}
		else{
			ans1 = rec(i,j+1,pos);
			ans2 = rec(i+1,j,pos);
		}
		if(ans1.length() > 	ans2.length()){
			dp[i][j][pos] = ans1.toString();
			return ans1;
		}
		else{
			dp[i][j][pos] = ans2.toString();
			return ans2;
		}
	}
    public static void main(String args[])
    {
        fastio in=new fastio(System.in);
        PrintWriter pw=new PrintWriter(System.out);

         s1=in.readString();
         s2=in.readString();
         virus=in.readString();
        
         lps=new int[virus.length()];
         r201b ob=new r201b();
         ob.callps(virus);
         dp=new String[s1.length()][s2.length()][virus.length()];
         
         for(int i=0;i<s1.length();i++)
             for(int j=0;j<s2.length();j++)
                 for(int k=0;k<virus.length();k++)
                     dp[i][j][k]="0";
         
         String x=ob.rec(0, 0, 0).reverse().toString();
         
         if(x.length()==0)
             pw.println(0);
         else
             pw.println(x);
        pw.close();
    }

    static class fastio {
     
            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int cchar, snchar;
            private SpaceCharFilter filter;
     
            public fastio(InputStream stream) {
                this.stream = stream;
            }
     
            public int nxt() {
                if (snchar == -1)
                    throw new InputMismatchException();
                if (cchar >= snchar) {
                    cchar = 0;
                    try {
                        snchar = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snchar <= 0)
                        return -1;
                }
                return buf[cchar++];
            }
     
            public int nextInt() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
     
            public long nextLong() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = nxt();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = nxt();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
     
            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }
     
            public String readString() {
                int c = nxt();
                while (isSpaceChar(c)) {
                    c = nxt();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isSpaceChar(c));
                return res.toString();
            }
     
            public String nextLine() {
                int c = nxt();
                while (isSpaceChar(c))
                    c = nxt();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = nxt();
                } while (!isEndOfLine(c));
                return res.toString();
            }
     
            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
     
            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }
     
            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
    

}