Under construction

Still being built. Things may change

Physical Education

Time limit2sMemory limit1024 MB

Summary
Concatenate n rows of boys (B) and girls (G) in any order, then find the maximum number of boys standing at odd positions in the merged row.
Level

Medium6 of 10

Topics
Greedy, Sorting, Implementation
Solved
No attempts yet

Problem

There is a physical education lesson at a school. Unfortunately, there are many classes but only one teacher, so nn classes take the lesson together. The students in each class form a row, and boys and girls are mixed within each row.

It is inconvenient to teach several rows separately, so the teacher decides to merge all the rows into one. The teacher can pick two rows and place all students from one of them at the end of the other, which makes one long row. The order of students inside each row cannot be changed.

Once the teacher has one single row, the students are split into two groups. Going along the row, the students say "First", "Second", "First", "Second", and so on. Students who stand in odd positions form the "First" group and go play football. Students who stand in even positions form the "Second" group and go play volleyball.

Boys like football, and girls do not. The teacher wants to arrange the students so that as many boys as possible play football. Find the maximum number of boys who can play football.

Input

The first line contains one integer nn (1≤n≤100,0001 \le n \le 100,000), the number of classes.

The next nn lines each describe the initial row of one class. Each line is a string of the letters B and G. B means a boy and G means a girl. The first letter of a string is the first student in that row. Each row is not empty and contains at most 100 letters.

The total number of students does not exceed 10610^6.

Output

Print a single integer, the maximum possible number of boys who play football.

Hint

In the sample above, not all boys can play football at the same time. However, if the rows are arranged as BGG, BB, GG, GBG, then three of the four boys can play football.

Examples1

  1. Example 1

    Input
    4
    GBG
    BB
    GG
    BGG
    
    Expected output
    3