#C4824. Longest Palindrome with Leftovers

    ID: 48405 Type: Default 1000ms 256MiB

Longest Palindrome with Leftovers

Longest Palindrome with Leftovers

You are given a string s and an integer n. Each character in s appears at least twice, and n extra characters (leftovers) are allowed to be used to extend a palindrome. Your task is to determine the length of the longest palindrome that can be formed using all characters in s and by possibly adding at most n extra characters. Essentially, the answer is given by the formula: \(\text{answer} = |s| + n\), where \(|s|\) denotes the length of string s.

Note: The additional characters can be any characters and are used to 'pad' the original palindrome structure to increase its overall length.

inputFormat

The input consists of two lines:

  1. The first line contains the string s, where 1 ≤ |s| ≤ 200. The string can be assumed to have characters that usually appear in pairs.
  2. The second line contains a single integer n (0 ≤ n ≤ 100), representing the number of extra (leftover) characters available.

outputFormat

Output a single integer -- the length of the longest palindrome that can be formed.

The answer is computed as \(\text{length} = |s| + n\).

## sample
aabbcc
3
9

</p>