Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# --------------------------------------
# 関数定義
# --------------------------------------


def chmin(a, b):
    if a > b:
        a = b
    return a

# --------------------------------------
# メイン処理
# --------------------------------------


def main():
    INF = 10 ** 10
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [INF] * N
    dp[0] = 0

    for i in range(1, N):
        for j in range(1, K + 1):
            if i - j < 0:
                continue
            dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

    print(dp[N-1])


# --------------------------------------
# 実行
# --------------------------------------
if __name__ == "__main__":
    main()


Fixed submission:
# --------------------------------------
# 関数定義
# --------------------------------------


def chmin(a, b):
    if a > b:
        a = b
    return a

# --------------------------------------
# メイン処理
# --------------------------------------


def main():
    INF = 10 ** 10
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [INF] * N
    dp[0] = 0

    for i in range(1, N):
        for j in range(1, K + 1):
            if i - j < 0:
                continue
            dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

    print(dp[N-1])


# --------------------------------------
# 実行
# --------------------------------------
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, l):
    l.sort()
    r = 0
    for i in range(n - 2):
        li = l[i]
        for j in range(i + 1, n - 1):
            lj = l[j]
            for k in range(j + 1, n):
                if li + lj <= l[k]:
                    break
                else:
                    # print(li, lj, l[k])
                    r += 1
    return r

def main():
    n = int(input())
    l = [int(x) for x in input().split()]
    print(solve(n, l))


main()

Fixed submission:
import bisect

def solve(n, l):
    l.sort()
    r = 0
    for i in range(n - 2):
        li = l[i]
        for j in range(i + 1, n - 1):
            r += bisect.bisect_left(l, li + l[j], j + 1) - j - 1
    return r

def main():
    n = int(input())
    l = [int(x) for x in input().split()]
    print(solve(n, l))


main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = []
for _ in range(n):
    s.append(sorted(input()))

cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1

print(cnt)



Fixed submission:
from collections import Counter

def list2str(l):
    s = ""
    for c in l:
        s += c
    return s

n = int(input())

s = []
for _ in range(n):
    s.append(list2str(sorted(input())))

"""
# TLE
cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1
"""

print(sum([x * (x - 1) // 2 for x in Counter(sorted(s)).values()]))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = [[]] * N
for i in range(M):
	p, s = input().split()
	S[int(p)-1] = S[int(p)-1] + [s]

r,w = 0,0
for i in S:
	if 'AC' in i:
		r += 1
		w += i.index('AC')

print(r,w)

Fixed submission:
N, M = map(int, input().split())
S = [0] * N
r,w = 0,0
for i in range(M):
	p, s = input().split()
	if S[int(p)-1] >= 0:
		if s == 'AC':
			r+=1
			w+=S[int(p)-1]
			S[int(p)-1] = -1
		else:
			S[int(p)-1] = S[int(p)-1] + 1
print(r,w)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [110]
a = list(map(int, input().sprit()))
a.sort(reverse=True)
 
Alis = 0
Bob = 0
for j in range(N):
  if j % 2 == 0:
    Alis += a[j]
  else:
    Bob += a[j]
 
print(Alis-Bob)

Fixed submission:
N = int(input())
a = [110]
a = list(map(int, input().split()))
a.sort(reverse=True)
 
Alis = 0
Bob = 0
for j in range(N):
  if j % 2 == 0:
    Alis += a[j]
  else:
    Bob += a[j]
    
print(Alis-Bob)

Buggy python submission (verdict: Runtime Error):
N = input()
a = [110]
for i in range(N):
  a[1] = input()
a.sort(reverse=True)

int Alis = 0
int Bob = 0
for j in range(N):
  if j % 2 == 0:
    Alis += a[j]
  else:
    Bob += [j]

print(Alis-Bob)
    

Fixed submission:
N = int(input())
a = [110]
a = list(map(int, input().split()))
a.sort(reverse=True)
 
Alis = 0
Bob = 0
for j in range(N):
  if j % 2 == 0:
    Alis += a[j]
  else:
    Bob += a[j]
    
print(Alis-Bob)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()

x = (a+b)/2

if x % 2 == 0:
  print(x)
else:
  print(1+(a+b)//2)

Fixed submission:
a, b = (int(x) for x in input().split())
 
x = (a+b)/2
 
if (a+b) % 2 == 0:
  print(int(x))
else:
  print(int(1+(a+b)//2))
Buggy python submission (verdict: Runtime Error):
n ,a,b= map(int,input().split())
cur = (b-a-1)
if cur %2==0:
    left = b-1
    right = n-a
    print(min(left,right))
else:
    cur +=1
    print(cur//2)

Fixed submission:
n ,a,b= map(int,input().split())
cur = (b-a-1)
if cur %2==0:
    left = a-1
    right = n-b
    if b-a == 1:
        print(min(n-a,b-1))
    else:
        cur =0
        if left<right:
            cur = left
            a = 1
            b -= left
        else:
            cur = right
            a+=right
            b=n
        if b-a ==1:
            print(cur+1)
        else:
            need = b-a
            if need %2 ==0:
                need+=2
            else:
                need+=1
            print(cur+(need)//2)
else:
    cur +=1
    print(cur//2)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
gcd = math.gcd(a,b)
print((a*b)//gcd)

Fixed submission:
def computeGCD(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small + 1):
        if ((x % i == 0) and (y % i == 0)):
            gcd = i

    return gcd
a,b = map(int,input().split())
gcd = computeGCD(a,b)
print((a*b)//gcd)
Buggy python submission (verdict: Runtime Error):
money = [0,1,2,3,4,5]
n = int(input())
p = 0
lm = n//100
need = n - (lm*100)
def dfs( cur,limit):
    global p,need
    if not p:
        for i in range(6):
            now = cur+money[i]
            if limit+1 == lm:
                if now == need:
                    p =1
                    break
            elif limit+1<=lm:
                dfs(now,limit+1)
if n>=100:
    dfs(0,0)
    print(1 if p else 0)
else:
    print(0)

Fixed submission:
money = [0,1,2,3,4,5]
n = int(input())
p = 0
lm = n//100
need = n - (lm*100)
if n>=100:
    print(1 if lm*5>= need else 0)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mx = int(10e6+1)
y=0
mn = int(10e13)
for v in range(1,mx):
    if v<=n and n%v==0:
        y=1
        left = n//v
        mn=min(v-1+left-1,mn)
    if v>n:
        break
if y:
    print(mn)
else:
    print(n-1)


Fixed submission:
n = int(input())
mx = int(10e6+1)
y=0
mn = int(10e13)
for v in range(1,mx):
    if v<=n and n%v==0:
        y=1
        left = n//v
        mn=min(v-1+left-1,mn)
    if v>n:
        break
if y:
    print(mn)
else:
    print(n-1)
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
count = [0 for _ in range(len(a))]
for i in range(len(a)):
    temp = i
    idex = i
    c = 0
    while(1):
        if a[idex]=='R' and a[idex+1]=='L':
            if c%2==0:
                count[idex]+=1
            else:
                count[idex+1] += 1
            break
        elif a[idex]=='L' and a[idex-1]=='R':
            if c%2==0:
                count[idex]+=1
            else:
                count[idex-1] += 1
            break
        else:
            idex =idex+1 if a[idex]=='R' else idex-1
        c+=1

print(* count)

Fixed submission:
a = input()
count = [0 for _ in range(len(a))]
walk_Right = [0 for _ in range(len(a))]
walk_Left = [0 for _ in range(len(a))]
c = 0
for i in range(len(a)-1,-1,-1):
    if a[i] == 'R':
        c += 1
        walk_Right[i]=c
    else:
        c = 0
        walk_Right[i]=c

c=0
for i in range(len(a)):
    if a[i] == 'L':
        c += 1
        walk_Left[i]=c
    else:
        c = 0
        walk_Left[i]=c

for i in range(len(a)):
    if a[i] == 'R':
        if walk_Right[i] % 2 == 0:
            count[i+ walk_Right[i]] += 1
        else:
            count[i + walk_Right[i] - 1] += 1
    else:
        if walk_Left[i] % 2 == 0:
            count[i - walk_Left[i]] += 1
        else:
            count[i- walk_Left[i] + 1] += 1
print(* count)

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
count = [0 for _ in range(len(a))]
for i in range(len(a)):
    temp = i
    idex = i
    c = 0
    while(1):
        if a[idex]=='R' and a[idex+1]=='L':
            if c%2==0:
                count[idex]+=1
            else:
                count[idex+1] += 1
            break
        elif a[idex]=='L' and a[idex-1]=='R':
            if c%2==0:
                count[idex]+=1
            else:
                count[idex-1] += 1
            break
        else:
            idex =idex+1 if a[idex]=='R' else idex-1
        c+=1

print(* count)

Fixed submission:
a = input()
count = [0 for _ in range(len(a))]
walk_Right = [0 for _ in range(len(a))]
walk_Left = [0 for _ in range(len(a))]
c = 0
for i in range(len(a)-1,-1,-1):
    if a[i] == 'R':
        c += 1
        walk_Right[i]=c
    else:
        c = 0
        walk_Right[i]=c

c=0
for i in range(len(a)):
    if a[i] == 'L':
        c += 1
        walk_Left[i]=c
    else:
        c = 0
        walk_Left[i]=c

for i in range(len(a)):
    if a[i] == 'R':
        if walk_Right[i] % 2 == 0:
            count[i+ walk_Right[i]] += 1
        else:
            count[i + walk_Right[i] - 1] += 1
    else:
        if walk_Left[i] % 2 == 0:
            count[i - walk_Left[i]] += 1
        else:
            count[i- walk_Left[i] + 1] += 1
print(* count)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
dp = [[0 for _ in range(13)] for _ in range(len(s)+1)]
s= '0'+s
dp[0][0] =1
mod = 1000000007
def factory (i,j):
    for premod in range(13):
        curMod = (premod*10+j)%13
        dp[i][curMod]+=dp[i-1][premod]
        dp[i][curMod]%=mod
for i in range(1,len(s)):
    if s[i]!='?':
        factory(i,int(s[i]))
    else:
        for num in range(10):
            factory(i,num)
print(dp[len(s)-1][5]%mod)

Fixed submission:
s = input()
dp = [[0 for _ in range(13)] for _ in range(len(s)+1)]
s= '0'+s
dp[0][0] =1
mod = 1000000007
def factory (i,j):
    for premod in range(13):
        curMod = (premod*10+j)%13
        dp[i][curMod]+=dp[i-1][premod]
        dp[i][curMod]%=mod
for i in range(1,len(s)):
    if s[i]!='?':
        factory(i,int(s[i]))
    else:
        for num in range(10):
            factory(i,num)
print(dp[len(s)-1][5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
mx = 1000000000
if n<mx:
    print(0, 0, 1, 0, 1, n)
else:
    l=1
    r=mx
    start = n
    while(start>mx):
        next = (l+r)//2
        start = n // next
        if start > mx:
            if next!=l:
                l = next
            else:
                l+=1
    for i in range(start,n+1):
        if n%i==0:
            ret = n//i
            if ret<=mx:
                break
    print(0,0,i,0,i,ret)


Fixed submission:
import math
n = int(input())
mx = 1000000000
# mx = 7
if n<mx:
    print(0, 0, 1, 0, 1, n)
else:
    mul = math.ceil((n*1.0)/mx)
    x3= mx*mul-n
    print(0,0,mx,1,x3,mul)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mx = 1000000000
for i in range(1,n+1):
    if n%i==0:
        ret = n//i
        if ret<=mx:
            break
print(0,0,i,0,i,ret)


Fixed submission:
import math
n = int(input())
mx = 1000000000
# mx = 7
if n<mx:
    print(0, 0, 1, 0, 1, n)
else:
    mul = math.ceil((n*1.0)/mx)
    x3= mx*mul-n
    print(0,0,mx,1,x3,mul)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = []
count = [0 for _ in range(2000001)]

for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(20000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        start = i
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))




Fixed submission:
import sys
n = int(input())
a = []
count = [0 for _ in range(200001)]
for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(200000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
s=0
start = a//c
end = b//c
a * b // math.gcd(a, b)
if start*c<a:
    s += end-(start+1)+1
else:
    s += end - start + 1
if d%c!=0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

    return gcd
last =c * d // gcd(c, d)
start = a//last
end = b//last
if start*c<a:
    s -= end-(start+1)+1
else:
    s -= end - start + 1
print((b-a+1)-s)

Fixed submission:
a, b, c, d = map(int, input().split())
s = 0
start = a // c
end = b // c
if start * c < a:
    s += end - (start + 1) + 1
else:
    s += end - start + 1
if d % c != 0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
    def gcd(x, y):
        while y != 0:
            (x, y) = (y, x % y)
        return x
        return gcd
    last = c * d // gcd(c, d)
    start = a // last
    end = b // last
    if start * last < a:
        s -= end - (start + 1) + 1
    else:
        s -= end - start + 1
print((b - a + 1) - s)

Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
s=0
start = a//c
end = b//c
a * b // math.gcd(a, b)
if start*c<a:
    s += end-(start+1)+1
else:
    s += end - start + 1
if d%c!=0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
last =c * d // math.gcd(c, d)
start = a//last
end = b//last
if start*c<a:
    s -= end-(start+1)+1
else:
    s -= end - start + 1
print((b-a+1)-s)


Fixed submission:
a, b, c, d = map(int, input().split())
s = 0
start = a // c
end = b // c
if start * c < a:
    s += end - (start + 1) + 1
else:
    s += end - start + 1
if d % c != 0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
    def gcd(x, y):
        while y != 0:
            (x, y) = (y, x % y)
        return x
        return gcd
    last = c * d // gcd(c, d)
    start = a // last
    end = b // last
    if start * last < a:
        s -= end - (start + 1) + 1
    else:
        s -= end - start + 1
print((b - a + 1) - s)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s= n
ans=[]
freeNode = [2]
cur=2
ans.append([1,2])
if n==2 :
    if k>0:
        print(-1)
    else:
        print(1)
        print(1, 2)
        exit()
else:
    s=0
    c=1
    if (n-2)*(n-1)//2<k:
        print(-1)
        exit()
    else:
        while(1):
            s += c
            cur+=1
            c+=1
            freeNode.append(cur)
            ans.append([1,cur])
            if s >=k:
                break
    if cur!=n:
        remove = s-k;
        if remove:
            for v in freeNode:
                ans.append([v,cur])
                remove-=1
                if remove==0:
                    break
        for i in range(cur + 1, n + 1):
            cur+=1
            for j in range(1, cur):
                ans.append([i, j])
        print(len(ans))
        for u,v in ans:
            print(u,v)
    else:
        remove = s - k;
        if remove:
            for v in freeNode:
                ans.append([v, cur])
                remove -= 1
                if remove == 0:
                    break
        print(len(ans))
        for u, v in ans:
            print(u, v)


Fixed submission:
n= int(input())
jobs = []
for i in range(n):
    a,b = map(int,input().split())
    jobs.append([a,b])
jobs = sorted(jobs,key=lambda x:[x[1],x[0]])
time = 0
for t,e in jobs:
    time+=t
    if time>e:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
h,w = map(int,input().split())
left = [[0 for x in range(w)]for _ in range(h)]
right = [[0 for x in range(w)]for _ in range(h)]
up = [[0 for x in range(w)]for _ in range(h)]
down = [[0 for x in range(w)]for _ in range(h)]
arr = []
for i in range(h):
    arr.append(sys.stdin.readline())
for i in range(h):
    s = 0
    for j in range(w):
        if arr[i][j]=='.':
            left[i][j]=s
            s+=1
        else:
            s=0
for i in range(h):
    s = 0
    s2 =0
    for j in range(w):
        if arr[i][j] == '.':
            left[i][j] = s
            s += 1
        else:
            s = 0
        if arr[i][w-1-j]=='.':
            right[i][w-1-j] = s2
            s2+=1
        else:
            s2=0
for i in range(w):
    s = 0
    s2 = 0
    for j in range(h):
        if arr[j][i] == '.':
            up[j][i] = s
            s+=1
        else:
            s=0
        if arr[h-1-j][i] == '.':
            down[h-1-j][i] = s2
            s2+=1
        else:
            s2=0
mm = 0
for i in range(h):
    for j in range(w):
        if arr[i][j] =='.':
            mm = max(mm,left[i][j]+right[i][j]+up[i][j]+down[i][j]+1)
print(mm)



Fixed submission:
import sys
h,w = map(int,input().split())
left = [[0 for x in range(w)]for _ in range(h)]
right = [[0 for x in range(w)]for _ in range(h)]
up = [[0 for x in range(w)]for _ in range(h)]
down = [[0 for x in range(w)]for _ in range(h)]
arr = []
for i in range(h):
    arr.append(sys.stdin.readline())
for i in range(h):
    s = 0
    for j in range(w):
        if arr[i][j]=='.':
            left[i][j]=s
            s+=1
        else:
            s=0
for i in range(h):
    s = 0
    s2 =0
    for j in range(w):
        if arr[i][j] == '.':
            left[i][j] = s
            s += 1
        else:
            s = 0
        if arr[i][w-1-j]=='.':
            right[i][w-1-j] = s2
            s2+=1
        else:
            s2=0
for i in range(w):
    s = 0
    s2 = 0
    for j in range(h):
        if arr[j][i] == '.':
            up[j][i] = s
            s+=1
        else:
            s=0
        if arr[h-1-j][i] == '.':
            down[h-1-j][i] = s2
            s2+=1
        else:
            s2=0
mm = 0
for i in range(h):
    for j in range(w):
        if arr[i][j] =='.':
            mm = max(mm,left[i][j]+right[i][j]+up[i][j]+down[i][j]+1)
print(mm)
Buggy python submission (verdict: Runtime Error):
tailA = 0
both = 0
c = 0
for i in range(int(input())):
    t = input()
    if t[0] =='B' and t[-1]=='A':
        both+=1
    elif t[0] == 'B':
        headB+=1
    elif t[-1] == 'A':
        tailA +=1
    c+=t.count('AB')
if both>0:
    c+=both-1
    headB+=1
    tailA+=1
print(c+min(headB,tailA))


Fixed submission:
headB = 0
tailA = 0
both = 0
c = 0
for i in range(int(input())):
    t = input()
    if t[0] =='B' and t[-1]=='A':
        both+=1
    elif t[0] == 'B':
        headB+=1
    elif t[-1] == 'A':
        tailA +=1
    c+=t.count('AB')
if both>0:
    if tailA+headB>0:
        if tailA:
            c+=1
            tailA-=1
        if headB:
            c+=1
            headB-=1
        c+=min(headB,tailA)
        c+=both-1
    else:
        c+=both-1
else:
    c+=min(tailA,headB)
print(c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
limit = int(math.ceil(math.sqrt(n)))
ans =0
for i in range(1,limit):
    a = n // i - 1
    if i * a + i == n:
        ans += a
print(ans)

Fixed submission:
limit = 0
n = int(input())
for v in range(1,n):
    if v*v >n:
        limit= v-1
        break
ans =0
for i in range(1,limit+1):
    a = n // i - 1
    if n//a == n%a:
        ans += a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
r,c = map(int,input().split())
grid = []
temp = []
limit = r*c
total = 0
count = 0
done = [[0 for _ in range(c)] for _ in range(r)]
for i in range(r):
    next = list(input())
    for j in range(c):
        if next[j]=='#':
            temp.append([i,j])
            total+=1
    grid.append(next)
while(total<limit):
    nextround = []
    while(len(temp)>0):
        x,y = temp.pop()
        # print('X:',x,'Y:',y)
        if x-1>-1:
            if grid[x-1][y] == '.':
                grid[x - 1][y] = '#'
                total +=1
                nextround.append([x-1,y])
        if x+1<r:

            if grid[x+1][y] == '.':
                grid[x + 1][y] = '#'
                total +=1
                nextround.append([x+1, y])
        if y-1>-1:
            if grid[x][y-1] == '.':
                grid[x][y-1] = '#'
                total +=1
                nextround.append([x,y-1])
        if y+1<c:
            if grid[x][y+1] == '.':
                grid[x][y+1] = '#'
                total +=1
                nextround.append([x,y+1])
    temp = copy.deepcopy(nextround)
    count+=1
print(count)

Fixed submission:
r,c = map(int,input().split())
grid = []
temp = []
limit = r*c
total = 0
count = 0
for i in range(r):
    next = list(input())
    for j in range(c):
        if next[j]=='#':
            temp.append([i,j])
            total+=1
    grid.append(next)
while(total<limit):
    nextround = []
    while(len(temp)>0):
        x,y = temp.pop()
        # print('X:',x,'Y:',y)
        if x-1>-1:
            if grid[x-1][y] == '.':
                grid[x - 1][y] = '#'
                total +=1
                nextround.append([x-1,y])
        if x+1<r:

            if grid[x+1][y] == '.':
                grid[x + 1][y] = '#'
                total +=1
                nextround.append([x+1, y])
        if y-1>-1:
            if grid[x][y-1] == '.':
                grid[x][y-1] = '#'
                total +=1
                nextround.append([x,y-1])
        if y+1<c:
            if grid[x][y+1] == '.':
                grid[x][y+1] = '#'
                total +=1
                nextround.append([x,y+1])
    temp = nextround
    count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(a[1] - a[0])
for i in range(2, n):
    dp[i]=dp[i-1]+abs(a[i]-a[i-1])
    for j in range(2,k+1):
        if j>i:
            break
        else:
            dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))
print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(a[1] - a[0])
for i in range(2, n):
    dp[i]=dp[i-1]+abs(a[i]-a[i-1])
    for j in range(2,k+1):
        if j>i:
            break
        else:
            dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))
print(dp[-1])