A library in a small town has all of its books in a massive stack due to the laziness of the librarians.
Regardless, many readers come and go every day, with readers on this particular day. When the readers borrow books, they always take the topmost books. When the readers return books, they always put their books on top of the stack. Each book has a number assigned to it, with the books in the original stack being numbered to from bottom to top. Different books can have the same number.
Bob plans to visit the library, but, being a picky reader, he wants to know what number the topmost book has. He will only visit if the number is a multiple of a specified integer . Help Bob figure out if he should go!
Input specification
The first line will contain (), the number of books originally in the stack, ), the number of readers, and ().
The next lines begin with a character , which will either be B
(borrow) or R
(return). If it's a borrow, it will be followed by an integer () denoting how many books the reader borrowed. If it's a return, it will be followed by an integer (), followed by integers (), denoting the numbers of the books returned, in the order they are placed.
It is guaranteed that no one will borrow more books than possible.
Output specification
Print YES
if the number of the top book is a multiple of and NO
otherwise.
Sample Input
10 3 5
B 3
B 4
R 2 8 5
Sample Output
YES
Explanation for Sample Output
The number of the topmost book is , which is divisible by .
Comments