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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return

#B
def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return

#C
def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return

# D
# 解説AC
# 実はi,i+1番目を順にみて文字が異なるなら
# max(i,n-k)文字を入れ替えればいいのである
def D():
    s = S()
    ans = inf
    n = len(s)
    for i in range(n - 1):
        if s[i] != s[i + 1]:
            ans = min(ans, max(i + 1, n - i - 1))
    print(ans if ans != inf else 0)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return

#B
def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return

#C
def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return

# D
# 解説AC
# 実はi,i+1番目を順にみて文字が異なるなら
# max(i,n-k)文字を入れ替えればいいのである
def D():
    s = S()
    ans = inf
    n = len(s)
    for i in range(n - 1):
        if s[i] != s[i + 1]:
            ans = min(ans, max(i, n - i))
    print(ans if ans != inf else 0)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return

#B
def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return

#C
def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return

#D
def D():
    s = S()
    lis = [0]
    i = 0
    while i < len(s):
        si = s[i]
        b = 0
        for k in range(i, len(s)):
            if si == s[k]:
                b += 1
                continue
            i = k
            lis.append(b)
            break
        else:
            i = k
            lis.append(b)
            if i == len(s) - 1:
                lis.append(0)
                i += 1
    if len(lis) == 4:
        print(max(lis[1:3]))
    else:
        ans = inf
        for i in range(1, len(lis) - 2):
            ans = min(ans, lis[i] + lis[i + 1])
        print(ans)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return

#B
def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return

#C
def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return

#D
def D():
    s = S()
    lis = [0]
    i = 0
    while i < len(s):
        si = s[i]
        b = 0
        for k in range(i, len(s)):
            if si == s[k]:
                b += 1
                continue
            i = k
            lis.append(b)
            break
        else:
            i = k
            lis.append(b)
            if i == len(s) - 1:
                lis.append(0)
                i += 1
    if len(lis) == 4:
        print(max(lis[1:2]))
    else:
        ans = inf
        for i in range(1, len(lis) - 2):
            ans = min(ans, lis[i] + lis[i + 1])
        print(ans)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
## WA
## 「長さKの区間を選んで」と思っていた
## 正しくは「長さK"以上の"区間を選んで」でした

from collections import Counter

S = input()

## 0を基準として、0と1の境目を調べる
boundary = []
pre_state = '0'
for i in range(len(S)):
  if S[i] != pre_state:
    boundary.append(i)
    pre_state = S[i]
else:
  if S[-1] == '1':
    boundary.append(len(S))
    
k = 2
while True:
  lst_mod = list(map(lambda x: x % k, boundary))
  count_mod = list(Counter(lst_mod).values())
  if not any(list(map(lambda x: x % 2, count_mod))): ## 達成できる場合
    k += 1
  else: ## 達成できない場合
    print(k-1)
    exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()

## 0を基準として、0と1の境目を調べる
boundary = []
pre_state = '0'
for i in range(len(S)):
  if S[i] != pre_state:
    boundary.append(i)
    pre_state = S[i]
else:
  if S[-1] == '1':
    boundary.append(len(S))
    
k = 2
while True:
  lst_mod = list(map(lambda x: x % k, boundary))
  count_mod = list(Counter(lst_mod).values())
  if not any(list(map(lambda x: x % 2, count_mod))): ## 達成できる場合
    k += 1
  else: ## 達成できない場合
    print(k-1)
    exit()

Submission status: Wrong Answer

Solution code:
S = input()
c0 = S[len(S)//2]
r = S.find("1" if c0 == "0" else "0", len(S)//2)
if r < 0: r = len(S)//2
l = S.rfind("1" if c0 == "0" else "0", 0, len(S)//2)
l += 1
K = min(r, len(S)-l)
#print(l, r, K)
print(K)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
ans=10**18
for i in range(1,l):
  if s[i]!=s[i-1]:
    tmp=max(i,l-i)
    ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
ans=10**18
for i in range(l-1):
  if s[i]!=s[i+1]:
    tmp=max(i+1,l-i-1)
    ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
"""
s = '101'
s = '100000000'
s = '00001111'
"""
k = len(s) 
l = 1
for i in range(1, len(s)-1):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = min(k, max(i, len(s)-i))
print(k)

Submission status: Wrong Answer

Solution code:
s = input()
"""
s = '101'
s = '100000000'
s = '00001111'
"""
k = 1
l = 1
for i in range(1, len(s)-1):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = min(k, max(i, len(s)-i))
print(k)

Submission status: Wrong Answer

Solution code:
s = input()
"""
s = '101'
s = '100000000'
s = '00001111'
"""
k = 1
l = 1
for i in range(1, len(s)-1):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = max(i, len(s)-i)
print(k)

Submission status: Wrong Answer

Solution code:
s = input()
#s = '0000010'
k = 0
l = 1
for i in range(1, len(s)):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = min(k, l)
        l = 1
    else:
        l += 1
print(max(k, l))

Submission status: Wrong Answer

Solution code:
s = input()
#s = '00001111'
k = 0
l = 1
for i in range(1, len(s)-1):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = max(k, l)
        l = 1
    else:
        l += 1
print(max(k, l))

Submission status: Wrong Answer

Solution code:
s = input()
#s = '00001111'
k = 0
l = 1
for i in range(1, len(s)):
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = max(k, l)
        l = 1
    else:
        l += 1
print(max(k, l))

Submission status: Wrong Answer

Solution code:
s = input()
#s = '00001111'
k = 0
l = 1
for i in range(1, len(s)):
    print(s[i-1:i+1])
    if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
        k = max(k, l)
        l = 1
    else:
        l += 1
print(max(k, l))

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
ans = float('inf')
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:
S = input()

ans = len(S)
for i in range(len(S) - 1):
    if S[i] != S[i+1]:
        ans = min(max(len(S) - i, i),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
for i in range(len(S)):
    if S[i] == "0":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
S += '2'
SS = []
olds = S[0]
length = 0
for i in range(len(S)):
  if S[i] == olds:
    length += 1
  else:
    SS.append(length)
    length = 1
    olds = S[i]
if len(SS) == 1:
  ans = len(SS)
elif len(SS) == 2:
  ans = max(SS[0],SS[1])
else:
  ans = 0
  for i in range(len(SS)-2):
    ans = min(ans, SS[i+1]+min(SS[i],SS[i+2]))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
S += '2'
SS = []
olds = S[0]
length = 0
for i in range(len(S)):
  if S[i] == olds:
    length += 1
  else:
    SS.append(length)
    length = 1
    olds = S[i]
if len(SS) == 1:
  ans = len(SS)
elif len(SS) == 2:
  ans = max(SS[0],SS[1])
else:
  ans = 0
  for i in range(len(SS)-2):
    ans = max(ans, SS[i+1]+min(SS[i],SS[i+2]))
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
change_cnt = 0
prev_length = 1
length = 1
for i in range(n):
    if s[i] == "0" and change_cnt % 2 == 1:
        change_cnt += 1
        prev_length = length
        length = n - i
    if s[i] == "1" and change_cnt % 2 == 0:
        change_cnt += 1
        prev_length = length
        length = n - i
print(max(min(prev_length, n - length), length))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
for k in range(N - 1):
    if S[k] != S[k + 1]:
        ans = max(ans, max(k + 1, N - k - 1))
        
if ans != 0:
    print(ans)
else:
    print(N)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
for k in range(N - 1):
    if S[k] != S[k + 1]:
        ans = max(ans, max(k + 1, N - k - 1))
        
if ans != 0:
    print(ans)
elif '0' in S:
    print(0)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
if n%2==0:
    ans=n//2
    if s[n//2-1]==s[n//2]:
        a=s[n//2]
        x=n//2-1
        y=n//2
        while True:
            if x==0:
                break
            x,y=x-1,y+1
            if s[x]==a and s[y]==a:
                ans=ans+1
            else:
                break
else:
    a=s[(n-1)//2]
    ans=(n-1)//2+1
    x=(n-1)//2
    y=(n-1)//2
    while True:
        if x==0:
            break
        x,y=x-1,y+1
        if s[x]==a and s[y]==a:
            ans=ans+1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

S = input()
L = len(S)
K = float('inf')
for i in range(L-1):
    if S[i] != S[i+1]:
        K = min(K, max(i+1, L-i-1))
print(K)

Submission status: Wrong Answer

Solution code:
S = input()
if S.count('1') == 0 or S.count('0') == 0:
    print(len(S))
    exit()

c = S[0]
mx = 0
len_s = len(S)
for s in range(1,len_s):
    if c != S[s]:
        mx = max(mx, len_s -s, s)
    c = S[s]
print(mx)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
if S.count('1') == 0:
    print(len(S))
    exit()
for s in S:
  if s == '1':
    break
  ans += 1
for s in S[::-1]:
  if s == '1':
    break
  ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

mi = len(S) // 2 + len(S) % 2 

if len(S) % 2 == 0:
  l = mi - 1
  r = mi
  if S[l] != S[r]:
    print(r)
    exit()
else:
  l = mi - 1
  r = mi - 1

re = S[l]
for i in range(l):
  if S[l - 1 - i] != re or S[r + 1 - i] != re:
    ans = r + i + 1
    break
else:
  ans = len(S)


print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

mi = len(S) // 2 + len(S) % 2 

if len(S) % 2 == 0:
  l = mi - 1
  r = mi
  if S[l] != S[r]:
    print(r)
  exit()
else:
  l = mi - 1
  r = mi - 1

re = S[l]
for i in range(l):
  if S[l - 1 - i] != re or S[r + 1 - i] != re:
    ans = r + i + 1
    break
else:
  ans = len(S)


print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

re = S[0]
f = 0
for i in range(1, len(S)):
  if S[i] != re:
    l = i
    break
else:
  l = len(S)

re = S[-1]
for i in range(1, len(S)):
  if S[-1 - i] != re:
    r = i
    break
else:
  r = len(S)

print(max(l, r, len(S) // 2 + len(S) % 2))

Submission status: Wrong Answer

Solution code:
s = input()
ans, cnt = 0, 0
for i in s:
    if i == '1':
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0
print(ans)

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    bound=0
    ans=[]
    s=input()
    if all(i=="0" for i in s):
        print(0)
        exit()
    for k,v in groupby(s):
        bound+=len(list(v))
#        ans.append()
        ans.append(max(bound,len(s)-bound))
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    ans = inf
    S=ST()
    for i in range(1, len(S)):
        if S[i] != S[i - 1]:
            ans = min(ans, max(i, len(S) - i ))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
zero = 0
one = 0
for i in S:
    if i == '0':
        zero += 1
    else:
        one += 1
K = max(zero, one)
print(K)

Submission status: Wrong Answer

Solution code:
S = input()
K = 0
for i in S:
    if i == '0':
        K += 1
print(K)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):

    if int(S) == 0 or int(S) == 1:
        print(len(S))
        return

    N = len(S)
    ts = INF
    for i in range(1, N):
        if S[i] != S[i-1]:
            ts = min(ts, max(i, N-i))
    print(ts)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):

    if int(S) == 0:
        print(len(S))
        return

    N = len(S)
    ts = INF
    for i in range(1, N):
        if S[i] != S[i-1]:
            ts = min(ts, max(i, N-i))
    print(ts)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):

    if int(S) == 0:
        print(len(S))
        return

    N = len(S)
    ts = INF
    for i, c in enumerate(S):
        if i == 0:
            continue
        if S[i-1] != S[i]:
            ts = min(ts, max(i, N-i))
    print(ts)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
ss=s[0]
ct=1
flag=0
C=[]
for i in range(1,n):
  if s[i]!=ss and flag==0:
    C.append(ct)
    ct=1
    flag=1
  else:
    ct+=1
    flag=0
  ss=s[i]
if flag==0:
  C.append(ct)
print(max(C))

Submission status: Wrong Answer

Solution code:
S=raw_input()
s0=s1=0
for c in S:
    if c=='0':s0+=1
    else: s1+=1
print(max(s0,s1))

Submission status: Wrong Answer

Solution code:
S = input()

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

print(ans)

Submission status: Wrong Answer

Solution code:
import decimal

S = input()

ans = decimal.Decimal("inf")
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(i+1, len(S)-i-1))

print(ans)

Submission status: Wrong Answer

Solution code:
import decimal

S = input()

ans = decimal.Decimal("inf")
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(i, len(S)-i))

print(ans)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
S = input()

# 0と1の個数のうち、大きい方
cnt = 0
for i in range(len(S)):
    if S[i] == "0":
        cnt += 1
cnt = max(cnt, len(S) - cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
bef=S[0]
ans=len(S)
for i in range(1,len(S)):
    if bef!=S[i]:
        ans=min(ans,max(len(S)-i,i))
        bef=S[i]
if '1' not in S:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
ans=n//2

la=[0]
lb=[0]

def f(i):
    if n%2==0:
        return 2**(2*i)-1
    else:
        return 2**(2*i+1)-1

for i in range(1,n//2+1):
    if int(s[n//2-i:n//2+i],2)==0 or int(s[n//2-i:n//2+i],2)==f(i):
        ans=n//2+i
        
if n%2==0:
    print(ans)
else:
    print(ans+1)

Submission status: Wrong Answer

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

la=[0]
lb=[0]

for i in s:
    if i=="0":
        la.append(la[-1]+1)
        lb.append(lb[-1])
    else:
        lb.append(lb[-1]+1)
        la.append(la[-1])


for i in range(n//2+1):
    if la[n//2+i]-la[n//2-i]==0 or lb[n//2+i]-lb[n//2-i]==0:
        ans=n//2+i
if n%2==0:
    print(ans)
else:
    print(ans+1)

Submission status: Wrong Answer

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

cntl = []
tmp = S[0]
cnt = 1
for i in range(1,N):
  if tmp == S[i]:
    cnt += 1
  else:
    cntl.append(cnt)
    cnt = 1
    tmp = S[i]
else:
  cntl.append(cnt)

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

if ans == 0:
  print(N)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

pos_0 = [0]
pos_1 = [0]
for i, s in enumerate(S):
    if s == '0':
        pos_0.append(i)
    else:
        pos_1.append(i)
pos_0.append(len(S)-1)
pos_1.append(len(S)-1)

interval_0 = [pos_0[i+1] - pos_0[i] for i in range(len(pos_0) - 1)]
interval_1 = [pos_1[i+1] - pos_1[i] for i in range(len(pos_1) - 1)]

print(max(max(interval_0), max(interval_1)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	s=list(io())[:-1]
	if len(s)% 2==1:
		center=len(s)//2
		mm=s[center]
		ret=center+1
		la=s[center-1::-1]
		lb=s[center+1:]
		for ca,cb in zip(s[:center-1:-1],s[center+1:]):
			#print(ca,cb)
			if ca == mm and cb == mm:
				ret += 1
			else:
				break
	else:
		center=len(s)//2
		ret=center
		mm=-1
		la=s[center-1::-1]
		lb=s[center:]
		for ca, cb in zip(la, lb):
			if (mm == ca or mm == -1) and ca == cb:
				ret+=1
				mm=ca
			else:
				break
				
	if 0:
		print(la)
		print(lb)
	return ret

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	s=list(io())
	if len(s)% 2==1:
		center=len(s)//2
		mm=s[center]
		ret=center
		for ca,cb in zip(s[:center-1:-1],s[center+1:]):
			#print(ca,cb)
			if ca == mm and cb == mm:
				ret += 1
			else:
				break
	else:
		center=len(s)//2
		ret=center
		mm=-1
		la=s[center:-1]
		lb=s[center:]
		for ca, cb in zip(la, lb):
			#print(mm,ca,cb, center)
			if (mm == ca or mm == -1) and ca == cb:
				ret+=1
				mm=ca
			else:
				break
	return ret

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Wrong Answer

Solution code:
s = input()
if len (s) % 2 == 1:
    l = r = (len(s) + 1) // 2
    k = l-1
else:
    l = len(s) // 2
    r = len(s) // 2 + 1
    k = l

while s[l-1] == s[r-1]:
    k += 1
    l -= 1
    r += 1
    if l - 1 < 0:
        break

print(k)

Submission status: Wrong Answer

Solution code:
s = input()
if len (s) % 2 == 1:
    l = r = (len(s) + 1) // 2
    k = l-1
else:
    l = len(s) // 2
    r = len(s) // 2 + 1
    k = l

while s[l-1] == s[r-1] and l - 1 > 0:
    k += 1
    l -= 1
    r += 1

print(k)

Submission status: Wrong Answer

Solution code:
s=input();n=len(s);print(min([max(i,n-i)for i in range(1,n)if s[i-1]!=s[i]]or[s[0]]))

Submission status: Wrong Answer

Solution code:
s=input();n=len(s);print(min([max(i,n-i)for i in range(1,n)if s[i-1]!=s[i]]or[0]))

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline().rstrip()
A = []
pre = None
count = 0
for c in S:
    if pre is None:
        pre = c
        count = 0
    if pre == c:
        count += 1
    else:
        A.append(count)
        pre = c
        count = 1
A.append(count)
lenA = len(A)
lenA2 = (lenA + 1) // 2
s = sum(A[:lenA2])
B = [s]
for i in range(lenA - lenA2):
    s = s - A[i] + A[i + lenA2]
    B.append(s)
#print(B)
if len(A) == 1:
    print(A[0])
elif len(A) == 2:
    print(max(A[0],A[1]))
elif lenA % 2 == 1:
    print(min(B))
else:
    s = min(B[1:-1])
    print(max(min(B[0],s),min(B[-1],s)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
sen=len(s)
ans=(len(s)+1)//2
chk=0
t=s[0]
d=[]
for i in range(sen):
    if t==s[i]:
        chk+=1
    else:
        d.append(chk)
        t=s[i]
        chk=1
    if i==sen-1: d.append(chk)
    ans=max(ans,chk)
nen=len(d)
if nen>2:
    for i in range(1,nen-1):
        ans=max(ans,min(d[i-1]+d[i],d[i]+d[i+1]))
        if (i>1 and i<nen-1): ans=max(ans,(d[i-1]+d[i]+d[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
sen=len(s)
ans=(len(s)+1)//2
chk=0
t=s[0]
d=[]
for i in range(sen):
    if t==s[i]:
        chk+=1
    else:
        d.append(chk)
        t=s[i]
        chk=1
    if i==sen-1: d.append(chk)
    ans=max(ans,chk)
nen=len(d)
if nen>2:
    for i in range(1,nen-1):
        ans=max(ans,min(d[i-1]+d[i],d[i]+d[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
sen=len(s)
ans=(len(s)+1)//2
chk=0
t=s[0]
d=[]
for i in range(sen):
    if t==s[i]:
        chk+=1
    else:
        d.append(chk)
        t=s[i]
        chk=1
    if i==sen-1: d.append(chk)
    ans=max(ans,chk)
nax=max(d)
nen=len(d)
if nen>2:
    for i in range(1,nen-1):
        if (nax==d[i]): ans=max(ans,min(d[i-1]+d[i],d[i]+d[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
sen=len(s)
ans=(len(s)+1)//2
chk=0
t=s[0]
d=[]
for i in range(sen):
    if t==s[i]:
        chk+=1
    else:
        d.append(chk)
        t=s[i]
        chk=1
    if i==sen-1: d.append(chk)
    ans=max(ans,chk)
nax=max(d)
nen=len(d)
if nen>2:
    for i in range(1,nen-1):
        if (nax==d[i]): ans=max(ans,min(d[-3]+d[-2],d[-2]+d[-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=(len(s)+1)//2
chk=1
t=""
for i in s:
    if t==i:
        chk+=1
    else:
        t=i
        chk=1
    ans=max(ans,chk)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(string):
    l = [s == "1" for s in string]
    l_r = l[::-1]
    index = 0
    h = len(string) // 2
    for i, (c, n, c_r, n_r) in enumerate(zip(l[:h], l[1:h + 1], l_r[:h], l_r[1:h + 1])):
        if c ^ n or c_r ^ n_r:
            index = i + 1
    print(len(string) - index)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
s=input()
ans=1
t=1
l=len(s)
m=s[0]
for i in range(1,l):
  if i==l-1: t-=1
  if s[i]==m:
    t+=1
  else:
    m=s[i]
    t=2
  ans=max(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=1
t=1
l=len(s)
m=s[0]
for i in range(1,l):
  if i==l-1: t-=1
  if s[i]==m:
    t+=1
  else:
    m=s[i]
    t=2
  ans=max(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=1
t=0
l=len(s)
m=""
for i in range(l):
  if i==l-1: t-=1
  if s[i]==m:
    t+=1
  else:
    m=s[i]
    t=1
  ans=max(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=1
t=0
l=len(s)
m=""
for i in range(l):
  if i==l-1: t-=1
  if s[i]==m:
    t+=1
    ans=max(ans,t)
  else:
    m=s[i]
    t=1
print(ans)