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


public class B {
	
	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	
	static int[] compute_prefix_function(char[] p){
		int[] pi=new int[p.length];
		pi[0]=-1;
		int k=-1;
		for(int i=1;i<p.length;i++){
			while(k>=0 &&  p[k+1]!=p[i]) k=pi[k];
			if (p[k+1]==p[i])k++;
			pi[i]=k;
		}
		return pi;
	}
	
	static int[][] buildAutomaton(String ss){
		char[] s = ss.toCharArray();
		int[][] ret = new int[s.length][26];
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < s.length; i++){
			for(int j = 0; j < 26; j++){
				char actual = (char)(j + 'A');
				String current = sb.toString() + (actual + "");
				int q = 0;
				for(int k = i + 1; k > 0; k--){
					String prefix = ss.substring(0, k);
					if (current.endsWith(prefix)){
						q = k;
						break;
					}
				}
				ret[i][j] = q;
			}
			sb.append(s[i]+"");
		}
		return ret;
	}
	
	
	static Integer[][][] dp;
	static Integer[][][] opcode;
	static char[] s1, s2, virus;
	
	static int dp(int n, int m, int k){
		
		if (dp[n][m][k] !=  null)
			return dp[n][m][k];
		if (k == virus.length){
			dp[n][m][k] = -1;
			return -1;
		}
		if (n == s1.length){
			dp[n][m][k] = 0;
			return 0;
		}
		if (m == s2.length){
			dp[n][m][k] = 0;
			return 0;
		}
		int mejor = -1;
		if (s1[n] == s2[m]){
			
			int nk = p[k][s1[n]-'A'];
			int ans = dp(n + 1, m + 1, nk);
			if (ans != -1){
				mejor = ans + 1;
				opcode[n][m][k] = 0;
			}
		}
		int ans1 = dp(n + 1, m, k);
		if (ans1 != -1 && ans1 > mejor){
			mejor = ans1;
			opcode[n][m][k] = 1;
		}
		int ans2 = dp(n, m + 1, k);
		if (ans2 != -1 && ans2 > mejor){
			mejor = ans2;
			opcode[n][m][k] = 2;
		}
		dp[n][m][k] = mejor;
		return dp[n][m][k];
	}
	
	static int[][] p;
	
	public static void main(String args[]) throws NumberFormatException, IOException{
		Scanner sc = new Scanner();
		/*
		String ss = "ABABBABABBABABBABABBABABBABABBABABBABABBABABBABABCBABABBABABBABABBABABBABABBABABBABABBABABBABABBABABB";
		int[][] matrix = buildAutomaton(ss);
		for(int i = 0; i < matrix.length; i++){
			for(int j = 0; j < 3; j++)
				System.out.print(matrix[i][j]+" "); 
			System.out.println();
		}*/
		s1 = sc.next().toCharArray();
		s2 = sc.next().toCharArray();
		String vv = sc.next();
		virus = vv.toCharArray();
		p = buildAutomaton(vv);
		//p =  compute_prefix_function(virus);
		dp = new Integer[s1.length + 1][s2.length + 1][virus.length + 1];
		opcode = new Integer[s1.length + 1][s2.length + 1][virus.length + 1];
		int tam = dp(0,0,0);
		if (tam == 0)
			System.out.println(0);
		else{
			StringBuilder sb  =new StringBuilder();
			int n = 0;
			int m = 0;
			int k = 0;
			while(n < s1.length && m < s2.length){
				//System.out.println("("+n+" "+m+" "+k+")");
				//System.out.println("opcode:"+opcode[n][m][k]);
				int op = opcode[n][m][k];
				if (op == 0){
					sb.append(s1[n]+"");
					//k = (s1[n] == virus[k])?k + 1:((k == 0)?0:p[k - 1]);
					k = p[k][s1[n]-'A'];
					n++;
					m++;
				}
				else if (op == 1)
					n++;
				else
					m++;
			}
			System.out.println(sb.toString());
		}
	}
	

}
