import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val s = sc.next().toCharArray
    
    val rs = new Array[Int](n)
    val gs = new Array[Int](n)
    val bs = new Array[Int](n)
    
    for (i <- s.indices) {
      if (i > 0) {
        s(i) match {
          case 'R' =>
            rs(i) = rs(i - 1) + 1
            gs(i) = gs(i - 1)
            bs(i) = bs(i - 1)
          case 'G' =>
            rs(i) = rs(i - 1)
            gs(i) = gs(i - 1) + 1
            bs(i) = bs(i - 1)
          case 'B' =>
            rs(i) = rs(i - 1)
            gs(i) = gs(i - 1)
            bs(i) = bs(i - 1) + 1
        }
      } else {
        s(i) match {
          case 'R' =>
            rs(i) = 1
            gs(i) = 0
            bs(i) = 0
          case 'G' =>
            rs(i) = 0
            gs(i) = 1
            bs(i) = 0
          case 'B' =>
            rs(i) = 0
            gs(i) = 0
            bs(i) = 1
        }
      }
    }
    
    var ans = 0L
    
    for (i <- n - 1 to 2 by -1) {
      for (j <- i - 1 to 1 by -1) {
        println(i, j, j - (i - j))
        if ((s(i) == 'R' && s(j) == 'G') || (s(i) == 'G' && s(j) == 'R')) {
          ans += bs(j)
          val m = i - j
          val n = j - m
          if (0 <= n && s(n) == 'B') {
            ans -= 1
          }
        } else if ((s(i) == 'R' && s(j) == 'B') || (s(i) == 'B' && s(j) == 'R')) {
          ans += gs(j)
          val m = i - j
          val n = j - m
          if (0 <= n && s(n) == 'G') {
            ans -= 1
          }
        } else if ((s(i) == 'B' && s(j) == 'G') || (s(i) == 'G' && s(j) == 'B')) {
          ans += rs(j)
          val m = i - j
          val n = j - m
          if (0 <= n && s(n) == 'R') {
            ans -= 1
          }
        }
      }
      
    }
    
    printArray(gs)
    printArray(rs)
    printArray(bs)
    println(ans)
  }
  
  def printArray[T](arr: Array[T]): Unit = {
    for (i <- arr.indices) {
      print(s"${arr(i)} ")
    }
    println()
  }
}