import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()

  val n = s.length
  if (n < 2) {
    println(0)
    return
  }

  var tmps = s

  while (!tmps.isEmpty() && tmps[0] != tmps[1]) {
    tmps = tmps.substring(2)
  }

  var pre = 0
  var index = 1
  while (index < tmps.length) {
    if (tmps.isEmpty()) {
      break
    }
    if (tmps[pre] != tmps[index]) {
      val s1 = tmps.substring(0, pre)
      val s2 = tmps.substring(index + 1)
      tmps = s1 + s2
      pre--
      index--
      if (pre < 0) pre = 0
      if (index < 1) index = 1
      continue
    } 
    pre++
    index++
  }

  println(n - tmps.length)
}

