Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02953 (python)

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
for i in range(N-1):
    if H[i] - H[i+1] > 1:
        print("No")
        quit()

for i in range(1, N-1):
    if H[i] > H[i+1] or H[i-1] < H[i]:
        H[i] -= 1
        if H[i-1] > H[i] or H[i] > H[i+1]:
            print("No")
            break
    else:
        continue
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
H[1] -= 1
for i in range(1, N-1):
    if H[i-1] > H[i] or H[i] > H[i+1]:
        H[i] -= 1
        if H[i-1] > H[i] or H[i] > H[i+1]:
            print("No")
            break
        else:
            continue
else:
    print("Yes")
Problem p02971 (python)

Fixed submission:
N = int(input())
num_line = [int(input()) for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[N-1]:
        print(sort_line[N-2])
    else:
        print(sort_line[N-1])

Buggy submission (verdict: Runtime Error):
import sys

N = int(stdin.readline().restrip())
num_line = [stdin.readline().restrip() for _ in range(N)]
for i in range(N):
    save_num = num_line[i]
    num_line.pop(i)
    print(max(num_line))
    num_line.insert(i, save_num)
Problem p03037 (python)

Fixed submission:
import numpy as np
N, M = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(M)]
l = np.array(l)
ans = list(range(l[:, 0].max(), l[:, 1].min() + 1))
print(len(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(M)]
l = np.array(l)
ans = list(range(l[:, 0].max(), l[:, 1].min() + 1))
print(len(ans))
Problem p03043 (python)

Fixed submission:
import math
N, K = map(int, input().split())
#S = list(input())
ans = []
for i in range(1, N+1):
    if i < K:
        ans.append(1/N * (0.5) ** (math.ceil(math.log2(K/i))))
    else:
        ans.append(1/N)
print(sum(ans))

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
#S = list(input())
ans = []
for i in range(1, N+1):
    if i < K:
        ans.append(1/N * (0.5) ** (math.ceil(math.log2(K/i))))
    else:
        ans.append(1/N)
print(sum(ans))
Problem p03161 (python)

Fixed submission:
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [10**10] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i-j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [np.Infinity] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i-j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [math.inf] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i-j]))
print(dp[-1])
Problem p04043 (python)

Fixed submission:
input = input().split()
count = 0
for num in input:
  if num == "7":
    count += 1
 
if count == 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
input = input().split()
count = 0
for num in input:
  if num == "7":
    count += 1

if count = 1:
  print("YES")
else:
  print("NO")
Problem p02683 (python)

Fixed submission:

import itertools
import sys
import numpy as np
INF = float("inf")
N, M, X = list(map(int, sys.stdin.buffer.readline().split()))
A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
 
A = np.array(A, dtype=int)
mat = A[:, 1:]
C = A[:, 0]
 
ans = INF
for choices in itertools.product((True, False), repeat=N):
    choices = np.array(list(choices), dtype=bool)
    if np.all(mat[choices, :].sum(axis=0) >= X):
        ans = min(ans, C[choices].sum())
if ans == INF:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):

import itertools
import sys
import numpy as np
INF = float("inf")
N, M, x= map(int, input().split())
nap = []

for _ in range(N):
    nap.append(list(map(int, input().split()))) 
mon=[]
value=[]
for x in nap:
    mon.append(x[0])
for y in nap:
    value.append(y[1:])
mon=np.array(mon)
value=np.array(value)
for i in itertools.product((0,1),repeat=N):
    choice = np.array(list(i), dtype=bool)
    if all(value[choice,:].sum(axis=0) >=x):
        ans = min(ans,mon[choice].sum())
if ans == INF:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M, x= map(int, input().split())
dp=[[0 for i in range(N+1)] for j in range(M+1)]
nap = []
dp[0][0]=0
answ = [10]*M
for _ in range(N):
    nap.append(list(map(int, input().split()))) 

mon=[]
value=[]
for x in nap:
    mon.append(x[0])
for y in nap:
    value.append(y[1:])

ans = []
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = dp[i][j]+value[i][j]
for m in range(M):
    if answ[m] > ans[m]:
        print(-1)
        exit()


return dp[N][M]

Buggy submission (verdict: Runtime Error):
N, M, x= map(int, input().split())
dp=[[0 for i in range(N+1)] for j in range(M+1)]
nap = []
dp[0][0]=0
answ = [10]*M
for _ in range(N):
    nap.append(list(map(int, input().split()))) 

mon=[]
value=[]
for x in nap:
    mon.append(x[0])
for y in nap:
    value.append(y[1:])

ans = []
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = dp[i][j]+value[i][j]
for m in range(M):
    if answ[m] > ans[m]:
        print(-1)
        exit()


return dp[N][W]
Problem p02696 (python)

Fixed submission:
import math
 
a, b, n = map(int, input().split())
ans = 0
tmp = 0
 
if n > b - 1:
    n = b-1
 
ans = math.floor(a*n/b) - a*math.floor(n/b)
 
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A,B,N = map(int,input().split())
res = 0
for i in range(1,N+1):
    res_bar = math.floor((A*i)/B)-A*math.floor(i/B)
    if res_bar >= res:
        res = res_bar
        ans = i
    else:
        break
print(res)

Buggy submission (verdict: Runtime Error):
A,B,N = map(int,input().split())
res = 0
ans = 0
for i in range(1,N+1):
    res_bar = math.floor((A*i)/B)-A*math.floor(i/B)
    if res_bar >= res:
        res = res_bar
        ans = i
    else:
        break

        
        
print(res)

Buggy submission (verdict: Runtime Error):
A,B,N = map(int,input().split())
res = 0
ans = 0
for i in range(1,N+1):
    res_bar = math.floor((A*i)/B)-A*math.floor(i/B)
    if res_bar > res:
        res = res_bar
        ans = i
print(ans)
Problem p02700 (python)

Fixed submission:
import math
a,b,c,d = map(int,input().split())

cb = -(-c//b)
ad = -(-a//d)
if ad < cb :
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())

while True:

    cd = c - b
    if cd <= 0:
        print('Yes')
        break
    
    ad = a - d 
        if ad <= 0:
        print('No')
        break
Problem p02702 (python)

Fixed submission:
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        ans += mods[current % 2019]
        mods[current % 2019] += 1
        x = x * 10 % 2019
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 % 2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 %2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 %2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
 
if __name__ == '__main__':
    main()
Problem p02713 (python)

Fixed submission:
from math import gcd
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=gcd(gcd(i,j),k)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
      jj = math.gcd(i,j)
        for k in range(1,n+1):
            ans+=math.gcd(jj,k)
print(ans)
Problem p02720 (python)

Fixed submission:
k=int(input())
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9): #上記の操作を9回繰り返せば10^5個以上のルンルン数を列挙できる
 tmp=[]
 for val in cand[-1]:
   if val%10!=0: #末尾が0のときは(末尾-1)を付け加えた数はルンルン数にならない
     tmp.append(val*10+(val%10-1))
   tmp.append(val*10+(val%10))
   if val%10!=9: #末尾が9のときは(末尾+1)を付け加えた数はルンルン数にならない
     tmp.append(val*10+(val%10+1))
 cand.append(tmp)
ans=[]
for i in range(len(cand)):
 for val in cand[i]:
   ans.append(val)
ans=sorted(ans)
print(ans[k-1])

Buggy submission (verdict: Runtime Error):
ans=0
runrun = 0
i =0
while runrun = K:
    if i < 10:
        runrun +=1
    else:
        a = list(map(int,str(i)))
        for j in range(1,len(a)):
            tmp = 0
            if abs(a[j]-a[j-1])<=1:
                tmp +=1
        if tmp == len(a)-1:
            runrun +=1
            ans = i
    i +=1
print(ans)
Problem p02934 (python)

Fixed submission:
import numpy as np
n =int(input())
a = list(map(float,input().split()))

b = sum(np.reciprocal(a))

print(np.reciprocal(b))

Buggy submission (verdict: Runtime Error):

import numpy as np
n =int(input())
a = list(map(float,input().split()))


b = sum(np.reciprocal(a))

print(np.reciprocal(b))
Problem p02716 (python)

Fixed submission:
N = int(input())
S = list(map(int,input().split()))
import numpy as np
get_DP  = [[-np.inf for i in range(3)] for j in range(N)]
pass_DP = [[-np.inf for i in range(3)] for j in range(N)]
for i in range(N):
    # 常にとるやつ
    get_DP[i][0] = (pass_DP[i-1][0] if i>0 else 0) + S[i] 
    pass_DP[i][0] = get_DP[i-1][0]
    if i>0:
        get_DP[i][1] = (pass_DP[i-1][1] if i!=1 else 0) + S[i]
        pass_DP[i][1] = max(pass_DP[i-1][0], get_DP[i-1][1])
    if i>1:
        get_DP[i][2] = (pass_DP[i-1][2] if i!=2 else 0) + S[i]
        pass_DP[i][2] = max(pass_DP[i-1][1], get_DP[i-1][2])

    
print(max(get_DP[-1]+pass_DP[-1][:1+N%2]))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
import numpy as np
get_DP  = [[-np.inf for i in range(3)] for j in range(N)]
pass_DP = [[-np.inf for i in range(3)] for j in range(N)]
for i in range(N):
    # 常にとるやつ
    get_DP[i][0] = (pass_DP[i-1][0] if i>0 else 0) + S[i] 
    pass_DP[i][0] = get_DP[i-1][0]
    if i>0:
        get_DP[i][1] = (pass_DP[i-1][1] if i!=1 else 0) + S[i]
        pass_DP[i][1] = max(pass_DP[i-1][0], get_DP[i-1][1])
    if i>1:
        get_DP[i][2] = (pass_DP[i-1][2] if i!=2 else 0) + S[i]
        pass_DP[i][2] = max(pass_DP[i-1][1], get_DP[i-1][2])

    
print(max(get_DP[-1]))
Problem p02743 (python)

Fixed submission:
a,b,c = list(map(int,input().split()))

if c-a-b>0 and 4*a*b<(c-a-b)**2:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import sqrt

a,b,c = list(map(int,input().split()))

if np.isclose(sqrt(a) +sqrt(b),sqrt(c),rtol=0,atol=1e-10):
  print("No")
elif sqrt(a) +sqrt(b) < sqrt(c):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import fractions
a = list(map(int, input().split()))
ans = a[0]
for i in a:
    ans = fractions.gcd(ans, i)

A = a[0]//ans
B = a[1]//ans
C = a[2]//ans

def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        #print l,m,r,fl,fm,fr,n
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)

def try_square_root(n2):
    return bisearch(lambda n:n*n, n2)

if try_square_root(A) + try_square_root(B) == try_square_root(C):
  print("No")
elif sqrt(A) +sqrt(B) < sqrt(C):
  print("Yes")
else:
  print("No")
Problem p02783 (python)

Fixed submission:
from math import ceil
(lambda H,A : print( ceil(H/A) ))(*map(int,input().split()))

Buggy submission (verdict: Runtime Error):
from math import ceil
(lambda H,A : print( ceil(H/A) ))(map(int,input().split()))
Problem p02838 (python)

Fixed submission:
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys())|set([0]))
print(int(sum([((2**i)* (N-d[i])*d[i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Buggy submission (verdict: Runtime Error):
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys()) )
print(int(sum([((2**i)* (N-d[i])*d[i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Buggy submission (verdict: Runtime Error):
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys()) )

A=1
res=0
for i in range(m+1):
  res += (A* (N-d[i])*d[i])%(1e9+7) 
  A = int((A*2) %(1e9+7))
  
print(int(res%(1e9+7)))
Problem p02866 (python)

Fixed submission:
N = int(input())
from collections import Counter
D = [int(i) for i in input().split()]
c = Counter(D)


if D[0] != 0:
  print(0)
  quit()
if c[0] != 1:
  print(0)
  quit()
if len(c.keys()) != max(c.keys())+1:
  print(0)
  quit()

  
res = 1
for i in range(1,1+max(c.keys())):
  res *= c[i-1]**c[i]
  res %= 998244353
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
from collections import Counter
D = [int(i) for i in input().split()]
c = Counter(D)


if D[0] != 0:
  break
if c[0] != 1:
  print(0)
  quit()
if len(c.keys()) != max(c.keys())+1:
  print(0)
  quit()

  
res = 1
for i in range(1,1+max(c.keys())):
  res *= c[i-1]**c[i]
  res %= 998244353
print(res)
Problem p02885 (python)

Fixed submission:
A,B = list(map(int,input().split()))

print(max(0,(A - B*2)))

Buggy submission (verdict: Runtime Error):
A,B = list(map(int,input().split()))

print(max(0,(A - B*2))
Problem p02963 (python)

Fixed submission:
s = int(input())
v = 1000000000
x=(v-s%v)%v
y=(s+x)//v
print("0 0 1000000000 1",int(x),int(y))

Buggy submission (verdict: Runtime Error):
S = int(input())
v = 1e9
x=(v-s%v)%v
y=(s+x)/v
print("0 0 1000000000 1 ",x,y)
Problem p02983 (python)

Fixed submission:
L,R = list(map(int,input().split()))
from itertools import combinations

numbers = [i for i in range(L,min(R+1,L+2019))]
ans = 2019
for conb in combinations(numbers,2):
  if ans > (conb[0]*conb[1])%2019:
     ans = (conb[0]*conb[1])%2019
    
print(ans)

Buggy submission (verdict: Runtime Error):
L,R = list(map(int,input().split()))

from collections import defaultdict

d = defaultdict(int)

for i in range(L,R+1):
  d[i%2019] += 1
  if d[0]>0:
    break

cnt = 0a
ans = list()
for k,v in sorted(d.items()):
  _v = v
  
  while _v > 0:
    cnt +=1
    ans += [k]
    _v -= 1
    if cnt >=2:
      print((ans[0]*ans[1])%2019)
      break
  if cnt >=2:
    break
Problem p03044 (python)

Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())

tree_dict = defaultdict(list)
for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    tree_dict[u].append((v, w))
    tree_dict[v].append((u, w))


# 任意の1点を選んで周辺を判定していく
FROM, TO = 0, 1
q = [(TO, FROM)]

paint_dict = defaultdict(int)
# 明示的な代入
paint_dict[TO] = 0

idx = 0
while idx < N:
    # 現在のノード(now)から隣接ノード(to)の白黒を定め，そのノードを探索のqに回す
    now_node, prev_node = q[idx]
    for to_node, w in tree_dict[now_node]:
        if to_node != prev_node:
            if (w + paint_dict[now_node]) % 2 == 0:
                paint_dict[to_node] = 0
            else:
                paint_dict[to_node] = 1
            q.append((to_node, now_node))
    idx += 1
for i in range(N):
    print(paint_dict[i+1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())

tree_dict = defaultdict(list)
for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    tree_dict[u].append((v, w))
    tree_dict[v].append((u, w))
# print(tree_dict)


key=u

paint_dict = dict()

q = [key]
paint_dict[key] = 0

idx = 0
while idx < N:
    k = q[idx]
    #print("k", k, paint_dict[k])
    for to, w in tree_dict[k]:
        if to not in [i[0] for i in tree_dict[to]]:
            if (w + paint_dict[k]) % 2 == 0:
                paint_dict[to] = 0
            else:
                paint_dict[to] = 1
            #print(paint_dict[to], to, w)
            q.append(to)
    idx += 1
for i in range(N):
    print(paint_dict[i+1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())

tree_dict = defaultdict(list)
for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    tree_dict[u].append((v, w))
    tree_dict[v].append((u, w))
# print(tree_dict)


# 探索
for key, value in tree_dict.items():
    if len(value) == 1:
        break
# print(key)
paint_dict = dict()

q = [key]
paint_dict[key] = 0

idx = 0
while idx < N:
    k = q[idx]
    #print("k", k, paint_dict[k])
    for to, w in tree_dict[k]:
        if to not in [i[0] for i in tree_dict[to]]:
            if (w + paint_dict[k]) % 2 == 0:
                paint_dict[to] = 0
            else:
                paint_dict[to] = 1
            #print(paint_dict[to], to, w)
            q.append(to)
    idx += 1
for i in range(N):
    print(paint_dict[i+1])
Problem p03069 (python)

Fixed submission:
N = int(input())
S = input()

import numpy as np

N = np.zeros((len(S),2))
B,W = 0,1
# 左から.W 右へ#B
for idx,s in enumerate(S):
  if s is "#":
    N[idx,B] = N[idx-1,B] + 1
    N[idx,W] = N[idx-1,W]
  else:
    N[idx,B] = N[idx-1,B]
    N[idx,W] = N[idx-1,W] + 1

print(int(min([N[i,B]+N[-1,W]-N[i,W] for i in range(len(S)-1)]+[N[-1,W],N[-1,B]]   )))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
N = [[0 for _ in range(len(S))] for _  in  range(2)]
B,W = 0,1
# 左から.W 右へ#B
for idx,s in enumerate(S):
  if s is "#":
    N[idx][B] = N[idx-1][B] + 1
    N[idx][W] = N[idx-1][W]
  else:
    N[idx][B] = N[idx-1][B]
    N[idx][W] = N[idx-1][W] + 1

print(int(min([N[i][B]+N[-1][W]-N[i][W] for i in range(len(S)-1)]+[N[-1][W],N[-1][B]]   )))
Problem p03074 (python)

Fixed submission:
N, K = tuple(map(int, input().split()))
S = "1"+input()+"1"

prev = S[0]
if prev == "0":
  fst_is_0 = True
else:
  fst_is_0 = False

cnt = 0
cnt_0 = 0

cnt_lst = []
for idx, s in enumerate(S):
  if s == prev:
    cnt += 1
  else:
    cnt_lst.append(cnt)
    cnt = 1
    if s == "0":
      cnt_0 += 1
    prev = s
else:
  cnt_lst.append(cnt)
#print(cnt_lst)


if cnt_0 <= K:
  print(len(S)-2)
else:
  prev = "1"
  cnt_lst = [0]
  for idx,s in enumerate(S):
    if prev != s:
      cnt_lst.append(idx)
    prev=s
  cnt_lst.append(len(S))
  s_ =[]
  for idx in range( int( (len(cnt_lst)+1)/2) -K):
    #print(2*idx+2*K,idx*2,cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2])
    if idx==0 or idx==int( (len(cnt_lst)+1)/2) -K-1:
      s_.append(cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2]-1)
    else:
      s_.append(cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2])
  print(max(s_))

Buggy submission (verdict: Runtime Error):
N, K = tuple(map(int, input().split()))
S = "1"+input()+"1"

prev = S[0]
if prev == "0":
  fst_is_0 = True
else:
  fst_is_0 = False

cnt = 0
cnt_0 = 0

cnt_lst = []
for idx, s in enumerate(S):
  if s == prev:
    cnt += 1
  else:
    cnt_lst.append(cnt)
    if s == "0":
      cnt_0 += 1
    prev = s
else:
  cnt_lst.append(cnt)
#print(cnt_lst)


if cnt_0 <= K:
  print(len(S)-2)
else:
  l = [cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2] for idx in range( int( (len(cnt_lst)+1)/2) -K)   ]
  #print(l)
  ss = []
  for idx,sss in enumerate(l):
    if idx == 0:
      ss.append(sss-1)
    elif idx == len(l)-1:
      
      ss.append(sss-1)
    else:
      ss.append(sss)
      
  print(max(ss))
Problem p03086 (python)

Fixed submission:
string = input()
ch = string[0]
max_string_len = 0
prev_len = 0
for idx,ch in enumerate(string):
  if ch  in {"A","T","G","C"}:
    prev_len += 1
    max_string_len = max(max_string_len,prev_len)
  else:
    prev_len = 0
    
print(max_string_len)

Buggy submission (verdict: Runtime Error):
string = input()
ch = string[0]
max_string_len = 0
prev_len = 0
for idx,ch in enumerate(string):
  if ch  in {"A","T","G","C"}:
    prev_len += 1
  	max_string_len = max(max_string_len,prev_len)
  else:
    prev_len = 0
    
print(max_string_len)
Problem p03088 (python)

Fixed submission:
N = int(input())

def checkAGC(string):
    str0 = string[0] +string[1] +string[2] +string[3]
    str1 = string[1] +string[0] +string[2] +string[3]
    str2 = string[0] +string[2] +string[1] +string[3]
    str3 = string[0] +string[1] +string[3] +string[2]
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 or "AGC" in str3:
        return True
    else:
        return False

def checkAGC3(string):
    str0 = string[0] +string[1] +string[2]
    str1 = string[1] +string[0] +string[2] 
    str2 = string[0] +string[2] +string[1] 
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 :
        return True
    else:
        return False
      

import itertools

words = list(itertools.product("ATGC", "ATGC","ATGC"))

#3文字のインデックスを返す
nucleotide_dict =  dict(list( (words[i],i) for i in range(len(words))))

import numpy as np
# 重み行列を求める
W = np.zeros((len(words),len(words)))
for word_prev in words:
    for word_next in words:
        if word_prev[1:] == word_next[:-1] and not checkAGC(word_prev[:-1]+word_next[1:]):
            #print(nucleotide_dict[word_next],nucleotide_dict[word_prev],word_prev[:-1]+word_next[1:] )
            W[nucleotide_dict[word_next],nucleotide_dict[word_prev]] = 1
b = np.array([0 if checkAGC3(i) else 1 for i in words])

def mod(num):
    return num % int(pow(10,9)+7)
  
res = b
for i in range(N-3):
    res = np.vectorize(lambda x: mod(x))(np.dot(W,res))
print(int(mod(np.sum(res))))

Buggy submission (verdict: Runtime Error):
def checkAGC(string):
    str0 = string[0] +string[1] +string[2] +string[3]
    str1 = string[1] +string[0] +string[2] +string[3]
    str2 = string[0] +string[2] +string[1] +string[3]
    str3 = string[0] +string[1] +string[3] +string[2]
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 or "AGC" in str3:
        return True
    else:
        return False

def checkAGC3(string):
    str0 = string[0] +string[1] +string[2]
    str1 = string[1] +string[0] +string[2] 
    str2 = string[0] +string[2] +string[1] 
    
    if "AGC" in str0 or "AGC" in str1 or "AGC" in str2 :
        return True
    else:
        return False
      

import itertools

words = list(itertools.product("ATGC", "ATGC","ATGC"))

#3文字のインデックスを返す
nucleotide_dict =  dict(list( (words[i],i) for i in range(len(words))))

import numpy as np
# 重み行列を求める
W = np.zeros((len(words),len(words)))
for word_prev in words:
    for word_next in words:
        if word_prev[1:] == word_next[:-1] and not checkAGC(word_prev[:-1]+word_next[1:]):
            #print(nucleotide_dict[word_next],nucleotide_dict[word_prev],word_prev[:-1]+word_next[1:] )
            W[nucleotide_dict[word_next],nucleotide_dict[word_prev]] = 1
b = np.array([0 if checkAGC3(i) else 1 for i in words])

def mod(num):
    return num % int(pow(10,9)+7)
  
res = b
for i in range(N-3):
    res = np.vectorize(lambda x: mod(x))(W@res)
print(int(mod(np.sum(res))))