#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
int n;
pair<int, int> a[N];
string s;
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  long long cnta = a.first * 1ll * b.second;
  long long cntb = b.first * 1ll * a.second;
  return cnta > cntb;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    int H = 0, second = 0;
    for (int j = 0; j < s.length(); ++j)
      if (s[j] == 'h')
        ++H, ans += second;
      else
        ++second;
    a[i] = make_pair(second, H);
  }
  sort(a + 1, a + n + 1, cmp);
  long long cnts = 0, cnth = 0;
  for (int i = 1; i <= n; ++i) {
    ans += a[i].second * cnts;
    cnts += a[i].first;
  }
  cout << ans;
  return 0;
}
