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

public class LuckyCommonSubsequence {

    static String s1;
    static String s2;
    static String s3;
    static int dp[][][];

    static int lcs(int i, int j, int k) {
        if (i == s1.length() || j == s2.length())
            return 0;
        if (dp[i][j][k] != -1)
            return dp[i][j][k];

        if (s1.charAt(i) == s2.charAt(j)) {
            if (s1.charAt(i) == s3.charAt(k) && k == s3.length() - 1)
                return dp[i][j][k] = max(lcs(i, j + 1, k), lcs(i + 1, j, k));
            if (s1.charAt(i) == s3.charAt(k) && k < s3.length() - 1)
                return dp[i][j][k] = max(1 + lcs(i + 1, j + 1, k + 1), max(lcs(i, j + 1, k), lcs(i + 1, j, k)));
            else
                return dp[i][j][k] = 1 + lcs(i + 1, j + 1, (s1.charAt(i) == s3.charAt(0)) ? 1 : 0);
        }
        return dp[i][j][k] = Math.max(lcs(i + 1, j, k), lcs(i, j + 1, k));
    }
    
    static StringBuilder sb = new StringBuilder();
    
    static void path(int i, int j, int k) {
        if (i == s1.length() || j == s2.length())
            return;
        
        
        if (s1.charAt(i) == s2.charAt(j)) {
            if (s1.charAt(i) == s3.charAt(k) && k > s3.length() - 2)
                if (dp[i][j][k] == lcs(i, j + 1, k)) {
                    path(i, j + 1, k);
                    return ;
                } else {
                    path(i + 1, j, k);
                    return ;
                }
             if (s1.charAt(i) == s3.charAt(k) && k <= s3.length() - 2) {
                int c = dp[i][j][k];
                if (c == 1 + lcs(i+1, j +1, k +1)) {
                    sb.append(s1.charAt(i));
                    path(i+1, j +1, k +1);
                    return ;
                } else if (c == lcs(i,j+1, k)) {
                    path(i,j+1, k);
                    return ;
                } else {
                    path(i + 1, j, k);
                    return ;
                }
//                return dp[i][j][k] = max(1 + lcs(i + 1, j + 1, k + 1), max(lcs(i, j + 1, k), lcs(i + 1, j, k)));
            } else {
                sb.append(s1.charAt(i));
                path(i + 1, j + 1, (s1.charAt(i) == s3.charAt(0)) ? 1 : 0);
//                return dp[i][j][k] = 1 + lcs(i + 1, j + 1, (s1.charAt(i) == s3.charAt(0)) ? 1 : 0);
                return ;
            }
        }
        int c = dp[i][j][k];
        if (c == lcs(i+1, j , k)) {
            path(i+1, j , k);
        } else {
            path(i, j+1 , k);
        }
//        return dp[i][j][k] = Math.max(lcs(i + 1, j, k), lcs(i, j + 1, k));
    }
//
//    static void pr(int i, int j) {
//        if (i == s1.length() || j == s2.length()) {
//            return;
//        }
//
//        if (s1.charAt(i) == s2.charAt(j)) {
//            out.append(s1.charAt(i));
//            pr(i + 1, j + 1);
//        } else if (lcs(i + 1, j) > lcs(i, j + 1)) {
//            pr(i + 1, j);
//        } else {
//            pr(i, j + 1);
//        }
//    }
//    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        s1 = in.next();
        s2 = in.next();
        s3 = in.next();
        dp = new int[s1.length()][s2.length()][s3.length()];
        for (int i = 0; i < s1.length(); i++) {
            for (int j = 0; j < s2.length(); j++) {
                for (int k = 0; k < s3.length(); k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
       lcs(0, 0, 0);
        path(0, 0, 0);
        int s =sb.indexOf(s3);
        if (s>0) {
            sb.deleteCharAt(s);
        }
        System.out.println(sb.length() == 0 ? "0": sb);
//        System.out.println(lcs(0, 0, 0));
//        pr(0, 0);
//        if (out.length() == 0) {
//            System.out.println("0");
//        } else {
//            System.out.println(out);
//        }
    }
}