AlgoUniversity
  • Go Back
Discussion
Box Of Crayons :

Author

Akshay Sharma

Difficulty Level : Hard

Submissions : 506

Asked In : Sprinklr

Marks :100

: 15 | : 2

You are given a box of crayons with different colours represented by different alphabets. In one operation, you can remove several continuous crayons of the same colour. You may perform this operation several times until the box is empty. Each time you can choose the crayon set. They must be continuous and of the same colours (i.e., set of x crayons, x>=1). After removing them, you will get x*x points.

Input

You are given an integer N where N denotes the total number of crayons in the box. You are also given an array of colours denoting the N colours in the box, where each colour is represented by an English alphabet. ($$$1 \le N \le 60$$$)

Output

Return the maximum points, you can get in the given scenario.

Example

Input
9
abcccbaba
Output
23

Note

Example 1 : colors array == [ a ,b , c , c , c , b , a ,b ,a]

Remove c ( + 9 ) -> [ a , b , b , a , b , a]

Remove a ( + 1 ) -> [ a , b ,b ,b , a ]

Remove b ( + 9 ) -> [ a , a ]

Remove a ( + 4 ) -> []

Ans -> 23

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.