import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

class Tree
{
    Tree[26] children;
    long[26] counts;
    char c;

    this(char c) {
        this.c = c;
    }

    void add(string s) {
        assert(this.c == '\n');

        auto last = s[$-2];
        if (children[last - 'a'] is null) {
            children[last - 'a'] = new Tree(last);
        }
        long[26] cs;
        cs = children[last - 'a'].add(s[0..$-2], cs);
        foreach (i, c; cs) this.counts[i] += c;
    }

    long[26] add(string s, long[26] cs) {
        if (s.empty) {
            ++cs[this.c - 'a'];
            return cs;
        }

        auto last = s[$-1];
        if (children[last - 'a'] is null) {
            children[last - 'a'] = new Tree(last);
        }
        cs = children[last - 'a'].add(s[0..$-1], cs);

        foreach (i, c; cs) this.counts[i] += c;
        if (cs[this.c - 'a'] == 0) cs[this.c - 'a'] = 1;
        return cs;
    }

    long count(string s) {
        if (s[$-1] == '\n') s = s[0..$-1];

        if (s.length == 1) {
            return this.counts[s[0] - 'a'] - 1;
        } else {
            return this.children[s[$-1] - 'a'].count(s[0..$-1]);
        }
    }
}

void main()
{
    auto N = readln.chomp.to!int;
    auto tree = new Tree('\n');
    string[] ss;
    long[string] memo;
    foreach (_; 0..N) {
        auto s = readln;
        if (s[$-1] != '\n') s ~= '\n';
        tree.add(s);
        ss ~= s;
        ++memo[s];
    }
    long r;
    foreach (s; ss) r += tree.count(s);
    foreach (_, n; memo) r -= n * (n-1) / 2;
    writeln(r);
}