1063A.md (2160B)
1 Source: https://codeforces.com/problemset/problem/1063/A 2 3 A. Oh Those Palindromes 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not. 22 23 A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not. 24 25 Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is $6$ because all its substrings are palindromes, and the palindromic count of the string "abc" is $3$ because only its substrings of length $1$ are palindromes. 26 27 You are given a string $s$. You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count. 28 29 Input 30 31 The first line contains an integer $n$ ($1 \le n \le 100\,000$) — the length of string $s$. 32 33 The second line contains string $s$ that consists of exactly $n$ lowercase characters of Latin alphabet. 34 35 Output 36 37 Print string $t$, which consists of the same set of characters (and each characters appears exactly the same number of times) as string $s$. Moreover, $t$ should have the maximum possible value of palindromic count among all such strings strings. 38 39 If there are multiple such strings, print any of them. 40 41 Examples 42 43 Input 44 45 ``` 46 5 47 oolol 48 ``` 49 50 Output 51 52 ``` 53 ololo 54 ``` 55 56 Input 57 58 ``` 59 16 60 gagadbcgghhchbdf 61 ``` 62 63 Output 64 65 ``` 66 abccbaghghghgdfd 67 ``` 68 69 Note 70 71 In the first example, string "ololo" has $9$ palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string. 72 73 In the second example, the palindromic count of string "abccbaghghghgdfd" is $29$.