#include <bits/stdc++.h>
using namespace std;
struct node {
  string s;
  long long sn, hn;
} store[100005];
bool cmp(node& a, node& b) {
  long long f = a.sn * b.hn, s = a.hn * b.sn;
  if (f != s)
    return f > s;
  else
    return (a.sn + a.hn) > (b.sn + b.hn);
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) cin >> store[i].s;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (store[i].s.size()); ++j) {
      if (store[i].s[j] == 's')
        store[i].sn++;
      else
        store[i].hn++;
    }
  sort(store, store + n, cmp);
  long long ret = 0;
  int hh = 0;
  for (int i = n - 1; i >= 0; i--) {
    int l = store[i].s.size();
    for (int j = l - 1; j >= 0; j--) {
      if (store[i].s[j] == 'h')
        hh++;
      else
        ret += hh;
    }
  }
  cout << ret << endl;
  return 0;
}
