#include <bits/stdc++.h>
using namespace std;
int64_t count(string s) {
  int size = s.size();
  int64_t count = 0;
  int counth = 0;
  for (int i = size - 1; i >= 0; i--) {
    if (s[i] == 'h')
      counth++;
    else
      count += counth;
  }
  return count;
}
bool cmp(string s1, string s2) { return count(s1 + s2) > count(s2 + s1); }
int main() {
  int n;
  cin >> n;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    v.push_back(str);
  }
  sort(v.begin(), v.end(), cmp);
  int size = v.size();
  string ans = "";
  for (int i = 0; i < size; i++) ans += v[i];
  int64_t max = count(ans);
  cout << max << endl;
  return 0;
}
