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

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

r = S.count("R")
g = S.count("G")
b = S.count("B")

ct = r*g*b

for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k<=N-1:
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ct-=1
print(ct)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())

posR = []
posG = []
posB = []

ctR = 0
ctG = 0
ctB = 0

for i in range(N):
    if S[i]=="R":
        posR.append(i)
        ctR += 1
    if S[i]=="G":
        posG.append(i)
        ctG += 1
    if S[i]=="B":
        posB.append(i)
        ctB += 1


def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid


def calc(pos1,pos2,pos3):
    ct = 0
    for i in pos1:
        buff = upper_bound(i,pos2)
        for j in pos2[buff:]:#大丈夫？
            buff2 = upper_bound(j,pos3)
            ct += len(pos3)-buff2
            #print(i,j,len(pos3)-buff2)
            if 2*j-i in pos3:
                ct -= 1
    return ct

ans = 0
ans += calc(posR,posG,posB)
ans += calc(posR,posB,posG)
ans += calc(posG,posR,posB)
ans += calc(posG,posB,posR)
ans += calc(posB,posR,posG)
ans += calc(posB,posG,posR)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())

posR = []
posG = []
posB = []

ctR = 0
ctG = 0
ctB = 0

for i in range(N):
    if S[i]=="R":
        posR.append(i)
        ctR += 1
    if S[i]=="G":
        posG.append(i)
        ctG += 1
    if S[i]=="B":
        posB.append(i)
        ctB += 1


def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid


def calc(pos1,pos2,pos3):
    ct = 0
    for i in pos1:
        buff = upper_bound(i,pos2)
        for j in pos2[buff:]:#大丈夫？
            buff2 = upper_bound(j,pos3)
            ct += len(pos3)-buff2
            #print(i,j,len(pos3)-buff2)
            if 2*j-i in pos3:
                ct -= 1
    return ct

ans = 0
ans += calc(posR,posG,posB)
ans += calc(posR,posB,posG)
ans += calc(posG,posR,posB)
ans += calc(posG,posB,posR)
ans += calc(posB,posR,posG)
ans += calc(posB,posG,posR)
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N,Q = [int(i) for i in input().split()] #N個の頂点、Q回の操作
aaabbb = [[int(i) for i in input().split()] for j in range(N-1)] #木の辺
pppxxx = [[int(i) for i in input().split()] for j in range(Q)] #操作

tree = [[] for i in range(N+1)]

for a,b in aaabbb:
    tree[a].append(b)
    tree[b].append(a)

#print(tree)

counter = [0 for i in range(N+1)]

for p,x in pppxxx:
    counter[p] += x

#print(counter)

def dfs(pos,parent,add):
    counter[pos] += add
    for next_pos in tree[pos]:
        if not next_pos == parent:
            dfs(next_pos,pos,counter[pos])

dfs(1,0,0)

#print(counter)

print(" ".join([str(i) for i in counter[1:]]))

Buggy submission (verdict: Runtime Error):
N,Q = [int(i) for i in input().split()] #N個の頂点、Q回の操作
aaabbb = [[int(i) for i in input().split()] for j in range(N-1)] #木の辺
pppxxx = [[int(i) for i in input().split()] for j in range(Q)] #操作

tree = [[] for i in range(N+1)]

for a,b in aaabbb:
    tree[a].append(b)

#print(tree)

counter = [0 for i in range(N+1)]

for p,x in pppxxx:
    counter[p] += x

#print(counter)

def dfs(pos):
    for next_pos in tree[pos]:
        counter[next_pos] += counter[pos]
        dfs(next_pos)

dfs(1)

#print(counter)

print(" ".join([str(i) for i in counter[1:]]))

Buggy submission (verdict: Runtime Error):
N,Q = [int(i) for i in input().split()]
aaabbb = [[int(i) for i in input().split()] for j in range(N-1)]
pppxxx = [[int(i) for i in input().split()] for j in range(Q)]

tree = [[] for i in range(N+1)]

for a,b in aaabbb:
    a = a
    b = b
    tree[a].append(b)

#print(tree)

counter = [0 for i in range(N+1)]

def dfs(pos,x):
    #print(pos)
    counter[pos]+=x
    for next_pos in tree[pos]:
        dfs(next_pos,x)

for p,x in pppxxx:
    #print("newdfs")
    dfs(p,x)

print(" ".join([str(i) for i in counter[1:]]))

Buggy submission (verdict: Runtime Error):
N,Q = [int(i) for i in input().split()]
aaabbb = [[int(i) for i in input().split()] for j in range(N-1)]
pppxxx = [[int(i) for i in input().split()] for j in range(Q)]

tree = [[] for i in range(N+1)]

for a,b in aaabbb:
    a = a
    b = b
    tree[a].append(b)

#print(tree)

counter = [0 for i in range(N+1)]

def dfs(pos,x):
    #print(pos)
    counter[pos]+=x
    for next_pos in tree[pos]:
        dfs(next_pos,x)

for p,x in pppxxx:
    #print("newdfs")
    dfs(p,x)

print(counter[1:])
Problem p02975 (python)

Fixed submission:
N = int(input())
aaa = sorted([int(i) for i in input().split()])

ans = 0
for a in aaa:
    ans = ans^a
if ans==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
aaa = sorted([int(i) for i in input().split()])


count0 = aaa.count(0)
countleft = aaa.count(aaa[0])
countright = aaa.count(aaa[-1])
buff1 = aaa[0]
buff2 = aaa[-1]
aaa = [i for i in aaa if i!=buff1 and i!=buff2]
buff3 = aaa[0]
countmid = aaa.count(buff3)

if count0 == N:
    print("Yes")
    exit()
elif N%3==0 and count0 == N/3 and countright == N/3*2:
    print("Yes")
    exit()
elif N%3==0 and countleft == N/3 and countright == N/3 and countmid == N/3:
    print("Yes")
    exit()
print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
aaa = sorted([int(i) for i in input().split()])
ini = aaa[0]
first = aaa[0]
for i in range(1,N):
    second = aaa[i]
    for j in range(N-1):
        next_hat = first^second
        #print(first,second,next_hat)
        if next_hat in aaa:
             aaa.remove(next_hat)
        else:
            break
        first = second
        second = next_hat
    else:
        if first&second==ini:
            print("Yes")
            exit()
print("No")
Problem p03087 (python)

Fixed submission:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = [0]
for i in range(1,len(S)):
    if S[i-1]=="A" and S[i]=="C":
        Asite.append(Asite[-1]+1)
    else:
        Asite.append(Asite[-1])


for l,r in lrlist:
    print(Asite[r]-Asite[l])

Buggy submission (verdict: Runtime Error):
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = []
for i in range(len(S)):
    if S[i]=="A" and S[i+1]=="C":
        Asite.append(i)


for l,r in lrlist:
    ans = 0
    for i in Asite:
        if l <= i and i+1 <= r:
            ans+=1
    print(ans)
Problem p03363 (python)

Fixed submission:
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = float("inf")
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = math.inf
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
print(BBB)
BBB=sorted(BBB)
print(BBB)
prev = math.inf
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))
Problem p03836 (python)

Fixed submission:
sx,sy,tx,ty = [int(i) for i in input().split()]
ans = ""
for i in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "R"
for i in range(ty-sy):
    ans += "D"
for i in range(tx-sx):
    ans += "L"
ans += "L"
for i in range(ty-sy+1):
    ans += "U"
for i in range(tx-sx+1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(ty-sy+1):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
ans += "U"

print(ans)

Buggy submission (verdict: Runtime Error):
sx,sy,tx,ty = [int(i) for i in input().split()]
ans = ""
for i in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "R"
for i in range(ty-sy):
    ans += "D"
for i in range(tx-sx):
    ans += "L"
ans += "L"
for i in range(ty-sy+1):
    ans += "U"
for i in range(tx-sx+1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(ty-sy+1):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
ans += "U"

print(ans==ex)
Problem p02631 (python)

Fixed submission:
n = int(input())
aa = input().split(" ")
a = [int(c) for c in aa]

s = a[0]

for num in a[1:]:
	s ^= num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split(" ")

s = a[0]

for num in a[1:]:
	s ^= num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split(" ")

s = a[0]

for num in a[1:]:
	s^=num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)
Problem p02787 (python)

Fixed submission:
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]

dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Buggy submission (verdict: Runtime Error):
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]


dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Buggy submission (verdict: Runtime Error):
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]


dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])
Problem p02690 (python)

Fixed submission:
x = int(input())

for i in range( -1000, 1000) :
    for j in range(-1000, 1000):
        if i**5 - j**5 == x:
            print(i,j)
            exit(0)

Buggy submission (verdict: Runtime Error):
x = int(input())

for i in range( -1000, 1000) :
  for j in range(-1000, 1000):
	if i**5 - j**5 == x:
      print(i,j)
Problem p02744 (python)

Fixed submission:
# D
N = int(input())

al = [chr(ord('a') + i) for i in range(26)]

def dfs(S, i):
    if len(S) == N:
        yield ''.join(S)
        return
    for j in range(i):
        for w in dfs(S + [al[j]], i):
            yield w
    for w in dfs(S + [al[i]], i + 1):
        yield w

for w in dfs([], 0):
    print(w)

Buggy submission (verdict: Runtime Error):
# D
import itertools
from scipy.special import comb
N = int(input())
ans_list = []
K = 0
for i in range(N):
    perm_list = ['a'] * (N - 1 - i)
    perm_list += ['x'] * (i)
    tmp_list = []
    al = [chr(ord('b') + j) for j in range(i)]

    K += comb(N-1, i)

    for v in itertools.permutations(perm_list, len(perm_list)):
        tmp = 'a'
        for j in range(len(perm_list)):
            tmp += v[j]
        tmp_list.append(tmp)
    tmp_list = list(set(tmp_list))
    
    n = len(tmp_list)
    for j in range(n):
        cnt = 0
        for k in range(N):
            if tmp_list[j][k] == "x":
                tmp_list[j] = tmp_list[j].replace("x", al[cnt], 1)
                cnt += 1
        ans_list.append(tmp_list[j])
ans_list.sort()
K = int(K)
for i in range(K):
    print(ans_list[i])
Problem p02804 (python)

Fixed submission:
# 組み合わせ(高速，フェルマーの小定理を利用)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10 ** 5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans_max = 0
ans_min = 0
# ans_minを求める
for i in range(N-K+1):
    ans_min += A[i] * cmb(N-1-i, K-1, mod)
    ans_min %= mod
for i in range(K-1, N):
    ans_max += A[i] * cmb(i, K-1, mod)
    ans_max %= mod
##print(ans_max, ans_min)
print((ans_max - ans_min + mod)%mod)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(N):
    now_A = A[i]
    tmp = 1
    count = 1
    for k in range(i+K-1, N):
        ans += (A[k] - now_A) * tmp
        ans %= mod
        tmp *= (K - 2 + count) / count
        tmp = int(tmp)
        count += 1
        ##print(ans, tmp, count)

print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(N-K+1):
    now_A = A[i]
    tmp = 1
    count = 1
    for k in range(i+K-1, N):
        ans += (A[k] - now_A) * tmp
        ans %= mod
        tmp *= (K - 2 + count) / count
        tmp = int(tmp)
        count += 1
        ##print(ans, tmp, count)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(N-K+1):
    now_A = A[i]
    tmp = 1
    count = 1
    for k in range(i+K-1, N):
        ans += (A[k] - now_A) * tmp
        ans %= mod
        tmp *= (K - 2 + count) / count
        tmp = int(tmp)
        count += 1
        ##print(ans, tmp, count)

print(ans)
Problem p02963 (python)

Fixed submission:
S = int(input())
M = 10 ** 9
X1 = 0
Y1 = 0
X2 = M
Y2 = 1
X3 = (M - S%M)%M
Y3 = (S + X3) // M
print(X1, Y1, X2, Y2, X3, Y3)

Buggy submission (verdict: Runtime Error):
S = int(input())
int_max = 10 ** 9
X1 = 0
Y1 = 0
X2 = int_max
Y2 = 1
X3 = int_max * Y3 - S
Y3 = (S + X3) // int_max
print(X1, Y1, X2, Y2, X3, Y3)
Problem p02975 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
flag = True
if max(a) == 0:   # 全て0の時は必ず成り立つ
    flag = True
else:
    if N % 3 != 0:   # 全て0でなくて，Nが3の倍数出ない時は成り立たない
        flag = False
    else:
        n = N // 3
        a_set = set(a)
        if len(a_set) == 2:
            count = [] 
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if value[0] == 0 and count[0] == n and count[1] == n * 2:
                flag = True
            else:
                flag = False
        elif len(a_set) == 3:
            count = []
            value = []
            for number in a_set:
                count.append(a.count(number))
                value.append(number)
            if count[0] == count[1] == count[2]:
                if value[0] ^ value[1] ^ value[2] == 0:
                    flag = True
                else:
                    flag = False
            else:
                flag = False
        else:
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if N % 3  != 0:
    if max(a) == 0:
        print('Yes')
    else:
        print('No')
else:
    if N == 3:
        if a[0] == a[1] ^ a[2] and a[1] == a[2] ^ a[0] and a[2] == a[0] ^ a[1]:
            print('Yes')
        else:
            print('No')
    else:
        n = int(N / 3)
        a = sorted(a)
        for i in range(n):
            tmp_list = a[n * i : n*(i + 1)]
            if min(tmp_list) == max(tmp_list):
                pass
            else:
                flag = False
        if flag:
            print('Yes')
        else:
            print('No')

Buggy submission (verdict: Runtime Error):
# A
N = int(input())
a = list(map(int, input().split()))
flag = True
if N % 3  != 0:
    if max(a) == 0:
        print('Yes')
    else:
        print('No')
else:
    if N == 3:
        if a[0] == a[1] ^ a[2] and a[1] == a[2] ^ a[0] and a[2] == a[0] ^ a[1]:
            print('Yes')
        else:
            print('No')
    else:
        n = int(N /3)
        a = sorted(a)
        for i in range(n):
            tmp_list = a[n * i : n*(i + 1)]
            if min(tmp_list) == max(tmp_list):
                pass
            else:
                flag = False
        if flag:
            print('Yes')
        else:
            print('No')
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
ans = []
if R - L >= 2019:
    print(0)
else:
    if l >= r:
        print(0)
    else:
        for i in range(l, r):
            for k in range(l+1, r+1):
                ans.append(i * k % 2019)                
    print(min(ans))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
ans = []
if R - L >= 2019:
    print(0)
else:
    if l >= r:
        print(0)
    else:
        for i in range(l, r):
            for k in range(l+1, r+1):
                ans.append(i * k % 2019)
print(min(ans))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
ans= []
if R - L >= 2019:
    print(0)
else:
    for i in range(l, r):
    　　　　for k in range(l+1, r+1):
        　　　　ans.append(i * k % 2019)
print(min(ans))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
ans= []
for i in range(l, r):
    for k in range(l+1, r+1):
        ans.append(i * k % 2019)
print(min(ans))
Problem p02995 (python)

Fixed submission:
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
if A % C == 0:
    ac -= 1
if A % D == 0:
    ad -= 1
if A % E == 0:
    ae -= 1
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())

E = lcm(C, D)
count_A = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//E
count_B = B - B//C - B//D + B//E

print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
# C問題
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)
Problem p03000 (python)

Fixed submission:
# -*-coding: utf-8 -*-
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
for i in range(1, N+1):
    D += L[i-1]
    # print(i+1, D)
    if D > X:
        ans = i
        break
    if i == N:
        ans = i+1

print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
i = 1
while D <= X:
    D += L[i-1]
    i += 1
print(i-1)
Problem p03014 (python)

Fixed submission:
H, W = map(int, input().split())
field = [input() for _ in range(H)]

# Left
Left = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W):
        if field[h][w] == '#':
            cnt = 0
        else:
            cnt += 1
        Left[h][w] = cnt

# Right
Right = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W-1, -1, -1):
        if field[h][w] == '#':
            cnt = 0
        else:
            cnt += 1
        Right[h][w] = cnt

# Up
Up = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H):
        if field[h][w] == '#':
            cnt = 0
        else:
            cnt += 1
        Up[h][w] = cnt

# Down
Down = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H-1, -1, -1):
        if field[h][w] == '#':
            cnt = 0
        else:
            cnt += 1
        Down[h][w] = cnt

# 集計
ans = -1
for h in range(H):
    for w in range(W):
        ans = max(ans, Left[h][w] + Right[h][w] + Up[h][w] + Down[h][w] - 3)
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0

# 尺取り法
right = 0
tmp = 0
for i in range(N):
    for k in range(right, N, 1):
        tmp += A[k]
        if tmp >= K:
            right = k
            ans += N - right
            tmp -= A[i]
            tmp -= A[right]
            break
        if k == N-1:
            tmp -= A[k]
            tmp -= A[i]
            right = k
            break 


print(ans)
Problem p03085 (python)

Fixed submission:
b = input()
if b == "A":
    print("T")
elif b == "T":
    print("A")
elif b == "C":
    print("G")
else:
    print("C")

Buggy submission (verdict: Runtime Error):
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))
Problem p03087 (python)

Fixed submission:
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
cnt_list = [0] * N
tmp = 0
for i in range(N-1):
    cnt_list[i] = tmp
    if S[i] == "A" and S[i+1] == "C":
        tmp += 1
cnt_list[N-1] = tmp
##print(cnt_list)
for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])

Buggy submission (verdict: Runtime Error):
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))