G. Gerrymandering
time limit per test
10 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
2 1
RR
RG
RR
Output
2
Input
7 2
RRRRRRR
RRRRRRR
RRRRRRR
Output
21