import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  val n = readLine.trim.toInt
  val store = readLine.trim
  val fromStart = Array.tabulate(n + 1){_ ⇒ Array.tabulate(4){it ⇒ if (it == 0) 1L else 0L}}
  for (i ← 0 until n){
    for (j ← 0 until 4) fromStart(i + 1)(j) = fromStart(i)(j)
    store(i) match{
      case 'J' ⇒ fromStart(i + 1)(1) += fromStart(i)(0)
      case 'O' ⇒ fromStart(i + 1)(2) += fromStart(i)(1)
      case 'I' ⇒ fromStart(i + 1)(3) += fromStart(i)(2)
      case _ ⇒
    }
  }//fromStart(i)(s) [0, i)の店でs個のスタンプをもらう
  val toEnd = Array.tabulate(n + 1){_ ⇒ Array.tabulate(4){it ⇒ if (it == 0) 1L else 0}}
  for (i ← (0 until n).reverse){
    for (j ← 0 until 4) toEnd(i)(j) = toEnd(i + 1)(j)
    store(i) match{
      case 'J' ⇒ toEnd(i)(3) += toEnd(i + 1)(2)
      case 'O' ⇒ toEnd(i)(2) += toEnd(i + 1)(1)
      case 'I' ⇒ toEnd(i)(1) += toEnd(i + 1)(0)
      case _ ⇒
    }
  }//toEnd(i)(s) [i, n)の店でs個のスタンプをもらう
  var maxIncrease = 0L
  for (i ← 0 to n){//i番目の店の前に店を出す場合
    for (j ← 1 to 3){
      if (maxIncrease < fromStart(i)(j - 1) * toEnd(i)(3 - j)) maxIncrease = fromStart(i)(j - 1) * toEnd(i)(3 - j)
    }
  }
  println(
    toEnd(0)(3) + maxIncrease
  )
}

