//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 0xccccccc; const ll LINF = 922337203685477580LL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int N = 2e5+10; //head int n; string s[N]; ll dfs(int l, int r, int now) { ll res = 0; for(int i = l; i < r; i++) if(s[i].size() != now) { int j = i; char c = s[i][now]; while(j < r and s[j].size() != now and s[j][now] == c) j++; int u = j-i; res += (ll)u*(u+1)*(u+2)/6 + dfs(i, j, now+1); i = j-1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; rep(i, n) cin >> s[i]; cout << dfs(0, n, 0) << endl; }