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.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B346 {
  static FastScanner in;
  static FastWriter out;
  static int[][] t1, t2, t3;
  static int N, M, K;
  static int[][][] memo;
  
  public static void main(String[] args) throws IOException {
    in = new FastScanner(System.in);
    out = new FastWriter(System.out);
    
    char[] s1 = in.next().toCharArray();
    char[] s2 = in.next().toCharArray();
    char[] virus = in.next().toCharArray();
    t1 = ssTable(s1);
    t2 = ssTable(s2);
    t3 = kmpTable(virus);
    N = s1.length;
    M = s2.length;
    K = virus.length;
    
    memo = new int[N][M][K];
    for (int[][] a : memo)
      for (int[] b : a)
        Arrays.fill(b, -1);
    
    int l = go(0, 0, 0);
    if (l == 0) {
      out.println(0);
    } else {
      StringBuilder ans = new StringBuilder();
      int iAt = 0, jAt = 0, kAt = 0;
      while (l != 0) {
        for (int letter = 0; letter < 26; letter++) {
          int ni = t1[iAt][letter];
          int nj = t2[jAt][letter];
          int nk = t3[kAt][letter];
          if (ni == -1 || nj == -1 || nk == K) continue;
          if (go(ni + 1, nj + 1, nk) == l - 1) {
            ans.append((char) ('A' + letter));
            iAt = ni + 1;
            jAt = nj + 1;
            kAt = nk;
            l--;
            break;
          }
        }
      }
      out.println(ans.toString());
    }
    
    out.close();
  }
  
  static int go(int i, int j, int k) {
    if (i == N || j == M || k == K) return 0;
    if (memo[i][j][k] != -1) return memo[i][j][k];
    int ret = 0;
    
    for (int letter = 0; letter < 26; letter++) {
      int ni = t1[i][letter];
      int nj = t2[j][letter];
      int nk = t3[k][letter];
      if (ni == -1 || nj == -1 || nk == K) continue;
      ret = Math.max(ret, 1 + go(ni + 1, nj + 1, nk));
    }
    
    return memo[i][j][k] = ret;
  }
  
  static int[][] ssTable(char[] a) {
    int[][] ret = new int[a.length][26];
    for (char letter = 'A'; letter <= 'Z'; letter++) {
      int last = -1;
      for (int i = a.length - 1; i >= 0; i--) {
        if (a[i] == letter) last = i;
        ret[i][letter - 'A'] = last;
      }
    }
    return ret;
  }
  
  static int[][] kmpTable(char[] v) {
    int[][] table = new int[v.length][26];
    table[0][v[0] - 'A'] = 1;
    for (int X = 0, j = 1; j < v.length; j++) {
      for (int c = 0; c < 26; c++)
        table[j][c] = table[X][c]; // Copy mismatch cases.
      table[j][v[j] - 'A'] = j + 1; // Set match case.
      X = table[X][v[j] - 'A']; // Update restart state.
    }
    return table;
  }
  
  static class FastScanner {
    BufferedReader br;
    StringTokenizer st;
    
    public FastScanner(InputStream in) {
      br = new BufferedReader(new InputStreamReader(in));
      st = new StringTokenizer("");
    }
    
    public FastScanner(File f) throws IOException {
      br = new BufferedReader(new FileReader(f));
      st = new StringTokenizer("");
    }
    
    public int nextInt() throws IOException {
      return Integer.parseInt(next());
    }
    
    public long nextLong() throws IOException {
      return Long.parseLong(next());
    }
    
    public double nextDouble() throws IOException {
      return Double.parseDouble(next());
    }
    
    public String next() throws IOException {
      if (st.hasMoreTokens()) return st.nextToken();
      st = new StringTokenizer(br.readLine());
      return next();
    }
  }
  
  static class FastWriter extends PrintWriter {
    public FastWriter(OutputStream out) throws IOException {
      super(new BufferedWriter(new OutputStreamWriter(out)));
    }
    
    public FastWriter(File f) throws IOException {
      super(new BufferedWriter(new FileWriter(f)));
    }
  }
}