#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  a %= m;
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ((ret % m) * (a % m)) % m;
    a = ((a % m) * (a % m)) % m;
    b >>= 1;
  }
  return ret;
}
bool cmp(pair<string, pair<long long, long long> > a,
         pair<string, pair<long long, long long> > b) {
  return (a.second.first * b.second.second) >
         (b.second.first * a.second.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<pair<string, pair<long long, long long> > > second;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long hcount = 0;
    long long scount = 0;
    for (char ch : s) {
      if (ch == 'h')
        hcount++;
      else
        scount++;
    }
    second.push_back(make_pair(s, make_pair(scount, hcount)));
  }
  sort(second.begin(), second.end(), cmp);
  long long scount = 0;
  long long hcount = 0;
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    string s = second[i].first;
    for (char ch : s) {
      if (ch == 'h') {
        hcount++;
        ans += scount;
      } else
        scount++;
    }
  }
  cout << ans << endl;
  return 0;
}
