atcoder#AGC048B. [AGC048B] Bracket Score
[AGC048B] Bracket Score
Score : points
Problem Statement
In this problem, we consider strings consisting of (
, )
, [
, and ]
.
A string is said to be a good parentheses sequence if and only if one of the following conditions is satisfied:
- is an empty sequence.
- There is a good parentheses sequence such that concatenating
(
, , and)
in this order results in . - There is a good parentheses sequence such that concatenating
[
, , and]
in this order results in . - There are non-empty good parentheses sequences and such that concatenating and in this order results in .
For example, []
, ([()])
, and ()[()]
are good parentheses sequences, but neither ())
nor ([)]
is a good parentheses sequence.
Given are an even number and integer sequences and of length each. Here, we define a score for a good parentheses sequence of length , , as follows:
- The score for is the sum of the scores of its characters.
- The score for the -th character () is if is
(
or)
, and if is[
or]
.
Find the maximum possible score for a good parentheses sequence of length .
Constraints
- is an even number.
- All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
4 2 3 1
2 3 2 4
12
For ()[]
, the score is , which is the maximum possible value.
10
866111664 844917655 383133839 353498483 472381277 550309930 378371075 304570952 955719384 705445072
178537096 218662351 231371336 865935868 579910117 62731178 681212831 16537461 267238505 318106937
6629738472