Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
data = []
for _ in range(h):
    data.append( list(input()) )

next_data = []
# 横列処理
for d in data:
    if "#" in d:
        next_data.append( d )

next_next_data = []
origin_v_data = []
# 縦列処理
for i in range( len(next_data[0]) ):
    # 縦配列生成
    v_data = []
    for j in range( len(next_data) ):
        v_data.append( next_data[j][i] )

    # 配列チェック
    if "#" in v_data:
        origin_v_data.append( v_data )

ans_data = []
for i in range( len(origin_v_data[0]) ):
    join_data = []
    for j in range( len(origin_v_data) ):
        join_data.append( origin_v_data[i][j] )
    ans_data.append( join_data )

# 標準出力
for a in ans_data:
    print("".join(a))


Fixed submission:
h, w = map(int, input().split())
data = []
for _ in range(h):
    data.append( list(input()) )

next_data = []
# 横列処理
for d in data:
    if "#" in d:
        next_data.append( d )

next_next_data = []
origin_v_data = []
# 縦列処理
for i in range( len(next_data[0]) ):
    # 縦配列生成
    v_data = []
    for j in range( len(next_data) ):
        v_data.append( next_data[j][i] )

    # 配列チェック
    if "#" in v_data:
        origin_v_data.append( v_data )

ans_data = []
for i in range( len(origin_v_data[0]) ):
    join_data = []
    for j in range( len(origin_v_data) ):
        join_data.append( origin_v_data[j][i] )
    ans_data.append( join_data )

# 標準出力
for a in ans_data:
    print("".join(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n > 999:
    print("ABD)
else:
    print("ABC")


Fixed submission:
n = int(input())
if n > 999:
    print("ABD")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split)
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")


Fixed submission:
a, b = map(int, input().split())
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
if int(input()) * int(input()) % 2 == 0:
  print("Even")
else:
  print("Odd")


Fixed submission:
a, b = map(int, input().split())
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
# 累積和

import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

# ナイーブな実装
def calc(l, r):
    ans = 0
    # 処理系
    for i in range(l, r+1):
        if is_prime(i) and is_prime((i+1)//2):
            ans += 1
    return ans

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(calc(l, r))


Fixed submission:
# 累積和

import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

# 2017数 かどうかのマップ
data = [0] * 10**5
# 処理系
for i in range(1, 10**5 + 1):
    if is_prime(i) and is_prime((i+1)//2):
        data[i-1] = 1

cumulative_sum = [0] * 10**5
cumulative_sum[0] = data[0]
for i in range(10**5 - 1):
    cumulative_sum[i+1] += cumulative_sum[i] + data[i+1]

# s_0 = 0 となるように
cumulative_sum = [0] + cumulative_sum

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cumulative_sum[r] - cumulative_sum[l-1])
    # print(sum(data[l:r+1]))
Buggy python submission (verdict: Runtime Error):
a, s, c = map(int, input().split())
print(a[0] + s[0] + c[0])


Fixed submission:
a, s, c = map(str, input().split())
print(a[0] + s[0] + c[0])
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

res = []
cnt = 0
for i in range(len(S)-len(T)):
  s = S[i:i+len(T)]
  cnt = 0
  for j,k in zip(s,T):
    if j != k:
      cnt += 1
  res.append(cnt)

print(min(res))

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

z = len(S)-len(T)

res = []
cnt = 0
if z == 0:
  for a,b in zip(S,T):
    if a != b:
      cnt += 1
  print(cnt)
  exit();
else:
  for i in range(z):
    s = S[i:i+len(T)]
    cnt = 0
    for j,k in zip(s,T):
      if j != k:
        cnt += 1
    res.append(cnt)
  print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]

d = 10**9+7
s = 0

for i in range(N):
  for j in range(i+1,N):
    s += A[i]*A[j] % d
    
print(s % d)

Fixed submission:
from itertools import accumulate

N = int(input())

A = [int(x) for x in input().split()]

B = list(accumulate(A))

d = 10**9+7
s = 0

for i in range(N):
    s += (A[i]*(B[-1]-B[i])) % d
    
print(s % d)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul
from collections import deque

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

A = [int(i) for i in input().split()]

B = deque(A[:K])

C = reduce(mul,B)

for i in range(K,N):
  B.popleft()
  B.append(A[i])
  D = reduce(mul,B)
  if C < D:
    print('Yes')
  else:
    print('No')
  C = D

Fixed submission:
from collections import deque

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

A = [int(i) for i in input().split()]

B = deque(A[:K])

for i in range(K,N):
  if B.popleft() < A[i]:
    print('Yes')
  else:
    print('No')    
    
  B.append(A[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for x in range(1,N+1):
  cnt = 0
  for i in range(1,100):
    for j in range(1,100):
      for k in range(1,100):
        if (i+j+k)**2-(i*j+i*k+j*k) == x:
          cnt += 1
  
  print(cnt)

Fixed submission:
N = int(input())

ans = [0]*10050

for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = (i+j+k)**2-(i*j+i*k+j*k)
      if v < len(ans):
        ans[v] += 1
  
for x in range(1,N+1):
  print(ans[x])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]

Q = int(input())

for _ in range(Q):
  B,C = map(int,input().split())
  for i,v in enumerate(A):
    if v == B:
      A[i] = C
  
  print(sum(A))

Fixed submission:
from collections import Counter

N = int(input())

A = [int(x) for x in input().split()]
T = sum(A)
Z = Counter(A)

Q = int(input())

for _ in range(Q):
  B,C = map(int,input().split())
  x = Z[B]
  y = Z[C]
  Z.pop(B,0)
  Z[C] = x+y
  T = T-(B*x)+(C*x)
  print(T)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul

N = int(input())

A = [int(i) for i in input().split()]

if 0 in A:
  print(0)
  exit();
  
B = reduce(mul,A)

print(B if B <= 10**18 else '-1')

Fixed submission:
N = int(input())

A = sorted([int(i) for i in input().split()],reverse=True)

if 0 in A:
  print(0)
  exit();

x = A[0]  
for i in A[1:]:
  x *= i
  if x > 10**18:
    print('-1')
    exit();
    
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())

total = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      total += math.gcd(math.gcd(a,b),c)

print(total)  

Fixed submission:
from math import gcd
 
K = int(input())
 
total = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      total += gcd(gcd(a,b),c)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

i = list(range(1,K+1))

j = itertools.product(i,i,i)

total = 0
for x in j:
  total += gcd(*x)
   
print(total)  
 

Fixed submission:
from math import gcd
 
K = int(input())
 
total = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      total += gcd(gcd(a,b),c)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

total = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      total += gcd(a,b,c)
      
print(total)  

Fixed submission:
from math import gcd
 
K = int(input())
 
total = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      total += gcd(gcd(a,b),c)

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

for i in range(N):
  z = c[A[i]] - 1
  ans = 0
  for k,v in c.items():
    if v > 1:
      ans += (v*(v-1))//2
      
  print(ans-z, sep="\n")

Fixed submission:
import collections

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

ans = 0
for v in c.values():
  if v > 1:
    ans += (v*(v-1))//2

for i in range(N):
  z = c[A[i]] - 1   
  print(ans-z, sep="\n")

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

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

ans = 0
for i in range(N):
  for k,v in c.items():      
    if v > 1 and k != A[i]:
      ans += (v*(v-1))//2
    elif v > 1 and k == A[i]:
      ans += ((v-1)*(v-2))//2
    else:
      continue
  print(ans, sep="\n");ans=0

Fixed submission:
import collections

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

ans = 0
for v in c.values():
  if v > 1:
    ans += (v*(v-1))//2

for i in range(N):
  z = c[A[i]] - 1   
  print(ans-z, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

Q = int(input())

for i in range(Q):
  *T, = map(str,input().split())
  if int(T[0]) == 1:
    S = S[::-1]
  elif int(T[1]) == 1:
    S = T[2]+S
  else:
    S = S+T[2]
    
print(S) 

Fixed submission:
from collections import deque

S = deque(input())

Q = int(input())

c = False
for i in range(Q):
  *T, = map(str,input().split())
  if len(T) == 1:
    c = not c  
  elif (int(T[1]) == 1 and not c) or (int(T[1]) == 2 and c):
    S.appendleft(T[2])
  else:
    S.append(T[2])

print("".join(S) if not c else "".join(list(reversed(S))))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

res = 0
for j in range(N-K+1):
  ans = 0
  for i in range(K):
    ans += p[j+i]
  res = max(res,ans)
  
print(res)  

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

res = 0
for j in range(N-K+1):
  ans = sum([x for x in p[j:j+K]])
  res = max(res,ans)
  
print(res) 

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]


res = 0
for j in range(N-K+1):
  res = max(res,sum(p[j:j+K]))
  
print(res) 

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)

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

p = [int(x) for x in input().split()]

res = 0
for j in range(N-K+1):
  q = p[j:j+K]
  ans = 0
  for i in q:
    ans += ((1+i)*i/2)/i
  res = max(res,ans)
  
print(res) 

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

P = [int(x) for x in input().split()]

cnt = 0
for i in range(N)[::-1]:
  for j in range(N)[i::-1]:
    if P[i] > P[j]:
      break
    elif j == 0:
      cnt += 1

print(cnt)  

Fixed submission:
N = int(input())

P = [int(x) for x in input().split()]

cnt = 1
m = P[0]
for i in P[1:]:
  if i < m:
    m = i
    cnt += 1

print(cnt)

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

P = [int(x) for x in input().split()]

Q = sorted(P,key=P.index,reverse=True)

cnt = 1
for i in range(1,N):
  if Q[i-1] < min(Q[i:]):
    cnt += 1  

print(cnt) 

Fixed submission:
N = int(input())

P = [int(x) for x in input().split()]

cnt = 1
m = P[0]
for i in P[1:]:
  if i < m:
    m = i
    cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

if M == 0:
  print(0,0)
  exit();

x = {}  
for _ in range(M):
  a,w = map(str,input().split())
  x.setdefault(int(a),[]).append(w)  
  
ac = wa = 0  
for k in x.keys():
  for j in x[k]:
    if 'AC' not in x[k]:
      break
    elif j == 'AC':
      ac += 1
      break
    elif j =='WA':
      wa += 1
      
print(ac,wa)      

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

if M == 0:
  print(0,0)
  exit();

x = {}  
for _ in range(M):
  a,w = map(str,input().split())
  x.setdefault(int(a),[]).append(w)
  
ac = at = wa = wt = 0  
for k,v in x.items():
  for j in v:
    if j == 'AC':
      at += 1
      break
    elif j =='WA':
      wt += 1
  if at == 0:
    wt = 0
  else:
    ac += at
    wa += wt
    at = 0
    wt = 0
      
print(ac,wa)

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

if M == 0:
  print(0,0)
  exit();

x = {}  
for _ in range(M):
  a,w = map(str,input().split())
  x.setdefault(int(a),[]).append(w) 

ac = wa = 0  
for k,v in x.items():
  for j in x[k]:
    if 'AC' not in v:
      break
    elif j == 'AC':
      ac += 1
      break
    elif j =='WA':
      wa += 1
  
print(ac,wa)

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

if M == 0:
  print(0,0)
  exit();

x = {}  
for _ in range(M):
  a,w = map(str,input().split())
  x.setdefault(int(a),[]).append(w)
  
ac = at = wa = wt = 0  
for k,v in x.items():
  for j in v:
    if j == 'AC':
      at += 1
      break
    elif j =='WA':
      wt += 1
  if at == 0:
    wt = 0
  else:
    ac += at
    wa += wt
    at = 0
    wt = 0
      
print(ac,wa)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

H = list(map(int,input().split()))

cnt = 0
t = 0

for l in range(N):
  r = l + 1
  while r < N and H[r-1] >= H[r]:
    cnt += 1
    r += 1
  t = max(t,cnt)
  cnt = 0

print(t)

Fixed submission:
N = int(input())

H = list(map(int,input().split()))

H = H[::-1]

l = 0
cnt = 0
t = 0

while l < N - 1:
  if H[l] <= H[l+1]:
    cnt += 1
  else:
    t = max(t,cnt)
    cnt = 0
  l += 1

print(max(t,cnt))

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

H = list(map(int,input().split()))

cnt = 0
t = []

for l in range(N):
  r = l + 1
  while r < N and H[r-1] >= H[r]:
    cnt += 1
    r += 1
  t.append(cnt)
  cnt = 0

print(max(t))

  

Fixed submission:
N = int(input())

H = list(map(int,input().split()))

H = H[::-1]

l = 0
cnt = 0
t = 0

while l < N - 1:
  if H[l] <= H[l+1]:
    cnt += 1
  else:
    t = max(t,cnt)
    cnt = 0
  l += 1

print(max(t,cnt))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())

s = [Counter(input()) for _ in range(N)]
  
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
      if s[i] == s[j]:
        cnt += 1
        
print(cnt)

Fixed submission:
import math
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0  
for i in c.values():
  if i >= 2:
    cnt += combinations_count(i, 2)

print(cnt)

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

N = int(input())

s = [Counter(input()) for _ in range(N)]
  
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
      if s[i] == s[j]:
        cnt += 1
        
print(cnt)

Fixed submission:
import math
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0  
for i in c.values():
  if i >= 2:
    cnt += combinations_count(i, 2)

print(cnt)

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

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))   

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

print(cnt)

Fixed submission:
import math
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0  
for i in c.values():
  if i >= 2:
    cnt += combinations_count(i, 2)

print(cnt)

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

s = []
for _ in range(N):
  t = sorted(list(str(input())))
  s.append(''.join(t))          

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

print(cnt)

Fixed submission:
import math
from collections import Counter

N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))
  
c = Counter(s) 

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0  
for i in c.values():
  if i >= 2:
    cnt += combinations_count(i, 2)

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

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

for i in range(N):
  print(max([elem for idx,elem in enumerate(A) if idx != i])) 

Fixed submission:
N = int(input())

A = [(i,int(input())) for i in range(N)]

A.sort(key=lambda x :x[1],reverse=True)

for i in range(N):
  if A[0][0] != i:
    print(A[0][1])
  else:
    print(A[1][1])
Buggy python submission (verdict: Runtime Error):
L,R = map(int,input().split())

if L == 0 or L%2019 == 0 or R%2019 == 0:
  print(0)
  exit()
elif R - L == 1:
  print(L*R)
  exit()

a = list(range(L,R+1))

N = len(a)
r = 0
total = []

for l in range(N):
  r = l + 1
  while r < N:
    total.append((a[l]*a[r])%2019)
    r += 1
  if l == r:
    l += 1
    
print(min(total))


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

total = 2019

if R-L >= 2019:
  print(0)
  exit()

for l in range(L,R):
  for r in range(L+1,R+1):
    if l*r%2019 == 0:
      print(0)
      exit()
    else:
      total = min(total,l*r%2019)
    
print(total)

Buggy python submission (verdict: Runtime Error):
L,R = map(int,input().split())

a = list(range(L,R+1))

N = len(a)
r = 0
total = []

for l in range(N):
  r = l + 1
  while r < N:
    total.append((a[l]*a[r])%2019)
    r += 1
  if l == r:
    l += 1
    
print(min(total))

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

total = 2019

if R-L >= 2019:
  print(0)
  exit()

for l in range(L,R):
  for r in range(L+1,R+1):
    if l*r%2019 == 0:
      print(0)
      exit()
    else:
      total = min(total,l*r%2019)
    
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())

x = []  
for _ in range(M):
  L,R = map(int,input().split())
  x.extend(list(range(L,R+1)))
    
c = collections.Counter(x)

print(len([i[0] for i in c.items() if i[1] == M]))

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

L = []
R = []
for _ in range(M):
  x,y = map(int,input().split())
  L.append(x)
  R.append(y)

if min(R) >= max(L):
  print(min(R)-max(L)+1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())

S = input()

for _ in range(Q):
  l,r = map(int,input().split())
  print(S[l-1:r].count('AC'))

Fixed submission:
N,Q = map(int,input().split())
 
S = [x for x in input()]

cnt =[0]
for a,b in zip(S,S[1:]):
  if a == 'A' and b == 'C':
    cnt.append(cnt[-1] + 1)    
  else:
    cnt.append(cnt[-1])

    
for _ in range(Q):
  l,r = map(int,input().split())
  print(cnt[r-1]-cnt[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[0]*100010
h[:N]=[int(x) for x in input().split()]

dp=[float('inf')]*100100
dp[0] = 0
for i in range(N+1):
  for j in range(1,K+1):
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i] - h[i+j]))

print(dp[N-1])

Fixed submission:
N,K=map(int,input().split())
h=[int(x) for x in input().split()]

dp=[float('inf')]*N
dp[0] = 0

for i, hi in enumerate(h):
  if i > 0:
    x = max(0,i-K)
    dp[i]=min([dpj + abs(hi-hj) for dpj, hj in zip(dp[x:i], h[x:i])])
     
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[int(x) for x in input().split()]
h.extend([0]*(N+K))
dp=[float('inf')]*(len(h))
dp[0] = 0
for i in range(N):
  for j in range(1,K+1):
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i] - h[i+j]))
     
print(dp[N-1])

Fixed submission:
N,K=map(int,input().split())
h=[int(x) for x in input().split()]

dp=[float('inf')]*N
dp[0] = 0

for i, hi in enumerate(h):
  if i > 0:
    x = max(0,i-K)
    dp[i]=min([dpj + abs(hi-hj) for dpj, hj in zip(dp[x:i], h[x:i])])
     
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[int(x) for x in input().split()]
h.extend([0]*(N+1000))
dp=[float('inf')]*(len(h))
dp[0] = 0
for i in range(N):
  for j in range(1,K+1):
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i] - h[i+j]))
     
print(dp[N-1])

Fixed submission:
N,K=map(int,input().split())
h=[int(x) for x in input().split()]

dp=[float('inf')]*N
dp[0] = 0

for i, hi in enumerate(h):
  if i > 0:
    x = max(0,i-K)
    dp[i]=min([dpj + abs(hi-hj) for dpj, hj in zip(dp[x:i], h[x:i])])
     
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())

if (N%7)%4 == 0 or (N%4)%7 == 0
  print('Yes')
else:
  print('No')

Fixed submission:
import itertools

N = int(input())

if N%4 ==0 or N%7 ==0:
  print('Yes')
  exit()
else:
  i = itertools.product(range(N//4+1),range(N//7+1))
  

c = [a for a in i]
for i in c:
  if i[0]*4+i[1]*7 == N:
    print('Yes')
    exit()
  else:
    continue

print('No')
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())

if N == K:
  print(1)
  exit()
elif N % (K-1) != 0:
  print(N//(k-1)+1)
else:   
  print(N//(K-1))

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

for g in range(1,N):
  if K+(K-1)*(g-1) >= N:
    print(g)
    exit()
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

z = []
for i in range(1,N):
  x = S[:i]
  y = S[i:]
  if set(x) & set(y):
    z.append(len(set(x)&set(y)))
  else:
    continue

print(max(z))

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

z = []
for i in range(1,N):
  x = S[:i]
  y = S[i:]
  if set(x) & set(y):
    z.append(len(set(x)&set(y)))
  else:
    continue

print(max(z) if len(z) != 0 else 0)