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
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {
    static final int UNCALC = -1;
    static final int INF = (int) 1e9;
    static int memo[][][], dfa[][];
    static char[] s1, s2, virus;
    static StringBuilder ans;


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        s1 = sc.next().toCharArray();
        s2 = sc.next().toCharArray();
        virus = sc.next().toCharArray();
        dfa = new int[26][virus.length];
        int[] pi = prefixFunction(virus);
        dfa[virus[0] - 'A'][0] = 1;
        for (int i = 1; i < virus.length; i++) {
            dfa[virus[pi[i - 1]] - 'A'][i] = pi[i - 1] + 1;
            dfa[virus[i] - 'A'][i] = i + 1;
        }
        memo = new int[virus.length][s1.length][s2.length];
        for (int[][] a : memo)
            for (int[] b : a)
                Arrays.fill(b, UNCALC);
        ans = new StringBuilder();
        if (dp(0, 0, 0) == 0) out.println(0);
        else {
            trace(0, 0, 0);
            out.println(ans);
        }
        out.flush();
        out.close();
    }

    static int[] prefixFunction(char[] s) {
        int n = s.length;
        int[] pi = new int[n];
        for (int i = 1, j = 0; i < n; i++) {
            while (j > 0 && s[i] != s[j])
                j = pi[j - 1];
            if (s[i] == s[j])
                j++;
            pi[i] = j;
        }
        return pi;
    }

    static void trace(int v, int i, int j) {
        if (i == s1.length || j == s2.length) return;
        int best = dp(v, i, j);
        if (dp(v, i + 1, j) == best) {
            trace(v, i + 1, j);
            return;
        }
        if (dp(v, i, j + 1) == best) {
            trace(v, i, j + 1);
            return;
        }
        if (s1[i] == s2[j] && best == 1 + dp(dfa[s1[i] - 'A'][v], i + 1, j + 1)) {
            ans.append(s1[i]);
            trace(dfa[s1[i] - 'A'][v], i + 1, j + 1);
            return;
        }
    }

    static int dp(int v, int i, int j) {
        if (v == virus.length) return -INF;
        if (i == s1.length || j == s2.length) return 0;
        if (memo[v][i][j] != UNCALC) return memo[v][i][j];
        int max = Math.max(dp(v, i + 1, j), dp(v, i, j + 1));
        if (s1[i] == s2[j]) max = Math.max(1 + dp(dfa[s1[i] - 'A'][v], i + 1, j + 1), max);
        return memo[v][i][j] = max;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }


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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }


        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}