#include #include #include using namespace std; void bins(int col, int minRow, int maxRow); int n; vector vs(2e5); long long ans; int main() { cin >> n; vs.resize(n); for (int i = 0; i < n; i++) { cin >> vs[i]; } // sort(vs.begin(), vs.end()); // for (int i = 0; i < n; i++) cout << vs[i] << endl; bins(0, 0, n-1); cout << ans << endl; return 0; } void bins(int col, int minRow, int maxRow) { int lRow = minRow; for (int row = minRow; row <= maxRow; row++) { if (vs[lRow].size() <= col) { lRow = row; continue; } if (vs[row].size() <= col) { lRow = row; continue; } else if (vs[row][col] == vs[lRow][col]) { continue; } int len = row - lRow; if (len == 1) { ans += (long long)vs[lRow].size() - (long long)col; } else { long long lp = 1, rp = len; while (lp <= rp) { ans += lp * rp * (lp == rp ? 1LL : 2LL); lp++; rp--; } bins(col + 1, lRow, row - 1); } lRow = row; } if (vs[lRow].size() > 0) { int row = maxRow + 1; int len = row - lRow; if (len == 1) { ans += (long long)vs[lRow].size() - (long long)col; } else { long long lp = 1, rp = len; while (lp <= rp) { ans += lp * rp * (lp == rp ? 1LL : 2LL); lp++; rp--; } bins(col + 1, lRow, row - 1); } } }