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 static java.lang.Math.* ;
import static java.util.Arrays.* ;

import java.util.*;
import java.io.*;

public class C
{
    char [] s1 , s2 , virus ;
    int n , m , k ;
    final int INF = 1 << 30 ;
    int memo [][][] ;
    StringBuilder sb = new StringBuilder() ;
    int [] failure ;
    void preprocess()
    {
        failure = new int [k + 1] ;
        for(int i = 1 , j = 0; i < k ; i ++)
        {
            while(j > 0 && virus[i] != virus[j]) j = failure[j - 1] ;
            if(virus[i] == virus[j]) j++ ;
            failure[i] = j ;
        }
    }
    int dp(int i , int j , int l)
    {
        if(l == k)
            return -INF ;
        if(i == n && j == m)
            return 0 ;

        if(memo[i][j][l] != -1)
            return memo[i][j][l] ;

        int ans =  -INF ;

        if(i < n && j < m && s1[i] == s2[j])
        {
            int nxt = l ;
            while(nxt > 0 && virus[nxt] != s1[i])nxt = failure[nxt - 1] ;
            if(s1[i] == virus[nxt])
                ans = max(ans , 1 + dp(i + 1 , j + 1 , nxt + 1)) ;
            else
                ans = max(ans , 1 + dp(i + 1 , j + 1 , nxt)) ;
        }
        if (i < n)
           ans = max(ans, dp(i + 1, j, l));

        if (j < m)
            ans = max(ans, dp(i, j + 1, l));

        return memo[i][j][l] = ans ;
    }
    void print(int i , int j , int l)
    {
        if(l == m)
            return;
        if(i == n && j == m)
            return;
        int ans = dp(i , j , l) ;
        if(i < n && j < m && s1[i] == s2[j])
        {
            int nxt = l ;
            while(nxt > 0 && virus[nxt] != s1[i])nxt = failure[nxt - 1] ;
            if(s1[i] == virus[nxt] && ans == 1 + dp(i + 1 , j + 1 , nxt + 1))
            {
                sb.append(s1[i]) ;
                print(i + 1 , j + 1 , nxt + 1);
                return;
            }
            else if(ans == 1 + dp(i + 1 , j + 1 , nxt))
            {
                sb.append(s1[i]) ;
                print(i + 1 , j + 1 , nxt);
                return;
            }
        }
        if (i < n)
        {
            if(ans == dp(i + 1 , j , l))
            {
                print(i + 1 , j , l);
                return;
            }
        }
        if (j < m) {
            if(ans == dp(i  , j , l))
            {
                print(i  , j + 1 , l);

            }
        }


    }
    void main() throws Exception
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        s1 = sc.next().toCharArray() ;
        s2 = sc.next().toCharArray() ;
        virus = sc.next().toCharArray() ;
        n = s1.length ;
        m = s2.length ;
        k = virus.length ;
        memo = new int[n + 1][m + 1][k + 1] ;
        for(int [][] x : memo)
            for(int [] y : x)
                fill(y , -1);
        preprocess();
        if(dp(0 , 0  , 0) == 0)
            out.print(0);
        else {
            print(0, 0, 0);
            out.println(sb);
        }
        out.flush();
        out.close();

    }
    public static void main (String [] args) throws Exception
    {
        new C().main() ;
    }
    class Scanner
    {
        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream in)
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws Exception
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws Exception { return Integer.parseInt(next()); }

        long nextLong() throws Exception { return Long.parseLong(next()); }

        double nextDouble() throws Exception { return Double.parseDouble(next());}
    }
}