Pushok the dog has been chasing Imp for a few hours already.

Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. 

While moving, the robot generates a string *t* consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string *t* as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (*i*, *j*), that *i* &lt; *j* and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fa3acb2a51fec405fff3ffa731bf524c21b71047.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/84e6f388d5468490ab0877195de0181911c46019.png" style="max-width: 100.0%;max-height: 100.0%;"/>. 

The robot is off at the moment. Imp knows that it has a sequence of strings *t*<sub class="lower-index">*i*</sub> in its memory, and he can arbitrary change their order. When the robot is started, it generates the string *t* as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.

Help Imp to find the maximum noise he can achieve by changing the order of the strings.
The first line contains a single integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the number of strings in robot's memory.

Next *n* lines contain the strings *t*<sub class="lower-index">1</sub>, *t*<sub class="lower-index">2</sub>, ..., *t*<sub class="lower-index">*n*</sub>, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 10<sup class="upper-index">5</sup>.
The optimal concatenation in the first sample is *ssshhshhhs*.
4
ssh
hs
s
hhhs
18
2
h
s
1
6
h
s
hhh
h
ssssss
s
40
1
s
0
10
sshshss
hssssssssh
hhhhhh
hhhs
hshhh
hhhhshsh
hh
h
shs
sshhshhss
613
100
h
shh
h
hs
shh
hh
h
ssh
hss
h
hh
h
h
h
h
h
h
h
h
h
hh
h
h
h
h
hhh
h
h
hhh
sh
hh
hs
h
h
shs
h
h
h
shh
hs
hs
h
h
h
hhh
h
hhs
hh
h
ssh
h
h
hh
sh
h
hss
h
hh
sh
hh
hh
hhh
hs
h
h
h
shs
hs
shs
sh
h
h
hs
h
h
h
h
sh
ssh
h
h
hh
hhh
ssh
h
ssh
hs
hh
h
hss
hhh
h
hhh
hss
hhh
h
hhh
sh
h
h
5058
n=int(input())
arr=[]
for i in range(n):
    arr.append(input())
arr.sort(key=lambda x:x.count("h")-x.count("s")*0.9999999)
s=''.join(arr)
cn=0
ans=0
for i in range(len(s)):
    cr=s[i]
    if(cr=="s"):
        cn+=1
    else:
        ans+=cn
print(ans)