Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

A.sort()
Sum = sum(A)

for i in range(Q):
    L = bisect.bisect_left(A, B[i])
    R = bisect.bisect_right(A, B[i])
    num = R - L
    Sum += num * (C[i] - B[i])

    for j in range(L, R):
        A[j] = C[i]

    A.sort()
    print(Sum)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

DP = [0]*(10**5+1)

for i in range(len(A)):
    DP[A[i]] += 1

Sum = sum(A)

for i in range(Q):
    Sum += (C[i]-B[i])*DP[B[i]]
    DP[C[i]] += DP[B[i]]
    DP[B[i]] = 0
    print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
# 同じ町に二回到達したときに、前回たどり着いたときとの差を観る

import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))

X = [0] * (N + 1)
X[0] = 1

for i in range(1, K + 1):
    if A[X[i - 1] - 1] in X:
        # 前回の位置を取得
        hoge = X.index(A[X[i - 1] - 1])
        print(X[hoge + ((K - hoge) % ((i-1) - hoge + 1))])
        sys.exit()
    else:
        X[i] = A[X[i - 1] - 1]

print(X[K])


Fixed submission:
# 同じ町に二回到達したときに、前回たどり着いたときとの差を観る

import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))

Flag = [0] * (N+1)
X = [0] * (N + 1)
X[0] = 1

for i in range(1, K + 1):
    if Flag[A[X[i - 1] - 1]] == 1:
        # 前回の位置を取得
        hoge = X.index(A[X[i - 1] - 1])
        print(X[hoge + ((K - hoge) % ((i-1) - hoge + 1))])
        sys.exit()
    else:
        X[i] = A[X[i - 1] - 1]
        Flag[A[X[i - 1] - 1]] = 1


print(X[K])
Buggy python submission (verdict: Runtime Error):
print(hoge)

Fixed submission:
A,B,N = map(int, input().split())
print(A*min(N,B-1)//B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
X = [0] * N

for i in range(N):
    if S[i] == "R":
        X[i] = 1
    elif S[i] == "G":
        X[i] = 2
    elif S[i] == "B":
        X[i] = 3

Sum = 0

for i in range(N - 2):
    s1 = X[i]
    for j in range(i + 1, N - 1):
        s2 = X[j]
        if s1 != s2:
            for k in range(j + 1, N):
                if (6 - s1 - s2 == X[k]) and (j - i) != (k - j):
                    Sum += 1

print(Sum)



Fixed submission:
N = int(input())
S = str(input())
X = [0] * N

Sum1 = 0
Sum2 = 0
Sum3 = 0

for i in range(N):
    if S[i] == "R":
        X[i] = 1
        Sum1 += 1
    elif S[i] == "G":
        X[i] = 2
        Sum2 += 1
    elif S[i] == "B":
        X[i] = 4
        Sum3 += 1

Sum = Sum1 * Sum2 * Sum3

for i in range(N):
    for j in range(1, N):
        if i - j < 0 or N <= i + j:
            break
        else:
            if (X[i] + X[i - j] + X[i + j]) == 7:
                Sum -= 1

print(Sum)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for key in A:
    d[key] += 1
    #print(d)

Sum = 0
for i in d:
    n = d[A[i]]
    Sum += (n * (n - 1)) // 2
    #print((n * (n - 1)) // 2)
    #print(d[A[i]],i)
    #print(d)

#print(Sum)

for i in range(N):
    n = d[A[i]]
    hoge = Sum - (n*(n-1))//2
    n -= 1
    hoge += (n*(n-1))//2
    print(hoge)

Fixed submission:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for key in A:
    d[key] += 1
    #print(d)

Sum = 0
for i in d:
    n = d[i]
    Sum += (n * (n - 1)) // 2
    #print((n * (n - 1)) // 2)
    #print(d[A[i]],i)
    #print(d)

#print(Sum)

for i in range(N):
    n = d[A[i]]
    hoge = Sum - (n*(n-1))//2
    n -= 1
    hoge += (n*(n-1))//2
    print(hoge)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
Q = int(input())

R = 0

for i in range(Q):
    Query = str(input())
    if len(Query) == 1:
        R = (R+1)%2
    else:
        T,F,C = map(str,Query.split())

        if (R + int(F) ) % 2 == 1:
            S.insert(0,C)
        else:
            S.append(C)

if R == 1:
    S = S[::-1]

for i in range(len(S)):
    print(S[i],end="")

Fixed submission:
from collections import deque

S = list(str(input()))
Q = int(input())

d = deque(S)
R = 0

for i in range(Q):
    Query = str(input())
    if len(Query) == 1:
        R = (R+1)%2
    else:
        T,F,C = map(str,Query.split())

        if (R + int(F)) % 2 == 1:
            d.appendleft(C)
        else:
            d.append(C)

if R == 1:
    d.reverse()

for i in range(len(d)):
    print(d[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
Q = int(input())

for i in range(Q):
    Query = str(input())
    if len(Query) == 1:
        S = S[::-1]
    else:
        T,F,C = map(str,Query.split())

        if F == "1":
            S.insert(0,C)
        else:
            S.append(C)

for i in range(len(S)):
    print(S[i],end="")

Fixed submission:
from collections import deque

S = list(str(input()))
Q = int(input())

d = deque(S)
R = 0

for i in range(Q):
    Query = str(input())
    if len(Query) == 1:
        R = (R+1)%2
    else:
        T,F,C = map(str,Query.split())

        if (R + int(F)) % 2 == 1:
            d.appendleft(C)
        else:
            d.append(C)

if R == 1:
    d.reverse()

for i in range(len(d)):
    print(d[i],end="")
Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
a = [0] * M
b = [0] * M
for i in range(M):
    a[i], b[i] = map(int, input().split())

for i in range(10**N):
    for j in range(M):
        Number = str(i)

        

        if str(Number[a[j] - 1]) != str(b[j]) or len(str(i)) != N:
            break

        if j == M - 1:
            print(i)
            sys.exit()
            
print(-1)

Fixed submission:
import sys

N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())


for i in range(1000):
    S = str(i)

    if len(S) != N:
        continue

    for j in range(M):
        if int(S[s[j]-1]) != c[j]:
            break
        if j == M-1:
            print(S)
            sys.exit()

    if M == 0:
        print(S)
        sys.exit()

print("-1")
Buggy python submission (verdict: Runtime Error):
N,R = map(int, input().split())

if N >= 10:
    print(R)
else:
    print(R + (100*(10-K)))
    

Fixed submission:
N,R = map(int, input().split())

if N >= 10:
    print(R)
else:
    print(R + (100*(10-N)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
S = [str(input()) for _ in range(N)]

d = defaultdict(int)
for key in S:
    d[key] += 1
    
dl = sorted(d.items(), key=lambda x: x[0], reverse=False)

for i in range(len(dl)):
  if dl[i][1] == max(d.values()):
    print(dl[i][0])

Fixed submission:
from collections import defaultdict

N = int(input())
S = [str(input()) for _ in range(N)]

d = defaultdict(int)
for key in S:
    d[key] += 1
    
dl = sorted(d.items(), key=lambda x: x[0], reverse=False)
Max = max(d.values())

for i in range(len(dl)):
  if dl[i][1] == Max:
    print(dl[i][0])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
S = [str(input()) for _ in range(N)]

d = defaultdict(int)
for key in S:
    d[key] += 1
    
hoge = []

for key in d.keys():
  if d[key] == max(d.values()):
    hoge.append(key)

hoge.sort()
for i in range(len(hoge)):
	print(hoge[i])

Fixed submission:
from collections import defaultdict

N = int(input())
S = [str(input()) for _ in range(N)]

d = defaultdict(int)
for key in S:
    d[key] += 1
    
dl = sorted(d.items(), key=lambda x: x[0], reverse=False)
Max = max(d.values())

for i in range(len(dl)):
  if dl[i][1] == Max:
    print(dl[i][0])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))


def Com_kai(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 ** 6
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)


A.sort()

Max_Sum = 0
Min_Sum = 0
Mod = 1000000007

for i in range(N):
    Min_Sum = (Min_Sum + (A[i] * Com_kai(N - (i + 1), K - 1, Mod)) % Mod) % Mod
    Max_Sum = (Max_Sum + (A[i] * Com_kai(i, K - 1, Mod)) % Mod) % Mod

print((Max_Sum - Min_Sum + Mod) % Mod)


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


def Com_kai(n, r, mod):
    if (r < 0 or r > n or n < 0):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 6
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)

A.sort()

Max_Sum = 0
Min_Sum = 0
Mod = 1000000007

for i in range(n):
    Min_Sum = (Min_Sum + (A[i] * Com_kai(n - (i + 1), K - 1, Mod)) % Mod) % Mod
    Max_Sum = (Max_Sum + (A[i] * Com_kai(i, K - 1, Mod)) % Mod) % Mod


print((Max_Sum - Min_Sum + Mod) % Mod)

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


def Kaijo():
    Max = 510000
    Mod = 1000000007

    table = [0] * Max

    table[0] = 1
    table[1] = 1
    for i in range(2, Max):
        table[i] = table[i - 1] * i % Mod

    return table


def Com_kai(n, r, table):
    Mod = 1000000007

    if n < 0 or r < 0:
        return 0
    else:
        return (table[n] // ((table[n - r] * table[r]) % Mod)) % Mod


Table = Kaijo()

A.sort()

Max_Sum = 0
Min_Sum = 0
Mod = 1000000007

for i in range(N):
    Min_Sum = (Min_Sum + A[i] * Com_kai(N - (i + 1), K - 1, Table))%Mod
    Max_Sum = (Max_SumA[i] * Com_kai(i, K - 1, Table))%Mod

print((Max_Sum - Min_Sum +Mod)%Mod)

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


def Com_kai(n, r, mod):
    if (r < 0 or r > n or n < 0):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 6
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)

A.sort()

Max_Sum = 0
Min_Sum = 0
Mod = 1000000007

for i in range(n):
    Min_Sum = (Min_Sum + (A[i] * Com_kai(n - (i + 1), K - 1, Mod)) % Mod) % Mod
    Max_Sum = (Max_Sum + (A[i] * Com_kai(i, K - 1, Mod)) % Mod) % Mod


print((Max_Sum - Min_Sum + Mod) % Mod)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = list(map(int, input().split()))

Sum = 0
mod = (10 ** 9) + 7

for i in range(int(math.log2(max(A))) + 1):
    Sum_1 = 0
    for j in range(N):
        #print(i, j)
        if ((A[j] >> i) & 1):
            Sum_1 += 1

    Sum_0 = N - Sum_1

    Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
    # print(Sum_0,Sum_1)

print(Sum)


Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))

Sum = 0
mod = (10 ** 9) + 7

for i in range(len(bin(max(A)))-2):
    Sum_1 = 0
    for j in range(N):
        #print(i, j)
        if ((A[j] >> i) & 1):
            Sum_1 += 1

    Sum_0 = N - Sum_1

    Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
    # print(Sum_0,Sum_1)

print(Sum)

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

Sum = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        Sum = (Sum + ((A[i] ^ A[j]) % ((10 ** 9) + 7))) % ((10 ** 9) + 7)

print(Sum)


Fixed submission:
import math

N = int(input())
A = list(map(int, input().split()))

Sum = 0
mod = (10 ** 9) + 7

for i in range(len(bin(max(A)))-2):
    Sum_1 = 0
    for j in range(N):
        #print(i, j)
        if ((A[j] >> i) & 1):
            Sum_1 += 1

    Sum_0 = N - Sum_1

    Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
    # print(Sum_0,Sum_1)

print(Sum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

import itertools
import numpy as np
import math

np.sqrt(x)

p = list(itertools.permutations(range(N)))

Sum_N = 0

for i in range(len(p)):

    Sum = 0

    for j in range(N - 1):
        Sum += np.sqrt((x[p[i][j]] - x[p[i][j + 1]]) ** 2 + (y[p[i][j]] - y[p[i][j + 1]]) ** 2)

    Sum_N += Sum

print(Sum_N / len(p))



Fixed submission:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

import itertools
import numpy as np
import math

p = list(itertools.permutations(range(N)))

Sum_N = 0

for i in range(len(p)):

    Sum = 0

    for j in range(N - 1):
        Sum += math.sqrt((x[p[i][j]] - x[p[i][j + 1]]) ** 2 + (y[p[i][j]] - y[p[i][j + 1]]) ** 2)

    Sum_N += Sum

print(Sum_N / len(p))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(M):
    A[A.index(max(A))] //= 2

print(sum(A))

Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:int(x)*(-1), input().split()))

heapq.heapify(A)

for i in range(M):
    x = heapq.heappop(A) * -1
    x //= 2
    heapq.heappush(A, x*(-1))

print(sum(A)*(-1))
Buggy python submission (verdict: Runtime Error):
S = str(input())
T = str(input())

Sum = 0

for i in range(S):
    if S[i] == T[i]:
        Sum += 1
        
print(Sum)

Fixed submission:
S = str(input())
T = str(input())

Sum = 0

for i in range(len(S)):
    if S[i] == T[i]:
        Sum += 1
        
print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        Sum += math.factorial(hoge) // (math.factorial(hoge - 2) * math.factorial(2))
        hoge = 1

print(Sum)

Fixed submission:
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        #Sum += math.factorial(hoge) // (math.factorial(hoge - 2) * math.factorial(2))
        Sum += hoge*(hoge-1)//2
        hoge = 1

print(Sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = str(input())

Sum = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        S1 = sorted(S[i])
        S2 = sorted(S[j])
        
        for k in range(10):
            if S1[k] != S2[k]:
                break
            if k == 9:
                Sum += 1

print(Sum)

Fixed submission:
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        #Sum += math.factorial(hoge) // (math.factorial(hoge - 2) * math.factorial(2))
        Sum += hoge*(hoge-1)//2
        hoge = 1

print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
a = list(map(int, input().split()))


for i in range(1,N):

    b = [-1]*N
    c = a[:]

    b[0] = c[0]
    c[0] = -1

    b[1] = c[i]
    c[1] = -1

    for j in range(2,N):
        if b[j-2]^b[j-1] in c:
            n = c.index(b[j-2]^b[j-1])
            b[j] = c[n]
            c[n] = -1
        else:
            break

        if j == N-1:
            print("Yes")
            sys.exit()

print("No")

Fixed submission:
import sys

N = int(input())
a = list(map(int, input().split()))

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    elif a[i] != l and a[i] != m and n == -1 :
        n = a[i]
    elif a[i] != l and a[i] != m and a[i] != n and o == -1:
        print("No")
        sys.exit()

if (m == -1 and n == -1) and l^l == l and a.count(l) == N:
    print("Yes")
elif n == -1 and a.count(l)+a.count(m) == N and ( (a.count(l)*2==a.count(m) and l^m==m) or (a.count(l)==a.count(m)*2 and l^m == l)):
    print("Yes")
elif a.count(l)+a.count(m)+a.count(n) == N and a.count(l) == a.count(m) and a.count(m) == a.count(n) and l^m==n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

min = 2*1000000000

for i in range(L,R):
    for j in range(i+1,R+1):
        if min > ((i % 2019) * (j % 2019))%2019:
            min = ((i % 2019) * (j % 2019))%2019

print(min)

Fixed submission:
L, R = map(int, input().split())

min = 2*1000000000

if R - L > 2019:
  R = L + 2019

for i in range(L,R):
    for j in range(i+1,R+1):
        if min > ((i % 2019) * (j % 2019))%2019:
            min = ((i % 2019) * (j % 2019))%2019

print(min)
Buggy python submission (verdict: Runtime Error):
S = input().split()

Flag = True

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
  Flag = False
  
if Flag == False:
  print("Bad")
else:
  print("Good")

Fixed submission:
S = int(input())

Flag = True

if (S//1000) == ((S%1000)//100) or ((S%1000)//100) == ((S%100)//10) or ((S%100)//10) == ((S%10)//1):
  Flag = False
  
if Flag == False:
  print("Bad")
else:
  print("Good")

Buggy python submission (verdict: Runtime Error):
S = input().sprit()

Flag = True

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
  Flag = False
  
if Flag == False:
  print("Bad")
else:
  print("Good")

Fixed submission:
S = int(input())

Flag = True

if (S//1000) == ((S%1000)//100) or ((S%1000)//100) == ((S%100)//10) or ((S%100)//10) == ((S%10)//1):
  Flag = False
  
if Flag == False:
  print("Bad")
else:
  print("Good")
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())

Sum = 0

for i in range(A,B+1):
  if (i%C)!=0 and (i%D)!=0:
  	Sum += 1    

print(Sum)

Fixed submission:
import fractions

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

Min = (C * D) // fractions.gcd(C, D)

Sum_A = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//(Min))
Sum_B = B - (B//C + B//D - B//(Min))
Sum = Sum_B - Sum_A

print(Sum)
Buggy python submission (verdict: Runtime Error):

dp = [1000000000] * N

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            if dp[i + j] > abs(h[i + j] - h[i]) + dp[i]:
                dp[i + j] = abs(h[i + j] - h[i]) + dp[i]
        else:
            break

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            if dp[i + j] > abs(h[i + j] - h[i]) + dp[i]:
                dp[i + j] = abs(h[i + j] - h[i]) + dp[i]
        else:
            break

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            if dp[i + j] > abs(h[i + j] - h[i]) + dp[i]:
                dp[i + j] = abs(h[i + j] - h[i]) + dp[i]
        else:
            break

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

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

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            if dp[i + j] > abs(h[i + j] - h[i]) + dp[i]:
                dp[i + j] = abs(h[i + j] - h[i]) + dp[i]
        else:
            break

print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp_v = [0] * (W+1)

for i in range(N):
    for j in (reversed(range(W+1))):
        if (j == 0 or dp_v[j] != 0) and j+w[i] <= W and dp_v[j+w[i]] < dp_v[j] + v[i]:
            dp_v[j+w[i]] = dp_v[j] + v[i]
            
max = 0        
for i in range(W+1):
    if max < dp_v[i]:
        max = dp_v[i]

print(max)


Fixed submission:
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
sum_v = 0
for i in range(N):
    w[i], v[i] = map(int, input().split())
    sum_v += v[i]

DP = [0] * (sum_v+1)

for i in range(N):
    for j in (reversed(range(sum_v))):
        if j == 0 or DP[j] != 0:
            if DP[j + v[i]] > DP[j] + w[i] or DP[j + v[i]] == 0:
                DP[j + v[i]] = DP[j] + w[i]
                

for j in (reversed(range(sum_v+1))):
    if DP[j] != 0 and DP[j] <= W:
        print(j)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

A = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

for i in range(len(B)):
    H -= B[i]
    Sum += 1
    if H <= 0:
        break
        
while H > 0:
    H -= A
    Sum += 1
    

print(Sum)

Fixed submission:
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

A = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

for i in range(len(B)):
    H -= B[i]
    Sum += 1
    if H <= 0:
        break

if H > 0:
    Sum += int((H-1)//A)+1


print(Sum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

rank = [0]*9

for i in range(N):😌
    if a[i] < 400:
        rank[0] += 1
    elif a[i] < 800:
        rank[1] += 1
    elif a[i] < 1200:
        rank[2] += 1
    elif a[i] < 1600:
        rank[3] += 1
    elif a[i] < 2000:
        rank[4] += 1
    elif a[i] < 2400:
        rank[5] += 1
    elif a[i] < 2800:
        rank[6] += 1
    elif a[i] < 3200:
        rank[7] += 1
    else:
        rank[8] += 1

sum = 0

for i in range(8):
    if rank[i] > 0:
        sum += 1

min = sum
max = sum + rank[8]

if min == 0:
  min = 1

print(min,max)

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

rank = [0]*9

for i in range(N):
    if a[i] < 400:
        rank[0] += 1
    elif a[i] < 800:
        rank[1] += 1
    elif a[i] < 1200:
        rank[2] += 1
    elif a[i] < 1600:
        rank[3] += 1
    elif a[i] < 2000:
        rank[4] += 1
    elif a[i] < 2400:
        rank[5] += 1
    elif a[i] < 2800:
        rank[6] += 1
    elif a[i] < 3200:
        rank[7] += 1
    else:
        rank[8] += 1

sum = 0

for i in range(8):
    if rank[i] > 0:
        sum += 1

min = sum
max = sum + rank[8]

if min == 0:
  min = 1

print(min,max)