Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:24:31 2017

@author: Kanoh
"""
import numpy as np
N = int(raw_input())#標準入力
A = raw_input()#標準入力
A_split=A.split(" ")
A_int=np.zeros((N))

for i in range(int(N)):
    A_int[i]=int(A_split[i])

counter=0
checker=0
while 1 :
    for i in range(N):
        if((A_int[i]%2)!=1) and((A_int[i])>1):
            A_int[i]=A_int[i]/2
        else:
            checker=1
    if(checker==1):
        break
    else:
        counter=counter+1
    
print counter

Fixed submission:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:14:39 2017

@author: Kanoh
"""

#Placing Marbles
input_line1 = raw_input()#標準入力
total=0
counter=0
for i in range(len(input_line1)):
    if(int(input_line1[i])==1):
        counter=counter+1
        
print counter

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:24:31 2017

@author: Kanoh
"""
import numpy as np
N = int(raw_input())#標準入力
A = raw_input()#標準入力
A_split=A.split(" ")
A_int=np.zeros((N))

for i in range(int(N)):
    A_int[i]=int(A_split[i])

counter=0
checker=0
while 1 :
    for i in range(N):
        if(A_int[i]%2)!=1:
            A_int[i]=A_int[i]/2
        else:
            checker=1
    if(checker==1):
        break
    else:
        counter=counter+1
    
print counter

Fixed submission:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:14:39 2017

@author: Kanoh
"""

#Placing Marbles
input_line1 = raw_input()#標準入力
total=0
counter=0
for i in range(len(input_line1)):
    if(int(input_line1[i])==1):
        counter=counter+1
        
print counter
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])

    counter = 0
    for c in C:
        b_count = bisect.bisect_left(B, c)
        for b in B[0:b_count]:
            a_count = bisect.bisect_left(A, b)
            counter += a_count

    print(counter)

if __name__ == "__main__":
    main()


Fixed submission:
import bisect

def main():
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])

    counter = 0
    for b in B:
        a_count = bisect.bisect_left(A, b)
        c_count = N - bisect.bisect_right(C, b)
        counter += a_count*c_count
            

    print(counter)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W, K = map(int, input().split())
    grid = [list(map(int, list(input().strip()))) for _ in range(H)]

    white_count = sum(sum(x) for x in grid)

    # 折れる箇所全部で折った数が最大値
    ans = (H - 1) * (W - 1)

    # 横線で割るパターン全てについて縦線での降り方を考える
    for i in range(2 ** (H - 1)):

        # 横方向に割った後のチョコの状態を生成
        snap = 0
        board = [[grid[0]]]
        for j in range(H-1):
            if ((i >> j) & 1):
                board.append([grid[j + 1]])
                snap += 1
            else:
                board[-1].append(grid[j + 1])

        w_count_board = [[] for _ in board]
        for x in range(W):
            # 縦方向に折るかのフラグ
            snap_flag = False
            for y, hori in enumerate(board):
                # その位置までおらなかった場合のチョコの個数を生成
                w_choco = sum(row[x] for row in hori)
                w_count_board[y].append(w_choco)

                # 上限超えたらおる
                if sum(w_count_board[y]) > K:
                    snap_flag = True

            # フラグがたってたら、x -1 まではおるので無視
            # チョコの個数カウントをx始まりで更新
            if snap_flag:
                w_count_board = [[wcb[-1]] for wcb in w_count_board]
                snap += 1

        ans = min(ans, snap)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# 足し合わせしすぎてるのでTLE
import sys
input = sys.stdin.readline

def main():
    H, W, K = map(int, input().split())
    grid = [list(map(int, list(input().strip()))) for _ in range(H)]

    # 折れる箇所全部で折った数が最大値
    ans = (H - 1) * (W - 1)

    # 横線で割るパターン全てについて縦線での降り方を考える
    for i in range(2 ** (H - 1)):
        snap = 0

        hori_grid = [grid[0]]
        for j in range(H - 1):
            if ((i >> j) & 1):
                hori_grid.append(grid[j+1])
                snap += 1
            else:
                hori_grid[-1] = [a + b for a,b in zip(hori_grid[-1], grid[j+1])]

        wc_count = [hori_grid[y][0] for y in range(snap + 1)]

        # 最初の列で超えてる場合はスキップ
        if max(wc_count) > K:
            continue

        for x in range(1, W):
            now_wc_count = [hori_grid[y][x] for y in range(len(wc_count))]
            next_wc_count = [a+b for a,b in zip(wc_count, now_wc_count)]

            if max(next_wc_count) > K:
                snap += 1
                wc_count = now_wc_count
            else:
                wc_count = next_wc_count

        ans = min(ans, snap)

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

STEPS = [
    (0, 1),
    (1, 0)
]
BLACK = '#'
WHITE = '.'
CHECKED = 't'

def main():
    H, W = map(int, input().split())
    board = [list(input().strip()) for _ in range(H)]

    ans = float('INF')

    if board[0][0] == WHITE:
        que = deque([[0, 0, WHITE, 0]])
    else:
        que = deque([[0, 0, BLACK, 1]])


    while que:
        y, x, color, rev = que.popleft()

        for (i,j) in STEPS:
            ny, nx = y + i, x + j
            if ny >= H or nx >= W:
                continue

            n_rev = rev
            target = board[ny][nx]

            if color == WHITE and target == BLACK:
                n_rev += 1

            if ny == H -1 and nx == W - 1:
                ans = min(ans, n_rev)

            que.append([ny, nx, target, n_rev])

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

STEPS = [
    (0, 1),
    (1, 0)
]
BLACK = '#'
WHITE = '.'
CHECKED = 't'
INF = float('INF')

def main():
    H, W = map(int, input().split())
    board = [list(input().strip()) for _ in range(H)]
    scores = [[INF] * W for _ in range(H)]


    if board[0][0] == WHITE:
        scores[0][0] = 0
    else:
        scores[0][0] = 1

    que = deque([[0, 0, board[0][0]]])


    while que:
        y, x, color = que.popleft()
        score = scores[y][x]

        for (i,j) in STEPS:
            ny, nx = y + i, x + j
            if ny >= H or nx >= W:
                continue

            target = board[ny][nx]
            n_score = score

            if color == WHITE and target == BLACK:
                n_score += 1

            if n_score < scores[ny][nx]:
                scores[ny][nx] = n_score
                que.append([ny, nx, target])

    print(scores[H-1][W-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    S = input().strip()
    Q = int(input())

    s = S
    for _ in range(Q):
        query = input().split()

        if query[0] == "1":
            s = s[::-1]
        elif query[0] == "2":
            F, C = query[1], query[2]
            if F == "1":
                s = C + s
            elif F == "2":
                s = s + C

    print(s)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    S = list(input().strip())
    Q = int(input())

    d = deque(S)
    mode = True

    for _ in range(Q):
        query = input().split()

        if query[0] == "1":
            mode = not mode
        elif query[0] == "2":
            F, C = query[1], query[2]
            if F == "1":
                if mode:
                    d.appendleft(C)
                else:
                    d.append(C)
            elif F == "2":
                if mode:
                    d.append(C)
                else:
                    d.appendleft(C)

    s = list(d)
    if not mode:
        s = s[::-1]

    print(''.join(s))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    
    
    ans_start = 0
    tmp = sum(p[:K])
    ms = tmp

    for i in range(K, N):
        tmp = tmp + p[i] - p[i - K]
        if tmp > ms:
            ans_start = i - (K - 1)
            ms = tmp
    
    target = p[ans_start:ans_start + K]
    
    
    ans = 0
    for t in target:
        l = [x for x in range(1, t + 1)]
        ans += sum(l) / t

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    
    pi_table = [0] + [(i * (i + 1) // 2) / i for i in range(1,1001)]
    
    pe = [None] * N
    for i in range(N):
        pe[i] = pi_table[p[i]]
    
    tmp = sum(pe[:K])
    ans = tmp
    for i in range(K, N):
        tmp += (pe[i] - pe[i - K])
        ans = max(ans, tmp)
        
    print(ans)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))

    ep = [0] * N
    for i, x in enumerate(p):
        t = [x for x in range(1, x + 1)]
        e = sum(t) / x
        ep[i] = e

    tmp = sum(ep[:K])
    ans = tmp

    for i in range(K, N):
        tmp = tmp + ep[i] - ep[i - K]
        ans = max(tmp, ans)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    
    pi_table = [0] + [(i * (i + 1) // 2) / i for i in range(1,1001)]
    
    pe = [None] * N
    for i in range(N):
        pe[i] = pi_table[p[i]]
    
    tmp = sum(pe[:K])
    ans = tmp
    for i in range(K, N):
        tmp += (pe[i] - pe[i - K])
        ans = max(ans, tmp)
        
    print(ans)



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
H,A = map(int,input.split())
q,mod= divmod(H,A)

if mod >0:
  q +=1
  
print(q)

Fixed submission:
H,A = map(int,input().split())

q,mod= divmod(H,A)

if mod > 0:
  q += 1
  
print(int(q))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readlin
INF = float('INF')


def main():
    H, N = map(int, input().split())
    skills = [None] * N
    max_a = 0
    for i in range(N):
        a, b = map(int, input().split())
        if a > max_a:
            max_a = a
        skills[i] = (a, b)

    # dpの配列準備
    # インデックス→体力、中身→その体力を削るための最小MP
    dp = [INF] * (H + max_a + 1111
    dp[0]=0


    # 各体力を削る最小MPをDPで更新していく
    for i in range(H):
        # そのHPをちょうど削る攻撃がない場合はそれ以降の行動を計算できないので飛ばす1
        if dp[i] == INF:
            continue

        # そうでない場合は、次の攻撃をシミュレーション
        for a, b in skills:
            # 攻撃した場合の累計消費MPを算出
            mp=dp[i] + b
            # その攻撃をした場合に削れる体力に割り当てられている消費MPと比較
            # より少ない消費MPで削れることがわかった場合は更新
            if mp < dp[i + a]:
                dp[i + a]=mp

    # 更新が終わったので、倒せるダメージのうち、累計消費MPが一番少ないものを出力
    print(min(dp[H:]))


 if __name__ == "__main__":
     main()


Fixed submission:
import sys
input = sys.stdin.readline
INF = float('INF')


def main():
    H, N = map(int, input().split())
    skills = [None] * N
    max_a = 0
    for i in range(N):
        a, b = map(int, input().split())
        if a > max_a:
            max_a = a
        skills[i] = (a, b)

    # dpの配列準備
    # インデックス→体力、中身→その体力を削るための最小MP
    dp = [INF] * (H + max_a + 1)
    dp[0] = 0

    # 各体力を削る最小MPをDPで更新していく
    for i in range(H):
        # そのHPをちょうど削る攻撃がない場合はそれ以降の行動を計算できないので飛ばす1
        if dp[i] == INF:
            continue

        # そうでない場合は、次の攻撃をシミュレーション
        for a, b in skills:
            # 攻撃した場合の累計消費MPを算出
            mp = dp[i] + b
            # その攻撃をした場合に削れる体力に割り当てられている消費MPと比較
            # より少ない消費MPで削れることがわかった場合は更新
            if mp < dp[i + a]:
                dp[i + a] = mp

    # 更新が終わったので、倒せるダメージのうち、累計消費MPが一番少ないものを出力
    print(min(dp[H:]))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 1
for i in range(1,N):
  if P[i] < min(P[:i]):
    ans += 1
  if P[i] == 1:
    break
    
print(ans)


Fixed submission:
def main():
  N = int(input())
  P = list(map(int, input().split()))

  ans = 1
  min_val = P[0]
  for i in range(1,N):
    if P[i] < min_val:
      ans += 1
      min_val = P[i]
    if min_val == 1:
      break

  print(ans)

if __name__ == "__main__":
	main()
Buggy python submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline

A,B = (int(x) for x in input().split())


print(A*B//math.gcd(A,B))

Fixed submission:
import fractions
import sys
input = sys.stdin.readline

A,B = (int(x) for x in input().split())


print(A*B//fractions.gcd(A,B))
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N%2:
    print(0)
else:
    t = N//10
    f = N//50
    
    ans = t+f+(N//200) - t//f
    print(ans)


Fixed submission:
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    
    # 奇数は終わる
    if N%2:
        print('0')
        quit()
    
    def calc(x,ans):
        fl = 2*(5**x)
        if N >= fl:
            ans += N//fl
            return calc(x+1,ans)
        else:
            return ans
    
    print(calc(1, 0))
        
    
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())

if N%2:
    print(0)
else:
    t = N//10
    f = N//50
    
    ans = t+f+(N//200) - t//f
    print(ans)


Fixed submission:
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    
    # 奇数は終わる
    if N%2:
        print('0')
        quit()
    
    def calc(x,ans):
        fl = 2*(5**x)
        if N >= fl:
            ans += N//fl
            return calc(x+1,ans)
        else:
            return ans
    
    print(calc(1, 0))
        
    
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())

if N%2:
    print(0)
else:

    ans = (N//10) + (N//50)+ (N//200) - ((N//10)//(N//50))
    print(ans)



Fixed submission:
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    
    # 奇数は終わる
    if N%2:
        print('0')
        quit()
    
    def calc(x,ans):
        fl = 2*(5**x)
        if N >= fl:
            ans += N//fl
            return calc(x+1,ans)
        else:
            return ans
    
    print(calc(1, 0))
        
    
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cleft = max((a - b), (b - a))
            cright = a + b
            left_index = bisect.bisect_left(L[bi+1:],cleft)
            right_index = bisect.bisect_left(L[bi+1:],cright)
            if left_index == right_index:
                if L[bi+1+left_index] < cright:
                    ans += 1
            else:
                ans += (right_index - left_index)
    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cmax = a + b
            m_index = bisect.bisect_left(L,cmax)
            ans += max(m_index - bi - 1, 0)

    print(ans)
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    used = 0
    while used < M:
        ma = max(A)
        idx = A.index(ma)
        A[idx] = A[idx] // 2
        used += 1
    print(sum(A))


    # TLE
    # for _ in range(M):
    #     A.sort()
    #     A[-1] = A[-1] // 2
    # print(sum(A))


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import heapq 
input = sys.stdin.readline

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

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

    print(sum(A) * -1)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))


    for _ in range(M):
        A.sort()
        A[-1] = A[-1] // 2

    print(sum(A))


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import heapq 
input = sys.stdin.readline

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

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

    print(sum(A) * -1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N, K = map(int, input().split())
    S = list(input())

    streak = [[S[0], 1]]
    for i in range(1,N):
        if S[i] != S[i-1]:
            streak.append([S[i],1])
        else:
            streak[-1][1] += 1

    # print(streak)
    idx = streak.index(max(streak, key=lambda x:x[1]))

    for _ in range(K):
        if len(streak) == 1:
            break

        if len(streak) >= 3:
            if idx == 0 or idx == len(streak) - 1:
                idx = streak.index(max(streak[1:-1], key=lambda x:x[1]))

        new_direct = 'L' if streak[idx][0] == 'R' else 'R'
        max_streak = streak[idx][1]
        max_streak += streak[idx-1][1] if idx > 0 else 0
        max_streak += streak[idx+1][1] if idx + 1 < len(streak) else 0

        new_streak = []
        new_idx = 0

        if idx - 1 > 0:
            new_streak.extend(streak[:idx - 1])

        new_streak.append([new_direct,max_streak])
        new_idx = len(new_streak) -1

        if idx + 2 < len(streak):
            new_streak.extend(streak[idx + 2:])

        streak = new_streak
        idx = new_idx
        # print(streak, idx)

    ans = sum(map(lambda x: x[1] - 1, streak))
    print(ans)


if __name__ == "__main__":
    main()


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

def main():
    N, K = map(int, input().split())
    S = list(input())

    rev = False
    rev_count = 0
    for i in range(1,N):
        if S[i] == S[i-1]:
            rev = False
        else:
            if not rev and rev_count < K:
                rev_count += 1
                rev = True

            if rev:
                S[i] = 'L' if S[i] == 'R' else 'R'


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

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if x+y+z == S:
                    count += 1
                    
    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z >= 0 and z <= K:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                # for make turple (x,y,z)
                # and calculate Sum of turple
                if sum((x,y,z)) == S:
                    count += 1
                    
    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z >= 0 and z <= K:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                # for make turple (x,y,z)
                # and calculate Sum of turple
                if sum((x,y,z)) == S:
                    count += 1
                    
    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    K,S = (int(x) for x in input().split())

    count = 0

    for x in range(K+1):
        for y in range(K+1):
            z = S - (x + y)
            if z >= 0 and z <= K:
                count += 1

    print(count)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
n = n[::-1]
n += '0'
cnt = 0
dp = [[float('inf')] * 2 for _ in range(len(n) + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(len(n)):
    a = int(n[i])
    dp[i + 1][0] = min(dp[i][0] + a, dp[i][1] + 10 - a)
    dp[i + 1][1] = min(dp[i][0] + a + 1, dp[i][1] + 10 - (a + 1))
print(min(dp[len(n)][0], dp[len(n)][1]))

Fixed submission:
n = input()
n = n[::-1]
n += '0'
cnt = 0
tmp = 0
for i in range(len(n)):
    a = int(n[i])
    a += tmp
    if a == 5:
        cnt += a
        if int(n[i + 1]) >= 5:
            tmp = 1
        else:
            tmp = 0
    elif a < 5:
        cnt += a
        tmp = 0
    else:
        cnt += 10 - a
        tmp = 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(x) for x in input().split()]
cnt = n
for i in range(n):
    for j in range(i):
        if p[i] <= p[j]:
            continue
        cnt -= 1
        break
print(cnt)

Fixed submission:
n = int(input())
p = [int(x) for x in input().split()]
cnt = 0
tmp = float('inf')
for i in range(n):
    if p[i] < tmp:
        tmp = p[i]
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(x) for x in input().split())
h = [0] + [int(x) for x in input().split()]
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[n])

Fixed submission:
n, k = (int(x) for x in input().split())
h = [0] + [int(x) for x in input().split()]
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[n])