fun main(args: Array) { val n = readLine()!!.toInt() val s = readLine()!! var c = 0 for (i in 0..(n - 3)) { if (!s[i].equals('U')) continue for (d in 1..((n - 1 - i) / 2)) { val j = i + d val k = j + d if (s[j].equals('M') && s[k].equals('G')) c++ } } println(c) }