Buna ziua dragi mei

am gasit o problema ce mi-sa parut divina ... ia uitati aici ...
You are given a string consisting of the brackets "<",">"; "(",")"; "{","}"; "[","]" and a series of N pairs of integers "i j" (1 ≤ i ≤ j ≤ 10^6)
The problem is to determine if a subsequence is a right bracket sequence (RBS)
Here is a definition of RBS: RBS + RBS = RBS; <RBS> = RBS, (RBS) = RBS, [RBS] = RBS, {RBS} = RBS.
The following sequences are RBS: (), ([]), <>()[](<>){{}}, <{{{}}()}>.
Input Sequence of brackets. The length of the sequence does not exceed 106.
N — the number of requests, N ≤ 2*10^6.
N lines with pairs of i and j.
Output N lines with answers: "Y" when subsequence is a RBS, "N" otherwise
Input#1
}<>(){)(<})[]
3
2 3
2 5
8 11
Output#1
Y
Y
N
Input#2
((><))>{<>}[[])
5
2 5
8 11
12 13
12 14
13 14
Output#2
N
Y
N
N
Y
Limita de timp : 3 secunde
Limita de memorie : 64Mb
Bafta