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

public class CF {

	void solve() {
		String s1 = in.next();
		String s2 = in.next();
		String vir = in.next();
		int[][] next = new int[vir.length() + 1][26];
		for (int i = 0; i <= vir.length(); i++) {
			String was = vir.substring(0, i);
			for (int ne = 0; ne < 26; ne++) {
				char c = (char) ('A' + ne);
				String newS = was + c;
				for (int from = 0; from < newS.length(); from++) {
					String substr = newS.substring(from);
					if (vir.startsWith(substr)) {
						next[i][c - 'A'] = Math.max(next[i][c - 'A'],
								newS.length() - from);
					}
				}
			}
		}
		int n = s1.length();
		int m = s2.length();
		int k = vir.length();
		int[][][] dpLen = new int[n + 1][m + 1][k + 1];
		int[][][] dpFromI = new int[n + 1][m + 1][k + 1];
		int[][][] dpFromJ = new int[n + 1][m + 1][k + 1];
		int[][][] dpFromLen = new int[n + 1][m + 1][k + 1];
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= m; j++) {
				Arrays.fill(dpLen[i][j], -1);
			}
		dpLen[0][0][0] = 0;
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= m; j++) {
				for (int wasLen = 0; wasLen < k; wasLen++) {
					if (dpLen[i][j][wasLen] == -1)
						continue;
					if (i + 1 <= n) {
						if (dpLen[i + 1][j][wasLen] < dpLen[i][j][wasLen]) {
							dpLen[i + 1][j][wasLen] = dpLen[i][j][wasLen];
							dpFromI[i + 1][j][wasLen] = i;
							dpFromJ[i + 1][j][wasLen] = j;
							dpFromLen[i + 1][j][wasLen] = wasLen;
						}
					}
					if (j + 1 <= m) {
						if (dpLen[i][j + 1][wasLen] < dpLen[i][j][wasLen]) {
							dpLen[i][j + 1][wasLen] = dpLen[i][j][wasLen];
							dpFromI[i][j + 1][wasLen] = i;
							dpFromJ[i][j + 1][wasLen] = j;
							dpFromLen[i][j + 1][wasLen] = wasLen;
						}
					}
					if (i < n && j < m)
						if (s1.charAt(i) == s2.charAt(j)) {
							int newLen = next[wasLen][s1.charAt(i) - 'A'];
							if (dpLen[i + 1][j + 1][newLen] < dpLen[i][j][wasLen] + 1) {
								dpLen[i + 1][j + 1][newLen] = dpLen[i][j][wasLen] + 1;
								dpFromI[i + 1][j + 1][newLen] = i;
								dpFromJ[i + 1][j + 1][newLen] = j;
								dpFromLen[i + 1][j + 1][newLen] = wasLen;
							}
						}
				}
			}
		int bestVal = -1, bestI = -1, bestJ = -1, bestLen = -1;
		for (int len = 0; len < k; len++)
			if (dpLen[n][m][len] > bestVal) {
				bestVal = dpLen[n][m][len];
				bestI = n;
				bestJ = m;
				bestLen = len;
			}
		if (bestVal <= 0) {
			out.println(0);
			return;
		}
		ArrayList<Character> res = new ArrayList<>();
		while (true) {
			int nextI = dpFromI[bestI][bestJ][bestLen];
			int nextJ = dpFromJ[bestI][bestJ][bestLen];
			int nextLen = dpFromLen[bestI][bestJ][bestLen];
			if (nextI != bestI && nextJ != bestJ) {
				res.add(s1.charAt(bestI - 1));
			}
			bestI = nextI;
			bestJ = nextJ;
			bestLen = nextLen;
			if (bestI == 0 || bestJ == 0)
				break;
		}
		for (int i = res.size() - 1; i >= 0; i--) {
			out.print(res.get(i));
		}
	}

	FastScaner in;
	PrintWriter out;

	void run() {
		in = new FastScaner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	void runWithFiles() {
		in = new FastScaner(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		solve();

		out.close();
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new CF().run();
	}

	class FastScaner {
		BufferedReader br;
		StringTokenizer st;

		FastScaner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		FastScaner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}