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

import static java.lang.Math.*;

public class Solution implements Runnable {
	
	int[] pFunction (String s) {
		int n = s.length();
		int p [] = new int [n];
		for (int i = 1; i < n; i++) {
			int j = p[i - 1];
			while (j > 0 && s.charAt(i) != s.charAt(j))
				j = p[j - 1];
			if (s.charAt(i) == s.charAt(j)) j++;
			p[i] = j;
		}
		return p;
	}
	
	public void solve() throws Exception {
		char a [] = in.readLine().toCharArray();
		char b [] = in.readLine().toCharArray();
		String virus = sc.nextToken();
		
		virus += "#";
		
		int n = a.length;
		int m = b.length;
		int K = virus.length();
		
		int p [] = pFunction(virus);
		int automata [][] = new int [K][26];
		for (int i = 0; i < K; i++)
			for (int c = 0; c < 26; c++) {
				if (i > 0 && (char)(c + 'A') != virus.charAt(i))
					automata[i][c] = automata[p[i - 1]][c];
				else
					automata[i][c] = i + ((char)(c + 'A') == virus.charAt(i) ? 1 : 0);
			}
		
		int dp [][][] = new int [n + 1][m + 1][K];
		
		int pi [][][] = new int [n + 1][m + 1][K];
		int pj [][][] = new int [n + 1][m + 1][K];
		int pk [][][] = new int [n + 1][m + 1][K];
		
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= m; j++)
				for (int k = 0; k < K; k++) {
					dp[i][j][k] = -1;
					pi[i][j][k] = -1;
					pj[i][j][k] = -1;
					pk[i][j][k] = -1;
				}
		
		dp[0][0][0] = 0;
		
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= m; j++)
				for (int k = 0; k < K - 1; k++) {
					if (i + 1 <= n) {
						if (dp[i + 1][j][k] < dp[i][j][k]) {
							dp[i + 1][j][k] = dp[i][j][k];
							pi[i + 1][j][k] = i;
							pj[i + 1][j][k] = j;
							pk[i + 1][j][k] = k;
						}
					}
					if (j + 1 <= m) {
						if (dp[i][j + 1][k] < dp[i][j][k]) {
							dp[i][j + 1][k] = dp[i][j][k];
							pi[i][j + 1][k] = i;
							pj[i][j + 1][k] = j;
							pk[i][j + 1][k] = k;
						}
					}
					if (i + 1 <= n && j + 1 <= m && a[i] == b[j]) {
						// get
						int nextk = automata[k][a[i] - 'A'];
						if (dp[i + 1][j + 1][nextk] < dp[i][j][k] + 1) {
							dp[i + 1][j + 1][nextk] = dp[i][j][k] + 1;
							pi[i + 1][j + 1][nextk] = i;
							pj[i + 1][j + 1][nextk] = j;
							pk[i + 1][j + 1][nextk] = k;
						}
					}
				}
		
		int curk = -1, bestans = 0;
		for (int k = 0; k < K - 1; k++) {
			if (dp[n][m][k] > bestans) {
				bestans = dp[n][m][k];
				curk = k;
			}
		}
		
		
		
		if (bestans == 0) {
			out.println(0);
			return;
		}
		
		StringBuilder sb = new StringBuilder();
		
		int curi = n, curj = m;
		
		while (curi > 0 || curj > 0) {
			int prei = pi[curi][curj][curk];
			int prej = pj[curi][curj][curk];
			int prek = pk[curi][curj][curk];
			
			if (curi - prei > 0 && curj - prej > 0) {
				sb.append(a[prei]);
			}
			
			curi = prei;
			curj = prej;
			curk = prek;
			
		}
		
		String ans = sb.reverse().toString();
		
		out.println(ans);
	}


	static Throwable t;

	BufferedReader in;
	FastScanner sc;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Solution.t = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", 1 << 26);
		thread.start();
		thread.join();
		if (Solution.t != null)
			throw t;
	}

}

class FastScanner {

	BufferedReader in;
	StringTokenizer st;

	public FastScanner(BufferedReader in) {
		this.in = in;
	}

	public String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	public int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

}