fun main() {
  val n = readLine()!!.toInt()
  val s = Array(n) { readLine()!!.reversed() }.sortedArrayWith(compareBy { it.length })
  val trie = Trie()
  var x = 0L
  for (si in s) {
    x += trie.count(si)
    trie.insert(si)
  }
  println(x)
}
class Trie {
  private var size = 0
  private val childs = Array<Trie?>(26) { null }

  fun insert(s: String) {
    var node = this
    for (c in s) {
      val n = c - 'a'
      if (node.childs[n] == null) node.childs[n] = Trie()
      node = node.childs[n]!!
    }
    node.size++
  }

  fun count(s: String): Long {
    val cnt = IntArray(26)
    for (c in s) {
      val n = c - 'a'
      cnt[n]++
    }
    var res = 0L
    var node = this
    for (c in s) {
      for (i in cnt.indices) {
        if (cnt[i] > 0 && node.childs[i] != null) {
          res += node.childs[i]!!.size
        }
      }
      val n = c - 'a'
      if (node.childs[n] == null) break
      node = node.childs[n]!!
      cnt[n]--
    }
    return res
  }
}