import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String str = in.nextLine();
HashMap<Character, Integer> map = new HashMap<>();
for (char c : str.toCharArray()) {
map.merge(c, 1, Integer::sum);
}
List<MyString> list = new LinkedList<>();
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
list.add(new MyString(entry.getKey(), entry.getValue()));
}
list.sort((o1, o2) -> {
if (o1.getValue().equals(o2.getValue())) {
return o1.getKey() - o2.getKey(); // 在个数相同的情况下,ASCII 小的在前面
}
return o2.getValue() - o1.getValue(); // 个数多的在前面
});
StringBuilder sb = new StringBuilder();
for (MyString s : list) {
sb.append(s.getKey());
}
System.out.println(sb.toString());
}
}
}
class MyString {
private Character key;
private Integer value;
public MyString(Character key, Integer value) {
this.key = key;
this.value = value;
}
public Character getKey() {
return key;
}
public void setKey(Character key) {
this.key = key;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}