#include <bits/stdc++.h>
const long long N = 10100;
const long long Q = 1000100;
const long long mod = 1e9 + 7;
const long long block = 500;
using namespace std;
int n;
string s;
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return x.first * y.second < y.first * x.second;
}
void solve() {
  cin >> n;
  long long ans = 0;
  vector<pair<long long, long long> > v;
  for (int i = 1; i <= n; i++) {
    long long a = 0, b = 0;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 'h') {
        a++;
        ans += b;
      } else {
        b++;
      }
    }
    v.push_back({a, b});
  }
  sort(v.begin(), v.end(), cmp);
  long long pa = 0, pb = 0;
  for (auto p : v) {
    ans += p.first * pb;
    pa += p.first;
    pb += p.second;
  }
  cout << ans << "\n";
}
bool mtest = false;
int main() {
  ios_base::sync_with_stdio(0);
  int TE = 1;
  if (mtest) cin >> TE;
  while (TE--) solve();
  return 0;
}
