A. Oh Those Palindromes

本文探讨了如何通过重新排列给定字符串中的字符,以获得最大数量的回文子串。核心策略是将所有相同字符聚集在一起,以实现最多的回文组合。文章包括问题描述、解决思路及代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

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.

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.

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.

Input

The first line contains an integer n

(1≤n≤100000) — the length of string s

.

The second line contains string s

that consists of exactly n

lowercase characters of Latin alphabet.

Output

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.

If there are multiple such strings, print any of them.

Examples

Input

Copy

5
oolol

Output

Copy

ololo

Input

Copy

16
gagadbcgghhchbdf

Output

Copy

abccbaghghghgdfd

Note

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.

In the second example, the palindromic count of string "abccbaghghghgdfd" is 29

.题意:

        给你一串字符,让你重新排序,使得它的回文子串最多。

思路:

       其实它给的样例挺狗的,你可以认为这是在迷惑你,但你观察可以发现,只要你把所有相同的字符放在一起,必定最多。。。。

code:

        

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
typedef long long LL;
int n,book[30];
char s[100100];
int main()
{
	cin>>n;
	scanf("%s",s);
	int sz=strlen(s);
	for(int i=0;i<sz;i++)
	{
		book[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
		for(int j=1;j<=book[i];j++)
			printf("%c",'a'+i);
	cout<<endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值