#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
ll get_ans(const string& a) {
  int h = 0;
  for (int i = 0; i < a.size(); ++i)
    if (a[i] == 'h') ++h;
  ll ans = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == 'h')
      --h;
    else
      ans += h;
  }
  return ans;
}
bool cmp(const string& a, const string& b) {
  return get_ans(a + b) > get_ans(b + a);
}
void solve() {
  int n;
  cin >> n;
  int h = 0;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (int j = 0; j < ((int)(a[i]).size()); ++j) h += a[i][j] == 'h' ? 1 : 0;
  }
  sort(a.begin(), a.end(), cmp);
  string res = "";
  for (int i = 0; i < n; ++i) res += a[i];
  cout << get_ans(res) << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  srand(time(0));
  int t = 1;
  while (t--) solve();
  return 0;
}
