Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
while 'ABC' in s:
        count += s.count('ABC')
        s = s.replace('ABC',"BCA")
print(count)

Fixed submission:
a = input()
b = []
count = 0
a = a.replace('BC','D')
for i in range(1,len(a)+1):
    if a[-i] == 'D':
        count += 1
    elif a[-i] == 'A':
        b.append(count)
    else:
        count = 0
print(sum(b))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
k = len(s)//2
for i in range(k):
        if 'ABC' in s:
                count += s.count('ABC')
                s = s.replace('ABC','BCA')
        else:
                break
print(count)

Fixed submission:
a = input()
b = []
count = 0
a = a.replace('BC','D')
for i in range(1,len(a)+1):
    if a[-i] == 'D':
        count += 1
    elif a[-i] == 'A':
        b.append(count)
    else:
        count = 0
print(sum(b))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
o = 0
while 'ABC' in s:
        o = s.count('ABC')
        s = s.replace('ABC','BCA')
        count += o
print(count)

Fixed submission:
a = input()
b = []
count = 0
a = a.replace('BC','D')
for i in range(1,len(a)+1):
    if a[-i] == 'D':
        count += 1
    elif a[-i] == 'A':
        b.append(count)
    else:
        count = 0
print(sum(b))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = [map(int,input().split()) for i in range(a) ]
c = [map(int,input().split()) for j in range(a) ]
e = 0
for k in range(a):
    d = b[k] - c[k]
    if d > 0:
        e += d
print(e)

Fixed submission:
a = int(input())
b = map(int,input().split())
c = map(int,input().split())
b,c = list(b),list(c)
e = 0
for k in range(a):
    d = b[k] - c[k]
    if d > 0:
        e += d
print(e)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = map(int,input().split())
b = list(b)
k = 1
for i in range(a-1):
    maxim = max(a[:i+1])
    if maxim <= a[i+1]:
        k += 1
print(k)

Fixed submission:
a = int(input())
b = map(int,input().split())
b = list(b)
k = 1
for i in range(a-1):
    maxim = max(b[:i+1])
    if maxim <= b[i+1]:
        k += 1
print(k)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
bis = 1
money = 0
d = [0]*a
if b >= c:
        bis = bis*a + 1
        print(bis)
else:
        for i in range(a):
                if money == 0 :
                        if bis < b:
                                bis += 1
                                d[i] = bis
                        else:
                                money += 1
                                bis -= b
                                d[i] = bis
                else:
                        bis += c
                        money -= 1
                        d[i] = bis
        if d[-1] > d[-2] :
                print(d[-1])
        else:
                print(d[-2]+1)

Fixed submission:
a,b,c = map(int,input().split())
kaisuu = int((a-(b-1))/2)
amari = (a-(b-1))%2
if b >= (c-2):
        print(a+1)
else:
        if amari == 1:
                print(kaisuu*(c-b)+1+b)
        else:
                print(kaisuu*(c-b)+b)
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    b = a.copy()
    b.remove(a[i])
    c = median(b)
    print(c)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = a.copy()
b.sort()
for i in range(n):
    if a[i] < b[n//2]:
        print(b[n//2])
    else:
        print(b[(n//2)-1])
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = [input() for i in range(a)]
c = int(input())
d = [input() for j in range(c)]
g = [0]*a
for k in b:
    e = b.count(k)
    f = d.count(k)
    g[k] = e - f
print(max(g))

Fixed submission:
a = int(input())
b = [input() for i in range(a)]
c = int(input())
d = [input() for j in range(c)]
g = [0]*a
t = 0
for k in b:
    e = b.count(k)
    f = d.count(k)
    g[t] = e - f
    t +=1
if max(g) < 0:
    print(0)
else:
    print(max(g))
Buggy python submission (verdict: Time Limit Exceeded):
s = int(input())
a = []
count = 0
for j in range(s):
        a.append(int(input()))
b = sorted(a)
for i in range(s):
    if  (i + b.index(a[i]))%2 == 1:
            count += 1
count = count//2 + count%2
print(count)

Fixed submission:
s = int(input())
a = []
b = []
o = 0
count = 0
for j in range(s):
        if j%2 == 0:
                a.append(int(input()))
        else:
                b.append(int(input()))
a = sorted(a)
c = sorted(a+b)
for i in range(s):
        if o == len(a):
                break
        if a[o] == c[i]:
                if i%2 == 1:
                        count += 1
                o += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for _ in range(n):
  print(a.count(_+1))


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
for _ in range(1, n+1):
  print(c[_])
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input(),split())
print(A*B/2)

Fixed submission:
A,B,C = map(int, input().split())
print(A*B//2)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())
Y = [A, B, C]
# A = list(map(int,input().split()))
A1 = list(map(lambda x: x+1,Y))
count = 0
sum = 0

for i in range(a):
    for j in range(b):
        for k in range(c):
            sum = 500*i + 100*j + 50*k 
            if X == sum:
                count+=1
print(count)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
sum = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            sum = 500*i + 100*j + 50*k 
            if X == sum:
                count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
slen = len(int(input()))
print('Yes' if slen > 3 else 'No')

Fixed submission:
a,b,c,d=input()
print("Yes" if a==b==c or b==c==d else "No")
Buggy python submission (verdict: Runtime Error):
s = len(input())-2
print(f'i{s}n')

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
d=min(abs(sum(a)-2*sum(a[0:i])) for i in range(N))
print(d)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
s=sum(a)
i=0
while s>0:
  s-=2*a[i]
  i+=1
d=min(abs(s),s+2*a[i-1])
print(d)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
board=list(input() for _ in range(h))
num=0
cutting=[[0 for _1 in range(w)] for _2 in range(h)]
for row in range(h):
  num+=1
  if board[row].count("#")==0:
    continue
  col=0
  while board[row][col]==".":
    cutting[row][col]=num
    col+=1
  cutting[row][col]=num
  col+=1
  while col < w:
    cutting[row][col]=num
    col+=1
    if board[row][col]=="#":
      num+=1
centrow = (h-1)//2
for row in range(centrow, h):
  if cutting[row][0]==0:
    cutting[row]=cutting[row-1]
  if cutting[h-1-row][0]==0:
    cutting[h-1-row]=cutting[h-row]

for row in range(h):
  print(*cutting[row])


Fixed submission:
import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
board=list(input() for _ in range(h))
num=0
cutting=[[0 for _1 in range(w)] for _2 in range(h)]
for row in range(h):
  if board[row].count("#")==0:
    continue
  num+=1
  col=0
  while board[row][col]==".":
    cutting[row][col]=num
    col+=1
  cutting[row][col]=num
  col+=1
  while col < w:
    if board[row][col]=="#":
      num+=1
    cutting[row][col]=num
    col+=1
    
for row in range(1,h):
  if cutting[row][0]==0:
    cutting[row]=cutting[row-1]
  if cutting[h-1-row][0]==0:
    cutting[h-1-row]=cutting[h-row]

for row in range(h):
  print(*cutting[row])
Buggy python submission (verdict: Runtime Error):
N=int(input())
distances=list(map(int,input().split()))
maximum=max(distances)

if distances[0]!=0 or distances.count(0)>=2 or maximum>=N:
    print(0)
else:
    count_dist=list(distances.count(i) for i in range(maximum+1))
    if count_dist.count(0) >= 1:
        print(0)
    else:
        count=1
        for i in range(maximum):
            count = count*power_mod(count_dist[i],count_dist[i+1],998244353)%998244353
        print(count)

def power_mod(a, n, mod):
    a=a%mod
    if n==0:
        return 1
    elif n==1:
        return a
    elif n%2==0:
        return power_mod(a,n//2,mod)**2%mod
    else:
        return (power_mod(a,(n-1)//2,mod)**2%mod)*a%mod

Fixed submission:
N=int(input())
print((N-1)//2)
Buggy python submission (verdict: Runtime Error):
weather=input()
weathers={"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy": "Sunny"}
print(weathers[wearther])

Fixed submission:
weather=input()
weathers={"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy": "Sunny"}
print(weathers[weather])
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))

Fixed submission:
N=int(input())
print(N * (N-1) // 2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        counts[string] = 1

print(count)

Fixed submission:
A,B = map(int,input().split())
print(max(A+B,A-B,A*B))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
count = 0
for string in strings:
    tmp = strings.count(string)
    if tmp > 1:
        count += (tmp - 1) / 2

print(int(count))

Fixed submission:
A,B = map(int,input().split())
print(max(A+B,A-B,A*B))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
count = 0
for string in strings:
    tmp = strings.count(string)
    if tmp > 1:
        count += (tmp - 1) / 2

print(int(count))

Fixed submission:
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
strings_set = set(strings)
count = 0
for string in strings_set:
    tmp = strings.count(string)
    if tmp > 1:
        count += tmp * (tmp - 1) // 2

print(count)

Fixed submission:
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

print(count)
Buggy python submission (verdict: Runtime Error):
N=int(inpuit())

p=list(map(int,input().split()))
sort=list(range(1,N+1))
count=[p[i]==sort[i] for i in range(N)].count(True)
if count > 2:
    print("NO")
else:
    print("YES")

Fixed submission:
N=int(input())

p=list(map(int,input().split()))
sort=list(range(1,N+1))
count=list(p[i]==sort[i] for i in range(N)).count(False)
if count > 2:
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
import math
a,b,c=input().split(' ')
a=int(a)
b=int(b)
c=int(c)
if ((math.sqrt(a)+math.sqrt(b))<math.sqrt(c):
    print("Yes")
else:
    print("No")

Fixed submission:
a,b,c=input().split(' ')
a=int(a)
b=int(b)
c=int(c)
if (c-a-b>0) and ((c-a-b)**2>4*a*b):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().stlip())
H = map(int,input().stlip())

ans = 0
for h in H:
    if h >= K:
        ans += 1
print(ans)

Fixed submission:
N,K = map(int,input().split())
H = map(int,input().split())
ans = 0
for h in H:
    if h >= K:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()

print(n*n*n)

Fixed submission:
n = int(input())
print(n*n*n)
Buggy python submission (verdict: Runtime Error):
[N, A, B]= list(map(int, input().split()))

ans = 0
ball = []

for i in range(N // (A + B)) :
    ball += list('b' * A + 'r' * B)

mod = N % (A + B)
if mod <= A :
    ball += list('b' * mod)
elif A < mod:
    ball += list('b' * A + 'r' * (mod - A))

#print(ball)
ans = ball.count('b')
print(ans)

Fixed submission:
N, A, B= map(int, input().split())
ans = 0

div = N//(A+B) * A
mod = N % (A+B)
ans = div + min(mod, A)

print(ans)

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

ans = 0
ball = []

for i in range(N // (A + B)) :
    ball += list('b' * A + 'r' * B)

mod = N % (A + B)
if mod <= A :
    ball += list('b' * mod)
elif A < mod:
    ball += list('b' * A + 'r' * (mod - A))

#print(ball)
ans = ball.count('b')
print(ans)

Fixed submission:
N, A, B= map(int, input().split())
ans = 0

div = N//(A+B) * A
mod = N % (A+B)
ans = div + min(mod, A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
[N, A, B]= list(map(int, input().split()))

ball = []
ans = 0
for k in range(N//(A+B)) :
    for i in range(A) :
        ball.append('b')
    for j in range(B) :
        ball.append('r')

mod = N % (A+B)
for l in range(N % (A+B)) :
    for m in range(A) :
        if mod > 0 :
            ball.append('b')
            mod -= 1
        else :
            break
    for n in range(B):
        if mod > 0 :
            ball.append('r')
            mod -= 1
        else :
            break

#print(ball)
ans = ball.count('b')
print(ans)

Fixed submission:
N, A, B= map(int, input().split())
ans = 0

div = N//(A+B) * A
mod = N % (A+B)
ans = div + min(mod, A)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = (int(i) for i in input().split()) 
 
for j in range(K):
  if A >0:
    A -= 1
  elif B >0:
    B -= 1
  else:
    break
 
print(A, B)

Fixed submission:
i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

if K <= A :
    A -= K
elif K <= A + B :
    B -= K - A
    A = 0
else :
    A = 0
    B = 0

print(A, B)

Buggy python submission (verdict: Runtime Error):
s = input().split()
A = s[0]
B = s[1]
K = s[2]
 
for j in range(K):
  if A >0:
    A -= 1
  elif B >0:
    B -= 1
  else:
    break
 
print(A, B)

Fixed submission:
i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

if K <= A :
    A -= K
elif K <= A + B :
    B -= K - A
    A = 0
else :
    A = 0
    B = 0

print(A, B)

Buggy python submission (verdict: Runtime Error):
s = [input() for i in range(3)]
A = s[0]
B = s[1]
K = s[2]
 
for j in range(K):
  if A >0:
    A -= 1
  elif B >0:
    B -= 1
  else:
    break
 
print(A)
print(B)

Fixed submission:
i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

if K <= A :
    A -= K
elif K <= A + B :
    B -= K - A
    A = 0
else :
    A = 0
    B = 0

print(A, B)

Buggy python submission (verdict: Runtime Error):
s = [input() for i in range(3)]
A = s[0]
B = s[1]
K = s[2]

for j in range(K):
  if A >0:
    A -= 1
  elif B >0:
    B -= 1
  else:
    break

print(A, B)

Fixed submission:
i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

if K <= A :
    A -= K
elif K <= A + B :
    B -= K - A
    A = 0
else :
    A = 0
    B = 0

print(A, B)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

i = list(map(int,input().split()))
A = i[0]
B = i[1]

ans = (A * B) // gcd(A, B)

print(ans)

Fixed submission:
a = [int(input()) for i in range(2)]
A = a[0]
B = a[1]

ans = 6 - (A + B)
print(ans)

Buggy python submission (verdict: Runtime Error):
from fraction import gcd

i = list(map(int,input().split()))
A = i[0]
B = i[1]

ans = (A * B) // gcd(A, B)

print(ans)

Fixed submission:
a = [int(input()) for i in range(2)]
A = a[0]
B = a[1]

ans = 6 - (A + B)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

i = list(map(int,input().split()))
A = i[0]
B = i[1]

ans = (A * B) // math.gcd(A, B)

print(ans)

Fixed submission:
from fractions import gcd

i = list(map(int,input().split()))
A = i[0]
B = i[1]

ans = (A * B) // gcd(A, B)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def solve(N):
    answer = 0
    for i in range(N):
        answer += i
    return answer


if __name__ == '__main__':
    N = int(input())

    answer = solve(N)
    print(answer)


Fixed submission:
def solve(N):
    return (N * (N - 1)) // 2
 
 
if __name__ == '__main__':
    N = int(input())
 
    answer = solve(N)
    print(int(answer))
Buggy python submission (verdict: Runtime Error):
def solve(A):
    current_max = 2
    current_min = 2
    for a_k in reversed(A):
        if current_max < a_k:
            print('-1')
            return

        current_max = (current_max // a_k) * a_k + (a_k - 1)
        current_min = ((current_min - 1) // a_k + 1) * a_k
        current_min = max(current_min, a_k)

    print("{} {}".format(current_min, current_max))
    return


if __name__ == '__main__':
    K = int(input())
    A = list(map(int, input().split()))
    solve(A)


Fixed submission:
N, A, B = map(int, input().split())
if (B - A) & 1:
    print("Borys")
else:
    print("Alice")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

max_range, sum_ = map(int, input().split())

count = 0
for x, y, z in itertools.combinations_with_replacement(range(max_range + 1), r=3):
    if x + y + z == sum_:
        len_set = len({x, y, z})
        if len_set == 1:
            count += 1
        elif len_set == 2:
            count += 3
        else:
            count += 6

print(count)


Fixed submission:
max_range, sum_ = map(int, input().split())

count = 0
for x in range(0, min(max_range + 1, sum_ + 1)):
    for y in range(0, min(max_range + 1, sum_ - x + 1)):
        if sum_ - x - y <= max_range:
            count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

max_range, sum_ = map(int, input().split())

count = 0
for x, y, z in itertools.product(range(max_range + 1), repeat=3):
    if x + y + z == sum_:
        count += 1
print(count)


Fixed submission:
max_range, sum_ = map(int, input().split())

count = 0
for x in range(0, min(max_range + 1, sum_ + 1)):
    for y in range(0, min(max_range + 1, sum_ - x + 1)):
        if sum_ - x - y <= max_range:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def hahaha():
    n=int(input())
    list=[]
    count=0
    for i in range(0,n):
        x=str(input())
        if not(x in list):
            count+=1
            list.append(x)

    print(count)
if __name__ == '__main__':
    hahaha()


Fixed submission:
def hahaha():
    n=int(input())
    count=1
    list=[]
    for i in range(0,n):
        list.append(str(input()))
    list.sort()
    a=list[0]
    for j in range(0,n):
        if a!=list[j]:
            a=list[j]
            count+=1
    print(count)
if __name__ == '__main__':
    hahaha()

Buggy python submission (verdict: Time Limit Exceeded):
def hahaha():
    n=int(input())
    list=[]
    count=0
    flag=0
    for i in range(0,n):
        list.append(str(input()))
        flag=0
        for j in range(0,i):
            if list[i]==list[j]:
                flag=1
        if flag==0:
            count=count+1
    print(count)
if __name__ == '__main__':
    hahaha()


Fixed submission:
def hahaha():
    n=int(input())
    count=1
    list=[]
    for i in range(0,n):
        list.append(str(input()))
    list.sort()
    a=list[0]
    for j in range(0,n):
        if a!=list[j]:
            a=list[j]
            count+=1
    print(count)
if __name__ == '__main__':
    hahaha()
Buggy python submission (verdict: Runtime Error):
S = input()


ans = 753

for i in range(len(S) - 2) :
    N = int(S[i:3])
    M = abs(753 - N)
    if ans > M :
        ans = M

print(ans)

Fixed submission:
S = input()


ans = 753

for i in range(len(S) - 2) :
    N = int(S[i:i+3])
    M = abs(753 - N)
    if ans > M :
        ans = M

print(ans)
Buggy python submission (verdict: Runtime Error):
from datetime import datetime
s = input()
t = datetime.strptime(s, '%y/%m/%d')
thres = datetime(2019, 4, 30)
print('heisei' if t <= thres else 'TBD')


Fixed submission:
from datetime import datetime
s = input()
t = datetime.strptime(s, '%Y/%m/%d')
thres = datetime(2019, 4, 30)
print('Heisei' if t <= thres else 'TBD')
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())

table = np.zeros(100)

for i in range(1, 10):
    for j in range(1, 10):
        table[i * j] = 1

if table[n] == 1:
    print('Yes')
else:
    print('No')



Fixed submission:
n = int(input())

table = [0 for i in range(0, 102)]

for i in range(1, 10):
    for j in range(1, 10):
        table[i * j] = 1

if table[n] == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R = [i for i in range(N) if S[i] == "R"]
G = [i for i in range(N) if S[i] == "G"]
B = [i for i in range(N) if S[i] == "B"]

ans = 0
for r in R:
    for g in G:
        for b in B:
            i, j, k = sorted([r, g, b])
            if j - i != k - j:
                ans += 1

print(ans)

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

R = [i for i in range(N) if S[i] == "R"]
G = [i for i in range(N) if S[i] == "G"]
B = [i for i in range(N) if S[i] == "B"]

ans = len(R) * len(G) * len(B)
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
             ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if j - i != k - j and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                 ans += 1

print(ans)

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

R = [i for i in range(N) if S[i] == "R"]
G = [i for i in range(N) if S[i] == "G"]
B = [i for i in range(N) if S[i] == "B"]

ans = len(R) * len(G) * len(B)
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
             ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n, s = map(int, input().split())
a = list(map(int, input().split()))
selections = []
for i in range(1, n + 1):
    for selection in combinations(range(n), i):
        if sum([a[j] for j in selection]) == s:
            selections.append(list(selection))

ans = 0
for selection in selections:
    ans += (selection[0] + 1) * (n - selection[-1])
print(ans % 998244353)

Fixed submission:
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353

dp = [[0] * (s + 1) for _ in range(n + 1)]
ans = 0
for i in range(n):
    dp[i][0] += 1
    for j in range(s + 1):
        dp[i + 1][j] += dp[i][j]
        dp[i + 1][j] %= MOD
        if j + a[i] <= s:
            dp[i + 1][j + a[i]] += dp[i][j]
            dp[i + 1][j + a[i]] %= MOD
    ans += dp[i + 1][s]
    ans %= MOD

print(ans)