Under construction

Still being built. Things may change

Controllers

Time limit2sMemory limit1024 MB

Summary
Given a string of + and - round symbols, decide for each pair of button values whether pressing one button per round can bring the final score to exactly 0.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

You are at your grandparents' house and 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 00. The game has nn rounds. For each 1≤i≤n1 ≤ i ≤ n, round ii works as follows.

A symbol sis_i appears on the screen. It is either + or -. Then you must press one of the two buttons exactly once. If you press a button with the number xx written on it, your score increases by xx when the symbol is +, and decreases by xx when the symbol is -. The round ends after you press the button.

After all nn rounds, you win if your score is 00.

Your grandparents have bought many different controllers over the years, so there are qq of them. The two buttons on the jj-th controller have the numbers aja_j and bjb_j. For each controller, determine whether you can win the game with it.

Input

The first line contains an integer nn (1≤n≤2⋅1051 ≤ n ≤ 2 \cdot 10^5), the number of rounds.

The second line contains a string ss of length nn, where sis_i is the symbol shown in round ii. ss contains only the characters + and -.

The third line contains an integer qq (1≤q≤1051 ≤ q ≤ 10^5), the number of controllers.

Each of the next qq lines contains two integers aja_j and bjb_j (1≤aj,bj≤1091 ≤ a_j, b_j ≤ 10^9).

Output

Print qq lines. On line jj, print YES if you can win the game with the jj-th controller, and NO otherwise.

Examples3

  1. Example 1

    Input
    8
    +-+---+-
    5
    2 1
    10 3
    7 9
    10 10
    5 3
    
    Expected output
    YES
    NO
    NO
    NO
    YES
    
  2. Example 2

    Input
    6
    +-++--
    2
    9 7
    1 1
    
    Expected output
    YES
    YES
    
  3. Example 3

    Input
    20
    +-----+--+--------+-
    2
    1000000000 99999997
    250000000 1000000000
    
    Expected output
    NO
    YES