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.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Queue;
import java.util.LinkedList;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Ankit Srivastava
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InReader in = new InReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    AhoCorasickDataStructure ds;
    int [][][] dp;
    String s1, s2;

    int go(int i, int j, int state) {
        if(dp[i][j][state] == -1) {
            dp[i][j][state] = -100000;
            if(!ds.found[state]) {
                if(i >= s1.length() || j >= s2.length()) dp[i][j][state] = 0;
                else {
                    dp[i][j][state] = Math.max(go(i + 1, j, state), go(i, j + 1, state));
                    if(s1.charAt(i) == s2.charAt(j))
                        dp[i][j][state] = Math.max(dp[i][j][state], go(i + 1, j + 1, ds.trans[state][s1.charAt(i)- 'A']) + 1);
                }
            }
        }
        return dp[i][j][state];
    }

    public void solve(int testNumber, InReader in, OutputWriter out) {
        s1 = in.readString();
        s2 = in.readString();
        String virus = in.readString();
        ds = new AhoCorasickDataStructure(26, 'A');
        ds.add(virus, 0);
        ds.bfs();
        ds.makeTrans();
        dp = new int[s1.length() + 1][s2.length() + 1][virus.length() + 1];
        ArrayUtils.fill3d(dp, -1);

        /*for (int i = 0; i <= s1.length(); i++) {
            for (int j = 0; j <= s2.length(); j++) {
                for (int state = 0; state < virus.length(); state++) {
                    if(i == 0 || j == 0 || ds.found[state]) {
                        dp[i][j][state] = 0;
                        continue;
                    }
                    dp[i][j][state] = Math.max(Math.max(dp[i - 1][j][state], dp[i][j - 1][state]), dp[i][j][state]);
                    if(s1.charAt(i - 1) == s2.charAt(j - 1) && ds.trans[state][s1.charAt(i - 1) - 'A'] != virus.length()) {
                        dp[i][j][ds.trans[state][s1.charAt(i - 1) - 'A']] = Math.max(dp[i - 1][j - 1][state] + 1, dp[i][j][ds.trans[state][s1.charAt(i - 1) - 'A']]);
                        //System.out.println("updated " + i + "  "+ j + "  "+ state + " changed to " + dp[i][j][ds.trans[state][s1.charAt(i - 1) - 'A']]);
                    }
                }
            }
        }
        for (int i = 0; i < s1.length() + 1; i++) {
            System.out.println(Arrays.deepToString(dp[i]));
        } */
        int i = 0, j = 0, state = 0;
        ArrayList<Character> ans = new ArrayList<Character>();
        while (i < s1.length() && j < s2.length()) {
            if(go(i, j, state) == go(i + 1, j ,state)) i++;
            else if(go(i, j, state) == go(i, j + 1, state)) j++;
            else {
                ans.add(s1.charAt(i));
                state = ds.trans[state][s1.charAt(i) - 'A'];
                i++;
                j++;
            }
        }
        if(ans.size() == 0) out.printLine(0);
        else for(char c : ans) out.print(c);

        //System.out.println(dp[s1.length()][s2.length()]);
    }
}

class AhoCorasickDataStructure {
    public int[][] trans;
    Node root;
    int stateCount;
    public boolean[] found;
    int alphabetSize;
    char zero;
    public int[] counts;
    int strCount;
    Node[] getNode;

    public AhoCorasickDataStructure(int size, char zero) {
        this.alphabetSize = size;
        this.zero = zero;
        root = new Node(' ');
        strCount = 0;
    }

    public void add(String s, int id) {
        Node node = root;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int ind = c - zero;
            if (node.child[ind] == null) node.child[ind] = new Node(c);
            node.child[ind].parent = node;
            node = node.child[ind];
        }
        node.isEnd = true;
        node.endId = id;
        strCount++;
        //System.out.println("Add success");
    }

    public void bfs() {
        counts = new int[strCount];
        root.fall = root;
        Queue<Node> queue = new LinkedList<Node>();
        stateCount = 0;
        queue.offer(root);
        while (!queue.isEmpty()) {
            Node v = queue.poll();

            v.state = stateCount++;
            for (Node child : v.child)
                if (child != null) queue.offer(child);
            if (v == root) continue;
            Node fall = v.parent.fall;
            while (fall.child[v.c - zero] == null && fall != root) fall = fall.fall;
            v.fall = fall.child[v.c - zero];
            if (v.fall == null || v.fall == v) v.fall = root;
            else {
                Node temp = fall.child[v.c - zero];
                if(temp.isEnd) {
                    v.isEnd |= temp.isEnd;
                    //v.endId = temp.endId;
                }
            }
        }
        //System.out.println("bfs success");
    }

    public void makeTrans() {
        getNode = new Node[stateCount];
        trans = new int[stateCount][alphabetSize];
        found = new boolean[stateCount];
        Queue<Node> queue = new LinkedList<Node>();
        queue.offer(root);
        while(!queue.isEmpty()) {
            Node v = queue.poll();
            getNode[v.state] = v;
            if(v.isEnd) found[v.state] = true;
            for (int i = 0; i < v.child.length; i++) {
                Node node = v;
                if(v.child[i] != null) queue.offer(v.child[i]);
                while(node.child[i] == null && node != root) node = node.fall;
                if(node.child[i] != null) {
                    trans[v.state][i] = node.child[i].state;
                }
                else trans[v.state][i] = root.state;
            }
        }


    }



    class Node {
        char c;
        Node[] child;
        boolean isEnd;
        Node parent;
        Node fall;
        int state;
        int endId;

        Node(char c) {
            this.c = c;
            child = new Node[alphabetSize];
            isEnd = false;
            parent = null;
            fall = null;
            endId = -1;
        }
    }
}

class InReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}


    public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

}

class ArrayUtils {

	public static void fill2d(int [][] array, int value) {
		for (int i = 0;i < array .length ;i++)
			Arrays.fill(array [i], value);
	}


	public static void fill3d(int [][][] array ,int value) {
		for(int i = 0;i < array .length ;i ++) {
			fill2d(array [i],value );
		}
	}

    }