#C4220. Form a Palindrome by Removing Characters

    ID: 47735 Type: Default 1000ms 256MiB

Form a Palindrome by Removing Characters

Form a Palindrome by Removing Characters

Given a string s and an integer k, determine whether it is possible to remove exactly k characters from s such that the remaining characters can be rearranged to form a palindrome.

A string is a palindrome if it reads the same forwards and backwards. In a palindrome, when written in terms of character counts, at most one character is allowed to have an odd count. Mathematically, if odd_count denotes the number of characters with an odd frequency, then for the rearranged string to be a palindrome, the following condition must hold: $$ k \geq odd\_count - 1 $$ where the expression is interpreted in \( \LaTeX \) format.

Your task is to implement a solution that reads the input from the standard input (stdin) and prints either True or False on the standard output (stdout) depending on whether such a removal is possible.

inputFormat

The input consists of two lines:

  • The first line contains the string s.
  • The second line contains an integer k, representing the exact number of characters to remove.

outputFormat

Output a single line: True if it is possible to remove exactly k characters such that the remaining characters can be rearranged to form a palindrome. Otherwise, output False.

## sample
abccba
2
True