#include <bits/stdc++.h>
using namespace std;
class dar {
 public:
  string st;
  long long ans, s, h;
};
bool compare(dar d1, dar d2) {
  return (d1.s * d2.h > d2.s * d1.h) or
         (d1.s * d2.h == d2.s * d1.h and d1.s > d2.s);
}
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<dar> darr(n);
  for (int i = 0; i < n; ++i) {
    cin >> darr[i].st;
    long long sije = darr[i].st.size(), ch;
    ch = darr[i].st[sije - 1] == 'h' ? 1 : 0;
    darr[i].ans = 0;
    for (int j = sije - 2; j >= 0; --j) {
      if (darr[i].st[j] == 's')
        darr[i].ans += ch;
      else
        ++ch;
    }
    darr[i].h = ch;
    darr[i].s = sije - ch;
  }
  sort(darr.begin(), darr.end(), compare);
  long long ret = darr[n - 1].ans;
  long long ch = darr[n - 1].h;
  for (int i = n - 2; i >= 0; --i) {
    ret += darr[i].ans + (darr[i].s * ch);
    ch += darr[i].h;
  }
  cout << ret;
}
