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:
//package cf.train;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class PrB {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);

    long[] readLongs() throws IOException {
        String[] s = reader.readLine().split(" ");
        long[] longs = new long[s.length];
        for(int i = 0; i < longs.length; i++) {
            longs[i] = Long.parseLong(s[i]);
        }
        return longs;
    }

    int[] readInts() throws IOException {
        String[] s = reader.readLine().split(" ");
        int[] ints = new int[s.length];
        for(int i = 0; i < ints.length; i++) {
            ints[i] = Integer.parseInt(s[i]);
        }
        return ints;
    }

    int[] tt;
    int tx = 0;
    int readInt() throws IOException {
        if(tt == null || tx >= tt.length) {
            tt = readInts();
            tx = 0;
        }
        return tt[tx++];
    }

    int[][] buildAutomaton(char[] s) {
        int n = s.length;
        int[][] ret = new int[n][26];
        char[] t = new char[n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < 26; j++) {
                for(int k = 0; k < i; k++) {
                    t[k] = s[k];
                }
                t[i] = (char)('A' + j);
                for(int p = 0; p <= i; p++) {
                    boolean ok = true;
                    for(int r = 0; r + p <= i; r++) {
                        if(s[r] != t[p + r]) ok = false;
                    }
                    if(ok) {
                        ret[i][j] = i - p + 1;
                        break;
                    }
                }
            }
        }
        return ret;
    }

    void solve() throws IOException {
        char[] s1 = reader.readLine().toCharArray();
        char[] s2 = reader.readLine().toCharArray();
        char[] virus = reader.readLine().toCharArray();
        int[][] a = buildAutomaton(virus);
        int[][][] dp = new int[s1.length + 1][s2.length + 1][virus.length];
        int[][][] pri = new int[s1.length + 1][s2.length + 1][virus.length];
        int[][][] prj = new int[s1.length + 1][s2.length + 1][virus.length];
        int[][][] prk = new int[s1.length + 1][s2.length + 1][virus.length];
        char[][][] letter = new char[s1.length + 1][s2.length + 1][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++) {
                    if(i + 1 <= s1.length && dp[i + 1][j][k] < dp[i][j][k]) {
                        dp[i + 1][j][k] = dp[i][j][k];
                        pri[i + 1][j][k] = i;
                        prj[i + 1][j][k] = j;
                        prk[i + 1][j][k] = k;
                    }
                    if(j + 1 <= s2.length && dp[i][j + 1][k] < dp[i][j][k]) {
                        dp[i][j + 1][k] = dp[i][j][k];
                        pri[i][j + 1][k] = i;
                        prj[i][j + 1][k] = j;
                        prk[i][j + 1][k] = k;
                    }
                    if(i < s1.length && j < s2.length && s1[i] == s2[j] && a[k][s1[i] - 'A'] != virus.length && dp[i + 1][j + 1][a[k][s1[i] - 'A']] < dp[i][j][k] + 1) {
                        dp[i + 1][j + 1][a[k][s1[i] - 'A']] = dp[i][j][k] + 1;
                        pri[i + 1][j + 1][a[k][s1[i] - 'A']] = i;
                        prj[i + 1][j + 1][a[k][s1[i] - 'A']] = j;
                        prk[i + 1][j + 1][a[k][s1[i] - 'A']] = k;
                        letter[i + 1][j + 1][a[k][s1[i] - 'A']] = s1[i];
                    }
                }
            }
        }
        int opti = 0;
        for(int i = 0; i < virus.length; i++) {
            if(dp[s1.length][s2.length][i] > dp[s1.length][s2.length][opti]) opti = i;
        }
        if(dp[s1.length][s2.length][opti] == 0) {
            writer.println(0);
        }
        else {
            int x = s1.length;
            int y = s2.length;
            int z = opti;
            StringBuffer ans = new StringBuffer();
            while(dp[x][y][z] > 0) {
                if(letter[x][y][z] > 0) ans.append(letter[x][y][z]);
                int newx = pri[x][y][z];
                int newy = prj[x][y][z];
                int newz = prk[x][y][z];
                x = newx;
                y = newy;
                z = newz;
            }
            writer.println(ans.reverse());
        }
        writer.flush();
    }

    public static void main(String[] args) throws IOException {
        new PrB().solve();
    }
}