

fun memorizedRecursive(state: IntArray, memo: Array<IntArray>, current: Int = 0, borderBarrier:Int = 0): Int {
    if (current >= state.size) return 0
    if (memo[current][borderBarrier] >= 0) return memo[current][borderBarrier]
    memo[current][borderBarrier] = when(state[current]){
        0 -> memorizedRecursive(state, memo, current + 1, (borderBarrier - 1).let{if (it >= 0) it else 0})
        1 -> maxOf(memorizedRecursive(state, memo, current + 1, 2) + 1, memorizedRecursive(state, memo, current + 1, (borderBarrier - 1).let{if (it >= 0) it else 0}))
        2 -> if (borderBarrier > 0) memorizedRecursive(state, memo, current + 1, borderBarrier - 1) else memorizedRecursive(state, memo, current + 1, 0) + 1
        else -> if (borderBarrier > 0) maxOf(memorizedRecursive(state, memo, current + 1, 2) + 1, memorizedRecursive(state, memo, current + 1, borderBarrier - 1)) else (memorizedRecursive(state, memo, current + 1, 0) + 1)
    }
    return memo[current][borderBarrier]
}
fun calState(state: Array<String>, x: Int, y: Int): Int {
    return (if (x + 2 < state[y].length && state[y][x] == 'R' && state[y][x + 1] == 'G' && state[y][x + 2] == 'W') 2 else 0) +
            (if (y + 2 < state.size && state[y][x] == 'R' && state[y + 1][x] == 'G' && state[y + 2][x] == 'W') 1 else 0)
}
fun main(args:Array<String>): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(n){readLine()!!.trim()}
    println(
            (0 until m).map{x ->
                if (x < n){
                    //println((0 .. x).map{y -> "(${x - y}, $y)"}.joinToString(","))
                    memorizedRecursive(IntArray(x + 1){y -> calState(state, x - y, y)}, Array(x + 1){IntArray(3){-1}})
                }else {
                    //println((0 until n).map{y -> "(${x - y}, $y)"}.joinToString(","))
                    memorizedRecursive(IntArray(n){ y -> calState(state, x - y, y)}, Array(n){IntArray(3){-1}})
                }
            }.sum() +
                    (1 until n).map{y ->
                        if (m + y < n){
                            //println((0 until m).map{x -> "(${m - x - 1}, ${y + x})"}.joinToString(","))
                            memorizedRecursive(IntArray(m){x -> calState(state, m - x - 1, y + x)}, Array(m){IntArray(3){-1}})
                        }else {
                            //println((0 until n - y).map{x -> "(${m - x - 1}, ${y + x})"}.joinToString(","))
                            memorizedRecursive(IntArray(n - y){ x -> calState(state, m - x - 1, y + x)}, Array(n - y){IntArray(3){-1}})
                        }
                    }.sum()
    )
}
