#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del(a,n) memset(a,n,sizeof(a))
#define loop(i,j) for(int i =0 ; i<j ; i++ )

int main()
{
    vector <int> x;
    int n , temp , i , f=0;
    scanf ("%d",&n);
    for ( i=0 ; i<n ; i++ )
    {
        scanf ("%d",&temp);
        x.pb(temp);
    }
    sort ( x.begin() , x.end() );
    for ( i=1 ; i<n ; i++ )
    {
        if ( x[i]> x[i-1] && x[i] - x[i-1]>1 )
        {
            f=1;
            printf ("%d\n",x[i-1]+1);
            break;
        }
    }
    if ( f==0 )
    {
        for ( i=0 ; i<n ; i++ )
        {
            if ( i+1 != x[i] )
            {
                f=1;
                printf ("%d\n",i+1);
                break;
            }
        }
    }
    if ( f==0 )
        printf ("%d\n",x[n-1]+1);
    return 0;
}


#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del(a,n) memset(a,n,sizeof(a))
#define loop(i,j) for(int i =0 ; i<j ; i++ )

int main()
{
    vector <int> x;
    int n , temp , i , f=0;
    scanf ("%d",&n);
    for ( i=0 ; i<n ; i++ )
    {
        scanf ("%d",&temp);
        x.pb(temp);
    }
    sort ( x.begin() , x.end() );
    for ( i=1 ; i<n ; i++ )
    {
        if ( x[i]> x[i-1] && x[i] - x[i-1]>1 )
        {
            f=1;
            printf ("%d\n",x[i-1]+1);
            break;
        }
    }
    if ( f==0 )
    {
        for ( i=0 ; i<n ; i++ )
        {
            if ( i+1 != x[i] )
            {
                printf ("%d\n",i+1);
                break;
            }
        }
    }
    return 0;
}


#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del(a,n) memset(a,n,sizeof(a))
#define loop(i,j) for(int i =0 ; i<j ; i++ )

int main()
{
    vector <int> x;
    int n , temp , i ;
    scanf ("%d",&n);
    for ( i=0 ; i<n ; i++ )
    {
        scanf ("%d",&temp);
        x.pb(temp);
    }
    sort ( x.begin() , x.end() );
    for ( i=1 ; i<n ; i++ )
    {
        if ( x[i]> x[i-1] && x[i] - x[i-1]>1 )
        {
            printf ("%d\n",x[i-1]+1);
            break;
        }
    }
    return 0;
}


#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del(a,n) memset(a,n,sizeof(a))
#define loop(i,j) for(int i =0 ; i<j ; i++ )

int main()
{
    vector <int> x;
    int n , temp , i ;
    scanf ("%d",&n);
    for ( i=0 ; i<n ; i++ )
    {
        scanf ("%d",&temp);
        x.pb(temp);
    }
    sort ( x.begin() , x.end() );
    for ( i=1 ; i<n ; i++ )
    {
        if ( x[i]> x[i-1] && x[i] - x[i-1]>1 )
        {
            printf ("%d\n",x[i-1]+1);
            break;
        }
    }
    if ( n==1 )
        printf ("%d\n",x[0]);
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        scanf("%d", &num);
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    if (n ==1)
    {
        cout << int(tmp[n-1] + 1) << endl;
    }
    else
    {
        for (int j=1; j<n; j++)
        {
            if (tmp[j] != 1) { cout << int(1) << endl; break; }
            if (tmp[j] - tmp[j-1] != 1) { cout << int(tmp[j-1] + 1) << endl; break; }
            if (j+1 == n) cout << int(tmp[j] + 1) << endl;
        }
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        cin >> num;
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    for (int j=1; j<n; j++)
    {
        if (tmp[j] - tmp[j-1] != 1) { cout << tmp[j-1] + 1 << endl; return 0; }
        if (j+1 == n) cout << tmp[j] + 1 << endl;
    }

}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        cin >> num;
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    for (int j=1; j<n; j++)
    {
        if (tmp[j] - tmp[j-1] != 1) { cout << tmp[j-1] + 1 << endl; return 0; }
        if (j+1 == n) cout << tmp[j] + 1 << endl;
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        scanf("%d", &num);
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    if (n ==1)
    {
        cout << int(tmp[n-1] + 1) << endl;
    }
    else
    {
        for (int j=1; j<n; j++)
        {
            if (tmp[j] - tmp[j-1] != 1) { cout << int(tmp[j-1] + 1) << endl; break; }
            if (j+1 == n) cout << int(tmp[j] + 1) << endl;
        }
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        scanf("%d", &num);
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    for (int j=1; j<n; j++)
    {
        if (tmp[j] - tmp[j-1] != 1) { cout << int(tmp[j-1] + 1) << endl; break; }
        if (j+1 == n) cout << int(tmp[j] + 1) << endl;
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        scanf("%d", &num);
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    if (n ==1)
    {
        cout << int(tmp[n-1] + 1) << endl;
    }
    else
    {
        for (int j=1; j<n; j++)
        {
            if (tmp[0] != 1) { cout << int(1) << endl; break; }
            if (tmp[j] - tmp[j-1] != 1) { cout << int(tmp[j-1] + 1) << endl; break; }
            if (j+1 == n) cout << int(tmp[j] + 1) << endl;
        }
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> tmp;
    int num;

    for (int i=0; i<n; i++)
    {
        scanf("%d", &num);
        tmp.push_back(num);
    }

    sort(tmp.begin(), tmp.end());

    if (n ==1)
    {
        if (tmp[0] != 1) { cout << int(1) << endl; return 0; }
        cout << int(tmp[n-1] + 1) << endl;
    }
    else
    {
        for (int j=1; j<n; j++)
        {
            if (tmp[0] != 1) { cout << int(1) << endl; break; }
            if (tmp[j] - tmp[j-1] != 1) { cout << int(tmp[j-1] + 1) << endl; break; }
            if (j+1 == n) cout << int(tmp[j] + 1) << endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue< long> pq;
    long k,x;
    cin>>k;
    int ar[30001]={0};
    for(int i=1;i<=k;i++)
    {
        cin>>x;
       ar[x]=1;
    }
    int i;
    for( i=1;i<=3000;i++)
    {if(ar[i]==0)
    {
        cout<<i<<endl;
        return 0;
    }}
    if(i==3001)
        cout<<3001<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue< long> pq;
    long k,x;
    cin>>k;
    int ar[30001]={0};
    for(int i=1;i<=k;i++)
    {
        cin>>x;
       ar[x]=1;
    }
    for(int i=1;i<=3000;i++)
        if(ar[i]==0)
    {
        cout<<i<<endl;
        return 0;
    }

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue< long> pq;
    long k,x;
    cin>>k;
    int ar[30001]={0};
    for(int i=1;i<=k;i++)
    {
        cin>>x;
       ar[x]=1;
    }
    for(int i=1;i<=3000;i++)
        if(ar[i]==0 and i<=3000)
    {
        cout<<i<<endl;
        return 0;
    }

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue< long> pq;
    long k,x;
    cin>>k;
    int ar[30001]={0};
    for(int i=1;i<=k;i++)
    {
        cin>>x;
       ar[x]=1;
    }
    int i;
    for( i=1;i<=3000;i++)
    {if(ar[i]==0)
    {
        cout<<i<<endl;
        return 0;
    }}
    if(i==3001)
        cout<<3000<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue< long> pq;
    long k,x;
    cin>>k;
    int ar[30001]={0};
    for(int i=1;i<=k;i++)
    {
        cin>>x;
       ar[x]=1;
    }
    for(int i=1;i<=3000;i++)
    if(ar[i]==0)
    {
        cout<<i<<endl;
        return 0;
    }
    if(i==3001)
        cout<<3000<<endl;

}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	int a[3000];
	bool found = false;
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	if(a[0]==1){
	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			found = true;
			break;
		}
	}if(!found)
		cout << a[n - 1] + 1 << endl;
	}	else cout << 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int a[3000];
	bool found = false;
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			found=true;
			break;
		}
	}if(!found)
		cout << a[n - 1] + 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int a[3000];
	bool found = false;
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			break;
		}
	}if(!found)
		cout << a[n - 1] + 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	int a[3000];
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int a[3000];
	bool found = false;
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			break;
		}
	}if(!found)
		cout << arr[n - 1] + 1 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n;
	int a[3000];
	bool found = false;
	cin >> n;
	for(int i = 0; i < n;i++)
		cin >> a[i];

	sort(a, a + n);

	if(a[0]==1){
	for(int i = 0; i < n-1;i++){
		if((a[i+1]-a[i])>1){
			cout << a[i] + 1 << endl;
			found = true;
			break;
		}
	}if(!found)
		cout << arr[n - 1] + 1 << endl;
	}	else cout << 1 << endl;
	return 0;
}


# include <iostream>
using namespace std;
bool data[3001];
int main()
{
long x, num, count = 1;

cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
}


# include <iostream>
using namespace std;
int main()
{
int skaicius, sek = 0, temp;
cin>>skaicius;
for (int i = 0; i<skaicius; i++)
{
    cin>>temp;
    if (i == 0) {
     sek = temp;
    } else {
    if (temp == sek+1)
    {
        sek = temp;
    }
    if (temp < sek-1)
    {
        sek = temp;
    }
    }

}
cout<<sek+1;
}


# include <iostream>
using namespace std;

int main()
{bool data[3001];
long x, num, count = 1;

cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
}


# include <iostream>
using namespace std;
int main()
{
int x, num, count = 1;
bool data[3001];
cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
}


# include <iostream>
using namespace std;

int main()
{
bool data[3001];
long x, num, count = 1;

cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
}


# include <iostream>
using namespace std;
int main()
{
int skaicius, sek = 0, temp;
cin>>skaicius;
for (int i = 0; i<skaicius; i++)
{
    cin>>temp;
    if (i == 0) {
     sek = temp;
    } else {
    if (temp == sek+1)
    {
        sek = temp;
    }
    }

}
cout<<sek+1;
}


# include <iostream>
using namespace std;
int main()
{
int x, num, count = 1;
bool data[3001];
cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
for (int i = 1; data[i]; i++)
{
    count++;
}
cout<<count;
}


# include <iostream>
using namespace std;
int main()
{
long x, num, count = 1;
bool data[3001];
cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
return 0;
}


#include <iostream>

using namespace std;

bool added[3003];

int main()
{
        long n, x;
        cin >> n;
        for (int i = 0; i < n; ++i){
                cin >> x;
                added[x] = true;
        }
        long i = 1;
        while (added[i]) ++i;
        cout << i;
        return 0;
}


# include <iostream>
using namespace std;
bool data[3001];
int main()
{

long x, num, count = 1;

cin>>x;
for (int i = 0; i<x; i++)
{
    cin>>num;
    data[num] = true;
}
while (data[count]) count++;
cout<<count;
}


#include<cstdio>
#include<algorithm>
using namespace std;
bool in[3005];
int main()
{
    int n,x,i;
    scanf("%d",&n);
    int min=1<<30,max=-1;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x<min)min=x;
        if(x>max)max=x;
        in[x]=1;
    }
    for(i=min;i<=max;i++)
    {
        if(!in[i]){printf("%d\n",i);return 0;}
    }

    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=1;i<=3001;i++)
    {
        if(arr[c]>i)break;
        c++;
    }
   // if(!flag)printf(".%d\n",i+1);
     printf("%d\n",i);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;

int arr[10000];
int main()
{
    int i,n,c=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(i=arr[0];i<n;i++,c++)
    {
        if(arr[c]>i)break;
    }
    printf("%d\n",i);
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-9;
const int maxn = 1e5+9;
const ll inf = 1e16+9;
const ll mod=998244353;
int n,s[maxn],h[maxn],pq[maxn];
char op[maxn];
bool cmp(int a,int b){
    if(!h[a]) return true;
    else if(!h[b]) return false;
    else return s[a]*1.0/h[a]>s[b]*1.0/h[b]+eps;
}
int main()
{
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;++i){
        scanf("%s",op);
        int th=0,m=strlen(op);
        for(int j=m-1;j>=0;--j){
            if(op[j]=='h') ++th;
            else ans+=th;
        }
        h[i]=th;
        s[i]=m-th;
        pq[i]=i;
    }
    sort(pq,pq+n,cmp);
    ll th=0;
    for(int i=n-1;i>=0;--i){
        ans+=s[pq[i]]*th;
        th+=h[pq[i]];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-9;
const int maxn = 1e5+9;
const ll inf = 1e16+9;
const ll mod=998244353;
int n,s[maxn],h[maxn],pq[maxn];
char op[maxn];
bool cmp(int a,int b){
    return 1ll*s[a]*h[b]>1ll*s[b]*h[a];
}
int main()
{
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;++i){
        scanf("%s",op);
        int th=0,m=strlen(op);
        for(int j=m-1;j>=0;--j){
            if(op[j]=='h') ++th;
            else ans+=th;
        }
        h[i]=th;
        s[i]=m-th;
        pq[i]=i;
    }
    sort(pq,pq+n,cmp);
    ll th=0;
    for(int i=n-1;i>=0;--i){
        ans+=s[pq[i]]*th;
        th+=h[pq[i]];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-9;
const int maxn = 1e5+9;
const ll inf = 1e16+9;
const ll mod=998244353;
int n,s[maxn],h[maxn],pq[maxn];
char op[maxn];
bool cmp(int a,int b){
    if(!h[a]) return true;
    else if(!h[b]) return false;
    else return s[a]*1.0/h[a]>s[b]*1.0/h[b];
}
int main()
{
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;++i){
        scanf("%s",op);
        int th=0,m=strlen(op);
        for(int j=m-1;j>=0;--j){
            if(op[j]=='h') ++th;
            else ans+=th;
        }
        h[i]=th;
        s[i]=m-th;
        pq[i]=i;
    }
    sort(pq,pq+n,cmp);
    ll th=0;
    for(int i=n-1;i>=0;--i){
        ans+=s[pq[i]]*th;
        th+=h[pq[i]];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define ios       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
     }
    return r;
}

int fun(string s){
    int ans = 0;
    int count = 0;
    int n = s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='s')
            count++;
        else
            ans += count;
    }
    return ans;
}

bool cpmr(string s, string t){
    if(fun(s+t)>=fun(t+s))
        return true;
    else
        return false;
}
void solve(){
    int n;
    cin >> n;
    vector <string> a(n);
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a.begin(),a.end(),cpmr);
    string ans ="";
    for(int i=0;i<n;i++)
        ans += a[i];
    cout << fun(ans) << endl;
    return;
}

int main(){
    ios
    int t=1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define ios       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
     }
    return r;
}

int fun(string s){
    int ans = 0;
    int count = 0;
    int n = s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='s')
            count++;
        else
            ans += count;
    }
    return ans;
}

bool cmp(const string &s,const string &t){
    if(fun(s+t)>fun(t+s))
        return true;
    else
        return false;
}
void solve(){
    int n;
    cin >> n;
    vector <string> a(n);
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a.begin(),a.end(),cmp);
    string ans ="";
    for(int i=0;i<n;i++)
        ans += a[i];
    cout << fun(ans) << endl;
    return;
}

int main(){
    ios
    int t=1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define ios       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
     }
    return r;
}

ll fun(string s){
    ll ans = 0;
    ll count = 0;
    ll n = s.size();
    for(ll i=0;i<n;i++){
        if(s[i]=='s')
            count++;
        else
            ans += count;
    }
    return ans;
}

bool cmp(const string &s,const string &t){
    if(fun(s+t)>fun(t+s))
        return true;
    else
        return false;
}
void solve(){
    ll n;
    cin >> n;
    vector <string> a(n);
    for(ll i=0;i<n;i++)
        cin >> a[i];
    sort(a.begin(),a.end(),cmp);
    string ans ="";
    for(ll i=0;i<n;i++)
        ans += a[i];
    cout << fun(ans) << endl;
    return;
}

int main(){
    ios
    int t=1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define ios       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
     }
    return r;
}
int fun(string s){
    int ans = 0;
    int count = 0;
    int n = s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='s')
            count++;
        else
            ans += count;
    }
    return ans;
}
void solve(){
    int n;
    cin >> n;
    vector <string> a(n);
    //cout << fun("s") << " " << fun("ssh") << endl;
    for(int i=0;i<n;i++)
        cin >> a[i];
    string fck = a[0];
    for(int i=1;i<n;i++){
        string t = a[i];
        int a = fun(fck+t);
        int b = fun(t+fck);
        if(a > b)
            fck += t;
        else
            fck = t+fck;
    }
    //cout << fck << endl;
    cout << fun(fck) << endl;
    return;
}

int main(){
    ios
    int t=1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


#include <stdio.h>
#include <algorithm>
#define ll long long

using namespace std;

struct st {
	ll K, U;
};
struct st C[100004];
bool comp(const struct st &a, const struct st &b) {
	return (ll)a.K * (ll)b.U > (ll)a.U * (ll)b.K;
}
int N;
char str[100004];
ll sum_K;
ll Answer;
int main() {
	scanf("%d", &N);
	sum_K = 0;
	Answer = 0;
	for (int i = 1; i <= N; i++) {
		scanf("%s", str);
		for (int j = 0; str[j] != NULL; j++) {
			if (str[j] == 's') {
				C[i].K++;
			}
			else {
				C[i].U++;
				Answer = Answer + C[i].K;
			}
		}
	}
	sort(C + 1, C + N + 1, comp);
	for (int i = 1; i <= N; i++) {
		Answer = Answer + sum_K * C[i].U;
		sum_K = sum_K + C[i].K;
	}
	printf("%lld", Answer);
}


#include <stdio.h>
#include <algorithm>
#define ll long long

using namespace std;

struct st {
	ll K, U, tot;
	int idx;
};
struct st C[100004];
bool comp(const struct st &a, const struct st &b) {
	return (ll)a.K * (ll)b.U > (ll)a.U * (ll)b.K;
}
int N;
char str[100004];
ll sum_K;
ll Answer;
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%s", str);
		for (int j = 0; str[j] != NULL; j++) {
			if (str[j] == 's') {
				C[i].K++;
			}
			else {
				C[i].U++;
				C[i].tot = C[i].tot + C[i].K;
			}
		}
		C[i].idx = i;
		sort(C + 1, C + N + 1, comp);
	}
	sum_K = 0;
	Answer = 0;
	for (int i = 1; i <= N; i++) {
		Answer = Answer + C[i].tot + sum_K * C[i].U;
		sum_K = sum_K + C[i].K;
	}
	printf("%lld", Answer);
}


#include <stdio.h>
#include <algorithm>
#define ll long long

using namespace std;

struct st {
	ll K, U;
};
struct st C[100004];
bool comp(const struct st &a, const struct st &b) {
	return (ll)a.K * (ll)b.U > (ll)a.U * (ll)b.K;
}
int N;
char str[100004];
ll sum_K;
ll Answer;
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%s", str);
		for (int j = 0; str[j] != NULL; j++) {
			if (str[j] == 's') {
				C[i].K++;
			}
			else {
				C[i].U++;
				Answer = Answer + C[i].K;
			}
		}
	}
	sort(C + 1, C + N + 1, comp);
	sum_K = 0;
	Answer = 0;
	for (int i = 1; i <= N; i++) {
		Answer = Answer + sum_K * C[i].U;
		sum_K = sum_K + C[i].K;
	}
	printf("%lld", Answer);
}


#include <stdio.h>
#include <algorithm>
#define ll long long

using namespace std;

struct st {
	int K, U, idx, tot;
};
struct st C[100004];
bool comp(const struct st &a, const struct st &b) {
	return (ll)a.K * (ll)b.U > (ll)a.U * (ll)b.K;
}
int N;
char str[100004];
int sum_K;
ll Answer;
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%s", str);
		for (int j = 0; str[j] != NULL; j++) {
			if (str[j] == 's') {
				C[i].K++;
			}
			else {
				C[i].U++;
				C[i].tot = C[i].tot + C[i].K*C[i].U;
			}
			C[i].idx = i;
		}
		sort(C + 1, C + N + 1, comp);
	}
	sum_K = 0;
	Answer = 0;
	for (int i = 1; i <= N; i++) {
		Answer = Answer + C[i].tot + sum_K * C[i].U;
		sum_K = sum_K + C[i].K;
	}
	printf("%lld", Answer);
}


#include <stdio.h>
#include <algorithm>
#define ll long long

using namespace std;

struct st {
	ll K, U, tot;
	int idx;
};
struct st C[100004];
bool comp(const struct st &a, const struct st &b) {
	return (ll)a.K * (ll)b.U > (ll)a.U * (ll)b.K;
}
int N;
char str[100004];
ll sum_K;
ll Answer;
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%s", str);
		for (int j = 0; str[j] != NULL; j++) {
			if (str[j] == 's') {
				C[i].K++;
			}
			else {
				C[i].U++;
				C[i].tot = C[i].tot + C[i].K*C[i].U;
			}
		}
		C[i].idx = i;
		sort(C + 1, C + N + 1, comp);
	}
	sum_K = 0;
	Answer = 0;
	for (int i = 1; i <= N; i++) {
		Answer = Answer + C[i].tot + sum_K * C[i].U;
		sum_K = sum_K + C[i].K;
	}
	printf("%lld", Answer);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a[100001];
int nh,ans;
int s1,s2,h1,h2;
bool cmp(string &s, string &t){
    s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    if(s1*h2<s2*h1){
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    nh=0;
    ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a[100001];
int nh,ans;
int s1,s2,h1,h2;
bool cmp(string &s, string &t){
    s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    return (s1*h2>s2*h1);
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    nh=0;
    ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool cmp(string s, string t){
    int s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    if(s1*h2<s2*h1){
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    string a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    ll nh=0;
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a[100001];
int nh,ans;
bool cmp(string s, string t){
    int s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    if(s1*h2<s2*h1){
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    nh=0;
    ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a[100001];
ll nh,ans;
ll s1,s2,h1,h2;
bool cmp(string &s, string &t){
    s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    return (s1*h2>s2*h1);
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    nh=0;
    ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
string a[100001];
int nh,ans;
int s1,s2,h1,h2;
bool cmp(string s, string t){
    s1=0,s2=0,h1=0,h2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='s'){
            s1++;
        }
        else{
            h1++;
        }
    }
    for(int i=0;i<t.size();i++){
        if(t[i]=='s'){
            s2++;
        }
        else{
            h2++;
        }
    }
    if(s1*h2<s2*h1){
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    nh=0;
    ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=a[i].size()-1;j>=0;j--){
            if(a[i][j]=='h'){
                nh++;
            }
            else{
                ans+=nh;
            }
        }
    }
    cout<<ans<<endl;
}


                                                                   //author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define ll 		int
#define int 		long long
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define vpi 		vector<pii>
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define fori(a,b,c) for(register int i=a;i<b;i+=c)
#define ford(a,b,c) for(register int i=a;i>=b;i-=c)
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
#define test4(x,y,z,a) 		cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;

void ctrl()
{
	cout<<"Control\n";
}
int cal(string st)
{
     int s=0,ans=0;

    for(int i=0;i<st.length();i++)
    {
        if(st[i]=='s')
        s++;
        else
        {
            ans+=s;
        }

    }
    return ans;
}
bool func(string a,string b)
{
     return cal(a+b)>cal(b+a);
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<string>v,pref,suff;
    fori(0,n,1)
    {
        string p;
        cin>>p;

        int h=0,ans=0,s=0;
        for(int j=0;j<p.length();j++)
        {
            if(p[j]=='s')
            s++;
            else
            {
                ans+=s;
                h++;
            }
        }
        if(h==p.length())
        suff.pb(p);
        else if(s==p.length())
        pref.pb(p);
        else
        v.pb(p);

       // k[i]=p;
    }

    sort(v.begin(),v.end(),func);

    string st="";

    for(auto it:pref)
    st+=it;

    for(auto it:v)
    st+=it;

    for(auto it:suff)
    st+=it;

   // cout<<st<<'\n';
    cout<<cal(st);

return 0;
}


                                                                   //author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int cal(string h)
{
    int S=0,ans=0;
    for(int i=0;i<h.length();i++)
    {
        if(h[i]=='s')
        S++;
        else
        ans+=S;
    }
    return ans;
}
bool f(string a,string b)
{
    return cal(a+b)>cal(b+a);
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    string p[n];
    for(int i=0;i<n;i++)cin>>p[i];

    sort(p,p+n,f);
    string h="";
    for(int i=0;i<n;i++)
    h+=p[i];
   // cout<<h<<endl;
    cout<<cal(h);
return 0;
}


                                                                   //author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define ll 		int
#define int 		long long
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define vpi 		vector<pii>
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define fori(a,b,c) for(register int i=a;i<b;i+=c)
#define ford(a,b,c) for(register int i=a;i>=b;i-=c)
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
#define test4(x,y,z,a) 		cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;

void ctrl()
{
	cout<<"Control\n";
}
bool func(pair<pii,int>a,pair<pii,int>b)
{
    return (a.f.f>b.f.f)||(a.f.f==b.f.f&&a.f.s>b.f.s);
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<pii,int>>v;
    vector<string>pref,suff;
    string k[n];
    fori(0,n,1)
    {
        string p;
        cin>>p;

        int h=0,ans=0,s=0;
        for(int j=0;j<p.length();j++)
        {
            if(p[j]=='s')
            s++;
            else
            {
                ans+=s;
                h++;
            }
        }
        if(h==p.length())
        suff.pb(p);
        else if(s==p.length())
        pref.pb(p);
        else
        v.pb({{ans,s},i});

        k[i]=p;
    }

    sort(v.begin(),v.end(),func);

    string st="";

    for(auto it:pref)
    st+=it;

    for(auto it:v)
    st+=k[it.s];

    for(auto it:suff)
    st+=it;

    int s=0,ans=0;

    for(int i=0;i<st.length();i++)
    {
        if(st[i]=='s')
        s++;
        else
        {
            ans+=s;
        }

    }

    //cout<<st<<'\n';
    cout<<ans;

return 0;
}


                                                                   //author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int cal(string h)
{
    int S=0,ans=0;
    for(int i=0;i<h.length();i++)
    {
        if(h[i]=='s')
        S++;
        else
        ans+=S;
    }
    return ans;
}
bool f(string a,string b)
{
    return cal(a+b)>cal(b+a);
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    string p[n];
    for(int i=0;i<n;i++)cin>>p[i];

    sort(p,p+n,f);
    string h="";
    for(int i=0;i<n;i++)
    h+=p[i];
    cout<<h<<endl;
    cout<<cal(h);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
long long f(string p)
{
    long long y = 0, o = 0;
    //cout << p.size() << " " << p << endl;
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='h') y++;
    }
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='s') o += y;
        else y--;
    }
    return o;
}
bool comp(string x, string y)
{
    long long v1 = f(x+y), v2 = f(y+x);
    //cout << x << " " << y << endl;
    if (v1<=v2) return false;
    else return true;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string a[n];
    int y = 0;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i];
    }
    sort(a,a+n,comp);
    int m = 0;
    string st;
    for(int i = 0; i<n; i++)
    {
        st += a[i];
    }
    cout << f(st);
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    pair < pair <int, int>, string> a[n];
    int y = 0;
    for(int i = 0; i<n; i++)
    {
        string s;
        cin >> s;
        int m = s.size();
        a[i].F.F = 0; a[i].F.S = 0;
        for(int j = 0; j<m; j++)
        {
            if (s[j]=='s') a[i].F.S--;
            else { a[i].F.F++; y++; }
        }
        a[i].S = s;
    }
    sort(a,a+n);
    int m = 0;
    string p;
    for(int i = 0; i<n; i++)
    {
        p += a[i].S;
    }
    m = p.size();
    int o = 0;
    for(int i = 0; i<m; i++)
    {
        if (p[i]=='s') o += y;
        else y--;
    }
    cout << o;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int f(string p)
{
    int y = 0, o = 0;
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='h') y++;
    }
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='s') o += y;
        else y--;
    }
    return o;
}
bool comp(string x, string y)
{
    int v1 = f(x+y), v2 = f(y+x);
    if (v1<v2) return false;
    else return true;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string a[n];
    int y = 0;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i];
    }
    sort(a,a+n,comp);
    int m = 0;
    string st;
    for(int i = 0; i<n; i++)
    {
        st += a[i];
    }
    cout << f(st);
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
long long f(string p)
{
    long long y = 0, o = 0;
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='h') y++;
    }
    for(int i = 0; i<p.size(); i++)
    {
        if (p[i]=='s') o += y;
        else y--;
    }
    return o;
}
bool comp(string x, string y)
{
    int v1 = f(x+y), v2 = f(y+x);
    if (v1<v2) return false;
    else return true;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string a[n];
    int y = 0;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i];
    }
    sort(a,a+n,comp);
    int m = 0;
    string st;
    for(int i = 0; i<n; i++)
    {
        st += a[i];
    }
    cout << f(st);
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
struct node{
	int s;
	int sh;
	int h;
	double p;//   s/h
}str[N];
int cmp(node a,node b){
	return a.p>b.p;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		char ss[N];
		scanf("%s",ss);
		int len=strlen(ss);
		int s=0,h=0,sh=0;
		for(int j=0;j<len;j++){
			if(ss[j]=='s') s++;
			else{
				sh+=s;
			    h++;
			}
		}
		str[i].s=s;
		str[i].h=h;
		str[i].sh=sh;
		if(h==0){
		  str[i].p=N;
		  continue;
		}
		str[i].p=1.0*s/h;
	}
	sort(str,str+n,cmp);
	ll ans=0,cnt=0;
	for(int i=0;i<n;i++){
		ans+=str[i].sh;
		ans+=str[i].h*cnt;
		cnt+=str[i].s;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX 0x3f3f3f3f
#define ll long long

typedef struct node {
    int s, h, sh;
    double s_h;
} SH;

bool cmp(const SH &A, const SH &B) {
    return A.s_h > B.s_h;
}

SH a[100010];
char str[100010];

int main() {
    int n, s, h, sh;
    scanf("%d", &n);
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
        scanf("%s", str);
        s = 0;
        h = 0;
        sh = 0;
        for (int j = 0; j < strlen(str); j++) {
            if (str[j] == 's')
                s++;
            else {
                h++;
                sh += s;
            }
            a[i].s = s;
            a[i].h = h;
            a[i].sh = sh;
            if (h) {
                a[i].s_h = (double)s / h;
            } else {
                a[i].s_h = MAX;
            }
        }
    }
    sort(a, a + n, cmp);
    ll ans = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        ans += cnt * a[i].h;
        ans += a[i].sh;
        cnt += a[i].s;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX 0x3f3f3f3f
#define ll long long

typedef struct node {
    int s, h, sh;
    double s_h;
} SH;

bool cmp(const SH &A, const SH &B) {
    return A.s_h > B.s_h;
}

SH a[100010];
char str[100010];

int main() {
    int n, len;
    scanf("%d", &n);
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
        scanf("%s", str);
        len = strlen(str);
        for (int j = 0; j < len; j++) {
            if (str[j] == 's')
                a[i].s++;
            else {
                a[i].h++;
                a[i].sh += a[i].s;
            }
            if (a[i].h) {
                a[i].s_h = 1.0 * a[i].s / a[i].h;
            } else {
                a[i].s_h = MAX;
            }
        }
    }
    sort(a, a + n, cmp);
    ll ans = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        ans += cnt * a[i].h;
        ans += a[i].sh;
        cnt += a[i].s;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

inline long long fn(string &x) {
  long long ret = 0, c = 0;
  for(int i = 0; i < x.length(); i++) {
    if(x[i] == 's') {
      c++;
    } else {
      ret += c;
    }
  }
  return ret;
}

main() {
  ios::sync_with_stdio(false), cin.tie(0);

  int t = 1, n, m, i, j, k, u, to, w;
  // cin >> t;
  // int tc = t;
  while (t--) {
    // cout << "Case #" << tc - t << ": ";
    cin >> n;
    vector<string> a(n);
    for(auto &it: a) {
      cin >> it;
    }
    sort(a.begin(), a.end(), [&](string x, string y) {
      return fn(x) < fn(y);
    });
    string s = "";
    for(auto it: a) {
      s += it;
    }
    cout << fn(s);
  }
}


#include <bits/stdc++.h>
using namespace std;

inline int cnt(string &x, char ch) {
  int ret = 0;
  for(auto &it: x) {
    ret += it == ch;
  }
  return ret;
}

main() {
  ios::sync_with_stdio(false), cin.tie(0);

  int t = 1, n, m, i, j, k, u, to, w;
  // cin >> t;
  // int tc = t;
  while (t--) {
    // cout << "Case #" << tc - t << ": ";
    cin >> n;
    vector<string> a(n);
    for(auto &it: a) {
      cin >> it;
    }
    sort(a.begin(), a.end(), [&](string x, string y) {
      if(cnt(x, 'h') == cnt(y, 'h')) {
        return cnt(x, 's') > cnt(y, 's');
      }
      return cnt(x, 'h') < cnt(y, 'h');
    });
    string s = "";
    for(auto it: a) {
      s += it;
    }
    long long ans = 0, c = 0;
    for(i = s.length() - 1; i >= 0; i--) {
      if(s[i] == 's') {
        ans += c;
      } else {
        c++;
      }
    }
    cout << ans;
  }
}


#include <bits/stdc++.h>
using namespace std;

inline long long fn(string x) {
  long long ret = 0, c = 0;
  for(int i = 0; i < x.length(); i++) {
    if(x[i] == 's') {
      c++;
    } else {
      ret += c;
    }
  }
  return ret;
}

main() {
  ios::sync_with_stdio(false), cin.tie(0);

  int t = 1, n, m, i, j, k, u, to, w;
  // cin >> t;
  // int tc = t;
  while (t--) {
    // cout << "Case #" << tc - t << ": ";
    cin >> n;
    vector<string> a(n);
    for(auto &it: a) {
      cin >> it;
    }
    sort(a.begin(), a.end(), [&](string x, string y) {
      return fn(x + y) > fn(y + x);
    });
    string s = "";
    for(auto it: a) {
      s += it;
    }
    cout << fn(s);
  }
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
int f(string s){
  ll st=0,ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='s')st++;
        else ans+=st;
    }
    return ans;
  }
bool cmp(string a,string b){
  return (f(a+b)>f(b+a));
}
int main(){
  IOS;
  ll n;
  cin>>n;
  vector<string>t(n);
  for(int i=0;i<n;i++)cin>>t[i];
  sort(all(t),cmp);
  string ans;
  for(int i=0;i<n;i++)ans+=t[i];
  cout<<f(ans)<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool comp(pair<ll,pair<ll,pair<ll,string> > >&a,pair<ll,pair<ll,pair<ll,string> > >&b){
    if(a.fi!=b.fi)return a.fi<b.fi;
    if(a.fi==b.fi && a.se.fi!=b.se.fi)return a.se.fi>b.se.fi;
    return a.se.se.fi>b.se.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll help[n]={0};
  vector<string>t(n);
  vector<pair<ll,pair<ll,pair<ll,string> > > >s;
  for(int i=0;i<n;i++){
    cin>>t[i];
    ll c=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j] == 'h')help[i]++;
      else c++;
    }
    ll hl = help[i],ans=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j]=='h')hl--;
      else ans+=hl;
    }
    s.pb({help[i],{ans,{c,t[i]}}});
  }
  sort(all(s),comp);
  // for(int i=0;i<n;i++)
  //     trace3(s[i].fi,s[i].se.fi,s[i].se.se);
  string f;ll hno=0,ans=0;
  for(int i=0;i<n;i++)f+=s[i].se.se.se,hno+=s[i].fi;
  //trace1(f);
  for(int i=0;i<f.length();i++){
      if(f[i]=='h') hno--;
      else ans+=hno;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
int f(string s){
  ll h=0,ans=0;
    for(int i=0;i<s.length();i++)if(s[i]=='h')h++;
    for(int i=0;i<s.length();i++){
        if(s[i]=='h')h--;
        else ans+=h;
    }
    return ans;
  }
bool cmp(string a,string b){
  return f(a+b)>f(b+a);
}
int main(){
  IOS;
  ll n;
  cin>>n;
  vector<string>t(n);
  for(int i=0;i<n;i++)cin>>t[i];
  sort(all(t),cmp);
  string f;
  for(int i=0;i<n;i++)f+=t[i];
  ll h=0,ans=0;
  for(int i=f.length()-1;i>=0;i--){
    if(f[i]=='h')h++;
    else ans+=h;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool cmp(pair<ll,pll>&a,pair<ll,pll>&b){
    if(a.fi!=b.fi)return a.fi<b.fi;
    return a.se.fi>b.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll help=0,tot=0;
  vector<string>t(n);
  vector<pair<ll,pair<ll,ll> > >v;
  for(int i=0;i<n;i++){
    cin>>t[i];
    help=0;
    for(int j=0;j<t[i].length();j++)if(t[i][j]=='h')help++;
    v.pb({help,{t[i].length()-help,i}});
    tot+=help;
  }
  sort(all(v),cmp);
  string f;ll ans=0;
  for(int i=0;i<n;i++)f+=t[v[i].se.se];
//  trace1(f);
  for(int i=0;i<f.length();i++){
      if(f[i]=='h')tot--;
      else ans+=tot;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool comp(pair<ll,pair<ll,string> >&a,pair<ll,pair<ll,string> >&b){
    if(a.fi!=b.fi)return a.fi<b.fi;
    return a.se.fi>b.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll help[n]={0};
  vector<string>t(n);
  vector<pair<ll,pair<ll,string> > >s;
  for(int i=0;i<n;i++){
    cin>>t[i];
    for(int j=0;j<t[i].length();j++)if(t[i][j] == 'h')help[i]++;
    ll hl = help[i],ans=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j]=='h')hl--;
      else ans+=hl;
    }
    s.pb({help[i],{ans,t[i]}});
  }
  sort(all(s),comp);
  // for(int i=0;i<n;i++)
  //     trace3(s[i].fi,s[i].se.fi,s[i].se.se);
  string f;ll hno=0,ans=0;
  for(int i=0;i<n;i++)f+=s[i].se.se,hno+=s[i].fi;
  for(int i=0;i<f.length();i++){
      if(f[i]=='h') hno--;
      else ans+=hno;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
int f(string s){
  ll st=0,ans=0;
    for(int i=0;i<s.length();i++)if(s[i]=='s')st++;
    for(int i=0;i<s.length();i++){
        if(s[i]=='s')st++;
        else ans+=st;
    }
    return ans;
  }
bool cmp(string a,string b){
  return (f(a+b)>f(b+a));
}
int main(){
  IOS;
  ll n;
  cin>>n;
  vector<string>t(n);
  for(int i=0;i<n;i++)cin>>t[i];
  sort(all(t),cmp);
  string f;
  for(int i=0;i<n;i++)f+=t[i];
  ll h=0,ans=0;
  cout<<f(ans)<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
ll f(string s){
  ll st=0,ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='s')st++;
        else ans+=st;
    }
    return ans;
  }
bool cmp(string a,string b){
  return (f(a+b)>f(b+a));
}
int main(){
  IOS;
  ll n;
  cin>>n;
  vector<string>t(n);
  for(int i=0;i<n;i++)cin>>t[i];
  sort(all(t),cmp);
  string ans;
  for(int i=0;i<n;i++)ans+=t[i];
  cout<<f(ans)<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool cmp(pair<ll,pll>&a,pair<ll,pll>&b){
    if(a.fi!=b.fi)return a.fi>b.fi;
    return a.se.fi>b.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll tot=0;
  vector<string>t(n);
  vector<pair<ll,pair<ll,ll> > >v;
  for(int i=0;i<n;i++){
    cin>>t[i];
    ll h=0,s=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j]=='h')h++;
      else s++;
    }
    double q;
    if(h>0 && s>0)
      q = (double)s/double(h);
    else if(h==0) q=1e18;
    else q=-1e18;
    v.pb({q,{s,i}});
    tot+=h;
  }
  sort(all(v),cmp);
  string f;ll ans=0;
  for(int i=0;i<n;i++)f+=t[v[i].se.se];
//  trace1(f);
  for(int i=0;i<f.length();i++){
      if(f[i]=='h')tot--;
      else ans+=tot;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool cmp(pair<ll,pll>&a,pair<ll,pll>&b){
    if(a.fi!=b.fi)return a.fi>b.fi;
    return a.se.fi>b.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll tot=0;
  vector<string>t(n);
  vector<pair<double,pair<ll,ll> > >v;
  for(int i=0;i<n;i++){
    cin>>t[i];
    ll h=0,s=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j]=='h')h++;
      else s++;
    }
    double q = (double)s/double(h);
    if(h==0) q=1e18;
    if(s==0) q=-1e18;
    v.pb({q,{s,i}});
    tot+=h;
  }
  sort(all(v));
  reverse(all(v));
  string f;ll ans=0;
  for(int i=0;i<n;i++)f+=t[v[i].se.se];
//  trace1(f);
  for(int i=0;i<f.length();i++){
      if(f[i]=='h')tot--;
      else ans+=tot;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<fstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<long long,long long>, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll  long long
#define ull unsigned int
#define ld long double
#define vii vector<int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define se second
#define fi first
#define ins insert
#define _rand(l,r) uniform_ll_distribution<ll>(l, r)(rng)
#define flush() cout.flush()
#define swap(a,b) {ll _temp=a;a=b;b=_temp;}
#define FOR(i,l,r) for(ll i=l;i<=r;++i)
#define FORr(i,r,l) for(ll i=r;i>=l;--i)
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define MD         1000000007
#define LN      14
#define fftmod      998244353,
#define EPS         (double)1e-10
#define PI          3.14159265358979323846264
#define inf 1e18
#define MAX 100005
#define kill {puts("-1");exit(0);}
ll m=998244353;
ll exp(ll a,ll b){ll res = 1LL;while(b){if(b&1){res = res*(a%m);res = (res+m)%m;}b=b>>1;a = (a%m)*(a%m);a  =(a+m)%m;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
bool cmp(pair<ll,pll>&a,pair<ll,pll>&b){
    if(a.fi!=b.fi)return a.fi>b.fi;
    return a.se.fi>b.se.fi;
}
int main(){
  IOS;
  ll n;
  cin>>n;
  ll tot=0;
  vector<string>t(n);
  vector<pair<ll,pair<ll,ll> > >v;
  for(int i=0;i<n;i++){
    cin>>t[i];
    ll h=0,s=0;
    for(int j=0;j<t[i].length();j++){
      if(t[i][j]=='h')h++;
      else s++;
    }
    double q;
    if(h>0 && s>0)
      q = (double)s/double(h);
    if(h==0) q=1e18;
    if(s==0) q=-1e18;
    v.pb({q,{s,i}});
    tot+=h;
  }
  sort(all(v),cmp);
  string f;ll ans=0;
  for(int i=0;i<n;i++)f+=t[v[i].se.se];
//  trace1(f);
  for(int i=0;i<f.length();i++){
      if(f[i]=='h')tot--;
      else ans+=tot;
  }
  cout<<ans<<endl;
}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
map<int,int> mp;
 map<int,int> hh,ss;

 bool cmp(lli a,lli b)
 {
    return ss[a]*hh[b]>ss[b]*hh[a];
 }

int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];

 vector<lli> vv;
 string temp="\0";
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    for(auto &k: s[j])
    {
        mp[k]++;
        if(k=='h')
            hh[j]++;
        else
            ss[j]++;
    }
    if(hh[j]==0)
        temp+=s[j];
    vv.push_back(j);
 }

 sort(vv.begin(),vv.end(),cmp);

 for(auto &j: vv)
 {
    temp+=s[j];
 }

 lli ans=0;
 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
    {
        ans+=mp['h'];
    }
    mp[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
map<int,int> mp;
 map<int,int> hh,ss;

 bool cmp(ll a,ll b)
 {
    if(a.first==b.first)
        return hh[a.second]<hh[b.second];
    return a.first>b.first;
 }

int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];

 vector<ll> vv;
 string temp="\0";
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    for(auto &k: s[j])
    {
        mp[k]++;
        if(k=='h')
            hh[j]++;
        else
            ss[j]++;
    }
    if(hh[j]==0)
        temp+=s[j];
 }

 for(int j=1;j<=n;j++)
 {
    if(hh[j]>0)
    vv.push_back({ss[j]*(mp['h'] - hh[j]),j});
 }

 sort(vv.begin(),vv.end(),cmp);

 for(auto &j: vv)
    {

        temp+=s[j.second];
    }

 // cout<<temp<<"\n";

 lli ans=0;
 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
        ans+=mp['h'];
    mp[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
map<int,int> mp;
 map<int,int> hh,ss;

 bool cmp(ll a,ll b)
 {
    if(a.first==b.first)
        return hh[a.second]<hh[b.second];
    return a.first>b.first;
 }

int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];

 vector<ll> vv;
 string temp="\0";
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    for(auto &k: s[j])
    {
        mp[k]++;
        if(k=='h')
            hh[j]++;
        else
            ss[j]++;
    }
    if(hh[j]==0)
        temp+=s[j];
 }

 for(int j=1;j<=n;j++)
 {
    lli uu=0;
    map<int,int> re=mp;

    for(auto &k: s[j])
    {
        if(k=='s')
            uu+=re['h'];
        re[k]--;
    }
    if(hh[j]>0)
    vv.push_back({uu,j});
 }

 sort(vv.begin(),vv.end(),cmp);

 for(auto &j: vv)
    {

        temp+=s[j.second];
    }

 // cout<<temp<<"\n";

 lli ans=0;
 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
        ans+=mp['h'];
    mp[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}

bool cmp(pair<ll,string> a,pair<ll,string> b)
{
    if(a.first.first==b.first.first)
        return a.first.second>b.first.second;
    return a.first.first<b.first.first;
}
int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];
 vector<pair<ll,string>> vv;
 map<int,int> tot;
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    map<int,int> mp;
    for(auto &k: s[j])
    {
        mp[k]++;
        tot[k]++;
    }
    vv.push_back({{mp['h'],mp['s']},s[j]});
 }

 sort(vv.begin(),vv.end(),cmp);

 string temp="\0";

 for(auto &j: vv)
 {
    temp+=j.second;
 }

 lli ans=0;

 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
    {
        ans+=tot['h'];
    }
    tot[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
map<int,int> mp;
 map<int,int> hh,ss;

 bool cmp(lli a,lli b)
 {
    return ss[a]*hh[b]>ss[b]*hh[a];
 }

int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];

 vector<lli> vv;
 string temp="\0";
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    for(auto &k: s[j])
    {
        mp[k]++;
        if(k=='h')
            hh[j]++;
        else
            ss[j]++;
    }
    if(hh[j]==0)
        temp+=s[j];
    else
    vv.push_back(j);
 }

 sort(vv.begin(),vv.end(),cmp);

 for(auto &j: vv)
 {
    temp+=s[j];
 }

 lli ans=0;
 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
    {
        ans+=mp['h'];
    }
    mp[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
map<int,int> mp;
 map<int,int> hh,ss;

 bool cmp(ll a,ll b)
 {
    if(a.first==b.first)
        return hh[a.second]<hh[b.second];
    return a.first>b.first;
 }

int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];

 vector<ll> vv;
 string temp="\0";
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    for(auto &k: s[j])
    {
        mp[k]++;
        if(k=='h')
            hh[j]++;
        else
            ss[j]++;
    }
    if(hh[j]==0)
        temp+=s[j];
 }

 for(int j=1;j<=n;j++)
 {
    lli uu=0;
    map<int,int> re;
    for(auto &k: s[j])
    {
        re[k]++;
    }
    for(auto &k: s[j])
    {
        if(k=='s')
            uu+=re['h'];
        re[k]--;
    }
    if(hh[j]>0)
    vv.push_back({ss[j]*(mp['h'] - hh[j]) + uu,j});
 }

 sort(vv.begin(),vv.end(),cmp);

 for(auto &j: vv)
    {

        temp+=s[j.second];
    }

 // cout<<temp<<"\n";

 lli ans=0;
 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
        ans+=mp['h'];
    mp[temp[j]]--;
 }

 cout<<ans;

}


/*
    NO
        TIME
            TO
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,k,m,d,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}

bool cmp(pair<ll,string> a,pair<ll,string> b)
{
    if(a.first.first==b.first.first&&a.first.second==b.first.second)
        return a.second>b.second;
    if(a.first.first==b.first.first)
        return a.first.second>b.first.second;
    return a.first.first<b.first.first;
}
int main()
{
  #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif

 IO;
 OS;
 int n;
 cin>>n;
 string s[n+1];
 vector<pair<ll,string>> vv;
 map<int,int> tot;
 for(int j=1;j<=n;j++)
 {
    cin>>s[j];
    map<int,int> mp;
    for(auto &k: s[j])
    {
        mp[k]++;
        tot[k]++;
    }
    vv.push_back({{mp['h'],mp['s']},s[j]});
 }

 sort(vv.begin(),vv.end(),cmp);

 string temp="\0";

 for(auto &j: vv)
 {
    temp+=j.second;
 }

 lli ans=0;

 for(int j=0;j<temp.length();j++)
 {
    if(temp[j]=='s')
    {
        ans+=tot['h'];
    }
    tot[temp[j]]--;
 }
 // cout<<temp<<" ";
 cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;

bool mycomp(string s1,string s2){
    int n=s1.length();
    int m=s2.length();
    long long int h=0;
    long long int c1=0;
    for(int i=n-1;i>=0;i--){
        if(s1[i]=='h')
        h++;
        else
        c1+=(h);
    }
     for(int i=m-1;i>=0;i--){
        if(s2[i]=='h')
        h++;
        else
        c1+=(h);
    }
    h=0;
    long long int c2=0;
      for(int i=m-1;i>=0;i--){
        if(s2[i]=='h')
        h++;
        else
        c2+=(h);
    }
     for(int i=n-1;i>=0;i--){
        if(s1[i]=='h')
        h++;
        else
        c2+=(h);
    }
    if(c1>c2)
    return false;
    return true;

}

int main(){
int n;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
cin>>s[i];
if(n>1)
sort(s,s+n,mycomp);

long long int ans =0;
long long int h=0;
for(int i=n-1;i>=0;i--){

    for(int j=s[i].length()-1;j>=0;j--){
        if(s[i][j]=='h')
        h++;
        else
        ans +=(h);
    }
}
cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;

bool mycomp(string s1,string s2){
    int n=s1.length();
    int m=s2.length();
    int h1=0;
    int h2 =0;
    int one_c=0;
    int two_c=0;
    for(int i=n-1;i>=0;i--){
        if(s1[i]=='h')
        h1++;
        else
            one_c+=(h1);

    }
      for(int i=m-1;i>=0;i--){
        if(s2[i]=='h')
        h2++;
        else
            two_c+=(h2);

    }
    if(h1==0){
        return true;
    }
    else if(h2==0){
        return false;
    }

    else{
        if(one_c>two_c)
        return true;
        else if(two_c>one_c)
        return false;
        else{
                 if(n-h1>m-h2){
        return true;
    }
    else if(m-h2>n-h1)
    return false;
            if(n>m)
            return false;
            else
            return true;
        }
    }
}

int main(){
int n;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
cin>>s[i];

sort(s,s+n,mycomp);

int ans =0;
int h=0;
for(int i=n-1;i>=0;i--){

    for(int j=s[i].length()-1;j>=0;j--){
        if(s[i][j]=='h')
        h++;
        else
        ans +=(h);
    }
}
cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;

bool mycomp(string s1,string s2){
    int n=s1.length();
    int m=s2.length();
    long long int h=0;
    long long int c1=0;
    for(int i=n-1;i>=0;i--){
        if(s1[i]=='h')
        h++;
        else
        c1+=(h);
    }
     for(int i=m-1;i>=0;i--){
        if(s2[i]=='h')
        h++;
        else
        c1+=(h);
    }
    h=0;

      for(int i=m-1;i>=0;i--){
        if(s2[i]=='h')
        h++;
        else
        c1-=(h);
    }
     for(int i=n-1;i>=0;i--){
        if(s1[i]=='h')
        h++;
        else
        c1-=(h);
    }
    if(c1>=0)
    return false;
    return true;

}

int main(){
int n;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
cin>>s[i];
if(n>1)
sort(s,s+n,mycomp);

long long int ans =0;
long long int h=0;
for(int i=n-1;i>=0;i--){

    for(int j=s[i].length()-1;j>=0;j--){
        if(s[i][j]=='h')
        h++;
        else
        ans +=(h);
    }
}
cout << ans << endl;

}