import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(string S) {
    auto groups = S.array.group.map!"a[1]".array;
    long moves;

    foreach (i; 0 .. groups.length - 1) {
        if (groups[i] < groups[i + 1]) {
            moves += groups[i];
            groups[i + 1] -= groups[i];
        } else {
            moves += groups[i + 1];
            if (i + 2 < groups.length) {
                groups[i + 2] += groups[i] - groups[i + 1];
                groups[i + 1] = 0;
            }
        }
    }

    return moves * 2;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S);
    else
        solve(S).writeln;
}
