Minimize Even Palindrome

AtCoder
IDarc209_b
Time2000ms
Memory256MB
Difficulty
For a string $s$ consisting of lowercase English letters, let $f(s)$ denote the number of substrings of $s$ that are palindromes of even length. More precisely, $f(s)$ is the number of pairs of integers $l, r$ that satisfy all of the following conditions: * $1 \leq l \leq r \leq |s|$. * $r - l + 1$ is even. * $s_l s_{l+1} \cdots s_{r}$ is a palindrome. Given a string $S$ consisting of lowercase English letters, output one string $S'$ obtained by rearranging the characters of $S$ such that $f(S')$ is minimized. You are given $T$ test cases. Solve each of them. ## Constraints * $1 \le T \le 10^5$ * $2 \le |S| \le 2 \times 10^5$ * $S$ consists of lowercase English letters. * The sum of $|S|$ over all test cases is at most $2 \times 10^5$. ## Input The input is given from Standard Input in the following format: $T$ $\text{case}_1$ $\text{case}_2$ $\vdots$ $\text{case}_T$ Each test case is given in the following format: $S$ [samples]
Samples
Input #1
3
see
xxxxxy
abracadabra
Output #1
ese
xxxyxx
abracadabra

For the first test case, the strings $S'$ obtained by rearranging the characters of $S$ are `see`, `ese`, and `ees`. Among these, only `ese` minimizes $f(S')$, so output it.
For the second test case, for example, outputting `xxyxxx` will also be considered correct.
API Response (JSON)
{
  "problem": {
    "name": "Minimize Even Palindrome",
    "description": {
      "content": "For a string $s$ consisting of lowercase English letters, let $f(s)$ denote the number of substrings of $s$ that are palindromes of even length. More precisely, $f(s)$ is the number of pairs of intege",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc209_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For a string $s$ consisting of lowercase English letters, let $f(s)$ denote the number of substrings of $s$ that are palindromes of even length. More precisely, $f(s)$ is the number of pairs of intege...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments