To store DNA sequences your company has developed a LongLongString class that can store strings with up to ten billion characters. The class supports two basic operations: 
 - Ins($p$, $c$): Insert the character $c$ at position $p$.
 - Del($p$): Delete the character at position $p$.

A DNA editing program is written as a series of Ins and Del operations. Your job is to write a program that compare two DNA editing programs and determine if they are identical, i.e., when applied to any sufficiently long string, whether the end result is the same.

For example:
 - Del(1) Del(2) and Del(3) Del(1) are identical.
 - Del(2) Del(1) and Del(1) Del(2) are different.
 - An empty sequence and Ins(1, $X$) Del(1) are identical.
 - Ins(14, $B$) Ins(14, $A$) and Ins(14, $A$) Ins(15, $B$) are identical.
 - Ins(14, $A$) Ins(15, $B$) and Ins(14, $B$) Ins(15, $A$) are different.

-----Input-----
Input will consist of the descriptions of two DNA editing programs.

Each program will consist of some number of operations (between $0$ and $2000$). Each operation will be given on its own line. The first character of the line will be D for a Del operation, I for an Ins operation, or E marking the end of the program.

A Del operation will have the D character, followed by a space, and then a single integer between $1$ and $10^{10}$, indicating the character position to delete. All characters after this deleted character will be shifted one position lower.

An Ins operation will have the I character, followed by a space, and then a single integer between $1$ and $10^{10}$, indicating the location to insert the new character; all pre-existing characters with this index and higher will be shifted one position higher. Following this integer will be another space and then an uppercase alphabetic character that is the character to insert.

-----Output-----
If the two programs are identical, print “0” on a single line (without quotation marks). Otherwise, print “1” on a single line (without quotation marks).

-----Examples-----
Sample Input 1:
D 1
D 2
E
D 3
D 1
E
Sample Output 1:
0

Sample Input 2:
D 2
D 1
E
D 1
D 2
E
Sample Output 2:
1

Sample Input 3:
I 1 X
D 1
E
E
Sample Output 3:
0

Sample Input 4:
I 14 B
I 14 A
E
I 14 A
I 15 B
E
Sample Output 4:
0

Source: kattis | Difficulty: HARD


Solutions: