Face the Right Way

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John has lined up his $N$ ($1 \le N \le 5000$) cows in a row. Some cows face forward, but the rest face backward, and Farmer John wants every cow to face forward.

He owns an automatic cow-flipping machine. Because he bought the discount model, the machine is permanently preset to a single value $K$ ($1 \le K \le N$): every time it is used, it reverses the facing direction of some $K$ consecutive cows. A forward cow becomes backward and a backward cow becomes forward, while every cow stays in its original position. The machine can never act on fewer than $K$ cows, so it can only be applied to a block of exactly $K$ cows that lies entirely within the row.

Farmer John must commit to one fixed value of $K$ before he starts. Help him choose $K$ so that the machine can make all cows face forward using as few operations as possible, and let $M$ be that minimum number of operations for the chosen $K$. If several values of $K$ allow the same minimum $M$, choose the smallest such $K$.

Input

  • Line $1$: a single integer $N$.
  • Lines $2 \dots N+1$: line $i+1$ contains a single character, F or B, indicating whether cow $i$ faces forward (F) or backward (B).

Output

Print two space-separated integers $K$ and $M$: the chosen value of $K$ (the one that minimizes the number of operations, and the smallest among ties) and the corresponding minimum number of operations $M$.

Hint

Consider seven cows facing backward, backward, forward, backward, forward, backward, backward.

With $K = 3$ the machine must be used three times — on cows $(1,2,3)$, then $(3,4,5)$, then $(5,6,7)$ — after which every cow faces forward. The diagram below traces each cow's direction as the three operations are applied; > marks a cow about to be flipped.

     B > F   F   F
     B > F   F   F
     F > B > F   F
     B   B > F   F
     F   F > B > F
     B   B   B > F
     B   B   B > F

No fixed $K$ can finish this row in fewer than three operations, so the answer is $K = 3$ and $M = 3$.