RNA is an important molecule in the body. The structure of an RNA molecule is written as a pair (S,P) that satisfies the following four conditions.
A, C, G, U.Here are two RNA structures, A1=(S1,P1) on the left and A2=(S2,P2) on the right.
ACCCGAACUU AAUAUCCCGAAU
((**)*(*)) *(**)(**)*()
For two RNA structures A=(S,P) and A′=(S′,P′), we call A′ a substructure of A if there are integers i≤j with S′=si…sj and P′=pi…pj. Since A′ is itself an RNA structure, the parentheses of P′ must be balanced too. For example, A3=(S3,P3)
CCCG
(**)
is a substructure of A1, while A4=(S4,P4)
ACCCGAACU
((**)*(*)
is not a substructure of A1, because the parentheses of P4 are not balanced.
For two RNA structures X and Y, a structure Z that is a substructure of both is called a common substructure of X and Y. A longest common substructure is a common substructure of maximum length.
For the A1 and A2 above, the longest common substructure has length 5 and is
CCCGA
(**)*
The following is not a common substructure of A1 and A2, because its parentheses are not balanced.
CCCGAA
(**)*(
You are given two RNA structures of length at most 450. Report the length of a longest common substructure.
The input consists of four lines. The first line is the base sequence S of the first RNA and the second line is its parenthesis sequence P. The third line is the base sequence S′ of the second RNA and the fourth line is its parenthesis sequence P′.
Within one RNA the base sequence and the parenthesis sequence have the same length, which is between 1 and 450.
Print the length of a longest common substructure on one line. Print 0 if there is no common substructure at all.