You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz and P'pairus, who decided to accompany you and give you some puzzles for seemingly unknown reasons.
One day, Sanz has created a crossword for you. Not any kind of crossword, but a 1D crossword! You are given a string of length
Whenever you find one of the
In order to solve the puzzle, you need to tell Sanz what's the maximum achievable number of points in the crossword.
Input Specification
The first line of input will contain one integer
Output Specification
Output a single integer – the maximal number of points you can get.
Constraints
Sample Input
6
abacba
2
aba 6
ba 3
3
Sample Output
12
Explanation
For example, with the string abacba
, words aba
(6 points) and ba
(3 points), and aba
appears once (abacba
), while ba
appears two times (abacba
). Note that for aba
and the first appearance of ba
.
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
OMG THIS IS A REFRENCE TO THE GAME UNDERTALE
who would've known 🤔