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:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(input())
N = len(S)
answer = (N+1)//2
streak = 1
cur = None
result = 0
for x in S:
    if cur == x:
        streak += 1
    else:
        cur = x
        streak = 1
    if streak > result:
        result = streak

while answer < N:
    S2 = S[-answer-1:answer+1]
    print(S2)
    if len(set(S2)) == 1:
        answer += 1
        continue
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(input())
N = len(S)
answer = (N+1)//2
streak = 1
cur = None
result = 0
for x in S:
    if cur == x:
        streak += 1
    else:
        cur = x
        streak = 1
    if streak > result:
        result = streak

if result > answer:
    print(result)
    exit()

while answer < N:
    S2 = S[-answer-1:answer+2]
    if len(set(S2)) == 1:
        answer += 1
        continue
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(input())
N = len(S)
answer = (N+1)//2
streak = 1
cur = None
result = 0
for x in S:
    if cur == x:
        streak += 1
    else:
        cur = x
        streak = 1
    if streak > result:
        result = streak

if result > answer:
    print(result)
    exit()

while answer <= N:
    S2 = S[-answer-1:answer+1]
    if len(set(S2)) == 1:
        answer += 1
        continue
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(input())
N = len(S)
answer = (N+1)//2
streak = 1
cur = None
result = 0
for x in S:
    if cur == x:
        streak += 1
    else:
        cur = x
        streak = 1
    if streak > result:
        result = streak

if result > answer:
    print(result)
    exit()

while True:
    S2 = S[-answer-1:answer+1]
    if len(set(S2)) == 1:
        answer += 1
        continue
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(input())
N = len(S)
answer = (N+1)//2
streak = 1
cur = None
result = 0
for x in S:
    if cur == x:
        streak += 1
    else:
        cur = x
        streak = 1
    if streak > result:
        result = streak

if result > answer:
    print(result)
    exit()

print(answer)

Submission status: Wrong Answer

Solution code:
S = input()

S = S + '2'
D = []
p = S[0]
l = 0
for i in range(len(S)):
  if S[i] == p:
    l += 1
  else:
    D.append((p,l))
    l = 1
    p = S[i]
#print(D)

if len(D) == 1:
  print(len(S)-1)
elif len(D) == 2:
  print(max(D[0][1],D[1][1]))
else:
  ans = float('inf')
  for i in range(len(D)-1):
    ans = min(D[i][1]+D[i+1][1],ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = [1]
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        l[-1] += 1
    else:
        l.append(1)
n = len(l)
if n % 2:
    print(min(sum(l[:n // 2]), sum(l[n // 2 + 1:])) + l[n // 2])
else:
    ans1 = min(sum(l) - l[-1], min(sum(l[:n // 2 - 1]),
                                   sum(l[n // 2:])) + l[n // 2 - 1])
    ans2 = min(sum(l) - l[0], min(sum(l[:n // 2]),
                                  sum(l[n // 2 + 1:])) + l[n // 2])
    print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
s = input()
l = [1]
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        l[-1] += 1
    else:
        l.append(1)
n = len(l)
if n % 2:
    print(min(sum(l[:n // 2]), sum(l[n // 2 + 1:])) + l[n // 2])
else:
    ans1 = min(sum(l) - l[-1], min(sum(l[n // 2 - 1:]),
                                   sum(l[:n // 2])) + l[n // 2 - 1])
    ans2 = min(sum(l) - l[0], min(sum(l[n // 2:]),
                                  sum(l[:n // 2 + 1])) + l[n // 2])
    print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
s = tuple(map(int, input()))
n = len(s)

ret = 1
p = s[0]
for i, x in enumerate(s):
    if x != p:
        ret = max(ret, max(i, n - i))
    p = x
print(ret)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 10**9
lenS = len(S)
for i in range(1,lenS):
    if S[i] != S[i-1]:
        ans = min(ans,max(i,len(S)-i))
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
c=''
p=[0]
for s in S:
    if c!=s:
        p.append(1)
        c=s
    else:
        p[-1]+=1
M=max(p)
for i in range(len(p)-1):
    p[i+1]+=p[i]
if len(p)%2:
    x=(len(p)-1)//2
    r=10**5
    for i in range(1,len(p)-x-1):
        r=min(r,p[i+x]-p[i])
    r=max(min(r,p[x]-p[0]),min(r,p[-1]-p[-1-x]))
else:
    x=len(p)//2
    r=10**5
    for i in range(len(p)-x):
        r=min(r,p[i+x]-p[i])
print(max(r,M))

Submission status: Wrong Answer

Solution code:
S=input()
c=''
p=[0]
for s in S:
    if c!=s:
        p.append(1)
        c=s
    else:
        p[-1]+=1
for i in range(len(p)-1):
    p[i+1]+=p[i]
if len(p)%2:
    x=(len(p)-1)//2
    ok,ng=1,len(S)+1
    while ok+1<ng:
        m=(ok+ng)//2
        f=1
        for i in range(1,len(p)-x-1):
            if p[i+x]-p[i]<m:
                f=0
        if p[x]-p[0]<m and p[-1]-p[-1-x]<m:
            f=0
        if f:
            ok=m
        else:
            ng=m
else:
    x=len(p)//2
    ok,ng=1,len(S)+1
    while ok+1<ng:
        m=(ok+ng)//2
        f=1
        for i in range(len(p)-x):
            if p[i+x]-p[i]<m:
                f=0
        if f:
            ok=m
        else:
            ng=m
print(ok)

Submission status: Wrong Answer

Solution code:
S=input()
c=''
p=[0]
for s in S:
    if c!=s:
        p.append(1)
        c=s
    else:
        p[-1]+=1
for i in range(len(p)-1):
    p[i+1]+=p[i]
if len(p)%2:
    x=(len(p)-1)//2
    r=10**5
    for i in range(1,len(p)-x-1):
        r=min(r,p[i+x]-p[i])
    print(max(min(r,p[x]-p[0]),min(r,p[-1]-p[-1-x])))
else:
    x=len(p)//2
    r=10**5
    for i in range(len(p)-x):
        r=min(r,p[i+x]-p[i])
    print(r)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

if N%2 == 1:
    ans = N//2+1
    s = S[N//2]
    for i in range(N//2+1):
        if S[N//2+i] != s or S[N//2-i] != s:
            break
    ans += i-1
else:
    ans = N//2+1
    s = S[N//2]
    for i in range(N//2):
        if s != S[N//2-1-i] or s != S[N//2+i]:
            break
    ans += i-1
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

length_list = []
length = 1
now = S[0]
for i in range(1, len(S)):
	if now != S[i]:
		length_list.append(length)
		now = S[i]
		length = 1
	else:
		length += 1
length_list.append(length)

sum_list = []
x = 0
for i in range(len(length_list)):
	x += length_list[i]
	sum_list.append(x)

ans = 0
for i in range(len(length_list) - 1):
	ans = max(ans, min(length_list[i] + length_list[i + 1], max(sum_list[i], len(S) - sum_list[i])))

print(ans)

Submission status: Wrong Answer

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

length_list = []
length = 1
now = S[0]
for i in range(1, len(S)):
	if now != S[i]:
		length_list.append(length)
		now = S[i]
		length = 1
	else:
		length += 1
length_list.append(length)

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

change = []
for i in range(1, N):
    if S[i - 1] != S[i]:
        change.append(min(i, N - i))
if change:
    print(N - max(change))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


s = S()
ret = INF


for i in range(len(s) - 1):
    if s[i] != s[i+1]:
        ret = min(ret, max(i + 1, len(s) - i - 1))



print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    sl = len(s)
    for i in range(sl // 2, sl + 1):
        ss = s[-i:i]
        if ss == '':
            continue
        if ss.count('0') == len(ss) or ss.count('1') == len(ss):
            continue
        print(i - 1)
        return


main()

Submission status: Wrong Answer

Solution code:
s = input()
print(s.count('0'))

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

    ans = int(1e9)
    for i in range(slen-1):
        if s[i]!=s[i+1]:
            ans = min(ans, max(i+1, slen -i-1))
    
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
S=input()

from itertools import groupby, accumulate

_l = [len(list(g)) for k,g in groupby(S)]
_l_cs = [0] + list(accumulate(_l))
_s = [_l_cs[i+(len(_l)+1)//2] - _l_cs[i] for i in range((len(_l)+1)//2)]
print(min(_s))

Submission status: Wrong Answer

Solution code:
S=input()

from itertools import groupby

_l = [len(list(g)) for k,g in groupby(S)]
if len(_l)==1:
  print(len(S))
elif len(_l)==2:
  print(max(_l))
else:
  _s = [_l[i]+_l[i+1] for i in range(len(_l)-1)]
  print(min(_s))

Submission status: Wrong Answer

Solution code:
S=input()

b = S[0]
n=len(S)
res=10**9
for i in range(1,n):
    if S[i]!=b:
        res=min(res,max(i,n-(i)))
    b=S[i]

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
ans = float('inf')
for i in range(len(S)-1):
  if S[i] != S[i+1]:
    k = max(i+1,len(S)-i-1)
    if k <= ans:
      ans = k
print(ans)

Submission status: Wrong Answer

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

left = 0
right = n-1
ans = [-1 for i in range(n)]

def judge(m):
    if n>=2*m:
        return 1

    for i in range(n-m,m-1):
        if s[i] != s[i+1]:
            return 0
    return 1

while left <= right:
    mid = (left+right)//2
    #print(mid)

    if judge(mid+1):
        ans[mid]  = 1
        left = mid+1

    else:
        ans[mid]  = 0
        right = mid-1
print(ans)

for i in range(n):
    if ans[-i-1] ==1:
        print(n-i)
        break

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
ans = n
now = 0
num = S[0]
for i in range(n):
    if S[i] == num:
        now += 1
    else:
        ans = min(ans,max(now,n-now))
        now = 0
        num = S[i]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
ans = n
now = 1
num = S[0]
for i in range(1,n-1):
    if S[i] == num:
        now += 1
    else:
        ans = min(ans,max(now,n-now))
        now = 0
        num = S[i]

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
ans = n
now = 0
num = S[0]
for i in range(1,n):
    if S[i] == num:
        now += 1
    else:
        ans = min(ans,max(now-1,n-now-1))
        now = 0
        num = S[i]

print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = []
for k in range(1, len(s)):
    if s[k] != s[k-1]:
        K.append(max(len(s)-k, k))
    else:
        continue

ans = 0
if not K:
    ans = 1
elif min(K) == 0:
    if all(v == "1" for v in s):
        ans = len(s)
else:
    ans = min(K)
print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = 0
elif all(c == '1' for c in s):
    K = len(s)
else:
    for k in range(1, len(s)):
        if s[k] != s[k-1]:
            K = min(K, max(k, len(s)-k))
        else:
            continue

print(K)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = 0
elif all(c == '1' for c in s):
    K = len(s)
else:
    for k in range(len(s)-1):
        if s[k] != s[k+1]:
            K = min(K, max(k+1, len(s)-k-1))
        else:
            continue

print(K)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = 0
for k in range(len(s)-1):
    if s[k] != s[k+1]:
        K = min(K, max(k+1, len(s)-k-1))
    else:
        continue

print(K)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
for k in range(len(s)-1):
    if s[k] != s[k+1]:
        K = min(K, max(k+1, len(s)-k))
    else:
        continue

print(K)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
for k in range(len(s)-1):
    if s[k] != s[k+1]:
        K = min(K, max(k+1, len(s)-k-1))
    else:
        continue

print(K)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

s = input()[::-1]

prev = s[0]
k = float('inf')
for i in range(1, len(s)):
    if s[i] != prev:
        k = min(k, max(i-1, len(s)-i+1))
        prev = s[i]
    else:
        continue

print(k)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

s = input()

l = []

p = s[0]
seq = 1

for c in s[1:]:
    if c == p:
        seq += 1
    else:
        l.append(seq)
        seq = 1
        p = c
l.append(seq)
ans = max(u+v for u, v in zip(l, l[1::]))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
 
p=s[0]
seq=1
 
for c in s[1:]:
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
l.append(seq)
ans=float("inf")
 
if len(l)>=3:
  d1=max([a+b for a,b in zip(l[0::2],l[1::2])])
  d2=max([a+b for a, b in zip(l[1::2],l[2::2])])
  print(max(d1,d2))
else:
  if s[0]=="1":
    print(sum(l)-l[0])
  else:
    print(l[0])

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
 
p=s[0]
seq=1
 
for c in s[1:]:
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
l.append(seq)
ans=float("inf")
 
if len(l)>=3:
  d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
  d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
  print(max(d1,d2))
else:
  if s[0]=="1":
    print(sum(l)-l[0])
  else:
    print(l[0])

Submission status: Wrong Answer

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

p=s[0]
seq=1

for c in s[1:]:
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
l.append(seq)
ans=float("inf")

if len(l)>=3:
  d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
  d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
  print(min(d1,d2))
else:
  if s[0]=="1":
    print(sum(l)-l[0])
  else:
    print(l[0])

Submission status: Wrong Answer

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

p=s[0]
seq=1

for c in s[1:]:
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
ans=float("inf")

if len(l)>=3:
  d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
  d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
  print(min(d1,d2))
else:
  print(sum(l))

Submission status: Wrong Answer

Solution code:
S=input()

l=len(S)

if l%2==0:
    count=l//2
    a=S[l//2-1]
    for i in range(l//2):
        if S[l//2-1-i]==a and S[l//2+i]==a:
            count+=1
        else:
            break
    print(count)
else:
    count=l//2+1
    a=S[l//2]
    for i in range(l//2):
        if S[l//2-1-i]==a and S[l//2+i]==a:

            count+=1
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
a = list(input())
b = []
for i in a:
    b.append(1 - int(i))
sa = 0
sb = 0
for i in a:
    sa += int(i)
for i in b:
    sb += int(i)
print(max(sa, sb))

Submission status: Wrong Answer

Solution code:
s = list(input())
s = list(map(int, s))

length = len(s)
i = 0
while i < len(s) - 1:
    if s[i] != s[i+1]:
        length = max(i+1, len(s) - i - 1)
    i += 1
print(length)

Submission status: Wrong Answer

Solution code:
s = list(input())
s = list(map(int, s))

length = len(s)
i, j, k = 0, None, 1
count = 0
flip = False
state = s[0]
opposit = (1 if s[0] == 0 else 0)

while k < len(s) - 1:
    if set(s[:k]) == {state} and set(s[k:]) == {opposit}:
        print(max(k, len(s) - k))
        break
    else: k += 1
else:
    while i < len(s):
        if s[i] == state:
            if flip:
                length = min(length, count)
                flip = False
                count = i - j + 1
                j = None
            else:
                count += 1
        else:
            if j == None:
                j = i
                flip = True
            count += 1
        i += 1

    length = min(length, count)
    print(length)

Submission status: Wrong Answer

Solution code:
s = list(input())
s = list(map(int, s))

length = len(s)
i, j, k = 0, None, 1
count = 0
flip = False
state = s[0]
opposit = (1 if s[0] == 0 else 0)

while k < len(s) - 1:
    if s[:k] == [state] * k and s[k:] == [opposit] * (len(s) - k):
        print(max(k, len(s) - k))
        break
    else: k += 1
else:
    while i < len(s):
        if s[i] == state:
            if flip:
                length = min(length, count)
                flip = False
                count = i - j + 1
                j = None
            else:
                count += 1
        else:
            if j == None:
                j = i
                flip = True
            count += 1
        i += 1

    length = min(length, count)
    print(length)

Submission status: Wrong Answer

Solution code:
def ARC088():
    S = list(input())
    ans = len(S) * 20
    for i in range(len(S) - 1):
        if S[i] != S[i + 1]:
            ans = min(max(i + 1, len(S) - i - 1), ans)
    print(ans)
ARC088()

Submission status: Wrong Answer

Solution code:
s=input()
N=len(s)
ans=N//2
for i in range(N//2+1,N):
  if s[N-i:i]=="0"*(2*i-N) or s[N-i:i]=="1"*(2*i-N):
    ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()+'2'
prev=S[0]
cnt=1
li=[]
for i in range(1,len(S)):
    if S[i]!=prev:
        li.append(cnt)
        prev=S[i]
        cnt=1
    else:
        cnt+=1
if len(li)==1:
    print(li[0])
elif len(li)==2:
    print(max(li))
elif len(li)%2==1:
    ans=li[0]+li[1]
    for i in range(len(li)-1):
        ans=min(ans,li[i]+li[i+1])
    print(ans)
else:
    ans1=li[0]+li[1]
    ans2=li[1]+li[2]
    for i in range(len(li)-2):
        ans1=min(ans1,li[i]+li[i+1])
    for i in range(1,len(li)-1):
        ans2=min(ans2,li[i]+li[i+1])
    print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = list(input())
n = len(s)
res = 10**5

for k in range(n-1):
    if s[k]!=s[k+1]:
        res = min(res, max(k+1, n-(k+1)))
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = list(input())
s0 = 0
s1 = 0
for n in s:
    if n=="0":
        s0 += 1
    else:
        s1 += 1
print(max(s0,s1))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 10 ** 9
for i in range(N - 1):
    if S[i] != S[i + 1]:
        ans = min(ans, max(i + 1, N - i - 1))
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]
    count = 0
    N = len(S)
    if len(S) % 2 == 0:
        for i  in range(0, N/2):
            if S[N/2] == S[N/2 - i - 1]  and S[N/2] == S[N/2 + i]:
                count += 2
            else:
                break

    else:
        count += 1
        for i in range(1, N/2):
            if S[N/2] == S[N/2 - i] and S[N/2] == S[N/2 + i]:
                count += 2
            else:
                break

    K = N -(N - count)/2

    print K

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
v=1e9
for k in range(n-1):
  if s[k]!=s[k+1]:
    v=min(v,max(k+1,n-k-1))
print(v)

Submission status: Wrong Answer

Solution code:
s = input()
s = list(map(int, list(s)))
 
now = s[0]
cnt = 0
stack = []
for e in s:
    if now == e:
        cnt += 1
    else:
        stack.append(cnt)
        cnt = 1
        now = e
stack.append(cnt)
 
# print(stack)
 
l = len(stack)
ans = -1
if l == 1:
    ans = len(s)
elif l == 2:
    ans = max(stack)
else:
    for i in range(l-1):
        tmp = stack[i] + stack[i+1]
        ans = max(ans, tmp)
 
print(ans)

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]


s = input()
s = list(map(int, list(s)))

now = s[0]
cnt = 0
stack = []
for e in s:
    if now == e:
        cnt += 1
    else:
        stack.append(cnt)
        cnt = 1
        now = e
stack.append(cnt)

# print(stack)

l = len(stack)
ans = -1
if l == 1:
    ans = len(s)
elif l == 2:
    ans = max(stack)
elif l == 3:
    ans = min(stack[0]+stack[1], stack[1]+stack[2])
else:
    tmp1 = min(stack[0]+stack[1], stack[-2]+stack[-1])
    
    hoge = stack[2:l-2]
    tmp2 = -1
    if s[0] == 0:
        tmp2 = min(hoge[::2])
    else:
        tmp2 = min(hoge[1::2])
    ans = min(tmp1, tmp2)


print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
n = len(S)

if len(set(S)) == 1:
	print(len(S))
else:
	ans = 1000000
	for i in range(n-1):
		if S[i] != S[i+1]:
			m = max(n - i - 1, i + 1)
			if m < ans:
				ans = m

	print(m)

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
n = len(S)

if len(set(S)) == 1:
	print(len(S))
else:
	ans = 2
	for i in range(n-1):
		if S[i] != S[i+1]:
			m = max(n - i - 1, i + 1)
			if m > ans:
				ans = m

	print(m)

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]


s = input()
s = list(map(int, list(s)))

now = s[0]
cnt = 0
stack = []
for e in s:
    if now == e:
        cnt += 1
    else:
        stack.append(cnt)
        cnt = 1
        now = e
stack.append(cnt)

# print(stack)

l = len(stack)
ans = -1
if l == 1:
    ans = len(s)
elif l == 2:
    ans = max(stack)
elif l == 3:
    ans = min(stack[0]+stack[1], stack[1]+stack[2])
else:
    tmp1 = min(stack[0]+stack[1], stack[-2]+stack[-1])
    tmp2 = min(stack[2:l-2])
    ans = min(tmp1, tmp2)


print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
n = len(S)

if len(set(S)) == 1:
	print(len(S))
else:
	succ = []
	num = 1
	for i in range(1, n):
		if S[i] == S[i-1]:
			num += 1
			if i == n-1:
				succ.append(num)
		else:
			succ.append(num)
			num = 1
			if i == n-1:
				succ.append(num)

	ans = 2
	if len(succ) == 2:
		print(max(succ))
	else:
		for i in range(1, len(succ)-1):
			m = min(succ[i-1] + succ[i], succ[i] + succ[i+1])
			if ans < m:
				ans = m

		print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))

zero = 1000000
one = 1000000
current_zero = 0
current_one = 0

for i in range(len(S)- 1):
	if S[i] == 0:
		current_zero += 1
	else:
		current_one += 1
	if S[i] != S[i+1]:
		if S[i] == 0 and current_zero < zero:
			zero = current_zero
		elif S[i] == 1 and current_one < one:
			one = current_one
		current_zero = 0
		current_one = 0
	elif i == len(S) - 2:
		if S[i] == 0:
			current_zero += 1
			if current_zero < zero:
				zero = current_zero
		else:
			current_one += 1
			if current_one < one:
				one = current_one
#print(zero, one)
print(max(2, max(zero, one)))

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))

zero = 1000000
one = 1000000
current_zero = 0
current_one = 0

for i in range(len(S)- 1):
	if S[i] == 0:
		current_zero += 1
	else:
		current_one += 1
	if S[i] != S[i+1]:
		if S[i] == 0 and current_zero < zero:
			zero = current_zero
		elif S[i] == 1 and current_one < one:
			one = current_one
		current_zero = 0
		current_one = 0
	elif i == len(S) - 2:
		if S[i] == 0:
			current_zero += 1
			if current_zero < zero:
				zero = current_zero
		else:
			current_one += 1
			if current_one < one:
				one = current_one
print(zero, one)
print(max(2, max(zero, one)))

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))

zero = 0
one = 0
current_zero = 0
current_one = 0

for i in range(len(S)- 1):
	if S[i] == 0:
		current_zero += 1
	else:
		current_one += 1
	if S[i] != S[i+1]:
		if current_zero > zero:
			zero = current_zero
		elif current_one > one:
			one = current_one
		current_zero = 0
		current_one = 0
	elif i == len(S) - 2:
		if S[i] == 0:
			current_zero += 1
			if current_zero > zero:
				zero = current_zero
		else:
			current_one += 1
			if current_one > one:
				one = current_one

print(max(2, max(zero, one)))

Submission status: Wrong Answer

Solution code:
s = input()
print(len(s) - s.count("1"))

Submission status: Wrong Answer

Solution code:
s= raw_input()
def solve():
    prev = s[0]
    ans = 0
    for i in range(1,len(s)):
        if prev != s[i]:
            ans = max(ans,max(i,len(s)-i))
            prev = s[i]
    print ans
solve()

Submission status: Wrong Answer

Solution code:
s= raw_input()
def solve():
    prev = ' '
    ans = 10**9+1
    for i in range(len(s)):
        if prev != s[i]:
            ans = min(ans,max(i+1,len(s)-i-1))
            prev = s[i]
    print ans
solve()

Submission status: Wrong Answer

Solution code:
s= raw_input()
def solve():
    prev = ' '
    cnt = 0
    ans = 0
    for i in range(len(s)):
        if prev != s[i]:
            ans = max(ans,cnt)
            cnt = 0
            prev = s[i]
        cnt += 1
    ans = max(ans,cnt)
    if ans == 1 and len(s) >=3:
        ans = 2
    print ans
solve()

Submission status: Wrong Answer

Solution code:
s = raw_input()

ln = len(s)
zc = 0

for c in s:
    if c == '0':
        zc+=1

oc = ln - zc
print max(zc,oc)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
seq = []
for i in range(n-1):
    if S[i] != S[i+1]:
        seq.append(max(i+1, n-i-1))

print(seq)

Submission status: Wrong Answer

Solution code:

def ok(S, K):
    s = ''
    for i in range(len(S)):
        if i < K and i >= len(S) - K:
            s += S[i]

    if s == '':
        return True
    return all([c == s[0] for c in s])


S = input()
lb = 1
ub = len(S)
while ub - lb > 1:
    mid = (ub + lb) // 2
    if ok(S, mid):
        lb = mid
    else:
        ub = mid

print(lb)

Submission status: Wrong Answer

Solution code:

def ok(S, K):
    if K * 2 <= len(S):
        return True

    s = ''
    for i in range(len(S)):
        if i < K and i >= len(S) - K:
            s += S[i]

    return all([c == s[0] for c in s])


S = input()
lb = 1
ub = len(S)
while ub - lb > 1:
    mid = (ub + lb) // 2
    if ok(S, mid):
        lb = mid
    else:
        ub = mid

print(lb)

Submission status: Wrong Answer

Solution code:
def getAns(s):
    if len(s)==1:
        return 1
    else:
        ans = 2
        pre = s[0]
        now = s[0]
        nowlen=1
        for i in range(1,len(s)):
            now = s[i]
            if now==pre:
                nowlen+=1
                ans = max(nowlen,ans)
            else:
                pre = now
                nowlen = 1
        return ans

s = input()
print(getAns(s))

Submission status: Wrong Answer

Solution code:
from collections import Counter

item = str(input())
item = item 
longest = [0,0]
shortest = [len(item),len(item)]
current = 1

def exchange(item):
    for i in range(1, len(item)):
        if item[i-1] != item[i]:
            return max(exchange(item[0:i]), exchange(item[i:]))
    return len(item)

N = len(item)
T = N
for k in range(1, N):
    if item[k-1] != item[k]:
        tmp = max(k+1, N-(k+1))
        if T > tmp:
            T = tmp

print(T)

Submission status: Wrong Answer

Solution code:
from collections import Counter

item = str(input())
item = item + "*"
longest = [0,0]
shortest = [len(item),len(item)]
current = 1

def exchange(item):
    for i in range(1, len(item)):
        if item[i-1] != item[i]:
            return max(exchange(item[0:i]), exchange(item[i:]))
    return len(item)

N = len(item)
T = N
for k in range(1, N):
    if item[k-1] != item[k]:
        tmp = max(k+1, N-(k+1))
        if T > tmp:
            T = tmp

print(T)