Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
li=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  li[i].append(li[i][0]-li[i][1])
  li[i].append(li[i][0]+li[i][1])

from operator import itemgetter
li=sorted(li, key=itemgetter(3))

ans=0
now=0

for i in range(n-1):
  if li[now][3]>=li[i+1][3]: #今調査してるやつが、次のやつを覆ってしまってる場合
    ans+=1
    now=i
  elif li[now][3]>li[i+1][2]:
    ans+=1
  else:
    now+=i

print(n-ans)

Fixed submission:
n=int(input())
li=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  li[i].append(li[i][0]-li[i][1])
  li[i].append(li[i][0]+li[i][1])

from operator import itemgetter
li=sorted(li, key=itemgetter(3))

ans=0
now=0

for i in range(n-1):
  if li[now][3]>=li[i+1][3]: #今調査してるやつが、次のやつを覆ってしまってる場合
    ans+=1
    now=i+1
  elif li[now][3]>li[i+1][2]:
    ans+=1
  else:
    now=i+1

print(n-ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

sa=float("inf")

for i in range(n-1):
  wa1=sum(a[0:1+i])
  wa2=sum(a[1+i:])
  temp=abs(wa1-wa2)
  sa=min(sa,temp)
print(sa)

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

sa=float("inf")


wa1=0
wa2=sum(a)

for i in range(n-1):
  wa1+=a[i]
  wa2-=a[i]
  temp=abs(wa1-wa2)
  sa=min(sa,temp)
print(sa)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n=int(input())
d=list(map(int,input().split()))

if d[0]!=0:
  print(0)
  exit()
  
kyori=[] #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)

for i in range(0,maxd+1):
  kyori.append(d.count(i))

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)

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

n=int(input())
d=list(map(int,input().split()))

if d[0]!=0:
  print(0)
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)

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

if d[0]!=0:
  print(0)
  exit()

#1番目以外で1との距離が0はありえんのでそれは消す
for i in range(n):
  if i!=0:
    if d[i]==0:
      print(0)
      exit()

kyori=[] #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)

for i in range(1,maxd+1):
  kyori.append(d.count(i))

#print(kyori)

ans=1
for i in range(maxd-1):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353

print(ans)

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

n=int(input())
d=list(map(int,input().split()))

if d[0]!=0:
  print(0)
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)

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

if d[0]!=0:
  print(0)
  exit()

#1番目以外で1との距離が0はありえんのでそれは消す
for i in range(n):
  if i!=0:
    if d[i]==0:
      print(0)
      exit()

kyori=[] #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)

for i in range(1,maxd+1):
  kyori.append(d.count(i))

#print(kyori)

ans=1
for i in range(maxd-1):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353

print(ans)

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

n=int(input())
d=list(map(int,input().split()))

if d[0]!=0:
  print(0)
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))

kaisuulist=[]
nowmax=0

for i in range(1,n):
  if h[i-1]<h[i]:
    kaisuulist.append(i-nowmax-1)
    nowmax=i

#print(kaisuulist)
print(max(max(kaisuulist),n-1-nowmax))

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

kaisuulist=[]
nowmax=0

for i in range(1,n):
  if h[i-1]<h[i]:
    kaisuulist.append(i-nowmax-1)
    nowmax=i

#print(kaisuulist)
if not kaisuulist:
  print(n-1-nowmax)
else:
  print(max(max(kaisuulist),n-1-nowmax))
Buggy python submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  temp=copy.deepcopy(a)
  temp.pop(i)
  print(max(temp))

Fixed submission:
a=int(input())
print(3*a**2)
Buggy python submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(a)!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy python submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy python submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(nums))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  temp=copy.deepcopy(a)
  temp.pop(i)
  print(max(temp))

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  temp=copy.deepcopy(a)
  temp.pop(i)
  print(max(temp))

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

#箱の状態を記録しておく配列
box=[0]*n


for i in range(1,n+1):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
from operator import mul
from functools import reduce
mod=10**9+7

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(1,k+1):
  print(cmb(n-k+1,i)*cmb(k-1,i-1)%mod)

Fixed submission:
n,k=map(int,input().split())
from operator import mul
from functools import reduce
mod=10**9+7

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(1,k+1):
  if n-k+1<i:
    print(0)
  else:
    print(cmb(n-k+1,i)*cmb(k-1,i-1)%mod)
Buggy python submission (verdict: Runtime Error):
p,q,r=map(int,input().split())
print(p+q+r-max[p,q,r])

Fixed submission:
p,q,r=map(int,input().split())
print(p+q+r-max([p,q,r]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if i+1 in a:
    nlist.append(0)
  else:
    nlist.append((nlist[i-1]+nlist[i-2])%1000000007)
print(nlist[n-1]%1000000007)

Fixed submission:
import sys

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]
analist=[0]*n
#O(N^2)を防ぐために、穴判定用配列作る
for i in range(m):
  analist[a[i]-1]="ana"

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if analist[i]=="ana":
    nlist.append(0)
  else:
    nlist.append((nlist[i-1]+nlist[i-2])%1000000007)
print(nlist[n-1]%1000000007)

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

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if i+1 in a:
    nlist.append(0)
  else:
    nlist.append((nlist[i-1]+nlist[i-2])%1000000007)
print(nlist[n-1]%1000000007)

Fixed submission:
import sys

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]
analist=[0]*n
#O(N^2)を防ぐために、穴判定用配列作る
for i in range(m):
  analist[a[i]-1]="ana"

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if analist[i]=="ana":
    nlist.append(0)
  else:
    nlist.append((nlist[i-1]+nlist[i-2])%1000000007)
print(nlist[n-1]%1000000007)

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

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if i+1 in a:
    nlist.append(0)
  else:
    nlist.append(nlist[i-1]+nlist[i-2])
print(nlist[n-1]%1000000007)

Fixed submission:
import sys

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
nlist=[]
analist=[0]*n
#O(N^2)を防ぐために、穴判定用配列作る
for i in range(m):
  analist[a[i]-1]="ana"

for i in range(1,m):
  if a[i]-a[i-1]==1:
    print(0)
    sys.exit()
if 1 in a:
  nlist.append(0)
  nlist.append(1)
elif 2 in a:
  nlist.append(1)
  nlist.append(0)
else:
  nlist.append(1)
  nlist.append(2)

for i in range(2,n):
  if analist[i]=="ana":
    nlist.append(0)
  else:
    nlist.append((nlist[i-1]+nlist[i-2])%1000000007)
print(nlist[n-1]%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=0
for i in range(m):
  l,r=map(int,input().split())
  temp=range(l,r+1)
  if i==0:
    s=set(temp)
  else:
    s&=set(temp)

print(len(s))


Fixed submission:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
maxl=0
minr=1000000
for i in range(m):
  maxl=max(li[i][0],maxl)
  minr=min(minr, li[i][1])
if maxl<=minr:
  print(minr-maxl+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
s=0
for i in range(m):
  l=li[i][0]
  r=li[i][1]
  temp=range(l,r+1)
  if i==0:
    s=set(temp)
  else:
    s&=set(temp)

print(len(s))

Fixed submission:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
maxl=0
minr=1000000
for i in range(m):
  maxl=max(li[i][0],maxl)
  minr=min(minr, li[i][1])
if maxl<=minr:
  print(minr-maxl+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=0
for i in range(m):
  l,r=map(int,input().split())
  temp=range(l,r+1)
  if i==0:
    s=set(temp)
  else:
    s&=set(temp)

print(len(s))

Fixed submission:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
maxl=0
minr=1000000
for i in range(m):
  maxl=max(li[i][0],maxl)
  minr=min(minr, li[i][1])
if maxl<=minr:
  print(minr-maxl+1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
a,b,t=int(input())
print((t//a)*b)

Fixed submission:
a,b,t=map(int,input().split())
print((t//a)*b)
Buggy python submission (verdict: Runtime Error):
li=list(map(int,input().split("\n")))
k=li[5]
if li[1]-li[0]>5 or li[2]-li[1]>5 or li[3]-li[2]>5 or li[4]-li[3]>5:
  print(":(")
else:
  print("Yay!")

Fixed submission:
li=[int(input()) for i in range(5)]
k=int(input())
if li[1]-li[0]>k or li[2]-li[1]>k or li[3]-li[2]>k or li[4]-li[3]>k or li[4]-li[0]>k:
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
if input=="A":
  print("T")
elif input=="T":
  print("A")
elif input=="C":
  print("G")
else input=="G":
  print("C")

Fixed submission:
s=input()
if s=="A":
  print("T")
elif s=="T":
  print("A")
elif s=="C":
  print("G")
else:
  print("C")
Buggy python submission (verdict: Runtime Error):
s=input()

temp=0
templi=[]
for i in range(len(s)):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    temp+=1
  else:
    templi.append(temp)
    temp=0
print(max(templi))

Fixed submission:
s=input()

temp=0
templi=[0]
for i in range(len(s)):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    temp+=1
  else:
    templi.append(temp)
    temp=0
templi.append(temp)

print(max(templi))
Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
retsu=[]
for i in range(len(s)):
  if s[i]=="A" and s[i+1]=="C":
    retsu.append(i+1)
#print(retsu)
#ここまではあってる

for i in range(q):
  temp=set(retsu)
  l,r=map(int,input().split())
  hani=set(range(l,r))
  #print(hani)
  hani&=temp

  print(len(hani))

Fixed submission:
n,q=map(int,input().split())
s=input()
hantei=[0]
for i in range(1,len(s)):
  if s[i-1]=="A" and s[i]=="C":
    hantei.append(hantei[i-1]+1)
  else:
    hantei.append(hantei[i-1])
#print(hantei)
#ここまではあってる

for i in range(q):
  l,r=map(int,input().split())
  print(hantei[r-1]-hantei[l-1])
Buggy python submission (verdict: Runtime Error):
 提出

Fixed submission:
a,b=map(int,input().split())
print(a+b if b%a==0 else b-a)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
gr=[0]*(n+1) #各グループの出現回数をメモする配列

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)

A=[] #大きい方からK個以内の配列で、2個以上あるやつの2番目以降のやつの大きさを記録

for i in range(k):
  if gr[li[i][0]]>=1:
    A.append(li[i][1])
  gr[li[i][0]]+=1

A.reverse()

B=[] #既に同じグループが登場してしまってない子の大きさを記録
for i in range(k,n):
  if gr[li[i][0]]==0:
    B.append(li[i][1])
  gr[li[i][0]]+=1

#現時点での種類数とポイントを測定
sp=set()
ans=0
for i in range(k):
  ans+=li[i][1]
  sp.add(li[i][0])
sp=len(sp)
ans+=sp*sp

koukan=[] #その交換で、累積でどの程度増減するか
zouka=0
for a,b in zip(A,B):
  zouka+=(sp+1)**2-sp**2-(a-b)
  #print(a,b,sp,zouka)
  koukan.append(zouka)
  sp+=1

#koukanの中で最大の増加を探して、ansに+する。
# print(A,B)
# print(koukan)
ans+=max(0,max(koukan))

print(ans)

Fixed submission:
n,k=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
gr=[0]*(n+1) #各グループの出現回数をメモする配列

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)

A=[] #大きい方からK個以内の配列で、2個以上あるやつの2番目以降のやつの大きさを記録

for i in range(k):
  if gr[li[i][0]]>=1:
    A.append(li[i][1])
  gr[li[i][0]]+=1

A.reverse()

B=[] #既に同じグループが登場してしまってない子の大きさを記録
for i in range(k,n):
  if gr[li[i][0]]==0:
    B.append(li[i][1])
  gr[li[i][0]]+=1

#現時点での種類数とポイントを測定
sp=set()
ans=0
for i in range(k):
  ans+=li[i][1]
  sp.add(li[i][0])
sp=len(sp)
ans+=sp*sp

koukan=[] #その交換で、累積でどの程度増減するか
zouka=0
for a,b in zip(A,B):
  zouka+=(sp+1)**2-sp**2-(a-b)
  #print(a,b,sp,zouka)
  koukan.append(zouka)
  sp+=1

#koukanの中で最大の増加を探して、ansに+する。
# print(A,B)
# print(koukan)
if koukan:
  ans+=max(0,max(koukan))

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(n-2):
  way1=dp[i]+abs(h[i+2]-h[i])
  way2=dp[i+1]+abs(h[i+2]-h[i+1])
  dp.append(min(way1,way2))
#print(dp)
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
if n>k-1:
  for i in range(k):
    dp.append(abs(h[i+1]-h[0]))
else:
  print(abs(h[n-1]-h[0]))
  exit()


#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
if n>k-1:
  for i in range(k):
    dp.append(abs(h[i+1]-h[0]))
else:
  print(abs(h[n-1]-h[0]))
  exit()


#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
if n>k-1:
  for i in range(k):
    dp.append(abs(h[i+1]-h[0]))
else:
  print(abs(h[n-1]-h[0]))
  exit()


#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())

li=set()

for i in range(len(s)):
  for j in range(i,len(s)):
    li.add(s[i:j+1])

li=list(li)
li.sort()

print(li[k-1])

Fixed submission:
s=input()
k=int(input())

li=set()

for p in range(5):
  for i in range(len(s)-p):
    li.add(s[i:i+1+p])
li=list(li)
li.sort()
#print(li)
print(li[k-1])
Buggy python submission (verdict: Runtime Error):
n,h=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(n)]

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][1]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))

Fixed submission:
n,h=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(n)]

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][0]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
hyou=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    while temp<syoki:
      temp+=hyou[j][2]
    syoki=temp+hyou[j][0]
  print(syoki)
print(0)

Fixed submission:
import math
n=int(input())
hyou=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    if temp<syoki:
      syoki=temp+math.ceil((syoki-temp)/hyou[j][2])*hyou[j][2]+hyou[j][0]
    else:
      syoki=temp+hyou[j][0]
  print(syoki)
print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
hyou=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    while temp<syoki:
      temp+=hyou[j][2]
    syoki=temp+hyou[j][0]
  print(syoki)
print(0)

Fixed submission:
import math
n=int(input())
hyou=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    if temp<syoki:
      syoki=temp+math.ceil((syoki-temp)/hyou[j][2])*hyou[j][2]+hyou[j][0]
    else:
      syoki=temp+hyou[j][0]
  print(syoki)
print(0)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
r=p[:]

ans=0
for i in range(n):
  if p[i]==i+1:
    ans+=1
    p[i]=r[i+1]
    p[i+1]=r[i]
    
print(ans)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
r=p[:]

ans=0
for i in range(n):
  if p[i]==i+1:
    ans+=1
    if i!=n-1:
      p[i]=r[i+1]
      p[i+1]=r[i]
      
print(ans)
Buggy python submission (verdict: Runtime Error):
import string
alp=string.ascii_lowercase

s=input()
for i in range(28):
  temp=alp[i]
  if temp not in s:
    print(temp)
    exit()
print("None")

Fixed submission:
import string
alp=string.ascii_lowercase

s=input()
for i in range(26):
  temp=alp[i]
  if temp not in s:
    print(temp)
    exit()
print("None")