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: Runtime Error

Solution code:
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var dic = new Dictionary<int, int>();
            dic[0] = 1;
            var s = consoleReader.String.Select(c => c == '0').ToArray();
            int startIndex = 0;
            for (var i = 1; i < s.Length; i++)
            {
                if (s[startIndex] == s[i])
                {
                    dic[startIndex]++;
                }
                else
                {
                    startIndex = i;
                    dic[i] = 1;
                }
            }
            var vals = dic.Values.ToArray();
            if (vals.Length == 1) return vals[0];

            vals[0]--;
            vals[vals.Length - 1]--;

            return vals.Max(i => i + 1);
        }

        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    public class ConsoleReader
    {
        private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = ReadLineSplit();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader : IEnumerable<ConsoleReader>
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator();
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

            public IEnumerable<string> String => this.Select(cr => cr.String);
            public IEnumerable<int> Int => this.Select(cr => cr.Int);
            public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1);
            public IEnumerable<long> Long => this.Select(cr => cr.Long);
            public IEnumerable<double> Double => this.Select(cr => cr.Double);
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
    #endregion
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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))
    
## 答えは、端から一番遠い境目
lst = []
for i in range(len(boundary)):
  lst.append(max(boundary[i], len(S)-boundary[i]))
ans = min(lst)
print(ans)

Submission status: Runtime Error

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,n-i-1)
    ans=min(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
#s = input()
"""
s = '101'
s = '100000000'
s = '00001011'
"""
k = len(s)
for i in range(1, len(s)):
    if s[i-1] != s[i+1]:
        k = min(k, max(i, len(s)-i))
print(k)

Submission status: Runtime Error

Solution code:
S = input()
b = []
for i in range(len(S) - 1):
    if S[i:i + 2] == "01" or S[i:i + 2] == "10":
        b.append(len(S) - (i + 1) if i < len(S) // 2 else i + 1)

print(min(b))

Submission status: Runtime Error

Solution code:



/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s; cin >> s;
  int n = s.size();
  int ans = INF;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) continue;
    int left = i + 1, right = n - i - 1;
    int mx = max(left, right);
    chmin(ans, mx);
  }

  print(ans);

  return 0;
}

Submission status: Runtime Error

Solution code:
S = input()
L = len(s)

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

Submission status: Runtime Error

Solution code:
S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
print(min(temp))

Submission status: Runtime Error

Solution code:
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2
    c = ans+1
    t = S[ans+1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
s = raw_input()
length = len(s)

T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
print min(T)

Submission status: Runtime Error

Solution code:
s = input()

if len(s) == 1:


tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))

Submission status: Runtime Error

Solution code:
s = input()

tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

print(max(tmp))

Submission status: Runtime Error

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

Submission status: Runtime Error

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


main()

Submission status: Runtime Error

Solution code:
# coding=utf-8
S = int(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: Runtime Error

Solution code:
S = input()
l = len(S)
if l%2:
    c = S[l//2]
    for i in range(1,l//2+1):
        if S[l//2-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
    print(l//2+i)
else:
    c = S[l//2]
    for i in range(l//2+1):
        if S[l//2-i] != c or S[l//2 - 1 + i] != c:
            break
    else:
        i += 1
    print(l//2 + i)

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
if n == 1:
    print(1)
else:
    prev = None
    cand = []
    for i in range(n):
        if i != 0:
            if S[i] != prev:
                cand.append(max(i, n-i))
        prev = S[i]    

    print(min(cand))

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    

print(min(cand))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    if len(S) % 2 == 1:
        mid = (len(S) - 1) // 2
        for i in range(mid):
            if S[mid] != S[mid + i] or S[mid] != S[mid -i]:
                ans = mid + i
                break
    else:
        midr = len(S) // 2
        midl = midr - 1
        for i in range(midr):
            if S[midr] != S[midr + i] or S[midr] != S[midl - i]:
                ans = midr + i
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    z = []
    o = []
    i = 0
    while i < len(S):
        j = i + 1
        while j < len(S) and S[i] == S[j]:
            j += 1
        if S[i] == '0':
            z.append(j-i)
        else:
            o.append(j-i)

        i = j

    z = sorted(z, key=lambda x: -x)
    o = sorted(o, key=lambda x: -x)

    if z[0] > o[0]:
        if len(z) > 2 and z[0] == z[1]:
            print(z[0] + 1)
        else:
            print(z[0])
    elif o[0] > z[0]:
        if len(o) > 2 and o[0] == o[1]:
            print(o[0] + 1)
        else:
            print(o[0])
    else:
        if len(z) > 2 and z[0] == z[1]:
            print(z[0] + 1)
        elif len(o) > 2 and o[0] == o[1]:
            print(o[0] + 1)
        else:
            print(o[0])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
k = 0
tmp = set()
while len(tmp) < 2:
    tmp.add(s[n // 2 + k])
    tmp.add(s[(n - 1) // 2 - k])
    k += 1
print(n // 2 + k - 1)

Submission status: Runtime Error

Solution code:
 = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
    if s[i] != t or s[j] != t:
        break
    ans += 1
    i -= 1
    j += 1

print(ans)

Submission status: Runtime Error

Solution code:
s = list(input())
sums = sum([int(ss) for ss in s])

if len(s) == 1:
    print(1)
elif sums == len(s):
    print(len(s))
else:
    a = []
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            a.append(max(i+1, len(s)-i-1))
            
    print(min(a))

Submission status: Runtime Error

Solution code:
s = list(input())

if s == '1':
    print(1)
else:
    a = []
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            a.append(max(len(s[:i+1]), len(s[i+1:])))
            
    print(min(a))

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
res = []
for i,(a,b) in enumerate(zip(s,s[1:])):
    if a != b:
        res.append(max(i+1,n-1-i))
print(min(res))

Submission status: Runtime Error

Solution code:
import sys
s=input()
len_s=len(s)
if(len_s==1):
    print(1)
    sys.exit()


if(len_s%2==1):
    l=len_s//2
    r=l
else:
    r=len_s//2
    l=r-1

saisyo=s[l]
if(s[l]==s[r]):
    while(saisyo==s[l-1] and saisyo==s[r+1]):
        l-=1
        r+=1
        if(l==0):
            break
else:
    r=l

print( (len_s + r-l +1)//2)

Submission status: Runtime Error

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

if(len_s%2==1):
    l=len_s//2
    r=l
else:
    r=len_s//2
    l=r-1

saisyo=s[l]
if(s[l]==s[r]):
    while(saisyo==s[l-1] and saisyo==s[r+1]):
        l-=1
        r+=1
        if(l<0):
            break
else:
    r=l

print( (len_s + r-l +1)//2)

Submission status: Runtime Error

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

if(len_s%2==1):
    l=len_s//2
    r=l
else:
    r=len_s//2
    l=r-1

saisyo=s[l]
if(s[l]==s[r]):
    while(saisyo==s[l-1] and saisyo==s[r+1] and 0<=l-1):
        l-=1
        r+=1
else:
    r=l

print( (len_s + r-l +1)//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

graph = [[] for _ in range(n)]
for _ in range(m):
    l,r,d = li()
    l -= 1
    r -= 1
    graph[l].append((d,r))
    graph[r].append((-d,l))
    
searched = [False]*n
dist = [float("inf") for _ in range(n)]

exist = True
for i in range(n):
    if not searched[i]:
        dist[i] = 0
        searched[i] = True
        stack = [(0,i)]
        
        while stack:
            cost, cur = stack.pop()
            for nex_cost, nex_node in graph[cur]:
                if searched[nex_node]:
                    if cost + nex_cost != dist[nex_node]:
                        exist = False
                        
                else:
                    stack.append((cost+nex_cost, nex_node))
                    dist[nex_node] = cost + nex_cost
                    searched[nex_node] = True
                    
print("Yes") if exist else print("No")

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2 + N%2
if N%2==0 and center != S[center_i+1]:
    print(ans)
    exit()
l = center_i - 1
r = center_i + 1 + (N%2==0)
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)

Submission status: Runtime Error

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

t = []
for i in range(1, n):
    if s[i] != s[i-1]:
        t.append(max(i, n-i))
print(min(t))

Submission status: Runtime Error

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

print(min(a))

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
ans = n//2
c = S[ans]

while ans <= n:
    if c == S[ans] == S[-ans-1]:
        ans += 1
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

# s = S[0]
temp_T = 100000
for i in range(len(S)-1):
    if(S[i+1] != s[i]):
        judge = max(i+1,len(S)-(i+1))
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Runtime Error

Solution code:
S = input()

s = S[0]
temp_T = 100000
for i in range(1, len(S)+1):
    if(S[i] != s):
        judge = max(i,len(S)-i)
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Runtime Error

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

if n == 1:
    print(1)
    exit()

big = []
for i, prev_c in enumerate(s):
    if i == len(s)-1:
        break

    next_c = s[i+1]
    if next_c != prev_c:
        big.append(max(i, n-i))

print(min(big))

Submission status: Runtime Error

Solution code:
s = list(input())
big = []
for i, prev_c in enumerate(s):
    if i == len(s)-1:
        break

    next_c = s[i+1]
    if next_c != prev_c:
        big.append(max(i, len(s)-1-i))


print(min(big))

Submission status: Runtime Error

Solution code:
def sokutei(s):
    b = [1,]
    for t in range(1, len(s)):
        if s[t] == s[t-1]:
            b[-1] += 1
        else:
            b.append(1)
    return max(b)

def main():
    S = input()
    B = sokutei(S)

    for K in range(len(S), 1, -1):
        a = [1,]
        for i in range(len(S) - K):
            s = ""
            for j in range(len(S)):
                if j<i or j>(i+K):
                    s += S[j]
                else:
                    if S[j]=="1":
                        s += "0"
                    else:
                        s += "1"
            a.append(sokutei(s))
        if B < max(a):
            return K+1
    return K

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import collections as col
s = input()
x,y = map(int,input().split())
col.Counter(s)
lr_check = True
ud_count = []
lr_count = []
F_count = 0

def dlr(i, p):
    global lr_count
    if i == 0:
        if p == lr_count[0]:
            return 1
        else:
            return 0
    else:
        return dlr(i-1,p+lr_count[i-1]) + dlr(i-1,p-lr_count[i-1])
    
def dud(i, p):
    global ud_count
    if i == 0:
        if p == ud_count[0]:
            return 1
        else:
            return 0
    else:
        return dud(i-1,p+ud_count[i-1]) + dud(i-1,p-ud_count[i-1])

for i in range(len(s)):
    if s[i] == 'T':
        if lr_check == True:
            lr_count.append(F_count)
        else:
            ud_count.append(F_count)
        lr_check = -lr_check
        F_count = 0
    else:
        F_count += 1
        if i == len(s)-1:
            if lr_check == True:
                lr_count.append(F_count)
            else:
                ud_count.append(F_count)

                
if dud(len(ud_count)-1,abs(y))*dlr(len(lr_count)-1,abs(x)) > 0:
    print ('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2
if N%2==1: c=n	# c:center

cnt=0
for i in range(1,n+1):
	if N%2==1:
		if S[c-i]==S[c+i]==S[c]:
			cnt=1+2*i
			pass
		else:
			if i==n:
				cnt+=1
			break
	else:	
		if S[n-i]==S[n+i]:
			cnt=2*n
		else:
			break
if N%2==1:
	print max(n+1,cnt)
else:
	print max(n, cnt)

Submission status: Runtime Error

Solution code:
S=raw_input()
c=[]
cnt=0
for i in S:
	if i=="0":
		cnt+=1
	else:
		if cnt!=0:
			c.append(cnt)
			cnt=0
else:
	if cnt!=0:
		c.append(cnt)

if len(c)==1:
	print c[0]
else:
	print max(c)+1

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    N = len(S)
    for k in range(N - 1, (N // 2) - 1, -1):
        first = S[0:k]
        union = k * 2 - N
        cut = first[-union:-1] + first[-1]
        if '1' in cut and '0' in cut:
            continue
        else:
            return print(k)


main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    N = len(S)
    for k in range(N - 1, N // 2 - 1, -1):
        first = S[0:k]
        union = k * 2 - len(S)
        cut = first[-union:-1] + first[-1]
        if '1' in cut and '0' in cut:
            continue
        else:
            return print(k)


main()

Submission status: Runtime Error

Solution code:
S=input()
if len(S)==1:
    print('1')
else:
    k=0
    L=[]
    while k < (len(S)-1):
        if S[k] != S[k+1]:
            L.append(max(k+1,len(S)-k-1))
            k += 1
        else:
            k += 1
    L.sort()
    print(L[0])

Submission status: Runtime Error

Solution code:
S=input()
if len(S)==1:
    print('1')
else:
    k=0
    L=[]
    while k < (len(S)-1):
        if S[k] != S[k+1]:
            L.append(max(k,len(S)-k))
            k += 1
        else:
            k += 1
    L.sort()
    print(L[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()

tempT = []
T = 0
for i in range(0,len(S)-1):
    if S[i] != S[i+1]:
        tempT.append(max([i+1,len(S)-(i+1)]))
T = min(tempT)

print(T)

Submission status: Runtime Error

Solution code:
s = input()

def func(k):
    cnt = 0
    buf = 0
    arr = [0 for _ in s]
    arr.append(0)
    for i in range(len(s)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        if (i+1 is not len(s)) and s[i] == s[i+1] :
            continue
        val = (int(s[i]) + cnt + buf)%2
        if val == 0:
            if i+k > len(s) :
                if buf > 0 :
                    buf -= 1
                    continue
                else :
                    return False
            cnt += 1
            arr[i+k] += 1
    return True

l, r = 1, len(s)+1
while r-l > 1:
    mid = (r+l)//2
    # print(mid, func(mid))
    if func(mid) : l = mid
    else : r = mid

print(l)

Submission status: Runtime Error

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

for i in range(1,n):
  x = n
  nx=0
  if l[i-1] != l[i]:
    nx = max(i, n-i)
  x = min(x,nx)
print(x)

Submission status: Runtime Error

Solution code:
S = input().strip()

Ks = []
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        Ks.append(max(i+1, len(S)-i-1))

print(min(Ks))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()

import math
N = len(S)
for i in range(math.ceil(N/2), N):
    if S[N-i:i] == '0'*(i-(N-i)) or S[N-i:i] == '1'*(i-(N-i)):
        K = i
print(K)

Submission status: Runtime Error

Solution code:
# coding:utf-8

S = input()

s_len = len(S)
s = [int(i) for i in S]

def reverse(A, L, R):
    for i in range(R-L+1):
        if A[L-1+i] == 0:
            A[L-1+i] = 1
        else:
            A[L-1+i] = 0

    return A
    

s_count = {}
for x in s:
    if x not in s_count:
        s_count[x] = 0
    s_count[x] += 1

#print(s_count)
if s_count[1] == 1:
    print(s_count[0])
else:
    print(s_count[1])

Submission status: Runtime Error

Solution code:
def main():
    S = input()

    len_ = len(S)
    if not S.count('0'):
        print(len_)
        return

    k = (len_ + 1) // 2
    for i in range(len_ // 2):
        l = S[k - 1 - i]
        r = S[k]
        if l != r or k + 1 == len_:
            break

    print(k + i)

main()

Submission status: Runtime Error

Solution code:
import math,sys

s=input()
k=math.ceil(len(s)/2)-1

if(s=='0'):
    print(0)
    sys.exit()
elif(s=='1'):
    print(1)
    sys.exit()

for i in range(int(math.ceil(len(s)/2))):
#    print(k+i,k-i)
    if(s[k+1] == s[k-1] and k-i == 0):
        k=k+i
    elif(s[k+i] == s[k-i]):
        continue
    else:
        k=k+i
print(k)

Submission status: Runtime Error

Solution code:
import math,sys

s=input()
k=math.ceil(len(s)/2)-1
for i in range(int(math.ceil(len(s)/2))):
#    print(k+i,k-i)
    if(s[k+1] == s[k-1] and k-i == 0):
        print(k+i)
        sys.exit()
    elif(s[k+i] == s[k-i]):
        continue
    else:
        print(k+i)
        sys.exit()
print(k)

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        tmplist = slist
        judge = testmethod(tmplist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(1, len(list)):
        if list[t-1:t] == '1'
            return 1
    
    return 0

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        tmplist = slist
        judge = testmethod(tmplist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t:t+1] == '1'
            return 1
    
    return 0

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    T = min(T)
    return T

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

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        tmplist = slist
        judge = testmethod(tmplist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t] == '1'
            return 1
    
    return 0

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        tmplist = slist
        judge = testmethod(tmplist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t] == '1'
            return 1
    
    return 0

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        judge = testmethod(slist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t] == '1'
            return 1
    
    return 0

Submission status: Runtime Error

Solution code:
import pandas as pd

def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        judge = testmethod(slist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t] == '1'
            return 1
    
    return 0

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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]]))

Submission status: Runtime Error

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]))

Submission status: Runtime Error

Solution code:

s = input()

max_k = 0


#バラバラ
slist = []
for i in range(len(s)):
    slist.append(s[i:i+1])

for k in range(len(slist)):
    judge = testmethod(slist, k)
    if judge == 0:
        max_k = k
        
print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target
    
    for t in range(len(list)):
        if list[t] == '1'
            return 1
    
    return 0

Submission status: Runtime Error

Solution code:
if __name__=="__main__":
    l = list(input())
    N = len(l)
    if N==1:
        print(1)
        exit()
    results = []
    for i in range(0,N-1):
        if not l[i]==l[i+1]:
            results.append(max(i+1,N-i-1))
    print(min(results))