There are N lights arranged in a single row, numbered from 1 to N from left to right. The color of each light is one of red, green, or blue. The colors of the lights are represented by the string S, where the color of light i (1 ≦ i ≦ N) is red if the i-th character of S is R, green if it is G, and blue if it is B. Initially, all lights are turned on.
As long as at least one light is turned on, JOI-kun can perform the following three types of operations any number of times in any order. It is also possible to perform no operations at all.
JOI-kun wants the row of lights to appear as a beautiful white color when viewed from a distance. To achieve this, the sequence of colors of the lights that are turned on, read from left to right, must be a repetition of RGB (red, green, blue), such as RGBRGB...RGB. Note that the case where no lights are turned on is also considered to satisfy this condition. Be careful that color sequences such as GBRGBR or RGBRG do not satisfy the condition.
Given the information about the lights and the costs of the operations, write a program that finds the minimum amount of money required to make the sequence of colors of the lights that are turned on a repetition of RGB.
R, G, or B.
The input is given in the following format.
N
S
A B C
Output the minimum amount of money required to make the sequence of colors of the lights that are turned on a repetition of RGB, omitting the unit (yen), in one line.
6 GRBBRG 3 4 5
16
For example, if the following 4 operations are performed, the sequence of colors of the lights that are turned on becomes a repetition of RGB. Lights that are turned off are represented by -.
-RBBRG.-RBBR-.-RBB--.-RGB--.
It is not possible to make the sequence of colors of the lights that are turned on a repetition of RGB by paying less than 16 yen, so output 16.
3 BRG 1000000000 1000000000 1
3
For example, if the following 3 operations are performed, the sequence of colors of the lights that are turned on becomes a repetition of RGB. Lights that are turned off are represented by -.
BGG.BGB.RGB.
It is not possible to make the sequence of colors of the lights that are turned on a repetition of RGB by paying less than 3 yen, so output 3.
3 GRB 9 11 14
27
For example, if the following 3 operations are performed, the sequence of colors of the lights that are turned on becomes a repetition of RGB. Lights that are turned off are represented by -.
-RB.--B.---.
It is not possible to make the sequence of colors of the lights that are turned on a repetition of RGB by paying less than 27 yen, so output 27. Note that the case where no lights are turned on also satisfies the condition.
9 RGBRGBRGB 1000000000 1000000000 1
0
Since the sequence of colors of the lights is already a repetition of RGB, output 0.
20 BRGBRGBBGBBBGRRBBBRB 1000000000 1000000000 1
2000000008
23 BBGRGBBBBBBGRRGGGGBGGGG 786820955 792349124 710671229
10107224827
Japan Olympiad in Informatics Committee "23rd Japan Olympiad in Informatics (JOI 2023/2024) Second Preliminary Round Problems"