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.*;
import java.math.*;
import java.io.*;

public class CF346B {
	class State {
		int at1, at2, node;
		public State(int aa1, int aa2, int nn) {
			at1 = aa1;  at2 = aa2;  node = nn;
		}
	}
	final int ALPHA = 26;
	int nodeCount, trie[][];
	boolean[] term;
	void aho(char[][] strs) {
		int maxNodes = 1;
		for(char[] s : strs) maxNodes += s.length;
		int[][] children = new int[ALPHA][maxNodes];
		boolean[] leaf = new boolean[maxNodes];
		nodeCount = 1;
		for(char[] s : strs) {
			int node = 0;
			for(char ch : s) {
				int c = ch - 'A';
				if(children[c][node] == 0) children[c][node] = nodeCount++;
				node = children[c][node];
			}
			leaf[node] = true;
		}
		trie = new int[ALPHA][nodeCount];
		term = new boolean[nodeCount];
		Deque<Integer> q = new ArrayDeque<>();
		q.add(0);  q.add(0);
		while(!q.isEmpty()) {
			int node = q.pop(), suffLink = q.pop();
			term[node] = leaf[node] || term[suffLink];
			for(int c = 0 ; c < ALPHA ; c++) {
				if(children[c][node] != 0) {
					trie[c][node] = children[c][node];
					q.add(children[c][node]);
					q.add(node == 0 ? 0 : trie[c][suffLink]);
				} else {
					trie[c][node] = trie[c][suffLink];
				}
			}
		}
	}
	int[][][] dp;
	int go(int at1, int at2, int node) {
		if(at1 == n1)
			return 0;
		if(dp[at1][at2][node] != -1)
			return dp[at1][at2][node];
		int res = 0;
		int let = s1[at1] - 'A';
		int take = -1;
		if(!term[trie[let][node]] && at2 < n2 && s1[at1] == s2[at2])
			take = go(at1 + 1, at2 + 1, trie[let][node]) + 1;
		int notake1 = go(at1 + 1, at2, node);
		int notake2 = at2 < n2 ? go(at1, at2 + 1, node) : 0;
		if(take >= notake1 && take >= notake2) {
			next[at1][at2][node] = new State(at1 + 1, at2 + 1, trie[let][node]);
			res = take;
		} else if(notake1 >= take && notake1 >= notake2) {
			next[at1][at2][node] = new State(at1 + 1, at2, node);
			res = notake1;
		} else {
			next[at1][at2][node] = new State(at1, at2 + 1, node);
			res = notake2;
		}
		dp[at1][at2][node] = res;
		return res;
	}
	char[] s1, s2;
	int n1, n2;
	State[][][] next;
	int[][] nextInd;
	public CF346B() {
		FS scan = new FS();
		s1 = scan.next().toCharArray();
		s2 = scan.next().toCharArray();
		n1 = s1.length;  n2 = s2.length;
		char[] virus = scan.next().toCharArray();
		char[][] dict = new char[1][];
		dict[0] = virus;
		aho(dict);
		next = new State[n1 + 1][n2 + 1][nodeCount];
		dp = new int[n1 + 1][n2 + 1][nodeCount];
		for(int i = 0 ; i <= n1 ; i++)
			for(int j = 0 ; j <= n2 ; j++)
				Arrays.fill(dp[i][j], -1);
		go(0, 0, 0);
		String res = "";
		State cur = new State(0, 0, 0);
		int prev = n2;
		while(next[cur.at1][cur.at2][cur.node] != null) {
			if(cur.at1 < next[cur.at1][cur.at2][cur.node].at1 && cur.at2 < next[cur.at1][cur.at2][cur.node].at2) {
				prev = cur.at2;
				res += s2[prev];
			}
			cur = next[cur.at1][cur.at2][cur.node];
		}
		if(res.length() == 0) System.out.println(0);
		else System.out.println(res);
	}
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() {
			while(!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) { e.printStackTrace(); }
			}
			return st.nextToken();
		}
		public int nextInt() { return Integer.parseInt(next()); }
	}
	public static void main(String[] args) { new CF346B(); }
}