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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Main {

    IIO io;

    Main(IIO io) {
        this.io = io;
    }

    public static void main(String[] args) throws IOException {

        Main m = new Main(new ConsoleIO());m.solve();

//        Tester test = new Tester();test.run();
    }


    class State{
        public State(int i,int j,int k,int size, boolean take){
            this.i = i;
            this.j = j;
            this.k = k;
            this.size = size;
            this.take = take;
        }
        public int i;
        public int j;
        public int k;
        public int size;
        public boolean take;
    }

    public void solve() {
        char[] a = io.readLine().toCharArray();
        char[] b = io.readLine().toCharArray();
        char[] v = io.readLine().toCharArray();
        int an = a.length;
        int bn = b.length;
        int vn = v.length;
        State[][][] dp = new State[an + 1][][];
        for (int i = 0; i <= an; i++) {
            dp[i] = new State[bn + 1][];
            for (int j = 0; j <= bn; j++)
                dp[i][j] = new State[vn + 1];
        }
        int[][] map = new int[vn + 1][];
        for (int i = 0; i <= vn; i++) {
            map[i] = new int[26];
        }

        for (int i = 0; i < vn; i++) {
            for (int c = 0; c < 26; c++) {
                if (v[i] - 'A' == c)
                    map[i][c] = i + 1;
                else {
                    int j = i - 1;
                    for (; j >= -1; j--) {
                        boolean good = true;
                        if (v[j + 1] - 'A' == c) {
                            for (int k = j; k >= 0; k--) {
                                if (v[k] != v[i - 1 - j + k]) {
                                    good = false;
                                    break;
                                }
                            }
                        } else good = false;
                        if (good) break;
                    }
                    map[i][c] = j + 2;
                }
            }
        }

        for (int i = 0; i <= an; i++)
            dp[i][0][0] = new State(-1, -1, -1, 0, false);

        for (int i = 0; i <= bn; i++)
            dp[0][i][0] = new State(-1, -1, -1, 0, false);

        for (int i = 1; i <= an; i++) {
            for (int j = 1; j <= bn; j++) {
                int ac = a[i - 1];
                int bc = b[j - 1];
                for (int k = 0; k < vn; k++) {
                    State s1 = dp[i - 1][j][k];
                    State s2 = dp[i][j - 1][k];
                    State s3 = dp[i][j][k];
                    if (s2 != null && (s3 == null || s2.size > s3.size)) {
                        s3 = new State(i, j - 1, k, s2.size, false);
                    }
                    if (s1 != null && (s3 == null || s1.size > s3.size)) {
                        s3 = new State(i - 1, j, k, s1.size, false);
                    }
                    dp[i][j][k] = s3;

                    if (ac == bc) {
                        State s4 = dp[i - 1][j - 1][k];
                        if (s4 != null) {
                            int next = map[k][ac - 'A'];
                            State s5 = dp[i][j][next];
                            if (s5 == null || s5.size < s4.size + 1) {
                                dp[i][j][next] = new State(i - 1, j - 1, k, s4.size + 1, true);
                            }
                        }
                    }
                }
            }
        }

        State best = null;
        int bestI = -1;
        int bestJ = -1;
        int bestK = -1;
        for (int i = 0; i < vn; i++) {
            State s = dp[an][bn][i];
            if (s != null && (best == null || s.size > best.size)) {
                best = s;
                bestI = an;
                bestJ = bn;
                bestK = i;
            }
        }
        if (best == null || best.size == 0) {
            io.writeLine("0");
            return;
        }
        char[] res = new char[best.size];
        boolean take = best.take;
        for (int q = best.size - 1; bestI > 0 && bestJ > 0; ) {

            best = dp[bestI][bestJ][bestK];
            if (best.take)
                res[q--] = a[bestI - 1];
            bestI = best.i;
            bestJ = best.j;
            bestK = best.k;
        }

        io.writeLine(new String(res));
    }

}

class ConsoleIO extends BaseIO {
    BufferedReader br;

    public ConsoleIO(){
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public void writeLine(String s) {
        System.out.println(s);
    }

    public void writeInt(int a) {
        System.out.print(a);
        System.out.print(' ');
    }

    public String readLine() {
        try {
            return br.readLine();
        }
        catch (Exception ex){
            return "";
        }
    }
}
abstract class BaseIO implements IIO {

    public int readInt() {
        return Integer.parseInt(this.readLine());
    }

    public long readLong() {
        return Long.parseLong(this.readLine());
    }

    public int[] readIntArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Integer.parseInt(nums[i]);
        }
        return res;
    }

    public long[] readLongArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        long[] res = new long[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Long.parseLong(nums[i]);
        }
        return res;
    }
}
interface IIO {
    void writeLine(String s);
    void writeInt(int a);
    String readLine();
    int readInt();
    long readLong();
    int[] readIntArray();
    long[] readLongArray();
}