Problem:
Score : 900 points

Problem Statement

Takahashi has an empty string S and a variable x whose initial value is 0.

Also, we have a string T consisting of 0 and 1.

Now, Takahashi will do the operation with the following two steps |T| times.

Insert a 0 or a 1 at any position of S of his choice.

Then, increment x by the sum of the digits in the odd positions (first, third, fifth, ...) of S. For example, if S is 01101, the digits in the odd positions are 0, 1, 1 from left to right, so x is incremented by 2.

Print the maximum possible final value of x in a sequence of operations such that S equals T in the end.

Constraints

1 \leq |T| \leq 2 \times 10^5

T consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

T

Output

Print the maximum possible final value of x in a sequence of operations such that S equals T in the end.

Sample Input 1

1101

Sample Output 1

5

Below is one sequence of operations that maximizes the final value of x to 5.

Insert a 1 at the beginning of S. S becomes 1, and x is incremented by 1.

Insert a 0 to the immediate right of the first character of S. S becomes 10, and x is incremented by 1.

Insert a 1 to the immediate right of the second character of S. S becomes 101, and x is incremented by 2.

Insert a 1 at the beginning of S. S becomes 1101, and x is incremented by 1.

Sample Input 2

0111101101

Sample Output 2

26

Solution in Rust (1.42.0) (judge verdict: Time Limit Exceeded)

use proconio::{input, fastout};

fn calc(a:&Vec<[i32;3]>)-> i32 {
    let mut r:i32 = 0;
    let mut i:i32 = a[0][1];
    let mut o:bool = true;
    while i >= 0 {
        if o {
            r += a[i as usize][0];
            o = !o;
        } else {
            o = !o;
        };
        i = a[i as usize][1];
    }
    r
}

fn delete(a:&mut Vec<[i32;3]>, i:i32)-> (i32,i32) {
    let j = a[i as usize][2];
    let k = a[i as usize][1];
    a[j as usize][1] = k;
    if k < 0 {
        a[0][2] = j;
    } else {
        a[k as usize][2] = j;
    }
    (k,j)
}

#[fastout]
fn main() {
    input! {
        tt: String,
    }

    let mut t: Vec<[i32;3]> = vec![[-1,1,1]];
    let mut i = 1;
    for c in tt.chars() {
        i += 1;
        t.push([if c == '0' {0} else {1}, i, i-2]);
    }
    t[(i-1) as usize][1] = -1;
    t[0][2] = i - 1;

    let mut ans : i32 = calc(&t);
    i = 1;
    let mut o = true;
    let mut state = 0;
    while i >= 0 {
        match state {
            0 => if t[i as usize][0] == 0 {
                i = delete(&mut t, i).0;
                ans += calc(&t);
            } else {
                i = t[i as usize][1];
                o = true;
                state = 1;
            },
            1 => if t[i as usize][0] == 1 {
                i = t[i as usize][1];
                o = !o;
            } else if o {
                i = t[i as usize][1];
                state = 2;
            } else {
                i = delete(&mut t, i).0;
                ans += calc(&t);
                state = 0;
            },
            2 => if t[i as usize][0] == 0 {
                i = delete(&mut t, i).0;
                ans += calc(&t);
            } else {
                i = t[i as usize][1];
                o = true;
                state = 3;
            },
            3 => if t[i as usize][0] == 1 {
                i = t[i as usize][1];
                o = !o;
            } else if o {
                i = t[i as usize][1];
                state = 2;
            } else {
                i = delete(&mut t, i).0;
                ans += calc(&t);
                state = 2;
            },
            _ => panic!("state illegal")
        }
    }
    i = t[0][2];
    while i > 0 {
        if t[i as usize][0] == 0 {
            i = delete(&mut t, i).1;
            ans += calc(&t);
        } else {
            i = t[i as usize][2];
        }
    }
    i = t[0][1];
    while i >= 0 {
        i = delete(&mut t, i).0;
        ans += calc(&t);
    }
    println!("{}", ans);
}