1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# @param {String[]} ideas
# @return {Integer}
def distinct_names(ideas)
    let={}
    ('a'..'z').each{|i|let[i]=[]}
    ideas.each{|s|let[s[0]]<<s[1..]}
    p let
    ans=0
    ('a'..'z').each do|i|
        ('a'..'z').each do|j|
            next if i==j
            m=(let[i]&let[j]).size
            ans+=(let[i].size-m)*(let[j].size-m)
        end
    end
    ans
end
cs