PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000040. Robot hút bụi (Robot Vacuum Cleaner)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Robot hút bụi (Robot Vacuum Cleaner)

Robot Vacuum Cleaner

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn strings consisting only of s and h. Concatenate them in some order. The score is the number of pairs (i,j)(i,j) with i<ji<j, character ii equal to s and character jj equal to h. Maximize the score.

Input

The first line contains nn. Each of the next nn lines contains one string.

Output

Print the maximum score.

Constraints

  • 1≤n≤1051\le n\le 10^5.
  • 1≤∣si∣1\le |s_i| và ∑i=1n∣si∣≤2⋅105\sum_{i=1}^n |s_i|\le 2\cdot10^5.
  • Each character of sis_i is s or h..

Subtasks

  • Subtask 1 (20 points): n≤8n\le 8.
  • Subtask 2 (30 points): n≤30n\le 30.
  • Subtask 3 (50 points): Full constraints.

Examples

Input

2
ssh
hhs

Output

6

Explanation

The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.