ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

[Online] ICPC Ural Regional Contest Qualifier 2026

About     Problems     Submit solution     Judge status     Standings
Contest is over

G. Correct Dryer

Time limit: 1.0 second
Memory limit: 256 MB
Sasha had been solving competitive programming problems with his friends for a long time, and they had sandwiches as a snack. All of Sasha’s guests have already left. Sasha threw away all the crumbs, and now he needs to wash the dishes. When he started washing the dishes, he looked at the dryer. The plates in the dryer reminded him of a bracket sequence. Depending on which way a plate is turned, it looks like an opening ‘(’ or closing ‘)’ bracket. The dryer may not be completely filled with plates; that is, some places may be empty. Sasha wondered which way it is better to place the washed plates. He is interested in which prefixes of the dryer he can turn into a correct bracket sequence.
The dryer can be represented as a string of length N consisting of the characters ‘(’, ‘)’ and ‘?’ . The character ‘?’ denotes an empty place where a plate can be placed. Sasha has Q independent questions, and in the i-th of them, one number ki is given. For each question, determine whether in the prefix of length ki it is possible to replace each character ‘?’ with ‘(’ or ‘)’ so that the resulting prefix becomes a correct bracket sequence.
Recall that a string is called a correct bracket sequence if it is either empty or has the form (S1)S2, where S1 and S2 are correct bracket sequences.

Input

The first line contains the number N (1 ≤ N ≤ 105) — the number of places in the dryer.
The second line contains a string of length N consisting of the characters ‘(’, ‘)’ and ‘?’ , describing the dryer.
The third line contains the number Q (1 ≤ Q ≤ N).
The fourth line contains Q distinct integers ki (1 ≤ ki ≤ N), where ki is the length of the prefix in the i-th question.

Output

Print Q lines. In the i-th line, print “YES”, if the prefix of length ki can be turned into a correct bracket sequence, and “NO” otherwise.

Samples

inputoutput
10
((?)()(??)
5
2 4 6 9 10
NO
YES
YES
NO
YES
5
???)?
3
2 4 5
YES
YES
NO
Problem Author: Timofey Imaev
Problem Source: The 2026 ICPC Ural Qualification