#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
string s[100005];
vector<long long> vec[100005];
bool cmp(int a, int b) {
  if (vec[a][0] * vec[b][1] > vec[a][1] * vec[b][0])
    return 1;
  else
    return 0;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> s[i], a[i] = i;
  int s1 = 0, h = 0;
  for (int i = 0; i < n; i++) {
    s1 = 0, h = 0;
    for (int j = 0; j < s[i].length(); j++) {
      if (s[i][j] == 'h')
        h++;
      else
        s1++;
    }
    vec[i].push_back(s1);
    vec[i].push_back(h);
  }
  sort((a).begin(), (a).end(), cmp);
  long long ans = 0;
  string st = "";
  long long c = 0;
  for (int i = 0; i < n; i++) st += s[a[i]];
  for (int i = 0; i < st.length(); i++) {
    if (st[i] == 's')
      c++;
    else
      ans += c;
  }
  cout << ans;
  cout << endl;
  return 0;
}
