'use strict'

const canRemove = (arr) => {
    for(let i = 0; i < arr.length - 1; i++) {
        if (arr[i] !== arr[i + 1]) return i 
    }
    return false
}

const remove = (arr, i) => {
    arr.splice(i, 2)
    return arr
}

const main = (input) => {
    let arr = input.split('\n')[0].split('')
    let ans = 0

    while (true) {
        for(let i = 0; i < arr.length - 1; i++) {
            if (arr[i] !== arr[i + 1]) {
                arr.splice(i, 2)
                ans += 2
            } 
        }

        let set = new Set(arr)
        if (set.size < 2) {
            console.log(ans)
            return
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))