#include <bits/stdc++.h>
using namespace std;
bool comp(pair<unsigned long long, unsigned long long> a,
          pair<unsigned long long, unsigned long long> b) {
  unsigned long long s1, s2, h1, h2;
  tie(s1, h1) = a;
  tie(s2, h2) = b;
  if (s1 * h2 > s2 * h1) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  unsigned long long ans = 0;
  string str;
  vector<pair<unsigned long long, unsigned long long> > arr(n);
  for (int i = 0; i < n; i++) {
    cin >> str;
    unsigned long long s1 = 0, h = 0;
    for (auto x : str) {
      if (x == 's')
        s1++;
      else if (x == 'h')
        h++, ans += s1;
    }
    arr[i] = make_pair(s1, h);
  }
  sort((arr).begin(), (arr).end(), comp);
  unsigned long long s1 = 0;
  for (auto i : arr) {
    ans += s1 * 1LL * (i.second);
    s1 += i.first;
  }
  cout << ans << '\n';
  return 0;
}
