#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<string> arr(a);
  for (int i = 0; i < a; i++) cin >> arr[i];
  long long x = 0;
  vector<pair<double, int> > info(a);
  for (int i = 0; i < a; i++) {
    int d = 0;
    for (int j = arr[i].size() - 1; j > -1; j--)
      if (arr[i][j] == 'h') d++;
    info[i] = make_pair((double(arr[i].size() - d) / double(d)), i);
  }
  sort(info.begin(), info.end());
  reverse(info.begin(), info.end());
  string r;
  for (int i = 0; i < a; i++) r += arr[info[i].second];
  long long d = 0;
  for (int i = r.size() - 1; i > -1; --i) {
    if (r[i] == 'h')
      d++;
    else
      x += d;
  }
  cout << x << endl;
}
