CF748D Santa Claus and a Palindrome

Description

Santa Claus likes palindromes very much. There was his birthday recently. $ k $ of his friends came to him to congratulate him, and each of them presented to him a string $ s_{i} $ having the same length $ n $ . We denote the beauty of the $ i $ -th string by $ a_{i} $ . It can happen that $ a_{i} $ is negative — that means that Santa doesn't find this string beautiful at all. Santa Claus is crazy about palindromes. He is thinking about the following question: what is the maximum possible total beauty of a palindrome which can be obtained by concatenating some (possibly all) of the strings he has? Each present can be used at most once. Note that all strings have the same length $ n $ . Recall that a palindrome is a string that doesn't change after one reverses it. Since the empty string is a palindrome too, the answer can't be negative. Even if all $ a_{i} $ 's are negative, Santa can obtain the empty string.

Input Format

The first line contains two positive integers $ k $ and $ n $ divided by space and denoting the number of Santa friends and the length of every string they've presented, respectively ( $ 1

Output Format

In the only line print the required maximum possible beauty.

Explanation/Hint

In the first example Santa can obtain abbaaaxyxaaabba by concatenating strings $ 5 $ , $ 2 $ , $ 7 $ , $ 6 $ and $ 3 $ (in this order).