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.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class b {
	static int memo[][][];
	static String a, b, v, answer;
	static AhoCorasick ac;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		a = in.next();
		b = in.next();
		v = in.next();
		answer = "";
		ac = new AhoCorasick();
		ac.createAhoCorasick(new String[] { v });
		memo = new int[a.length()][b.length()][ac.nodeCount];

		for (int c[][] : memo)
			for (int d[] : c)
				Arrays.fill(d, -1);
		int ans = go(0, 0, 0);
		rec(0, 0, 0);

		if (answer.length() == 0)
			answer = "0";
		System.out.println(answer);
	}

	private static class AhoCorasick {
		static final int ALPHA = 26;
		static int nodeCount, transition[][];
		static boolean[] term;

		static void createAhoCorasick(String[] strs) {
			int maxNodes = 1;
			for (String s : strs)
				maxNodes += s.length();

			int[][] children = new int[ALPHA][maxNodes];
			boolean[] leaf = new boolean[maxNodes];
			nodeCount = 1;
			for (String s : strs) {
				int node = 0;
				for (char ch : s.toCharArray()) {
					int c = ch - 'A';
					if (children[c][node] == 0)
						children[c][node] = nodeCount++;
					node = children[c][node];
				}
				leaf[node] = true;
			}

			transition = new int[ALPHA][nodeCount];
			term = new boolean[nodeCount];

			ArrayDeque<Integer> queue = new ArrayDeque<>();
			queue.add(0);
			queue.add(0);

			while (queue.size() > 0) {
				int node = queue.remove(), suffLink = queue.remove();

				term[node] = leaf[node] || term[suffLink];

				for (int ch = 0; ch < ALPHA; ch++) {
					if (children[ch][node] != 0) {
						transition[ch][node] = children[ch][node];
						queue.add(children[ch][node]);
						queue.add(node == 0 ? 0 : transition[ch][suffLink]);
					} else
						transition[ch][node] = transition[ch][suffLink];
				}
			}
		}
	}

	private static void rec(int i, int j, int k) {
		// System.out.println(i);
		if (ac.term[k])
			return;
		if (i >= a.length() && j >= b.length())
			return;
		if (i >= a.length() || j >= b.length())
			return;

		int temp1 = go(i + 1, j, k);
		int temp2 = go(i, j + 1, k);
		int temp3 = Integer.MIN_VALUE;

		if (a.charAt(i) == b.charAt(j)) {
			int nextK = ac.transition[a.charAt(i)-'A'][k];

			temp3 = 1 + go(i + 1, j + 1, nextK);
		}

		if (temp1 >= temp2 && temp1 > temp3) {
			rec(i + 1, j, k);
			return;
		}
		if (temp2 >= temp1 && temp2 > temp3) {
			rec(i, j + 1, k);
			return;
		}

		answer += a.charAt(i);
		int nextK = ac.transition[a.charAt(i)-'A'][k];
		rec(i + 1, j + 1, nextK);
	}

	private static int go(int i, int j, int k) {
		// System.out.println(i);
		if (ac.term[k])
			return -Integer.MAX_VALUE / 4;
		if (i >= a.length() && j >= b.length())
			return 0;
		if (i >= a.length() || j >= b.length())
			return 0;
		if (memo[i][j][k] != -1)
			return memo[i][j][k];

		int ans = go(i + 1, j, k);
		ans = Math.max(ans, go(i, j + 1, k));

		if (a.charAt(i) == b.charAt(j)) {
			int nextK = ac.transition[a.charAt(i)-'A'][k];

			ans = Math.max(ans, 1 + go(i + 1, j + 1, nextK));
		}

		return memo[i][j][k] = ans;
	}
}