#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long>& a, pair<long long, long long>& b) {
  return a.first * b.second > a.second * b.first;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> p[n];
  long long sum = 0, meow = 0;
  for (long long i = 0; i < n; i++) {
    string str;
    long long cnt = 0;
    cin >> str;
    for (char j : str)
      if (j == 'h')
        sum += cnt;
      else
        cnt++;
    p[i] = {cnt, str.size() - cnt};
  }
  sort(p, p + n, comp);
  for (long long i = 1; i < n; i++) {
    meow += p[i - 1].first;
    sum += meow * p[i].second;
  }
  cout << sum;
}
