Controllers
시간 제한2초메모리 제한1024 MB
각 컨트롤러마다 n개의 더하기와 빼기 라운드에서 두 버튼 값 중 하나를 골라 최종 점수를 0으로 만들 수 있는지 판정한다.
문제
You are at your grandparents’ house and you are playing an old video game on a strange console. Your controller has only two buttons and each button has a number written on it.
Initially, your score is . The game is composed of rounds. For each , the -th round works as follows.
On the screen, a symbol appears, which is either + (plus) or - (minus). Then you must press one of the two buttons on the controller once. Suppose you press a button with the number written on it: your score will increase by if the symbol was + and will decrease by if the symbol was -. After you press the button, the round ends.
After you have played all rounds, you win if your score is .
Over the years, your grandparents bought many different controllers, so you have of them. The two buttons on the -th controller have the numbers and written on them. For each controller, you must compute whether you can win the game playing with that controller.
입력
The first line contains a single integer () — the number of rounds.
The second line contains a string of length — where is the symbol that will appear on the screen in the -th round. It is guaranteed that contains only the characters + and -.
The third line contains an integer () — the number of controllers.
The following lines contain two integers and each () — the numbers on the buttons of controller .
출력
Output lines. On line print YES if the game is winnable using controller , otherwise print NO.