CF922D.Robot Vacuum Cleaner

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 tt consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string tt as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i,j)(i,j) , that i<ji<j and and .

The robot is off at the moment. Imp knows that it has a sequence of strings tit_{i} in its memory, and he can arbitrary change their order. When the robot is started, it generates the string tt 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 nn ( 1<=n<=1051<=n<=10^{5} ) — the number of strings in robot's memory.

Next nn lines contain the strings t1,t2,...,tnt_{1},t_{2},...,t_{n} , 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 10510^{5} .

输出格式

Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

输入输出样例

  • 输入#1

    4
    ssh
    hs
    s
    hhhs
    

    输出#1

    18
    
  • 输入#2

    2
    h
    s
    

    输出#2

    1
    

说明/提示

The optimal concatenation in the first sample is ssshhshhhsssshhshhhs .

首页