#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long sh;
  long long h;
  long long s;
} node[100005];
long long d[100005], p[100005];
int n;
bool cmp(struct Node a, struct Node b) { return a.s * b.h > a.h * b.s; }
int main() {
  string str;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    for (int j = 0; j < str.size(); j++) {
      d[j] = 0;
      p[j] = 0;
      if (str[j] == 'h') {
        p[j] = 1;
        node[i].h++;
      }
    }
    d[str.size()] = 0;
    p[str.size()] = 0;
    for (int j = str.size() - 1; j >= 0; j--) {
      p[j] += p[j + 1];
    }
    for (int j = 0; j < str.size(); j++) {
      if (str[j] == 's') {
        node[i].sh += p[j];
        node[i].s++;
      }
    }
  }
  sort(node, node + n, cmp);
  for (int i = n - 1; i >= 0; i--) {
    d[i] = d[i + 1] + node[i].h;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += node[i].sh + node[i].s * d[i + 1];
  }
  cout << ans << endl;
  return 0;
}
