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.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class LuckyCommonSubsequence {
	static Scanner sc;
	static String s1, s2, virus;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		s1 = sc.next();
		s2 = sc.next();
		virus = sc.next();
		TaskD solver = new TaskD();
		solver.solve(1);
	}

	static class TaskD {
		AhoCorasickDataStructure ds;
		int[][][] dp;

		int go(int i, int j, int state) {
			if (dp[i][j][state] == -1) {
				dp[i][j][state] = -100000;
				if (!ds.found[state]) {
					if (i >= s1.length() || j >= s2.length())
						dp[i][j][state] = 0;
					else {
						dp[i][j][state] = Math.max(go(i + 1, j, state),
								go(i, j + 1, state));
						if (s1.charAt(i) == s2.charAt(j))
							dp[i][j][state] = Math
									.max(dp[i][j][state],
											go(i + 1, j + 1, ds.trans[state][s1
													.charAt(i) - 'A']) + 1);
					}
				}
			}
			return dp[i][j][state];
		}

		public void solve(int testNumber) {
			ds = new AhoCorasickDataStructure(26, 'A');
			ds.add(virus, 0);
			ds.bfs();
			ds.makeTrans();
			dp = new int[s1.length() + 1][s2.length() + 1][virus.length() + 1];
			ArrayUtils.fill3d(dp, -1);
			int i = 0, j = 0, state = 0;
			ArrayList<Character> ans = new ArrayList<Character>();
			while (i < s1.length() && j < s2.length()) {
				if (go(i, j, state) == go(i + 1, j, state))
					i++;
				else if (go(i, j, state) == go(i, j + 1, state))
					j++;
				else {
					ans.add(s1.charAt(i));
					state = ds.trans[state][s1.charAt(i) - 'A'];
					i++;
					j++;
				}
			}
			if (ans.size() == 0)
				System.out.println(0);
			else
				for (char c : ans)
					System.out.print(c);
		}
	}

	static class AhoCorasickDataStructure {
		public int[][] trans;
		Node root;
		int stateCount;
		public boolean[] found;
		int alphabetSize;
		char zero;
		public int[] counts;
		int strCount;
		Node[] getNode;

		public AhoCorasickDataStructure(int size, char zero) {
			this.alphabetSize = size;
			this.zero = zero;
			root = new Node(' ');
			strCount = 0;
		}

		public void add(String s, int id) {
			Node node = root;
			for (int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				int ind = c - zero;
				if (node.child[ind] == null)
					node.child[ind] = new Node(c);
				node.child[ind].parent = node;
				node = node.child[ind];
			}
			node.isEnd = true;
			node.endId = id;
			strCount++;
		}

		public void bfs() {
			counts = new int[strCount];
			root.fall = root;
			Queue<Node> queue = new LinkedList<Node>();
			stateCount = 0;
			queue.offer(root);
			while (!queue.isEmpty()) {
				Node v = queue.poll();

				v.state = stateCount++;
				for (Node child : v.child)
					if (child != null)
						queue.offer(child);
				if (v == root)
					continue;
				Node fall = v.parent.fall;
				while (fall.child[v.c - zero] == null && fall != root)
					fall = fall.fall;
				v.fall = fall.child[v.c - zero];
				if (v.fall == null || v.fall == v)
					v.fall = root;
				else {
					Node temp = fall.child[v.c - zero];
					if (temp.isEnd) {
						v.isEnd |= temp.isEnd;
					}
				}
			}
		}

		public void makeTrans() {
			getNode = new Node[stateCount];
			trans = new int[stateCount][alphabetSize];
			found = new boolean[stateCount];
			Queue<Node> queue = new LinkedList<Node>();
			queue.offer(root);
			while (!queue.isEmpty()) {
				Node v = queue.poll();
				getNode[v.state] = v;
				if (v.isEnd)
					found[v.state] = true;
				for (int i = 0; i < v.child.length; i++) {
					Node node = v;
					if (v.child[i] != null)
						queue.offer(v.child[i]);
					while (node.child[i] == null && node != root)
						node = node.fall;
					if (node.child[i] != null) {
						trans[v.state][i] = node.child[i].state;
					} else
						trans[v.state][i] = root.state;
				}
			}

		}

		class Node {
			char c;
			Node[] child;
			boolean isEnd;
			Node parent;
			Node fall;
			int state;
			int endId;

			Node(char c) {
				this.c = c;
				child = new Node[alphabetSize];
				isEnd = false;
				parent = null;
				fall = null;
				endId = -1;
			}
		}
	}

	static class ArrayUtils {

		public static void fill2d(int[][] array, int value) {
			for (int i = 0; i < array.length; i++)
				Arrays.fill(array[i], value);
		}

		public static void fill3d(int[][][] array, int value) {
			for (int i = 0; i < array.length; i++) {
				fill2d(array[i], value);
			}
		}

	}
}
