#include <bits/stdc++.h>
using namespace std;
string q[100010];
bool cmp(string a, string b) {
  string ss = a + b;
  long long t1 = 0, t2 = 0;
  int flag = 0;
  for (int j = 0; j < ss.length(); j++)
    if (ss[j] == 's')
      flag++;
    else
      t1 += flag;
  flag = 0;
  ss = b + a;
  for (int j = 0; j < ss.length(); j++)
    if (ss[j] == 's')
      flag++;
    else
      t2 += flag;
  return t1 > t2;
}
int main() {
  int n;
  long long ans = 0;
  scanf("%d\n", &n);
  long long sum_h = 0;
  long long sum_s = 0;
  for (int i = 0; i < n; i++) {
    getline(cin, q[i]);
    for (int j = 0; j < q[i].length(); j++)
      if (q[i][j] == 'h')
        sum_h++;
      else
        sum_s++;
  }
  sort(q, q + n, cmp);
  int flag = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < q[i].length(); j++)
      if (q[i][j] == 's')
        flag++;
      else
        ans += flag;
  cout << ans << endl;
  return 0;
}
