Click
Here to go back to the homepage.
Seven Wonders Solution:
import java.util.*;
import java.util.stream.Collectors;
public class Kattis {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<Character, Integer> map = sc.nextLine().chars().boxed().collect(
Collectors.toMap(k -> ((char) k.intValue()), v -> 1, Integer::sum));
int total = 0;
int sets = Integer.MAX_VALUE;
int types = 0;
for (Map.Entry<Character, Integer> k : map.entrySet()) {
types++;
if(k.getValue() < sets)
sets = k.getValue();
total += Math.pow(k.getValue(), 2);
}
System.out.printf("%d", (types > 2)? total + 7 * sets:total);
}
}