n = gets.to_i
s = n.times.map {gets.chomp}.sort_by{|e| -e.size}

ans = 0
memo = Hash.new{|h,k| h[k] = Hash.new(0)}
s.each do |e|
    ans += memo[e[1 .. -1]][e[0]]
    
    x = {}
    e.size.times do |i|
        x[e[i]] = 0
        x.each_key{|k| memo[e[i+1 .. -1]][k] += 1}
    end
end

p ans