#P7044. 「MCOI-03」括号
「MCOI-03」括号
Background
Daily life in the MCOI q group ……
A little bookworm: If I can’t mine diamonds, I’m going to cry (lol).
WAPER420: But we clearly mine diamonds every time (confused).
A little bookworm: (a friendly smile).
7KByte: Why do you all like adding brackets so much (staring blankly).
A little bookworm: (laugh).
WAPER420: (laugh).
Kagamine Rin: (laugh).
7KByte: (laugh).
In this problem, a valid bracket sequence is defined as follows:
- The empty string is a valid bracket sequence.
- If
Ais a valid bracket sequence, then(A)is a valid bracket sequence. - If
A,Bare valid bracket sequences, thenABis a valid bracket sequence.
In this problem, a substring is defined as follows:
A substring of a string is a string formed by any consecutive characters in . A substring of can be represented by a starting position and an ending position , denoted as (, where denotes the length of S).
Problem Description
Define the level deviation value of a bracket string as the minimum number of operations needed to modify this bracket string into a valid bracket sequence. In one operation, you can insert a bracket at some position or delete a bracket at some position.
For , define the level deviation value of the string as the sum of the level deviation values over all substrings of this string.
Now you need to compute the level deviation value of a bracket string of length . The answer may be very large; output the result modulo .
Input Format
The first line contains two integers .
The second line contains a string representing the bracket sequence .
Output Format
Output one integer, the answer modulo .
3 1
(()
6
3 2
(()
15
Hint
Sample Explanation
For sample , the level costs of all substrings of are:
- , cost is .
- , cost is .
- , cost is .
- , cost is .
- , cost is .
- , cost is .
The total is .
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | ||
|---|---|---|---|
For of the testdata, .
Original idea: WAPER420
Translated by ChatGPT 5