object Main extends App {
  import scala.io.StdIn._
  readLine.trim.scanLeft(Empty: Per){
    case (per, char) ⇒ per.addLast(char)
  }.tail.foreach(p ⇒ println(p.countBalancedSubstring))
}
sealed trait BalancedSubstring {
  def countInner: Long
  def length: Long
  def +(that: BalancedSubstring): BalancedSubstring = Balanced(countInner + that.countInner + length * that.length, length + that.length)
}
case object EmptySubstring extends BalancedSubstring {
  override def countInner: Long = 0
  override def length: Long = 0
}
case class Balanced(override val countInner: Long, override val length: Long) extends BalancedSubstring
sealed trait Per {
  def addLast(char: Char): Per
  def countBalancedSubstring: Long
  def addLast(substring: BalancedSubstring, prevState: Per): Per
}
case object Empty extends Per{
  override def addLast(char: Char): Per = {
    char match {
      case '(' ⇒ Positive(1, EmptySubstring, this, this)
      case ')' ⇒ Negative(0, this)
      case _ ⇒ ???
    }
  }
  override def countBalancedSubstring: Long = 0
  override def addLast(substring: BalancedSubstring, prevState: Per): Per = Zero(substring, prevState)
}
case class Zero(balanced: BalancedSubstring, prev: Per) extends Per {
  override def addLast(char: Char): Per = {
    char match {
      case '(' ⇒ Positive(1, EmptySubstring, this, this)
      case ')' ⇒ Negative(balanced.countInner, this)
      case '-' ⇒ prev
      case _ ⇒ ???
    }
  }
  override def countBalancedSubstring: Long = balanced.countInner
  override def addLast(substring: BalancedSubstring, prevState: Per): Per = Zero(balanced + substring, prevState)
}
case class Positive(potential: Int, mid: BalancedSubstring, left: Per, prev: Per) extends Per {
  override def addLast(char: Char): Per = {
    char match {
      case '(' ⇒ Positive(potential + 1, EmptySubstring, this, this)
      case ')' ⇒ left.addLast(Balanced(mid.countInner + 1, 1), this)
      case '-' ⇒ prev
      case _ ⇒ ???
    }
  }
  override val countBalancedSubstring: Long = mid.countInner + left.countBalancedSubstring
  override def addLast(substring: BalancedSubstring, prevState: Per): Per = Positive(potential, mid + substring, left, prevState)
}
case class Negative(count: Long, prev: Per) extends Per {
  override def addLast(char: Char): Per = {
    char match {
      case '(' ⇒ Positive(1, EmptySubstring, this, this)
      case ')' ⇒ Negative(count, this)
      case '-' ⇒ prev
      case _ ⇒ ???
    }
  }
  override def addLast(substring: BalancedSubstring, prevState: Per): Per = Zero(Balanced(count + substring.countInner, substring.length), prevState)
  override def countBalancedSubstring: Long = count
}
