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.util.*;

import static java.lang.Math.*;


public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    String s1, s2, virus;
    int next[][];
    boolean used[][][];
    int ans[][][];

    int calcNext(int v, char ch) {
        if (virus.charAt(v) == ch)
            return v + 1;
        String s = virus.substring(0, v) + ch;
        int ans = 0;
        for (int i = 1; i < s.length(); i++) {
            if (s.substring(0, i).equals(s.substring(s.length() - i))) {
                ans = i;
            }
        }
        return ans;
    }

    int dp(int a, int b, int c) {
        if (c >= virus.length())
            return Integer.MIN_VALUE;
        if (a >= s1.length() || b >= s2.length())
            return 0;

        if (used[a][b][c])
            return ans[a][b][c];
        used[a][b][c] = true;

        int curr = 0;
        curr = max(curr, dp(a + 1, b, c));
        curr = max(curr, dp(a, b + 1, c));

        if (s1.charAt(a) == s2.charAt(b)) {
            curr = max(curr, 1 + dp(a + 1, b + 1, next[c][s1.charAt(a) - 'A']));
        }

        ans[a][b][c] = curr;
        return curr;
    }

    void vosst(int a, int b, int c) {
        if (a >= s1.length() || b >= s2.length() || c >= virus.length())
            return;

        int curr = 0;
        curr = max(curr, dp(a + 1, b, c));
        curr = max(curr, dp(a, b + 1, c));

        if (s1.charAt(a) == s2.charAt(b)) {
            curr = max(curr, 1 + dp(a + 1, b + 1, next[c][s1.charAt(a) - 'A']));
        }

        if (curr == dp(a + 1, b, c)) {
            vosst(a + 1, b, c);
        } else if (curr == dp(a, b + 1, c)) {
            vosst(a, b + 1, c);
        } else if (s1.charAt(a) == s2.charAt(b) && curr == 1 + dp(a + 1, b + 1, next[c][s1.charAt(a) - 'A'])) {
            out.print(s1.charAt(a));
            vosst(a + 1, b + 1, next[c][s1.charAt(a) - 'A']);
        }
    }

    public void solve() {
        s1 = in.next();
        s2 = in.next();
        virus = in.next();
        next = new int[virus.length()][26];

        for (int i = 0; i < virus.length(); i++) {
            for (char ch = 'A'; ch <= 'Z'; ch++) {
                next[i][ch - 'A'] = calcNext(i, ch);
            }
        }

        used = new boolean[s1.length()][s2.length()][virus.length()];
        ans = new int[s1.length()][s2.length()][virus.length()];

        int val = dp(0, 0, 0);
        if (val == 0)
            out.println(dp(0, 0, 0));
        vosst(0, 0, 0);
    }

    public void run() {
        if (FILE.equals("")) {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        } else {
            try {
                in = new FastScanner(new FileInputStream(FILE +
                        ".in"));
                out = new PrintWriter(new FileOutputStream(FILE +
                        ".out"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        solve();
        out.close();
    }

    public static void main(String[] args) {
        (new Main()).run();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

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

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

        public float nextFloat() {
            return Float.parseFloat(next());
        }
    }

    class Pair<A extends Comparable<A>, B extends Comparable<B>>
            implements Comparable<Pair<A, B>> {
        public A a;
        public B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair<A, B> o) {
            if (o == null || o.getClass() != getClass())
                return 1;
            int cmp = a.compareTo(o.a);
            if (cmp == 0)
                return b.compareTo(o.b);
            return cmp;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (a != null ? !a.equals(pair.a) : pair.a != null) return
                    false;
            return !(b != null ? !b.equals(pair.b) : pair.b != null);
        }
    }

    class PairInt extends Pair<Integer, Integer> {
        public PairInt(Integer u, Integer v) {
            super(u, v);
        }
    }

    class PairLong extends Pair<Long, Long> {
        public PairLong(Long u, Long v) {
            super(u, v);
        }
    }

}