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

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [(i + 1) / 2 for i in c]
e = sum(d[:b])
f = e
for i in range(a - b):
	f -= d[i]
	f += d[i + b]
	if f > e:
		e = f
print(e)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = []
for i in range(a - b + 1):
	h = 0
	h = sum(c[i:k + i])
	d.append(h)
e = 0
f = 0
g = d.index(max(d))
for i in range(b):
	f = sum(range(1, c[g + i] + 1))
	e += f / c[g + i]
print(e)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = input().split()
e = 0
for i in range(b):
	f = int(c[i + b - 1])
	d = 0
	for j in range(f):
		d += (j + 1)
	e += d / f
print(e)
Problem p02917 (python)

Fixed submission:
# coding: utf-8
N = int(input())
B = list(map(int, input().split()))
A = B
A.insert(0, B[0])
for i in range(1, N - 1):
    if A[i] > A[i+1]:
        A[i] = A[i+1]
print(sum(A))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
B = list(map(int, input().split()))
A = B
A.insert(0, B[0])
for i in range(1, N - 1):
    if A[i] == 0:
        A[i + 1] = A[i+2]
print(sum(A))
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
maxL = 1
minR = N
for i in range(M):
  L, R = map(int, input().split())
  maxL = max(maxL, L)
  minR = min(minR, R)
print(max(minR - maxL +1, 0))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
B = set()
for i in range(M):
  L, R = map(int, input().split())
  A = set(for j in range(L, R+1))
  if i == 0:
    B = A
  B = A & B
print(len(B))
Problem p03605 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a = int(input())
flg = 0
while a > 0:
	if a % 10 == 9:
		print("Yes")
		flg = 1
		break
	else:
		a = int(a / 10)
if flg == 0:
	print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = int(input())

for i in range(a):
	if a % 10 == 9:
		print("Yes")
        print(a)
    a = a / 10
    print(a)
#	b, c = map(int, input().split())
#	d = c - b + 1
#	e += d
Problem p03607 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a = int(input())
b = set()
for i in range(a):
	b ^= {input()}
print(len(b))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = int(input())
b = set()
for i in range(a):
	b ^= {input()}
	print(b)
print(len(b))
Problem p04012 (python)

Fixed submission:
w = list(input())
w.sort()
i = 0
if len(w) % 2 == 1:
    print('No')
    exit()

while i < len(w)-1:
	if w[i] != w[i+1]:
		print('No')
		exit()
	i += 2
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
w = list(input())
w.sort()
i = 0
if len(w) % 2 == 1:
    print('No')
    exit()

while i < len(w)-1:
	if w[i] != w[i+1]:
	    print('No')
            exit()
	i += 2
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
w = list(input())
w.sort()
i = 0
while i < len(w):
	if w[i] != w[i+1]:
		print('No')
		exit()
	i += 2
else:
	print('Yes')
Problem p03167 (python)

Fixed submission:
h, w = map(int, input().split())

mat = []
dp = []
m = 10**9+7

for i in range(h):
    mat.append(list(input()))
    dp.append(list([0]*w))

dp[0][0] = 1


for x in range(h):
    for y in range(w):

        if x != 0 or y != 0:
            if mat[x][y] == "#":
                dp[x][y] = 0

            else:
                dp[x][y] += (dp[x - 1][y] + dp[x][y - 1]) % m

print(dp[h - 1][w - 1])

Buggy submission (verdict: Runtime Error):
import sys


def find_paths(mat, n, m):

    for i in range(n):

        if mat[i][0] != "#":
            dp[i][0] = 1

        else:
            break

    for j in range(m):

        if mat[0][j] != "#":
            dp[0][j] = 1

        else:
            break

    dp[0][0] = 0

    for i in range(1, n):
        for j in range(1, m):
            if mat[i][j] == "#":
                dp[i][j] = 0

            else:
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

    # print(dp)
    return int(dp[n - 1][m - 1] % (1e9+7))



n, m = list(map(int, sys.stdin.readline().split()))

mat = []
dp = [[0 for i in range(1001)] for j in range(1001)]

for i in range(n):
    mat.append([ch for ch in sys.stdin.readline().strip()])

# print(mat)
print(find_paths(mat, n, m))

Buggy submission (verdict: Runtime Error):
import sys


def find_paths(mat, n, m, i, j, dp):

    if i == n - 1 and j == m - 1:
        return 1

    if i >= n or j >= m:
        return 0

    if mat[i][j] == "#":
        return 0

    if (i, j) in dp:
        return dp[(i, j)]

    dp[(i, j)] = int((find_paths(mat, n, m, i+1, j, dp) + find_paths(mat, n, m, i, j+1, dp)) % (1e9 + 7))
    return dp[(i, j)]



n, m = list(map(int, sys.stdin.readline().split()))

mat = []

for i in range(n):
    mat.append([ch for ch in sys.stdin.readline().strip()])


dp = {}
# print(mat)
print(find_paths(mat, n, m, 0, 0, dp))

Buggy submission (verdict: Runtime Error):
import sys


def find_paths(mat, n, m):

    dp = [[0 for i in range(m)] for j in range(n)]

    for i in range(n):

        if mat[i][0] != "#":
            dp[i][0] = 1

        else:
            break

    for j in range(m):

        if mat[0][j] != "#":
            dp[0][j] = 1

        else:
            break

    dp[0][0] = 0


    for i in range(1, n):
        for j in range(1, m):
            if mat[i][j] == "#":
                dp[i][j] = 0

            else:
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

    # print(dp)
    return int(dp[n - 1][m - 1] % (1e9+7))



n, m = list(map(int, sys.stdin.readline().split()))

mat = []

for i in range(n):
    mat.append([ch for ch in sys.stdin.readline().strip()])


dp = {}
# print(mat)
print(find_paths(mat, n, m))
Problem p02719 (python)

Fixed submission:
N, K = map( int, input().split() )
 
now_N = 10 ** 19
while True:
  N = min( abs( N % K ),abs( K - N ), now_N )
  if now_N == N:
    break
  now_N = N
print( now_N )

Buggy submission (verdict: Runtime Error):
N, K = map( int, input().split() )
 
now_N = 10 ** 19
while True:
  N = min( abs( N % K ),abs( K - N ),, now_N )
  if now_N == N:
    break
  now_N = N
print( now_N )
Problem p02768 (python)

Fixed submission:
N, A, B = map( int, input().split() )
MOD = 10 ** 9 + 7

def combi( n, r ):
  r = min( n - r, r )
  a = 1
  b = 1
  for i in range( 1, r + 1 ):
    a = ( a * ( n - i + 1 )) % MOD
    b = ( b * i ) % MOD

  return ( a * pow( b, MOD - 2, MOD )  % MOD ) 

n1 = combi( N, A )
n2 = combi( N, B )
ans = ( pow( 2, N, MOD ) - n1 - n2 - 1 ) % MOD
print( ans )

Buggy submission (verdict: Runtime Error):
n, a, b = map( int, input().split() )
max_mod =10 ** 9 + 7

r_1 = a
n_r_1 = ( n - a )
r_2 = b
n_r_2 = ( n - b )
n_ = 1
N = n % max_mod
for i in range( 1, N + 1 ):
  n_ *= i
  n_ %= max_mod
  if i == r_1:
    r_1 = n_
  if i == n_r_1:
    n_r_1 = n_
  if i == r_2:
    r_2 = n_
  if i == n_r_2:
    n_r_2 = n_
    
k_1 = n_ // ( r_1 * n_r_1 )
k_2 = n_ // ( r_2 * n_r_2 )
x = pow( 2, n, max_mod ) - 1
x -= ( k_1 + k_2 ) 
print( x )
Problem p02791 (python)

Fixed submission:
n, *p = map( int, open(0).read().split())
 
cnt = 0
min_val = 1000000
for i in range( len( p )):
  if p[i] < min_val:
    cnt += 1
    min_val = p[i]

print( cnt )

Buggy submission (verdict: Runtime Error):
n, *p = map( int, open(0).read().split())

cnt = 0
for i in range( 1, len( p )+1):
  p_2 = p[ : i ]
  print( p[i-1], p_2 )
  if p[i-1] == min( p_2 ):
    cnt += 1
print( cnt )
Problem p02837 (python)

Fixed submission:
n = int( input() )
l = [[]] * n
for i in range( n ):
  a = int( input() )
  k = [ -1 ] * n
  for _ in range( a ):
    x, y = map( int, input().split() )
    k[ x - 1 ] = y
  l[ i ] = k

ret = 0
for i in range( 2 ** n - 1, 0, -1 ):
  o = [int(i) for i in str( "{:b}".format(i).zfill(n) )]
  is_right = True
  for j in range( n ):
    for m in range( n ):
      if o[j] == 1:
        is_right &= ( l[j][m] in [-1, o[m]] )
    if not is_right:
      break
        
  if is_right:
    ret = sum(o)
    break
          
print( ret )

Buggy submission (verdict: Runtime Error):
n = int( input() )
l = [[]] * n
for i in range( n ):
  a = int( input() )
  k = [ -1 ] * n
  for _ in range( a ):
    x, y = map( int, input().split() )
    k[ x - 1 ] = y
  l[ i ] = k

ret = 0
for i in range( 2 ** n - 1, 0, -1 ):
  o = [int(i) for i in str( "{:b}".format(i).zfill(n) )]
  is_right = True
  for j in range( n ):
    for m in range( n ):
      if o[j] == 1:
        is_rzight &= ( l[j][m] in [-1, o[m]] )
    if not is_right:
      break
        
  if is_right:
    ret = sum(o)
    break
          
print( ret )
Problem p02885 (python)

Fixed submission:
a, b = map( int, input().split())
print( max( 0, a - b * 2 ))

Buggy submission (verdict: Runtime Error):
a, b = map( int, input())

print( max( 0, a - 2 * b ))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())


print(min( 0, a - 2 * b ))
Problem p02900 (python)

Fixed submission:
import math
A, B = map( int, input().split() )
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if ( n!=1 ) and ( arr==[] ):
        arr.append(n)

    return set( arr )

a = factorization(A)
b = factorization(B)
cnt = 0
for i in a:
  if i in b:
    cnt += 1

print( cnt + 1 )

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

# Euclid
a = max( A, B )
b = min( A, B )
r = a % b
while r != 0:
  a = b
  b = r
  r = a % b

prime = [0] * ( b + 1 )
for i in range( b + 1 ):
  prime[i] = i

for i in range( 2, b + 1 ):
  for k in range( 2, b + 1 ):
    if len( prime ) > i * k:
      prime[ i * k ] = 0
    else:
      break
prime = set( prime )
prime.remove( 0 )

cnt = 0
for i in prime:
  if ( ( A % i ) == 0 ) and ( ( B % i ) == 0 ):
    cnt += 1

print( cnt )
Problem p02910 (python)

Fixed submission:
s = input()
 
oddStep = ['R','U','D']
evenStep = ['L','U','D']
CNST_NO = 'No'
CNST_YES = 'Yes'
good_step = CNST_YES
 
for i in range( len( s ) ):
  if i % 2 == 1: # 0 start
    if not ( s[ i ] in evenStep ):
      good_step = CNST_NO
  else:
    if not( s[ i ] in oddStep ):
      good_step = CNST_NO
  if good_step == CNST_NO:
    break
print( good_step )

Buggy submission (verdict: Runtime Error):
s = input()

oddStep = ['R','U','D']
evenStep = ['L','U','D']
CNST_NO = 'No'
CNST_YES = 'Yes'
good_step = CNST_NO

for i, c in s:
  if i % 2 == 0:
    if c in oddStep:
		good_step = CNST_YES
  else:
    if c in evenStep:
		good_step = CNST_YES
  if good_step==CNST_YES:
    break
print( good_step )
Problem p02924 (python)

Fixed submission:
N = int( input() )
print( N * ( N - 1 ) // 2 )

Buggy submission (verdict: Runtime Error):
N = int( input() )
 
I = range( 1, N + 1 )
P = [ i for i in range(2, N + 1) ] + [ 1 ]
 
cnt = 0
for i in range( N ):
  cnt =　cnt + I[ i ] % P[ i ]

print( cnt )
Problem p03035 (python)

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

price = b
if ( 6 <= a ) & ( a <= 12 ):
  price //=2
elif ( a < 6 ):
  price = 0

print(price)

Buggy submission (verdict: Runtime Error):
N, M = map( int, input().split() )
a = list( map( int, input().split() ) )
 
d = []
for i in range( M ):
  b, c = map( int, input().split() )
  d += [ c ] * b
d.sort()
a += d
a.sort()
print(sum(a[-N:]))
Problem p03037 (python)

Fixed submission:
n, m = map(int, input().split())
 
left  = 0
right = n
for i in range(m):
  l, r = map( int, input().split() )
  left = max( left, l )
  right = min( right, r )

ans =  right - left + 1
if ans <= 0:
  ans = 0
print( ans )

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

left  = 0
right = n
for i in range(m):z
  l, r = map( int, input().split() )
  left = max( left, l )
  right = min( right, r )

print( right - left + 1 )
Problem p03341 (python)

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

R = len( S.replace("W", "") ) 
L = 0
ret = L + R 
for i in range( N ):
  if S[ i ] == "E":
    R -= 1
  ret = min( ret, L + R )
  if S[ i ] == "W":
    L += 1

print( ret )

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

if A + B > 2 * C:
  m = min( X, Y )
  print( min( 2 * C * m + ( X - m ) * A + ( Y - m ) * B, 
              2 * C * m + ( X - m ) * 2 * C + ( Y - m ) * 2 * C ) )
else:
  print( X * A + Y * B )
Problem p03355 (python)

Fixed submission:
s = input()
N = len( s )
K = int( input() )

s_set = set()
for j in range( 1, K + 1 ):
  for i in range( N - j + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

print( sorted( list( s_set ) )[ K - 1 ] )

Buggy submission (verdict: Runtime Error):
s = input()
N = len( s )
K = int( input() )

s_set = set()
for i in range( N - K + 1 ):
  for j in range( 1, K + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

print( sorted( list( s_set ) )[ K - 1 ] )
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split(" "))
Ai=list(map(int,input().split(" ")))
days=0
for a in Ai:
    days+=a
if days>n:
    print(-1)
else:
    print(n-days)

Buggy submission (verdict: Runtime Error):
a=map(int,input().split(" "))
Ai=map(int,input().split(" "))
n=a[0]
days=0
for i in range(a[1]):
    days+=Ai[i]
if days>n:
    print(-1)
else:
    print(n-days)

Buggy submission (verdict: Runtime Error):
a=map(int,input().split(" "))
Ai=map(int,input().split(" "))
n=a[0]
days=0
for A in Ai:
    days+=A
if days>n:
    print(-1)
else:
    print(n-days)
Problem p02708 (python)

Fixed submission:
import math

def fac(x):
    if x<=1:
        return 1
    s=1
    for i in range(1,x+1):
        s=s*i
    return s
def com(m,n):
    return fac(m)/(fac(n)*fac(m-n))


temps=input().split()
n=int(temps[0])
m=int(temps[1])
sum=0
for i in range(m,n+2):
    min=int((i-1)*i/2)
    max=int((2*n-i+1)*i/2)
    sum=sum+max-min+1
print(int(sum%(math.pow(10,9)+7)))

Buggy submission (verdict: Runtime Error):
import math

def fac(x):
    if x<=1:
        return 1
    s=1
    for i in range(1,x+1):
        s=s*i
    return s
def com(m,n):
    return fac(m)/(fac(n)*fac(m-n))

temps=input().split()
n=int(temps[0])
m=int(temps[1])
sum=0
for i in range(m,n+1):
    sum=sum+com(n+1,i)
print(int(sum%(math.pow(10,9)+7)))
Problem p02675 (python)

Fixed submission:
def cal():

    num = int(input())
    if num >= 10:
        ben = num % 10
    else:
        ben = num
    
    if ben == 3:
        print("bon")
    elif ben == 0 or ben == 1 or ben == 6 or ben == 8:
        print("pon")
    elif ben == 2 or ben == 4 or ben == 5 or ben == 7 or ben == 9:
        print("hon")
    


cal()

Buggy submission (verdict: Runtime Error):
def cal():
    k = int(input())
    string = input()
    if len(string) <= k:
        print(string)
    else:
        list1 = list(string)
        for i in range(k):
            print(list1[i], end='')
        print("...")

cal()

Buggy submission (verdict: Runtime Error):
N=int(input())
a=N%10
if a<10:
	if a==2 or a==4 or a==5 or a==7 or a==9:
    	print("hon")
    else if a==0 or a==1 or a==6 or a==8:
    	print("pon")
    else:
    	print("bon")
Problem p02677 (python)

Fixed submission:
import math


def cal():
    string = input()
    a, b, h, m = string.split(" ")
    a = int(a)
    b = int(b)
    h = int(h)
    m = int(m)
    minuteAngel = (float(m) * 360) / 60
    hourAngel = (float(h) % 12) * 30 + (float(m) * 30) / 60
    angel = abs(hourAngel - minuteAngel)
    angel=angel/180
    cosine = math.cos(math.pi*angel)
    ans = math.sqrt(a*a + b*b - 2*a*b*cosine)
    print(format(ans, '.20f'))
    # print(angle1)
    # print(angle2)
    # print(angle)
    # print(cosine)

cal()

Buggy submission (verdict: Runtime Error):
import math
def:
	A B H M=map(int,input().split(" "))
	if H>M/5:
		angle=(H/12-M/60)
	else:
		angle=(M/60-H/12)
    t=math.cos(math.pi*angle)
    d=(A^2+B^2-2AB*t)^0.5
    print(d)

Buggy submission (verdict: Runtime Error):
import math
def:
	A B H M=map(int,input().split(" "))
	if H>M/5:
		angle=(H/12-M/60)*360
	else:
		angle=(M/60-H/12)*360
    t=cos(angle)
    d=(A^2+B^2-2AB*t)^0.5
    print(d)
Problem p02678 (python)

Fixed submission:

import sys
import queue
sys.setrecursionlimit(10**7)


def inpl():
    return list(map(int, input().split()))


N, M = inpl()

lines = [[] for _ in range(N)]
for _ in range(M):
    a, b = inpl()
    a -= 1
    b -= 1
    lines[a].append(b)
    lines[b].append(a)


ans = [-1] * N


q = queue.Queue()
q.put((0, 0))
while not q.empty():
    s, b = q.get()

    if ans[s] != -1:
        continue
    else:
        ans[s] = b
        for t in lines[s]:
            q.put((t, s))


print("Yes")
for a in ans[1:]:
    print(a + 1)

Buggy submission (verdict: Runtime Error):

def inpl():
    return list(map(int, input().split()))


N, M = inpl()

lines = [[] for _ in range(N)]
for _ in range(M):
    a, b = inpl()
    a -= 1
    b -= 1
    lines[a].append(b)
    lines[b].append(a)


ans = [-1] * N


def dfs(s, b):
    global ans

    if ans[s] != -1:
        return
    else:
        ans[s] = b
        for t in lines[s]:
            dfs(t, s)


dfs(0, 0)


print("YES")
for a in ans[1:]:
    print(a + 1)
Problem p02690 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


X = inp()
MAX = 5000
for a in range(-MAX, MAX + 1):
    for b in range(-MAX, MAX + 1):
        tmp = pow(a, 5) - pow(b, 5)
        if X == tmp:
            print(a, b)
            exit()


assert False

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


X = inp()

for a in range(-100, 100):
    for b in range(-100, 100):
        tmp = a**5 - b**5
        if X == tmp:
            print(a, b)
            exit()


assert False
Problem p02697 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


N, M = inpl()

if N % 2 == 1:
    for i in range(M):
        print(i + 1, N - i - 1)
else:
    if M == 1:
        print(1, 2)
    else:
        for i in range(M):
            a, b = i + 1, N - i
            if b - a <= N // 2:
                b -= 1

            print(a, b)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


N, M = inpl()

if N % 2 == 1:
    for i in range(M):
        print(i + 1, N - i - 1)
else:
    assert False
    if M == 1:
        print(1, 2)
    else:
        for i in range(M):
            if i == M - 1:
                print(i + 1, i + 3)
            else:
                print(i + 1, N - i)
Problem p02700 (python)

Fixed submission:
t_hp, t_at, a_hp, a_at = map(int, input().split())

while True:
    a_hp -= t_at
    if a_hp <= 0:
        print("Yes")
        exit()

    t_hp -= a_at
    if t_hp <= 0:
        print("No")
        exit()

Buggy submission (verdict: Runtime Error):
t_at, t_hp, a_at, a_hp = map(int, input().split())

while True:
  a_hp -= t_at
  if a_hp <= 0:
    print("Yes")
  	exit()
  
  t_hp -= a_at
  if t_hp <= 0:
    print("No")
    exit()
Problem p02702 (python)

Fixed submission:

S = list(map(int, list(input())))

mod = 2019
ss = [0]
tmp = 0
for i, s in enumerate(S[::-1]):
    tmp += s * pow(10, i, mod)
    tmp %= mod
    ss.append(tmp)

cnts = [0] * 2019
ans = 0
for s in ss:
    ans += cnts[s]
    cnts[s] += 1

print(ans)

Buggy submission (verdict: Runtime Error):

S = list(map(int, list(input())))

mod = 2019
ss = [0]
tmp = 0
for i, s in enumerate(S[::-1]):
    tmp += s * pow(10, i, mod)
    tmp %= mod
    ss.append(tmp)

cnts = [0] * 2018
ans = 0
for s in ss:
    ans += cnts[s]
    cnts[s] += 1

print(ans)
Problem p02734 (python)

Fixed submission:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inpl(): return list(map(int, sys.stdin.readline().split()))


def inpl_str(): return list(sys.stdin.readline().split())


N, S = inpl()
aa = inpl()

dp = [0 for _ in range(3010)]
dp[0] = 0

ans = 0
for i, a in enumerate(aa):

    if S == a:
        ans += (i+1) * (N-i) % mod
    else:
        ans += dp[S-a] * (N-i) % mod
    ans %= mod

    for s in reversed(range(a, S)):
        if s == a:
            dp[s] += i+1
        else:
            dp[s] += dp[s-a]
        dp[s] %= mod


print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inpl(): return list(map(int, sys.stdin.readline().split()))


def inpl_str(): return list(sys.stdin.readline().split())


N, S = inpl()
aa = inpl()

dp = [0 for _ in range(S)]
dp[0] = N

ans = 0
for i, a in enumerate(aa):
    ans += dp[S-a] * (N-i) % mod
    ans %= mod

    for s in reversed(range(a, S)):
        if s == a:
            dp[s] += i+1
        else:
            dp[s] += dp[s-a]
        dp[s] %= mod


print(ans)
Problem p02747 (python)

Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

S = input()
S = S.replace("hi", "")

if S == "":
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,M = inpl()
H = 2**N-1
W = 2**M-1

ans = [[0] * W for _ in range(H)]
# for i in range(W):
    # for j in range(H):
        # ans[j][i] =

ans[0][0] = 1
ans[0][W-1] = 1
ans[H-1][0] = 1
ans[H-1][W-1] = 1
# ans[H//2][W//2] = 1
# ans[0][W//2] = 1
# ans[H-1][W//2] = 1
# ans[H//2][0] = 1
# ans[H//2][W-1] = 1

for a in ans:
    print("".join(map(str,a)))