import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val S = sc.next().toCharArray()

    var list = S.toList()
    var isRun = true
    var ans:Long = 0

    while (isRun) {
        isRun = false
        var pre = 'N'
        var nextList = mutableListOf<Char>()
        var stk = 0
        for (c in list) {
            if ((stk > 0 && pre == 'N') || (pre != 'N' && pre != c)) {
                ans += 2
                nextList.removeAt(nextList.size-1)
                isRun = true
                pre = 'N'
                stk--
            }else {
                stk++
                nextList.add(c)
                pre = c
            }
        }
        list = nextList
    }
    println(ans)
}