object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  println(solve(readLine.trim))
  def solve(string: String): Int = {
    implicit val memo = Array.tabulate(string.length){_ ⇒ Array.tabulate(string.length){_ ⇒ None:Option[Int]}}
    def searchWithPos(left: Int, right: Int): Int = {
      if (string.indices.contains(left) && string.indices.contains(right)){
        memo(left)(right) match{
          case Some(r) ⇒ r
          case None ⇒
            (if (List(string(left), string(right)).forall(c ⇒ c != 'i' && c != 'w') && string(left) == string(right).flip) {
              //println(s"left = ${string(left)}, right = ${string(right)}")
              searchWithPos(left - 1, right + 1) + 2
            }else {
              math.max(searchWithPos(left - 1, right), searchWithPos(left, right + 1))
            }).also{r ⇒ memo(left)(right) = Some(r)}
        }
      }else 0
    }
    def calMax(str: List[Char], position: Int = 0): Int = {
      str match {
        case 'i'::'w'::'i'::t ⇒ math.max(calMax('i'::t, position + 2), searchWithPos(position, position))
        case Nil ⇒ 0
        case h::t ⇒ calMax(t, position + 1)
      }
    }
    calMax(string.toList) + 3
  }
  implicit class CharFlip(val char: Char){
    def flip: Char = char match {
      case 'i' ⇒ 'i'
      case 'w' ⇒ 'w'
      case '(' ⇒ ')'
      case ')' ⇒ '('
      case '{' ⇒ '}'
      case '}' ⇒ '{'
      case '[' ⇒ ']'
      case ']' ⇒ '['
      case _ ⇒ ???
    }
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
