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



Sample input:
1101


Sample output:
5

Submission status: Wrong Answer

Solution code:
t = input()
one = t.count('1')
zero = t.count('0')
n = len(t)
c = 0
s = 0

for i in range(0, n):
	if i%2==1:
		if one>=1:
			one-=1
			c += 1
		else:
			zero -= 1
	if i%2==0:
		if zero>=1:
			zero -= 1
	else:
		one -= 1
	s += c
print(s)

Submission status: Wrong Answer

Solution code:
t = input()
one = t.count('1')
zero = t.count('0')
n = len(t)
c = 0
s = 0

for i in range(0, n):
	if i%2==1:
		if one>=1:
			one-=1
			c += 1
		else:
			zero -= 1
	if i%2==0:
		if zero>=1:
			zero -= 1
	s += c
print(s)

Submission status: Wrong Answer

Solution code:
def solve():
    T = list(input())
    x = 0
    while len(T) > 0:
        x += T[::2].count('1')
        if '0' in T[::2]:
            T.remove('0')
        else:
            del T[-1]
    print(x)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:

n = input()
zero_list = []
z_count = 0
ans = 0
for i in range(len(n)):
    if n[i] == "0":
        z_count += 1
    else:
        zero_list.append(z_count)
        z_count = 0
zero_list.append(z_count)

ones = n.count("1")

for i in range(1,ones+1):
    if i % 2 == 0:
        ans += i//2
    else:
        ans += i//2 + 1
             
test_string = ""
if ones % 2 == 0:
    test_string = "10"*(ones//2)
else:
    test_string = "10"*(ones//2)+"1"

print(test_string)
print(zero_list)

for i in range(len(test_string)):
    if test_string[i] == "0" and zero_list[i] > 0:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

#remove more than 1 zeros
for i in range(len(zero_list)):
    while zero_list[i] > 1:
        zero_list[i] -= 2
        ans += len(test_string)

#remove last zero from back
for i in range(len(zero_list)-1,-1,-1):
    if zero_list[i] == 1:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

print(ans)

Submission status: Wrong Answer

Solution code:

n = input()

zero_list = []
z_count = 0
ans = 0
for i in range(len(n)):
    if n[i] == "0":
        z_count += 1
    else:
        zero_list.append(z_count)
        z_count = 0
zero_list.append(z_count)

ones = n.count("1")

for i in range(1,ones+1):
    if i % 2 == 0:
        ans += i//2
    else:
        ans += i//2 + 1
             
test_string = ""
if ones % 2 == 0:
    test_string = "10"*(ones//2)
else:
    test_string = "10"*(ones//2)+"1"

for i in range(len(test_string)):
    if test_string[i] == "0" and zero_list[i] > 0:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

#remove more than 1 zeros
for i in range(len(test_string)):
    while zero_list[i] > 1:
        zero_list[i] -= 2
        ans += test_string.count("1") * 2

#remove last zero from back
for i in range(len(test_string),-1,-1):
    if zero_list[i] == 1:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

print(ans)

Submission status: Wrong Answer

Solution code:

n = input()

zero_list = []
z_count = 0
ans = 0
for i in range(len(n)):
    if n[i] == "0":
        z_count += 1
    else:
        zero_list.append(z_count)
        z_count = 0
zero_list.append(z_count)

ones = n.count("1")

for i in range(1,ones+1):
    if i % 2 == 0:
        ans += i//2
    else:
        ans += i//2 + 1
             
test_string = ""
if ones % 2 == 0:
    test_string = "10"*(ones//2)
else:
    test_string = "10"*(ones//2)+"1"

for i in range(len(test_string)):
    if test_string[i] == "0" and zero_list[i] > 0:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

#remove more than 1 zeros
for i in range(len(test_string)):
    while zero_list[i] > 1:
        zero_list[i] -= 1
        ans += test_string.count("1") * 2

#remove last zero from back
for i in range(len(test_string),-1,-1):
    if zero_list[i] == 1:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

print(ans)

Submission status: Wrong Answer

Solution code:

n = input()

zero_list = []
z_count = 0
ans = 0
for i in range(len(n)):
    if n[i] == "0":
        z_count += 1
    else:
        zero_list.append(z_count)
        z_count = 0
zero_list.append(z_count)

ones = n.count("1")

for i in range(1,ones+1):
    if i % 2 == 0:
        ans += i//2
    else:
        ans += i//2 + 1
             
test_string = ""
if ones % 2 == 0:
    test_string = "10"*(ones//2)
else:
    test_string = "10"*(ones//2)+"1"

for i in range(len(test_string)):
    if test_string[i] == "0" and zero_list[i] > 0:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

#remove more than 1 zeros
for i in range(len(test_string)):
    while zero_list[i] > 1:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

#remove last zero from back
for i in range(len(test_string),-1,-1):
    if zero_list[i] == 1:
        test_string = test_string[0:i]+test_string[i:len(test_string)].replace("0","2").replace("1", "0").replace("2", "1") 
        zero_list[i] -= 1
        ans += test_string.count("1")

print(ans)

Submission status: Wrong Answer

Solution code:

n = input()

if n == "0":
    print("0")
    exit()

ans = 0

two_zero = n.count("00")
n = n.replace("00","")
ans += n.count("1") * two_zero

s = len(n)-1
print(n)
print(n[0::2])
while s >= 0:
    if n[s] == "0":
        ans += n[0::2].count("1")  
        n = n[0:s]+n[s+1:len(n)]
    s-=1

s = len(n)-1
while s>= 0:
    if len(n) % 2 == 0:
        ans += len(n)//2
    else:
        ans += len(n)//2+1
    n = n[0:s]
    s-=1

print(ans)

Submission status: Wrong Answer

Solution code:

n = input()

def sum_odd(b):
    total=0
    odd = True
    for s in b:
        if odd and s=="1":
            total+=1
        odd = not odd
    return total

if n == "0":
    print("0")
    exit()


ans = 0

two_zero = n.count("00")
n.replace("00","")
ans += n.count("1") * two_zero

s = len(n)-1
while s >= 0:
    if n[s] == "0":
        ans += sum_odd(n)  
        n = n[0:s]+n[s+1:len(n)]
    s-=1

s = len(n)-1
while s>= 0:
    ans += sum_odd(n)
    n = n[0:s]+n[s+1:len(n)]
    s-=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
x = 0
while S:
    x += S[::2].count('1')
    if '0' in S:
        S = S.replace('0','',1)
    else:
        S = S[1::]
print(x)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    n=len(s)
    n2=n//2
    ans=n2*(n2+1)+n%2*n
    rem=0
    for i,c in enumerate(s):
        if c=="1":continue
        ans-=(rem+1)//2
        if rem%2==0 and i%2==0:ans-=1
        if (i-rem)%2==0:rem+=1
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

t = input()
s = t.replace("0", "")
q = len(s) # 1の数
n = len(t)
ps = [None]*(q+1)
c = 0
j = 0
for tmp in t:
    if tmp=="1":
        ps[j] = c
        j += 1
        c = 0
    else:
        c += 1
ps[-1] = c

dp = [0] * q # インデックスqの1までのベストな配置のときの奇数の個数
pp = [0] * (q+1) # 上を実現するために使うpsの個数
if not dp:
    print(0)
else:
    dp[0] = 1
    j = 1 # j : トータルのインデックス(1はじまり)
    for i in range(1,q):
        j += 1
        p = ps[i]
        if j%2:
            pp[i] = 0
            dp[i] = dp[i-1] + 1
        elif p:
            pp[i] = 1
            j += 1
            dp[i] = dp[i-1] + 1
        else:
            pp[i] = 0
            dp[i] = dp[i-1]
    if q%2==0:
        ans = q//2 * (q//2 + 1)
    else:
        ans = q//2 * (q//2 + 1) + q//2 + 1

    # 1をすべて入れたあとに得られる利得
    # ppを前から順にいれていく
    j = 0
    for i in range(q+1):
        j += 1
        if not pp[i]:
            continue
        # 0を１個いれる
        j += 1
        ans += dp[i]
        if j%2:
            ans += (q-i-1) // 2
        else:
            ans += (q-i-1) // 2 + (q-i-1)%2

    # 残りのpsを後ろから順にいれていく
    o = 0 # 現時点より後ろの(jを0としたときの)奇数番目の1の個数
    e = 0 # 現時点より後ろの(jを0としたときの)偶数番目の1の個数
    j = q + sum(pp) # 現在地のインデックス(1はじまり)
    for i in range(q, 0, -1):
        num = ps[i] - pp[i]
        if num>0:
            ans += dp[i-1] * num
            if num%2==0:
                ans += (num//2)*o + (num//2)*e
            else:
                ans += (num//2)*o + (num//2)*e + e if j%2==0 else o
                e,o = o,e
        j -= 1
        if pp[i-1]:
            j -= pp[i-1]
            e += 1
        else:
            o, e = 1 + e, o

    # 最初の0を入れる
    num = ps[0] - pp[0]

    if num%2==0:
        ans += (num//2)*o + (num//2)*e
    else:
        ans += (num//2)*o + (num//2)*e + e if j%2==0 else o

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

t = input()
s = t.replace("0", "")
q = len(s) # 1の数
n = len(t)
ps = [None]*(q+1)
c = 0
j = 0
for tmp in t:
    if tmp=="1":
        ps[j] = c
        j += 1
        c = 0
    else:
        c += 1
ps[-1] = c

dp = [0] * q # インデックスqの1までのベストな配置のときの奇数の個数
pp = [0] * (q+1) # 上を実現するために使うpsの個数
if not dp:
    print(0)
else:
    dp[0] = 0
    j = 0 # j : トータルのインデックス(1はじまり)
    for i in range(q):
        j += 1
        p = ps[i]
        if j%2:
            pp[i] = 0
            dp[i] = dp[i-1] + 1
        elif p:
            pp[i] = 1
            j += 1
            dp[i] = dp[i-1] + 1
        else:
            pp[i] = 0
            dp[i] = dp[i-1]
    if q%2==0:
        ans = q//2 * (q//2 + 1)
    else:
        ans = q//2 * (q//2 + 1) + q//2 + 1

    # 1をすべて入れたあとに得られる利得
    # ppを前から順にいれていく
    j = 0
    for i in range(q+1):
        j += 1
        if not pp[i]:
            continue
        # 0を１個いれる
        j += 1
        ans += dp[i]
        if j%2:
            ans += (q-i-1) // 2
        else:
            ans += (q-i-1) // 2 + (q-i-1)%2

    # 残りのpsを後ろから順にいれていく
    o = 0 # 現時点より後ろの(jを0としたときの)奇数番目の1の個数
    e = 0 # 現時点より後ろの(jを0としたときの)偶数番目の1の個数
    j = q + sum(pp) # 現在地のインデックス(1はじまり)
    for i in range(q, 0, -1):
        num = ps[i] - pp[i]
        if num>0:
            ans += dp[i-1] * num
            if num%2==0:
                ans += (num//2)*o + (num//2)*e
            else:
                ans += (num//2)*o + (num//2)*e + e if j%2==0 else o
                e,o = o,e
        j -= 1
        if pp[i-1]:
            j -= pp[i-1]
            e += 1
        else:
            o, e = 1 + e, o

    # 最初の0を入れる
    num = ps[0] - pp[0]

    if num%2==0:
        ans += (num//2)*o + (num//2)*e
    else:
        ans += (num//2)*o + (num//2)*e + e if j%2==0 else o

    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import re
T=input()
x=0
Td=T
d = len(re.sub(r'0', '', Td))
x += math.ceil((d/2+1)*d/2)
spT = T.split('0')
lenT = list(map(len, spT))

tmpX = math.ceil(d/2)
bT = 0
aT = d
tmp = ''
for i in range(len(spT) - 1):
    tmp += spT[i]
    bT += lenT[i]
    aT -= lenT[i]
    if bT % 2==1:
        bT += 1
        if aT % 2 ==1:
            tmpX += 1
        x += tmpX
        tmp += '0'
    else:
        tmp +='+'
tmp += spT[-1]

spT = tmp.split('+')
vT =[]
aT = bT
bT = 0
odT = 0
tmpOd = True

for i in range(len(spT)):
    
    od = len(re.sub(r'0', '', spT[i][0 if tmpOd else 1::2]))
    ev = len(re.sub(r'0', '', spT[i][1 if tmpOd else 0::2]))
    odT += od
    vT.append(od - ev)
    if len(spT[i]) %2 == 1:
        tmpOd = not tmpOd

print(x)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

t = input()
s = t.replace("0", "")
q = len(s) # 1の数
n = len(t)
ps = [None]*(q+1)
c = 0
j = 0
for tmp in t:
    if tmp=="1":
        ps[j] = c
        j += 1
        c = 0
    else:
        c += 1
ps[-1] = c

dp = [0] * q # インデックスqの1までのベストな配置のときの奇数の個数
pp = [0] * (q+1) # 上を実現するために使うpsの個数
if not dp:
    print(0)
else:
    dp[0] = 1
    j = 0 # j : トータルのインデックス(1はじまり)
    for i in range(q):
        j += 1
        p = ps[i]
        if j%2:
            pp[i] = 0
            dp[i] = dp[i-1] + 1
        elif p:
            pp[i] = 1
            j += 1
            dp[i] = dp[i-1] + 1
        else:
            pp[i] = 0
            dp[i] = dp[i-1]
    if q%2==0:
        ans = q//2 * (q//2 + 1)
    else:
        ans = q//2 * (q//2 + 1) + q//2 + 1

    # 1をすべて入れたあとに得られる利得
    # ppを前から順にいれていく
    j = 0
    for i in range(q+1):
        j += 1
        if not pp[i]:
            continue
        # 0を１個いれる
        j += 1
        ans += dp[i]
        if j%2:
            ans += (q-i-1) // 2
        else:
            ans += (q-i-1) // 2 + (q-i-1)%2

    # 残りのpsを後ろから順にいれていく
    o = 0 # 現時点より後ろの(jを0としたときの)奇数番目の1の個数
    e = 0 # 現時点より後ろの(jを0としたときの)偶数番目の1の個数
    j = q + sum(pp) # 現在地のインデックス(1はじまり)
    for i in range(q, 0, -1):
        num = ps[i] - pp[i]
        if num>0:
            ans += dp[i-1] * num
            if num%2==0:
                ans += (num//2)*o + (num//2)*e
            else:
                ans += (num//2)*o + (num//2)*e + e if j%2==0 else o
                e,o = o,e
        j -= 1
        if pp[i-1]:
            j -= pp[i-1]
            e += 1
        else:
            o, e = 1 + e, o

    # 最初の0を入れる
    num = ps[0] - pp[0]

    if num%2==0:
        ans += (num//2)*o + (num//2)*e
    else:
        ans += (num//2)*o + (num//2)*e + e if j%2==0 else o

    print(ans)

Submission status: Wrong Answer

Solution code:
T=input()
n=len(T)
i=r=a=0
for c in T:
  k=i-r
  if c=='0':
    r+=k&1
  else:
    a+=i//2-k//2+(k&1)*(n-i)
  i+=1
print(a)

Submission status: Wrong Answer

Solution code:
import math
import re
T=input()
x=0
Td=T
d = len(re.sub(r'0', '', Td))
x += math.ceil((d/2+1)*d/2)
spT = T.split('0')
lenT = list(map(len, spT))

tmpX = math.ceil(d/2)
bT = 0
aT = d
tmp = ''
for i in range(len(spT) - 1):
    tmp += spT[i]
    bT += lenT[i]
    aT -= lenT[i]
    if bT % 2==1:
        bT += 1
        if aT % 2 ==1:
            tmpX += 1
        x += tmpX
        tmp += '0'
    else:
        tmp +='+'
tmp += spT[-1]

spT = tmp.split('+')
vT =[]
aT = bT
bT = 0
odT = 0
ccT = 0
for i in range(len(spT)):
    vT.append([len(re.sub(r'0', '', spT[i][::2])), len(re.sub(r'0', '', spT[i][1::2]))])
    odT += vT[-1][0]
    ccT += vT[-1][1]

print(x)

Submission status: Wrong Answer

Solution code:
t = [int(item) for item in input()]
n = len(t)

# put ones
ones = sum(t)
# zeroes+
ans = 0
une2 = ones // 2
if ones % 2 == 0:
	ans += une2 * (une2 + 1)
else:
	ans +=  une2 * (une2 + 1)
	ans += (ones // 2) + 1
# print("ans after ones", ans)

new_str = []
even_count = 0
segment_len = 0

for i in range(n):
	# print("t[", i, "]", t[i])
	if t[i] == 1:
		segment_len += 1
	else:
		new_str.append(0)
		if segment_len % 2 == 0:
			even_count += segment_len
		else:
			even_count += segment_len - 1
			new_str.append(1)
		segment_len = 0

if segment_len > 0:
	if segment_len % 2 == 0:
		even_count += segment_len
	else:
		even_count += segment_len - 1
		new_str.append(1)


# print("even_count", even_count)
# print("new_str", new_str)
n_new = len(new_str)

zeroes_after = [0 for i in range(n_new)]
zeroes_before = [0 for i in range(n_new)]
for i in range(1, n_new):
	zeroes_before[i] = zeroes_before[i-1] + (1 - new_str[i-1])

for i in range(n_new-2, -1, -1):
	zeroes_after[i] = zeroes_after[i+1] + (1 - new_str[i+1])


rest_steps = n - ones

ans += (even_count // 2)* rest_steps
# print("ans after even", ans)


for i in range(n_new):
	if new_str[i] == 1:
		ans += zeroes_after[i] # after all is mine
		ans += (zeroes_before[i] // 2 )
print(ans)

Submission status: Wrong Answer

Solution code:
t = list(input())

zero = t.count("0")
rev = 1
count = 0
zero_n = 0
ans = 0

for i in range(len(t)):
    if zero_n % 2 == 0:
        if t[i] == "1" and i % 2 == 0:
            ans = ans + (zero - zero_n // 2) + 1
        elif t[i] == "1" and i % 2 != 0:
            ans = ans + zero_n // 2
        else:
            zero_n = zero_n + 1
            continue

    if zero_n % 2 != 0:
        if t[i] == "1" and i % 2 == 0:
            ans = ans + zero_n // 2 + 1
        elif t[i] == "1" and i % 2 != 0:
            ans = ans + (zero - zero_n // 2)
        else:
            zero_n = zero_n + 1

n = len(t) - zero

if n % 2 == 0:
    ans = ans + ((n - 2) // 2) * ((n - 2) // 2 + 1) + (n - 2) // 2 + 1
else:
    ans = ans + (n // 2) * (n // 2 + 1)


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
def check(s,t):
    count_1 = 0
    count_2 = 0
    count_3 = 0
    count_4 = 0
    s.append("0")
    s1 = list(s)
    if "".join(s1) in "".join(t):
        for j in range(len(s)):
            if j%2==0 and s[j]=="1":
                count_1+=1
    s.pop()
    s.appendleft("1")
    s2 = list(s)
    if "".join(s) in "".join(t):
        for j in range(len(s)):
            if j%2==0 and s[j]=="1":
                count_2+=1
    s.popleft()
    s.append("1")
    s1 = list(s)
    if "".join(s1) in "".join(t):
        for j in range(len(s)):
            if j%2==0 and s[j]=="1":
                count_3+=1
    s.pop()
    s.appendleft("0")
    s2 = list(s)
    if "".join(s) in "".join(t):
        for j in range(len(s)):
            if j%2==0 and s[j]=="1":
                count_3+=1
    s.popleft()
    if max(count_1,count_2,count_3,count_4)==count_1:
        s.append("0")
    elif max(count_1,count_2,count_3,count_4)==count_2:
        s.appendleft("1")
    elif max(count_1,count_2,count_3,count_4)==count_3:
        s.append("1")
    else:
        s.appendleft("0")
    return max(count_1,count_2,count_3,count_4)
t = list(input())
s = deque()
ans = 0
for i in range(len(t)):
    ans+=check(s,t)
print(ans)

Submission status: Wrong Answer

Solution code:
def removeOdd0(t):
    poppun=t.pop
    for i in range(len(t)//2):
        if t[2*i]=='0':
            poppun(2*i)
            return t
        else:
            pass
    else:
        poppun(0)
        return t

T=input()
t=list(T)

x=0

for j in range (len(t)):
    _tOdd=t[::2]
    _x=_tOdd.count('1')
    x+=_x
    removeOdd0(t)

print(x)

Submission status: Wrong Answer

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    T = input()
    output = 0
    n = e = o = 0
    for i in range(len(T)):
        if T[i] == '1': n += 1
        if i%2 == 0 and T[i] == '1': o += 1
        if i%2 == 1 and T[i] == '1': e += 1

    l = []
    x = y = 0
    for i in range(len(T)):
        if i%2 == 0 and T[i] == '1': x += 1
        if i%2 == 1 and T[i] == '1': y += 1
        if T[i] == '0':
            l.append([o-x, e-y])

    for i in range(1, (n+1)//2 + 1): output += 2 * i
    if n%2 == 1: output -= (n+1)//2

    for i in range(len(l)):
        e = o - l[i][0] + l[i][1]
        o = e - l[i][1] + l[i][0]
        x = o if i%2 == 0 else e
        output += x

    print(output)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import *
s = input()
no = s.count('1')
ans = 0
for i in range(1,no+1):
	ans += ceil(i/2)
ct,l = 0,no
o,e = 0,0
for i in range(len(s)-1,-1,-1):
	if(s[i] == '1'):
		ct += 1
		if(l%2 == 0):
			e += 1
		else:
			o += 1
		l -= 1
	else:
		ans += e + ceil((no-ct)/2)
		o,e = e,o
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
cnt = len(t)
zeros = t.count('0')

output = 0

for _ in range(zeros):
    c = sum([int(t[i]) for i in range(len(t)) if i % 2 == 0])
    output += c
    buf = t.rfind('0')
    if buf % 2 != 0:
        buf = t.rfind('0',0,buf)
    t = t[:buf] + t[buf+1:]

import math

output += sum([math.ceil((i+1)/2) for i in range(len(t))])
print(output)

Submission status: Wrong Answer

Solution code:
t = [int(item) for item in input()]
n = len(t)

# put ones
ones = sum(t)
# zeroes+
ans = 0
une2 = ones // 2
if ones % 2 == 0:
	ans += une2 * (une2 + 1)
else:
	ans +=  une2 * (une2 + 1)
	ans += (ones // 2) + 1
# print("ans after ones", ans)

new_str = []
even_count = 0
segment_len = 0

for i in range(n):
	# print("t[", i, "]", t[i])
	if t[i] == 1:
		segment_len += 1
	else:
		new_str.append(0)
		if segment_len % 2 == 0:
			even_count += segment_len
		else:
			even_count += segment_len - 1
			new_str.append(1)
		segment_len = 0

if segment_len > 0:
	if segment_len % 2 == 0:
		even_count += segment_len
	else:
		even_count += segment_len - 1
		new_str.append(1)


# print("even_count", even_count)
# print("new_str", new_str)
# put zeroes on even positions from end

rest_steps = n - ones

ans += (even_count // 2)* rest_steps
# print("ans after even", ans)


n_new = len(new_str)
for i in range(n_new):
	if new_str[i] == 1:
		ans += n_new -1  - i # after all is mine
		ans += (i // 2 )
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
n = len(t)

a = t.count("1")
b = [a//2+a%2, a//2]

z = []
for i in range(n):
    if t[i] == "0":
        z.append(i)

ans = 0
m = 1
for i in range(a):
    ans += m
    if i % 2 == 1:
        m += 1

for i in range(len(z)-1,-1,-1):
    if z[i] % 2 == 1:
        b = [b[1]+1, b[0]-1]
    else:
        b = [b[1], b[0]]
    ans += b[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

T = list(map(int, list(input())))
n = len(T)
ones = sum(T)

cnt = 0

for i in range(1, ones + 1):
    cnt += (i + 1) // 2

a, b = 0, 0
for i in range(n):
    if T[i] == 1:
        if i % 2 == 0:
            a += 1
        else:
            b += 1

l = 0
r = l - 1
ac = 0
bc = 0
for it in range(n - ones):
    if a < b:
        while T[l] == 1:
            if l % 2 == 0:
                ac += 1
            else:
                bc += 1
            l += 1
        cnt += a - ac
        a, b = b, a
    else:
        x = 0
        while T[r] == 1:
            x += 1
            r -= 1
        cnt += a
        if x % 2 != 0:
            a -= 1
            b += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import re
T=input()
x=0
Td=T
d = len(re.sub(r'0', '', Td))
x += math.ceil((d/2+1)*d/2)
for i in range(d, len(T)):
    tmpIdx = -1
    for i in range(len(Td)):
        if Td[i] == '0':
            tmpIdx =i
            if i%2==1:
                break
    if tmpIdx > -1:
        x += len(re.sub(r'0', '', Td[::2]))
        Td = Td[:tmpIdx] + Td[tmpIdx+1:]

print(x)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

T = list(map(int, list(input())))
n = len(T)
ones = sum(T)

cnt = 0

for i in range(1, ones + 1):
    cnt += (i + 1) // 2

a, b = 0, 0
for i in range(n):
    if T[i] == 1:
        if i % 2 == 0:
            a += 1
        else:
            b += 1
print(cnt)
l = 0
r = l - 1
ac = 0
bc = 0
for it in range(n - ones):
    if a < b:
        while T[l] == 1:
            if l % 2 == 0:
                ac += 1
            else:
                bc += 1
            l += 1
        cnt += a - ac
        a, b = b, a
    else:
        x = 0
        while T[r] == 1:
            x += 1
            r -= 1
        cnt += a
        if x % 2 != 0:
            a -= 1
            b += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import collections

ans = 0
t = input()
ls = []
one = t.count("1")
zero = t.count("0")
tmp = 0
for i in range(len(t)):
    if t[i] == "0":
        tmp += 1
        ls.append(-1)
    else:
        ls.append(tmp)
#print(ls)
cnt = 1
for i in range(len(t)):
    k = [ls[i],zero-ls[i]]
    if ls[i] != -1:
        if i % 2 == 0:
            ans += k[cnt]
        else:
            ans += k[cnt * -1]
    else:
        cnt *= -1

while one > 0:
    #print((one+1)//2)
    ans += (one+1) // 2
    one -= 1

print(ans)

Submission status: Wrong Answer

Solution code:

T = input()

ans = 0
onum = 0

for i in T:

    if i == "1":
        onum += 1
        ans += (onum+1)//2

odd = []
eve = []

nodd = 0
neve = 0
for i in range(len(T)-1,-1,-1):

    if T[i] == "0":
        odd.append(nodd)
        eve.append(neve)
        nodd = 0
        neve = 0
    else:
        if i % 2 == 0:
            nodd += 1
        else:
            neve += 1

ans += nodd * ( len(T) - onum)

for i in range(len(odd)):

    if i == 0:
        ans += len(odd)//2 * eve[i]
        ans += (len(odd) - len(odd)//2) * odd[i]
    else:
        ans += (len(odd)-i)//2 * eve[i]
        ans += (len(odd) - (len(odd)-i)//2 ) * odd[i]
        rem = (len(odd)-i)//2 + (len(odd) - (len(odd)-i)//2 )
        
        ans += rem * max(eve[i],odd[i])

print (ans)

Submission status: Wrong Answer

Solution code:
t=input()
num=0
for i in range(len(t)):
  num += t[1::2].count("1")
  t=t[:-1]
num1=0
for i in range(len(t)):
  num1 += t[1::2].count("1")
  t=t[1:]
print(max(num,num1))

Submission status: Wrong Answer

Solution code:
t = [int(item) for item in input()]
n = len(t)

# put ones
ones = sum(t)
# zeroes+
ans = 0
une2 = ones // 2
if ones % 2 == 0:
	ans += une2 * (une2 + 1) // 2
else:
	ans +=  une2 * (une2 + 1) // 2
	ans += (ones // 2) + 1
# print("ans after ones", ans)

new_str = []
even_count = 0
segment_len = 0

for i in range(n):
	# print("t[", i, "]", t[i])
	if t[i] == 1:
		segment_len += 1
	else:
		new_str.append(0)
		if segment_len % 2 == 0:
			even_count += segment_len
		else:
			even_count += segment_len - 1
			new_str.append(1)
		segment_len = 0

if segment_len > 0:
	if segment_len % 2 == 0:
		even_count += segment_len
	else:
		even_count += segment_len - 1
		new_str.append(1)


# print("even_count", even_count)
# print("new_str", new_str)
# put zeroes on even positions from end

rest_steps = n - ones

ans += (even_count // 2)* rest_steps
# print("ans after even", ans)


n_new = len(new_str)
for i in range(n_new):
	if new_str[i] == 1:
		ans += n_new -1  - i # after all is mine
		ans += (i // 2 + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
zero = []

for i in range(len(t)):
  if t[i] == '0':
    zero.append(i - len(t))

total = 0
for i in range(len(t) - len(zero)):
  total += 1 + i // 2

t = t.replace('0', '')
zero = sorted(zero, reverse=True)

if t == '1':
  total += 1

for i in range(len(zero)):
  t = t[:zero[i] + 1] + '0' + t[zero[i] + 1:]
  for j in range(0, len(t), 2):
    if t[j] == '1':
      total += 1
print(total)

Submission status: Wrong Answer

Solution code:
s = input()
def get(s):
    n = len(s)
    ans = 0
    a = 0
    for i in range(0, n, 2):
        if s[i] == "1":
            a += 1
    b = 0
    c = 0
    no = n
    for i in reversed(range(n)):
        if s[i] == "1":
            if i % 2 == 0:
                a -= 1
                b += 1
            else:
                c += 1
        else:
            no -= 1
            ans += b + a
            b, c = c, b
    for i in range(no + 1):
        ans += (i + 1) // 2
    return ans
ans = 0
if "0" in s:
    i = s.index("0")
    t = s[:i] + s[i + 1 :]
    for i in range(0, len(s), 2):
        if s[i] == "1":
            ans += 1
    ans += get(t)
ans = max(ans,get(s))
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
zero = []

for i in range(len(t)):
  if t[i] == '0':
    zero.append(i - len(t))

total = 0
for i in range(len(t) - len(zero)):
  total += 1 + i // 2

t = t.replace('0', '')
zero = sorted(zero, reverse=True)

if t == '1':
  total += 1

for i in range(len(zero)):
  print(t, '*', t[:zero[i] + 1], '*', t[zero[i] + 1:])
  t = t[:zero[i] + 1] + '0' + t[zero[i] + 1:]
  for j in range(0, len(t), 2):
    if t[j] == '1':
      total += 1
print(total)

Submission status: Wrong Answer

Solution code:
import math
import re
T=input()
x=0
Td=T
d = len(re.sub(r'0', '', Td))
x += math.ceil((d/2+1)*d/2)
azz = len(T) - d
for i in range(d, len(T)):
    tmpIdx = -1
    for i in range(len(Td)):
        if Td[i] == '0':
            tmpIdx =i
            if i%2==1:
                break
    if tmpIdx > -1:
        x += len(re.sub(r'0', '', Td[::2]))

print(x)

Submission status: Wrong Answer

Solution code:
def eval(string):
    return sum([s if i % 2 == 0 else 0 for i, s in enumerate(string)])


def main():
    T = [int(s) for s in list(input())]
    length = len(T)
    ans = eval(T)
    for _ in range(length-1):
        tmp = T[1:]
        next_T = tmp[:]
        max_score = eval(tmp)
        last_score = max_score
        for i in range(len(T)-1):
            if all(tmp):
                break
            else:
                score = last_score
                if i % 2 == 0:
                    score = score + int(T[i]) - int(tmp[i])
                else:
                    continue
                tmp[i] = T[i]
                if score > max_score:
                    max_score = score
                    next_T = tmp[:]
                last_score = score
        ans += max_score
        T = next_T[:]
    print(ans)


main()