Problem:


Score : 500 points

Problem Statement

You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.

Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.

Constraints

1\leq |S|\leq 10^5

S_i(1\leq i\leq N) is either 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.

Sample Input 1

010

Sample Output 1

2

We can turn all the characters of S into 0 by the following operations:

Perform the operation on the segment S[1,3] with length 3. S is now 101.

Perform the operation on the segment S[1,2] with length 2. S is now 011.

Perform the operation on the segment S[2,3] with length 2. S is now 000.

Sample Input 2

100000000

Sample Output 2

8

Sample Input 3

00001111

Sample Output 3

4



Sample input:
010


Sample output:
2

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

S = [int(x) for x in list(input())]

if len(S)==1:
    print(1)

elif len(S)==2:
    if S[0] == S[1]:
        print(2)
    else:
        print(1)
else:
    l = []
    c = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            c += 1
        else:
            l.append(c)
            c = 1
    l.append(c)
    ans = max(l)
    
    if ans in l[1:-1]:
        print(ans+1)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
array_S = list(raw_input())

#print array_S

len_array = []

head = array_S.pop(0)
c_sum = 1
while len(array_S) > 0:
    tmp =  array_S.pop(0)
#    print head, tmp
    if head == tmp:
        c_sum = c_sum + 1;
    else:
        head = tmp
        len_array.append(c_sum)
        c_sum = 1

len_array.append(c_sum)
#print len_array
print max(len_array)

Submission status: Wrong Answer

Solution code:
l=input()

def hntn(a,s,t):
  e=s+t
  n="".join([str((int(i)+1) % 2) for i in a[s:e]])
  return a[:s]+ n + a[e:]

for i in range(len(l),0,-1):
  c=[]
  for w in range(len(l),i-1,-1):
    d='0'*len(l)
    for j in range(2*(len(l)-i+1)):
      b='0'*(len(l)-i+1-len(str(format(j, 'b'))))+str(format(j, 'b'))
      for v in range(len(b)):
        if b[v]=='1':
          d=hntn(d,v,w)
    c.append(d)
  if l in c:
    break

print(i)

Submission status: Wrong Answer

Solution code:
# スペース区切りの整数の入力
bit = input()
length = len(bit)

num0 = 0
num1 = 0

for i in range(length):
    if bit[i] == '0':
        num0 += 1
    else:
        num1 += 1

K = max(num0, num1)
        
print(K)

Submission status: Wrong Answer

Solution code:
s = raw_input()
max0, max1 = -1, -1
cnt = 0
L = []
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        L.append(len(t))
        max1 = max(max1, len(t))
        t = "0" 
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1
        L.append(max0)

L.append(len(t))

if t.count("0") == 0:
    max1 = max(max1, len(t))
else:
    max0 = max(max0, len(t))

ans = 0
for i in range(len(L)-1):
    ans = max(ans, (L[i] + L[i+1]))


print 
if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(ans, 2)
else:
    print ans

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def solution(S):
    left = S.find("1")
    right = S.rfind("1")

    if left == right:
        if left == -1:
            return len(S)
        elif left == 0 or left == len(S) - 1:
            return len(S) - 1
        elif left == (len(S) - left - 1):
            return left + 1
        else:
            return max(left, len(S) - left - 1)
    else:
        S = "".join(map(
          lambda s: "0" if s == "1" else "1", S[left:right + 1]))
        return solution(S)

def main(argv):
    line = sys.stdin.readline()
    while line:
        S = line.rstrip("\n")
        print solution(S)
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
S=input()
l=[]
l.append(0)
x=int(S[0])
tmp=0
for i in S:
  if int(i)==x:
    tmp+=1
  else:
    l.append(tmp)
    tmp=1
    x=(x-1)*(-1)
l.append(tmp)
l.append(0)
ans=0
for i in range(len(l)-1):
  if l[i]+l[i+1]>ans:
    ans=l[i]+l[i+1]
print(str(ans)+'\n')

Submission status: Wrong Answer

Solution code:
import math
S = input()
t = len(S)-1
L = S[:math.ceil(len(S)//2)]
R = S[len(S)//2:]
i = 0 
j = 0
while i < len(L):
  if L[-i] == R[i]:
    j += 1
  i+=1
  
print(math.ceil(len(S)/2) + j)

Submission status: Wrong Answer

Solution code:
s = input()
ss = []

key = s[0]
cnt = 1
for i in range(1,len(s)):
    if key == s[i]:
        cnt += 1
    else:
        ss.append(cnt)
        key = s[i]
        cnt = 1

ss.append(cnt)

ans = 0
maxs = max(ss)
#print(ss)
if len(ss)==1 or len(ss)==2:
    ans = maxs
elif len(ss)==3:
    ans = max(min(ss[1]+ss[0],ss[1]+ss[2]),max(ss))

else:
# 端っこだったらこれで拾う。
    tmpmax = max(ss[0],ss[len(ss)-1])

# 端以外のMAX＋端じゃない長い方or短い端
    maxs = max(ss[1:len(ss)-2])
    for i in range(1,len(ss)-1 ):
        if ss[i] == maxs:
            if i == 1:
                if ss[0] > ss[2]:
                    tmp = maxs + ss[2] 
                else:
                    tmp = maxs + ss[0]
            elif i == len(ss)-2:
                if ss[len(ss)-1] > ss[len(ss)-3]:
                    tmp = maxs + ss[len(ss)-3]
                else:
                    tmp = maxs + ss[len(ss)-1]
            else:
                tmp= maxs+max(ss[i-1],ss[i+1])

#            print(i, tmp)

            if tmp > tmpmax:
                tmpmax = tmp
        else:
            pass

    ans = tmpmax

print(ans)

Submission status: Wrong Answer

Solution code:
def d_WideFlip(S):
    import re
    zero = re.findall(r'0+', S)
    one = re.findall(r'1+', S)
    zero = len(max(zero)) if zero != [] else 0
    one = len(max(one)) if one != [] else 0
    return max(zero, len(S) - one)

S = input()
print(d_WideFlip(S))

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
M = len(S)
a = S.count("0")
b = S.count("1")

if "01" and "10" in S:
    for i in range(1,M-1):
        if S[i] == "1":
            for j in range(i+1,M):
                if S[j] == "0":
                    P = max(i+1,len(S)-j+1)
                    ans = (max(ans,P))

else:
    ans = max(a,b)

print(ans)

Submission status: Wrong Answer

Solution code:
def d_WideFlip(S):
    import re
    from collections import Counter

    d = Counter(S)
    zero = d['0']
    one_continue = re.findall(r'1+', S)
    one_continue = len(max(one_continue)) if one_continue != [] else 0
    return max(zero, len(S) - one_continue)

S = input()
print(d_WideFlip(S))

Submission status: Wrong Answer

Solution code:
s = raw_input()
max0, max1 = -1, -1
cnt = 0
L = []
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        L.append(len(t))
        max1 = max(max1, len(t))
        t = "0" 
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1
        L.append(max0)

L.append(len(t))


ans = 0
for i in range(len(L)-1):
    ans = max(ans, (L[i] + L[i+1]))


print 
if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(ans, 2)
else:
    print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

S = [int(x) for x in list(input())]

if len(S)==1:
    print(1)

elif len(S)==2:
    if S[0] == S[1]:
        print(2)
    else:
        print(1)
else:
    l = []
    c = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            c += 1
        else:
            l.append(c)
            c = 1
    l.append(c)
    ans = max(l)
    print(l)
    if ans in l[1:-1]:
        print(ans+1)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

check = S[0]
left = 0
right = 0
for s in S:
    if s != check:
        break
    left += 1

Sr = S[::-1]
checkr = Sr[0]
for s in Sr:
    if s != checkr:
        break
    right += 1

if left + right == len(S):
    print(max(left,right))
else:
    print(min(len(S)-max(left,right)     ,max(S.count("1"), S.count("0"))))

Submission status: Wrong Answer

Solution code:
inputs = input()

idx = 0
count = 0
ans = 1000000000000000000

while idx < len(inputs):
    if inputs[idx] == '1':
        idx += 1
    else:
        idx += 1
        count += 1
        if idx < len(inputs):
            while inputs[idx] == '1':
                idx += 1
                count += 1
                if idx >= len(inputs):
                    break
                
        if idx < len(inputs):
            while inputs[idx] == '0':
                idx += 1
                count += 1
                if idx >= len(inputs):
                    break
    if ans > count and count != 0:
        ans = count
        count = 0       

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
one = s.count("1")
zero = s.count("0")
ans = []
ans.append(one)
ans.append(zero)
ans.sort(reverse = True)
print(ans[0])

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)
def aaa():
    s = [0]
    for K in range(N, 1, -1):
        new_s = []
        for i in range(N-K+1):
            a = ['0'] * (N - K)
            a.insert(i, '1' * K)
            sk = ''.join(a)
            for c in s:
                new_s.append(c ^ int(sk, 2))
        s = list(set(new_s))
        if int(S, 2) in s:
            return K
    return 1

print(aaa())

Submission status: Wrong Answer

Solution code:
import math
s = input()
count = 1 
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        count += 1
if count > math.ceil(len(s)/2):
    print(count)
else:
    print(math.ceil(len(s)/2))

Submission status: Wrong Answer

Solution code:
S = input()
s = max(S.count("0"), S.count("1"))
print(s)

Submission status: Wrong Answer

Solution code:
S = input()

check = S[0]
left = 0
right = 0
for s in S:
    if s != check:
        break
    left += 1

Sr = S[::-1]
checkr = Sr[0]
for s in Sr:
    if s != checkr:
        break
    right += 1

if left + right == len(S):
    print(max(left,right))
else:
    print(max(S.count("1"), S.count("0")))

Submission status: Wrong Answer

Solution code:
rS = list(str(input()))
import numpy
S0 = numpy.array(rS).astype(numpy.int32)
S1 = numpy.array(rS).astype(numpy.int32)
lS = len(S0)
def hanten(slist):
    for i in range(len(slist)):
        if(slist[i] == 0):
            slist[i] = 1
        else:
            slist[i] = 0
    return slist

for i in range(2,lS+1)[::-1]:
    for j in range(lS - i + 1):
        if(S0[j] == 0):
            S0[j:j+i] = hanten(S0[j:j+i])
        if(S1[j] == 1):
            S1[j:j+i] = hanten(S1[j:j+i])
            
    if(sum(S0[:-1]) == len(S0) - 1):
        print(i)
        break;
    if(sum(S1[:-1]) == len(S1) - 1):
        print(i)
        break;

Submission status: Wrong Answer

Solution code:
s = raw_input()
max0, max1 = -1, -1
cnt = 0
L = []
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        L.append(len(t))
        max1 = max(max1, len(t))
        t = "0" 
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1
        L.append(max0)

if t.count("0") == 0:
    max1 = max(max1, len(t))
    L.append(max1)
else:
    max0 = max(max0, len(t))
    L.append(max1)

ans = 0
for i in range(len(L)-1):
    ans = max(ans, (L[i] + L[i+1]))

if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(ans, 2)
else:
    print ans

Submission status: Wrong Answer

Solution code:
S = input()

check = S[0]
left = 0
right = 0
for s in S:
    if s != check:
        break
    left += 1

Sr = S[::-1]
checkr = Sr[0]
for s in Sr:
    if s != checkr:
        break
    right += 1

if left + right == len(S):
    print(max(left,right))
else:
    print(len(S) - max(left, right))

Submission status: Wrong Answer

Solution code:
S = input()
t = len(S)-1
while t >= len(S)//2:
  temp = (set(S[len(S)-t:t]))
  if len(temp) == 0:
    break
  elif len(temp) == 1: 
    break

  t -= 1
print(t)

Submission status: Wrong Answer

Solution code:
a=raw_input()
a=list(a)
ans0=0
ans1=0
for i in a:
    if i=="0":
        ans0+=1
    else:
        ans1+=1
if ans0>=ans1:
    print ans0
else:
    print ans1

Submission status: Wrong Answer

Solution code:
s = input()

key = s[0]
count = 1
c_list = []
for i in range(1, len(s)):
    if key == s[i]:
        count += 1
    else:
        c_list.append(count)
        key = s[i]
        count = 1
if count > 1 or len(s) == 1:
    c_list.append(count)
ans = max(c_list)

if max(c_list) < len(s) / 2:
    ans += 1
if ans*2 <= len(s)/2:
    ans = ans*2

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

check = S[0]
left = 0
right = 0
for s in S:
    if s != check:
        break
    left += 1

Sr = S[::-1]
checkr = Sr[0]
for s in Sr:
    if s != checkr:
        break
    right += 1

print(len(S) - max(left, right))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s = input()
ze=s.count('0')
on=s.count('1')
a=max((ze,on))
print(a)

Submission status: Wrong Answer

Solution code:
s=input()
z="0"

while z in s:
    if z in s:
        z+="0"
    else:
        break

o="1"

while o in s:
    if o in s:
        o+="1"
    else:
        break

if len(z) == 2 and len(o) == 2:
    print(1)
elif len(z) >= len(o):
    print(len(z)-1)
else:
    print(len(o))

Submission status: Wrong Answer

Solution code:
s = input()
ss = []

key = s[0]
cnt = 1
for i in range(1,len(s)):
    if key == s[i]:
        cnt += 1
    else:
        ss.append(cnt)
        key = s[i]
        cnt = 1

ss.append(cnt)

ans = 0
maxs = max(ss)
if len(ss)==1 or len(ss)==2:
    ans = maxs
elif len(ss)==3:
    ans = max(min(ss[1]+ss[0],ss[1]+ss[2]),max(ss))

else:
# 端っこだったらこれで拾う。
    tmpmax = max(ss[0],ss[len(ss)-1])

# 端以外のMAX＋端じゃない長い方or短い端
    for i in range(1,len(ss)-1 ):
        if ss[i] == maxs:
            if i == 1:
                if ss[0] > ss[2]:
                    tmp = maxs + ss[2] 
                else:
                    tmp = maxs + ss[0]
            elif i == len(ss)-2:
                if ss[len(ss)-1] > ss[len(ss)-3]:
                    tmp = maxs + ss[len(ss)-3]
                else:
                    tmp = maxs + ss[len(ss)-1]
            else:
                tmp= maxs+max(ss[i-1],ss[i+1])

            if tmp > tmpmax:
                tmpmax = tmp
        else:
            pass

    ans = tmpmax

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()

sl=list(s)
x=sl.count('1')
y=sl.count('0')
l=len(sl)-1
c=0
while l > 1:
    if(x==y):
        l=l-2
    else:
        l=l-1
    c=c+1
if(l>0):
    c=c+1
print(c)

Submission status: Wrong Answer

Solution code:
import math
S=list(str(input()))
a=['1','1','1']
b=0
one=0
zero=0
c=0
ansone=len(S)
anszero=len(S)
if S==a:
    print(int(3))
elif len(S)==3:
    print(2)
else:
    b=1

for i in range(0, len(S)-1):
    if S[i]=='1' and S[i+1]=='1':
        one +=1
        continue
    elif S[i]=='0' and S[i+1]=='0':
        zero +=1
        continue
    elif S[i]=='1' and S[i+1]=='0':
        ansone=min(ansone, one)
        one=0
        continue
    elif S[i]=='0' and S[i+1]=='1':
        anszero=min(anszero, zero)
        zero=0
        continue
    else:
        c=1
ansone=min(ansone, one)
anszero=min(anszero, zero)
if anszero==0 and b==1:
    print(ansone+1)
elif anszero !=0 and b==1:
    print(anszero+1)
else:
    b=1

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if (not "0" in l) or (not "1" in l):
    print len(l)
    sys.exit()

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        print mx, x, i
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
mx = max(mx, min(i, len(l)-x))
print mx

Submission status: Wrong Answer

Solution code:
str = input()

#要素をリストへ
s = []
for i in range(len(str)):
    s.append(str[i])

#リストを調べる
sep = 0
one = 0
zero = 0
if s[len(str) - 1] == '1':
        one += 1

if s[len(str) - 1] == '0':
        zero += 1

for i in range(len(str) - 1):
    #一の個数をカウント
    if s[i] == '1':
        one += 1
    #０の個数をカウント
    if s[i] == '0':
        zero += 1
    
    #入れ替わりの回数をカウント
    if s[i] != s[i+1]:
        sep += 1


#集計
#全部
if sep == 0:
    print(len(str))
#分かれてる
elif sep == 1:
    if one >= zero:
        print(one)
    else:
        print(zero)

#それ以外
else:
    print(len(str) - 1)

Submission status: Wrong Answer

Solution code:
S = input()

check = S[0]
left = 0
right = 0
for s in S:
    if s != check:
        break
    left += 1

Sr = S[::-1]
checkr = Sr[0]
for s in Sr:
    if s != checkr:
        break
        right += 1

print(len(S) - max(left, right))

Submission status: Wrong Answer

Solution code:
import math
s = input()
print(math.ceil(len(s)/2))

Submission status: Wrong Answer

Solution code:
s = input()

lst = []
add_lst = []
n = 0
for i in range(len(s)):
    if i == 0 or s[i] == s[i-1]:
        n +=1
    else:
        lst.append(n)
        n = 1
lst.append(n)

for i in range(len(lst) - 1):
    add_lst.append(lst[i] + lst[i + 1])

if len(lst) > 2:
    print(min(add_lst))
elif len(lst) == 2:
    print(max(lst))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s=input()

sl=list(s)
x=sl.count('1')
y=sl.count('0')
l=len(sl)-1
c=0
while l > 0:
    if(x==y):
        l=l-2
    else:
        l=l-1
    c=c+1
if(l>0):
    c=c+1
print(c)

Submission status: Wrong Answer

Solution code:
s = raw_input()
max0, max1 = -1, -1
cnt = 0
t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        max1 = max(max1, len(t))
        t = "0"
        cnt += 1
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"
        cnt += 1

if t.count("0") == 0:
    max1 = max(max1, len(t))
else:
    max0 = max(max0, len(t))

if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
elif cnt == 1:
    print max(max(max1, max0), 2)
else:
    print max1 + max0

Submission status: Wrong Answer

Solution code:
s = input()
length = 0
cntz = 0
for i in s:
    length += 1
    if i == '0':
        cntz += 1

if cntz > length // 2:
    print(cntz)
else:
    print(length - cntz)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

S = [int(x) for x in list(input())]

if len(S)==1:
    print(1)

elif len(S)==2:
    if S[0] == S[1]:
        print(2)
    else:
        print(1)
else:
    m = 2
    c = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            c += 1
        else:
            if m < c:
                m = c
                c = 1
    print(max(m,c))

Submission status: Wrong Answer

Solution code:
s = input()
length = len(s)
cntz = s.count('0')
if cntz > length // 2:
    print(cntz)
else:
    print(length - cntz)

Submission status: Wrong Answer

Solution code:
A=list(input())
L = len(A)
num = L
while True:
    pre = A[0]
    end = True
    for i in range(1,L):
        if A[i] != pre:
            if i*2 < L:
                num = L - i
            else:
                num = i
            for j in range(i):
                A[j] = '0' if A[j] == '1' else '1'
            end = False
            break
    if end:
        break
print(num)

Submission status: Wrong Answer

Solution code:
import random
S=list(input())
print(int(random.uniform(1,len(S))))

Submission status: Wrong Answer

Solution code:
S=raw_input()

c_val=""
cnt=0
a=[]
for i in S:
	if c_val=="":
		c_val=i
		cnt+=1
		continue
	else:
		if c_val==i:
			cnt+=1
		else:
			a.append(cnt)
			cnt=0
			c_val=i
else:
	a.append(cnt)

print max(a)

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
print mx

Submission status: Wrong Answer

Solution code:

import math

input_str = input().rstrip()

zero_num = 0
one_num = 0
for value in input_str:
	if int(value) == 0:
		zero_num = zero_num + 1
	else:
		one_num = one_num + 1

print(max(zero_num, one_num))

Submission status: Wrong Answer

Solution code:

s = input()
length = len(s)
cntz = s.count('0')
if length - cntz > cntz:
    print(length - cntz)
else:
    print(cntz)

Submission status: Wrong Answer

Solution code:
S=raw_input()

c_val=""
cnt=0
a=[]
for i in S:
	if c_val=="":
		c_val=i
		cnt+=1
		continue
	else:
		if c_val==i:
			cnt+=1
		else:
			a.append(cnt)
			cnt=0
			c_val=i
else:
	a.append(cnt)

if len(a)<=2:
	if a[0]==1:
		print max(a)+1
	else:
		print max(a)
else:
	print max(a)+1

Submission status: Wrong Answer

Solution code:
s=input()

sl=list(s)
x=sl.count('1')
y=sl.count('0')
l=len(sl)-1
c=0
while l > 0:
    if(x==y):
        l=l-2
    else:
        l=l-1
    c=c+1
print(c)

Submission status: Wrong Answer

Solution code:
s = raw_input()
max0, max1 = -1, -1

t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        max1 = max(max1, len(t))
        t = "0"
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        max0 = max(max0, len(t))
        t = "1"

if t.count("0") == 0:
    max1 = max(max1, len(t))
else:
    max0 = max(max0, len(t))

if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
else:
    print max(max(max1, max0), 2)

Submission status: Wrong Answer

Solution code:
S=input()
print(max(S.count("0"),S.count("1")))

Submission status: Wrong Answer

Solution code:

import sys
s = sys.stdin.readline()
length = len(s) - 1
cntz = s.count('0')
if length - cntz > cntz:
    print(length - cntz)
else:
    print(cntz)

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = l[0]
f = False
m = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        if m < i-x:
            m = i-x
            ms = x
            me = i
        elif m == i-x:
            if min(m+ms, m+len(l)-me) < min(i, len(l)-x):
                m = i-x
                ms = x
                me = i
        x = i
        s = n
print min(m+ms, m+len(l)-me)

Submission status: Wrong Answer

Solution code:
import sys
s = sys.stdin.readline()
cntz = s.count('0')
cnto = s.count('1')
print(max(cnto, cntz))

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = l[0]
f = False
m = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        if m < i-x:
            m = i-x
            ms = x
            me = i
        x = i
        s = n
print m+ms if ms < len(l)-me else m+len(l)-me

Submission status: Wrong Answer

Solution code:
S=input()
n=len(S)
j=0
for i in range(1,n):
    if S[i-1]!=S[i]:
        if abs(n//2-i)<abs(n//2-j):
            j=i
print(max([j,n-j]))

Submission status: Wrong Answer

Solution code:
S = input()
N = int(S)
ans = 0
M = len(S)
for i in range(M-1):
    if S[i] == "1":
        P = 1
        for j in range(i+1,M):
            if S[j] == "1":
                P += 1
            else:
                break
    if S[i] == "0":
        P = 1
        for j in range(i+1,M):
            if S[j] == "0":
                P += 1
            else:
                break        
    ans = max(ans,P)
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
s = sys.stdin.readline()
maxzeros = 0
maxones = 0
curzeros = 0
curones = 0
for i in s:
    if i == '0':
        curzeros += 1
        curones = 0
        if curzeros >= maxzeros:
            maxzeros = curzeros
    elif i == '1':
        curones += 1
        curzeros = 0
        if curones >= maxones:
            maxones = curones
if maxones == 1 and maxzeros == 1:
    print(maxones + maxzeros)
else:
    print(max(maxzeros, maxones))

Submission status: Wrong Answer

Solution code:
s = raw_input()
min0, min1 = 1e10, 1e10

t = ""
for i in range(len(s)):
    if i == 0:
        t += s[i]
    
    elif s[i] == "0" and s[i-1] == "0":
        t += s[i]
    elif s[i] == "0" and s[i-1] == "1":
        min1 = min(min1, len(t))
        t = "0"
    elif s[i] == "1" and s[i-1] == "1":
        t += s[i]
    elif s[i] == "1" and s[i-1] == "0":
        min0 = min(min0, len(t))
        t = "1"

if t.count("0") == 0:
    min1 = min(min1, len(t))
else:
    min0 = min(min0, len(t))

if s.count("0") == len(s) or s.count("1") == len(s):
    print "0"
elif len(s) == 2:
    print "1"
else:
    print max(max(min1, min0), 2)

Submission status: Wrong Answer

Solution code:
S = input()
print(max(S.count("0"), S.count("1")))

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flag = s[0]
count = 0
patern = [1]
for i in range(1, n):
    if flag != s[i]:
        flag = s[i]
        count += 1
        patern.append(1)
    else:
        patern[-1] += 1

if count == 0:
    print (n)
elif count == 1:
    print (max(patern[0], patern[1]))
elif count == 2:
    print (min(sum(patern[:2]), sum(patern[1:])))
else:
    min_change = n
    for i in range(1, len(patern)-2):
        tmp =  patern[i] + patern[i+1]
        if tmp < min_change:
            min_change = tmp
    if s[0] == s[-1]:
        print (min_change)
    else:
        print (min(min_change, sum(patern[:-1]), sum(patern[1:])))

Submission status: Wrong Answer

Solution code:
inputs = input()

z_count = 0
o_count= 0
for i in inputs:
    if i == '1':
        o_count += 1
    else:
        z_count += 1

if z_count > o_count:
    print(z_count)
else:
    print(o_count)

Submission status: Wrong Answer

Solution code:
def d_WideFlip(S):
    from collections import Counter
    d = Counter(S)
    return len(S) - d['1']

S = input()
print(d_WideFlip(S))

Submission status: Wrong Answer

Solution code:
S=input()
m=list(map(len,S.split("0")))
n=list(map(len,S.split("1")))
print(max(sum(m),sum(n)))

Submission status: Wrong Answer

Solution code:
S = input()
a = S.count("0")
b = S.count("1")
ans = max(a,b)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = "0"
f = False
m = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        f = True
    if n == s and f:
        f = False
        m = m if m > i-x else i-x
        x = i
s = "1"
f = False
x = 0
for i, n in enumerate(l):
    if not n == s:
        f = True
    if n == s and f:
        f = False
        m = m if m > i-x else i-x
        x = i
print m

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = "0"
f = False
m = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        f = True
    if n == s and f:
        f = False
        m = m if m > i-x else i-x
        x = i
s = "1"
f = False
x = 0
for i, n in enumerate(l):
    if not n == s:
        f = True
    if n == s and f:
        f = False
        m = m if m > i-x else i-x
        x = i
print m
print m

Submission status: Wrong Answer

Solution code:
#coding:utf-8                                                              

S = raw_input()
print S
ssz = S.split('0')
sso = S.split('1')
max = 0
for sss in ssz:
    if max < len(sss):
        max = len(sss)

for sss in sso:
    if max < len(sss):
        max = len(sss)
if S[0]== S[-1]:
    max+= 1
print max

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flag = s[0]
count = 0
patern = [1]
for i in range(1, n):
    if flag != s[i]:
        flag = s[i]
        count += 1
        patern.append(1)
    else:
        patern[-1] += 1

if count == 0:
    print (n)
elif count == 1:
    print (max(patern[0], patern[1]))
elif count == 2:
    print (min(sum(patern[:2]), sum(patern[1:])))
else:
    min_change = n
    for i in range(count):
        tmp =  patern[i] + patern[i+1]
        if tmp < min_change:
            min_change = tmp
    print (min(min_change, sum(patern[:-1]), sum(patern[1:])))

Submission status: Wrong Answer

Solution code:
a=input()
temp=a.split()
print(a.count("0"))

Submission status: Wrong Answer

Solution code:
import sys
l = list(raw_input())
if not "0" in l or not "1" in l:
    print len(l)

s = l[0]
f = False
t = 0
for i, n in enumerate(l):
    if not n == s:
        if f:
            f = False
            break
        f = True
        s = n
        t = i
else:
    print len(l[0:t]) if len(l[0:t]) > len(l[t:]) else len(l[t:])
    sys.exit()

s = l[0]
f = False
m = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        f = True
    if n == s and f:
        f = False
        m = m if m > i-x else i-x
        x = i
print m

Submission status: Wrong Answer

Solution code:
num = input()
print(num.count("0"))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=[int(i) for i in input()]

L = len(S)

K = L
while 1:
    if S[L-K:-L+K]== [1]*(2*K-L) or S[L-K:-L+K] == [0]*(2*K-L):
        break
    K -= 1
print(K)