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

public class B {

	static char[]s1,s2,vir;
	static int kmp[];
	static int dp[][][];
	static int n1,n2,n3;
	static char str[];
	static int id;
	static int g[][];
	public static void main(String[] args) {
		FS in = new FS();
		s1 = in.next().toCharArray();
		s2 = in.next().toCharArray();
		vir = in.next().toCharArray();
		n1 = s1.length;
		n2 = s2.length;
		n3 = vir.length;
		dp = new int[n1+1][n2+1][n3+1];
		for(int a[][]:dp)
			for(int b[]:a)
				Arrays.fill(b, -1);
		kmp = KMP_Construct(vir);
		g = new int[26][n3];
		for(int i = 0; i < n3; i++) {
			for(char c = 'A'; c <= 'Z'; c++) {
				int res = -1;
				if(vir[i] == c) res = i+1;
				else {
					int cur = kmp[i];
					while(true) {
						if(vir[cur] == c) {res = cur+1; break;}
						else {
							if(cur == 0) { res = cur; break;}
							cur = kmp[cur];
						}
					}
				}
				
				g[c-'A'][i] = res;
			}
		}
		
		int len = go(0,0,0);
		if(len == 0) {
			System.out.println(0);
		}
		else {
			str = new char[len];
			id = 0;
			buildback(0,0,0,len);
			System.out.println(new String(str));
		}
	}
	
	static void buildback(int a, int b, int c, int len) {
		if(c >= n3 || len == 0) return;
		if(a >= n1 || b >= n2) return;
		int res = 0;
		//try taking
		if(s1[a] == s2[b]) {
			res = max(res, 1 + go(a+1,b+1,g[s1[a]-'A'][c]));
			if(res == len) {
				str[id++] = s1[a];
				buildback(a+1,b+1,g[s1[a]-'A'][c],len-1);
				return;
			}
		}
		//skip
		res = max(res, go(a+1,b,c));
		if(res == len) {
			buildback(a+1,b,c,len);
			return;
		}
		res = max(res, go(a, b+1,c));
		buildback(a,b+1,c,len);
		return;
	}
	
	static int go(int a, int b, int c) {
		if(c >= n3) return -123123;
		if(a >= n1 || b >= n2) return 0;
		if(dp[a][b][c] != -1) return dp[a][b][c];
		
		int res = 0;
		//try taking
		if(s1[a] == s2[b]) {
			res = max(res, 1 + go(a+1,b+1,g[s1[a]-'A'][c]));
		}
		//skip
		res = max(res, go(a+1,b,c));
		res = max(res, go(a, b+1,c));
		
		return dp[a][b][c] = res;
	}
	static int max(int a, int b) {
		return a > b ? a : b;
	}
	static int[] KMP_Construct(char[] w) {
		int n = w.length + 1, k = 0;  int[] p = new int[n];  p[1] = 0;
		for(int i = 2; i < n; ++i) {
			while(k > 0 && w[k] != w[i-1]) k = p[k];
			if(w[k] == w[i-1]) k++;
			p[i] = k;
		}
		return p;
	}
	  
	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS(String s) throws Exception {
			try{ br = new BufferedReader(new FileReader(s)); }
			catch(Exception e) { throw new Exception(); }
		}
		public FS(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next()	{
			while(st == null ||!st.hasMoreElements()){
				try { st = new StringTokenizer(br.readLine());}
				catch(IOException e) { e.printStackTrace(); }			
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

}
