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 Java (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main
{
	private static Map<String,Integer> intMap = new HashMap<>();
	private static Map<String,Integer> intMap2 = new HashMap<>();
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		char c[] = str.toCharArray();
		int n = c.length;
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
		{
			a[i] = numToInt(c[i]);
		}
		int ans = solve(a, n, str);
		System.out.println(ans);
	}
	public static int solve(int[] a, int n, String str)
	{
		if(intMap.containsKey(str)){
			return intMap.get(str);
		}
		if (n == 0) {
			return 0;
		}
		int ans = count(a, n, str);
		int ans2 = 0;

		int a2[] = new int[n-1];
		for (int i = 0; i < n; i++)
		{
			String str2 = newStr2(str, i);
			a2 = newA2(str2);
			ans2 = Math.max(ans2, solve(a2, n-1, str2));
		}
		intMap.put(str, ans+ans2);
		return ans+ans2;
	}

	private static int[] newA2(String str2)
	{
		char c[] = str2.toCharArray();
		int n = c.length;
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
		{
			a[i] = numToInt(c[i]);
		}
		return a;
	}
	private static int[] newA(int[] a, int n, int i)
	{
		int a2[] = new int[n-1];
		int k =0;
		for (int j = 0; j < n; j++) {
			if (j != i) {
				a2[k]= a[j];
				k++;
			}
		}
		return a2;
	}
	private static String newStr(int[] a, int n, int i)
	{
	    StringBuilder sb = new StringBuilder();
		for (int j = 0; j < n; j++) {
			if (j != i) {
				sb.append(String.valueOf(a[j]));
			}
		}
		return sb.toString();
	}
	private static String newStr2(String str, int i)
	{
		if (i == 0) {
			return str.substring(1);
		} else if (i == str.length()) {
			return str.substring(0, str.length()-2);
		}
	    StringBuilder sb = new StringBuilder();
		sb.append(str.substring(0, i));
		sb.append(str.substring(i+1));
		return sb.toString();
	}


	private static int count(int[] a, int n, String str)
	{
		if(intMap2.containsKey(str)){
			return intMap2.get(str);
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				if (a[i] == 1) {
					ans += 1;
				}
			}
		}
		intMap2.put(str, ans);
		return ans;
	}
	static int numToInt(char a)
	{
		return a - '0';
	}

}