Problem list
Log in
#icpc00136 · ICPC SWERC 2022

Controllers

Gold III 2.0 s 2048 MB

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 0. The game is composed of $n$ rounds. For each $1 \le i \le n$, the $i-th$ round works as follows. On the screen, a symbol $s_{i}$ 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 $x$ written on it: your score will increase by $x$ if the symbol w$as + an$d will decrease by $x$ if the symbol was -. After you press the button, the round ends. After you have played all $n$ rounds, you win if your score is 0. Over the years, your grandparents bought many different controllers, so you have $q$ of them. The two buttons on the $j-th$ controller have the numbers $a_{j}$ and $b_{j}$ written on them. For each controller, you must compute whether you can win the game playing with that controller.

Input

The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{5}$) — the number of rounds. The second line contains a string $s$ of length $n$ — where $s_{i}$ is the symbol that will appear on the screen in the $i-th$ round. It is guaranteed that $s$ contains only the characte$rs + an$d -. The third line contains an integer $q$ ($1 \le q \le 10^{5}$) — the number of controllers. The following $q$ lines contain two integers $a_{j}$ and $b_{j}$ each ($1 \le a_{j}$, $b_{j} \le 10^{9}$) — the numbers on the buttons of controller $j$.

Output

Output $q$ lines. On line $j$ print YES if the game is winnable using controller $j$, otherwise print NO.

Example 1

Input
8
+-+---+-
5
2 1
10 3
7 9
10 10
5 3
Output
YES
NO
NO
NO
YES

Example 2

Input
6
+-++--
2
9 7
1 1
Output
YES
YES

Example 3

Input
20
+-----+--+--------+-
2
1000000000 99999997
250000000 1000000000
Output
NO
YES
Source
ICPC SWERC 2022
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code