#P12182. DerrickLo's Brackets (UBC002E)

DerrickLo's Brackets (UBC002E)

Description

DerrickLo has an integer array aa with nn numbers, and a array tt with nn characters which are either ( or ) (1n1061\le n\le 10^6, 1ai1091\le a_i\le 10^9). Now he will generate qq bracket strings by selecting an interval [l,r][l,r] (1lrn1\le l\le r\le n) and perform the following operation to a string SS which is initially empty.

  • For each integer ii from ll to rr, append aia_i copies of tit_i to SS.

After each generation, DerrickLo wants to know the longest good substring of SS. Please help him!

A good string is defined as,

  • An empty string is a good string.

  • If AA is a good string, then so does (A)(A).

  • If A,BA,B are both good strings, then so does ABAB.

  • Any other strings are not good strings.

Input Format

The first line contains two integers n,qn,q.

The second line contains nn integers representing aa.

The third line contains a string representing tt.

For the next qq lines, each one contains two integers representing l,rl,r for a generation.

Output Format

Output qq lines. The ii-th one representing the ii-th answer.

3 2
2 3 1
()(
1 3
2 3
4
0

Hint

SS of the first generation is (()))(. Its longest good substring is (()), so output 44.

SS of the second generation is )))(. Its longest good substring is an empty string, so output 00.