#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[derive(Debug)]
struct TrieNode {
    ch: char,
    count: usize,
    children: HashMap<char, TrieNode>,
}

impl TrieNode {
    fn with_char(ch: char) -> TrieNode {
        TrieNode {
            ch: ch,
            count: 0,
            children: HashMap::new(),
        }
    }
}

#[derive(Debug)]
struct Trie {
    node: TrieNode,
}

impl Trie {
    fn new() -> Trie {
        let node = TrieNode::with_char('#');
        Trie { node: node }
    }

    fn add_word(&mut self, word: &[char]) {
        let mut cur = &mut self.node;
        for &ch in word {
            if !cur.children.contains_key(&ch) {
                let node = TrieNode::with_char(ch);
                cur.children.insert(ch, node);
            }
            cur = cur.children.get_mut(&ch).unwrap();
        }
        cur.count += 1;
    }

    fn count(&self, word: &[char]) -> usize {
        let mut cur = &self.node;
        for &ch in word {
            if !cur.children.contains_key(&ch) {
                return 0;
            }
            cur = cur.children.get(&ch).unwrap();
        }
        cur.count
    }
}

fn main() {
    let n = read::<usize>();
    let mut s = vec![];
    for i in 0..n {
        let mut ss = read::<String>().chars().collect::<Vec<_>>();
        ss.reverse();
        s.push(ss);
    }
    s.sort_by_key(|x| x.len());
    let mut trie = Trie::new();
    let exist_length = s.iter().map(|x| x.len()).collect::<HashSet<_>>();

    let mut ans = 0i64;
    for word in &s {
        let mut count = HashMap::new();
        for ch in word {
            *count.entry(ch).or_insert(0) += 1;
        }
        let mut cur = &trie.node;
        for l in 0..word.len() {
            if exist_length.contains(&(l + 1)) {
                for ch in b'a'..b'z' + 1 {
                    let ch = ch as char;
                    if !count.contains_key(&ch) || count[&ch] == 0 {
                        continue;
                    }
                    if !cur.children.contains_key(&ch) {
                        continue;
                    }
                    let child = &cur.children[&ch];
                    ans += child.count as i64;
                    // debug!(cur_key, trie.count(&cur_key));
                }
            }
            if !cur.children.contains_key(&word[l]) {
                break;
            }
            cur = &cur.children[&word[l]];
            *count.get_mut(&word[l]).unwrap() -= 1;
        }
        trie.add_word(&word);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 236544