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:
/*
     D    A    R    K    L      _                 _         O    R    D    D    A
         K                    / |                 | \        L    O    R         D
        A         R         _ / |                 | \ _       K    L         O    R
  D         A    R    K     _ / |         _       | \ _        L    O    R    D    D
      R    K    L       _ / _   |       _ | \\    |   _ \       O    R    D    D
     R         K        _ / _   |       _ | \ \   |   _ \        L    O    R
    D    A    R     _ / _ / |   /     /         \ \   | \ _ \ _        K    L    O
   D    D           _ / _ / |   /     /          \ \   | \ _ \ _             A
       K        _ / _ /     | /     /     _       \ \ |     \ _ \ _      L    O    R
 D    A        _ / _ /      | /     /     _       \ \ |      \ _ \ _      R         K
            _ / _ /         | |     |   |   \ (O) / | |         \ _ \ _         O
    D      _ / _ /          | |     |   |    \   /  | |          \ _ \ _         D
   A      / _ /     |   |   | \     |   \ _   \|/   / |   |   |     \ _ \
  K      / _ /      |   |   | \     |   \ _    V    / |   |   |      \ _ \         L
        / /         |   |   |   \ _ /       \ _ _ /   |   |   |         \ \
       / /          |   |   |                         |   | | |          \ \
      / /       |   | | \     \       ROWECHEN      /     / | |   |       \ \
     / /    _ _ |   | | \     \        ZHONG        /     / | |   | _ _    \ \
    / / _ /   \ | | | |   \ / \ \                 / / \ /   | | | | /   \ _ \ \
   / / _ /    \ | | | |       \ \                 / /       | | | | /    \ _ \ \
  / / /         \ \ \ \ /       /                 \       \ / / / /         \ \ \
 \ / /          \ \ \ \ /       /                 \       \ / / / /          \ \ /
  \|/             \|/         |         |         |           \|/             \|/
  L         O     \|/         |         |   |     |           \|/        R    D
 A    R    K    L             / _ |     |   | _     \      O    R    D    D    A    R
     L    O         R         / _ |     |   | _     \       D    D         A    R
    L    O    R    D        / / / _     | _ | | \ _   \      D    A    R         K
   O    R    D              / / / _ |   | _ | | \ _   \       D    A    R    K    L
  R    D    D    A    R     | / / | | / | | \ / | | \ |        K    L    O    R    D
 A         R         K      | / / | | / | | \ / | | \ |              L    O         R
     D    A         R         /   \ / | | | / | | / \ /     K    L         O    R
         D    D         A     /   \ / | | | / | | / \/            R    K    L    O
             R         D    D     / | / \ |   \ /        A    R    K    L    O    R
       D    A    R    K    L      / | / \ |    \/              O    R    D    D
 R    K    L    O    R    D       \ /     |      D    A    R         K    L    O    R
          D    A    R             \/      |            K    L    O    R    D    D

*/
//TEMPLATE V2
	import java.io.*;
	import java.util.*;

public class B346 {
    //Solution goes below: ------------------------------------
    static int LPS (String pat, int n){
        int len = 0;
        int i = 1;
        int[] lps = new int[n];
        while (i < n) {
            if (pat.charAt(i) == pat.charAt(len)) lps[i++] = ++len;
            else if (len == 0) lps[i++] = len;
            else len = lps[len - 1];
        }
        return lps[n-1];
    }

    public void solution() throws IOException{
//        String test = "ABABA";
//        System.out.println(LPS(test, test.length()));

        char[] s1 = nextLine().toCharArray();
        char[] s2 = nextLine().toCharArray();
        String virus = nextLine();
        char[] v = virus.toCharArray();

        int n1 = s1.length,n2 = s2.length,n3 = v.length;
        String[][][] res = new String[n1+1][n2+1][n3+1];
        for(int i=0;i<=n1;i++) res[i][0][0] = "";
        for(int j=0;j<=n2;j++) res[0][j][0] = "";
        for(int i=1;i<=n1;i++){
            for(int j=1;j<=n2;j++){
                for(int k=0;k<n3;k++){
                    int a = (res[i-1][j][k] ==null)? Integer.MIN_VALUE : res[i-1][j][k].length();
                    int b = (res[i][j-1][k] ==null)? Integer.MIN_VALUE : res[i][j-1][k].length();
                    if(a>b) res[i][j][k] = res[i-1][j][k];
                    else res[i][j][k] = res[i][j-1][k];
                }
                if(s1[i-1]!=s2[j-1]) continue;
                for(int k=0;k<n3;k++){
                    if(res[i-1][j-1][k] == null) continue;
                    String x = res[i-1][j-1][k] + s1[i-1];
                    if(v[k] == s1[i-1]){
                        if(res[i][j][k+1] ==null || res[i][j][k+1].length() < x.length()){
                            res[i][j][k+1] = x;
                        }
                    }else{
                        String pat = virus +"$"+ x;
//                        System.out.println(pat);
                        int lps = LPS(pat, pat.length());
                        if(res[i][j][lps] ==null || res[i][j][lps].length() < x.length()){
                            res[i][j][lps] = x;
//                        dp[i][j][0] = Math.max(dp[i][j][0], dp[i-1][j-1][k]+1);
                        }
                    }
                }

            }
        }
        int max=0;
        String rres = "0";
        for(int k=0; k<n3;k++){
            if(res[n1][n2][k] == null) continue;
            if(res[n1][n2][k].length() > max){
                max = res[n1][n2][k].length();
                rres = res[n1][n2][k];
            }
        }
        System.out.println(rres);


    }

    //Solution goes above: ------------------------------------
    public static final String IN_FILE = "";
    public static final String OUT_FILE = "";
    //-------------------- ------------------------------------
    //IO
    public static BufferedReader br;
    public static StringTokenizer st;
    public static BufferedWriter bw;
    public static void main(String[] args) throws IOException{
        if(IN_FILE==""){
            br = new BufferedReader(new InputStreamReader(System.in));
        }else{
            try {
                br = new BufferedReader(new FileReader(IN_FILE));
            } catch (FileNotFoundException e) {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }
        if (OUT_FILE==""){
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }else{
            try {
                bw = new BufferedWriter (new FileWriter(OUT_FILE) );
            } catch (FileNotFoundException e) {
                bw = new BufferedWriter(new OutputStreamWriter(System.out));
            }
        }
        (new B346()).solution();
        bw.close();//Flushes too.
    }

    public static String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public static String nextLine() {
        st = null;
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    public static long nextLong() {
        return Long.parseLong(nextToken());
    }

    public static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    public static void println(Object s) throws IOException{
        bw.write(s.toString()+"\n");
    }

    public static void println() throws IOException{
        bw.newLine();
    }

    public static void print(Object s) throws IOException{
        bw.write(s.toString());
    }
    public static void flush() throws IOException{//Useful for debug
        bw.flush();
    }
    //Other
    public static class Arr<T> extends ArrayList<T> {} //I hate typing ArrayList
}