require 'rational'

n=gets.to_i
s=ARGF.map{|a|a.chomp}.sort_by{|a|a.size}
#p s
count=0
(0...n).each{|i|
    (i+1...n).each{|k|
        short = s[i]
        long = s[k]
        if long.end_with?(short[1...short.size]) && long[0...long.size-short.size+1].include?(short[0])
            #p [short,long]
            count += 1
        end
        }
    }
p count