#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
string s[maxn];
int id[maxn], n;
inline long long cnt(string w) {
  long long res = 0, t = 0;
  for (int i = 0; i < (int)w.length(); i++)
    if (w[i] == 'h')
      res += t;
    else
      t++;
  return res;
}
inline bool cmp(int a, int b) { return cnt(s[a] + s[b]) > cnt(s[b] + s[a]); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    id[i] = i;
  }
  sort(id + 1, id + n + 1, cmp);
  string res = "";
  for (int i = 1; i <= n; i++) res += s[id[i]];
  cout << cnt(res) << endl;
  return 0;
}
