Gerrymandering is a practice intended to establish a political advantage for a particular party or group by manipulating district boundaries.
An election between the political parties A and B has taken place in N counties. Therefore, each county has chosen to represent either A or B.
Each county is either small or large. You are to partition them into districts so that:
A is majority in a district if the number of counties (belonging to this district) voting for it is greater or equal to the number of counties voting for the opposite party.
Find a split which maximizes the number of districts in which A is majority. Print its number of districts.
The first line contain an integer N.
The next N lines characterize the counties with two letters.
The first letter is either A or B, representing the elected party in this county.
The second letter is either S or L, where S stands for small county and L large county.
Print the answer on the first line.
Input | Output | Explanation |
---|---|---|
2 A L B S | 1 | The counties that are belonging in the same district are inside the same [brackets] The large counties are underlined. [A B] The district has even votes, so the winner is party A. |
3 A L B S B L | 1 | [A][B B] The first district is won by party A while the second one goes to party B. |
13 A S A L B S B S B S B S A S A L B S B L B S B S A L | 3 | [A A B B][B B A A][B B B B][A] Party A has a majority in districts 1,2,4 while party B only has majority in district 3. |