Problem:


Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
min_index = a_list.index(1)
import math
print(math.ceil((len(a_list) - 1) / (k - 1)))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a=list(map(int, input().split()))

cnt=0
for i in range(k,n+1,k-1):
    cnt+=1
else:
    if i<n:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

import math

print(math.ceil((n-1)/(k-1)))

Submission status: Accepted

Solution code:
import math


n, k = (int(x) for x in input().split())
xs = [int(x) for x in input().split()]
ans = math.ceil((n - k) / (k - 1)) + 1
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 1 + int(math.ceil((n - k) / (k - 1)))

print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))     
ans = (N - 1)// (K - 1)                  
if (N-1) % (K -1) == 0:                  
    print(ans)                           
else:                                    
    print(ans + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]

z=0
for i, ai in enumerate(a):
#    print(i,ai)
    if ai == 0:
        z=i
        break


        
p=(n-1+k-1-1)//(k-1)

print(p)

Submission status: Accepted

Solution code:
N,K = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
if (N-1) % (K-1)  ==  0:
	print((N-1) // (K-1))
else:
	print((N-1) // (K-1) +  1)

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
A = list(map(int ,input().split()))
print(math.ceil((n-k)/(k-1)+1))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
N2 = N-K
d = K-1
print((N2-1)//d +2)

Submission status: Accepted

Solution code:
# C

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

if (N-1) % (K-1) == 0:
    print((N-1) // (K-1))
else:
    print((N-1) // (K-1) + 1)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
print(math.ceil((N-1) / (K-1)))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    if n == k:
        return 1
    a = LI()
    r = (n - k + k - 2) // (k-1) + 1

    return r


print(main())

Submission status: Accepted

Solution code:
#!python
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    print(-(-(N - 1) // (K - 1)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
l = [int(x) for x in input().split()]

ans = 1 
n-=k 
while n>0:
    n-=(k-1)
    ans+=1 
print(ans)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = math.ceil((n - 1) / (k - 1))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
_ = input()

print((N - 1 + K - 2) // (K - 1))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

print((N-2)//(K-1)+1)

Submission status: Accepted

Solution code:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n,k=map(int,input().split())

vals=1
ans=0
while vals<n:
    vals+=k-1
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input()))

cnt=1
num=k
while num<n:
  num+=(k-1)
  cnt+=1
  
print(cnt)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input()))

cnt=1
num=3
while num<n:
  num+=2
  cnt+=1
  
print(cnt)

Submission status: Runtime Error

Solution code:
index = a.index(1)
cnt = 0

if (n==k):
    print(1)
else:
    if index <= (k - 1):
        cnt += 1
        i = k - 1
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1
    elif index >= (n - k):
        cnt += 1
        i = n - k
        while i >= 1:
            i -= (k-1)
            cnt += 1
    else:
        i = index
        while i >= 1:
            i -= (k-1)
            cnt += 1

        i = index
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1

    print(cnt)

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
if n == 1:
    if m == 1:
      print(1)
    else:
      print(m - 2)
elif m == 1:
  print(n - 2)
else: 
  print((N-2)*(M-2))

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if x % (k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(n-k)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+2)

Submission status: Runtime Error

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

mini = min(A)
idx = N + 1
mid = N / 2

for i, a in enumerate(A):
  if a == mini and abs(idx - mid) > abs(i - mid):
    idx = i

ans = i // (K - 1)
rem = i % (K - 1)
if rem:
  ans += 1
  if (N - i - 1 - (K - rem)) // (K - 1) > 0:
    ans += (N - i - 1 - (K - rem)) // (K - 1)
    if (N - i - 1 - (K - rem)) % (K - 1) != 0:
      ans += 1
else:
  if (N - i - 1) // (K - 1) > 0:
    ans += (N - i - 1) // (K - 1)
    if (N - i - 1) % (K - 1) != 0::
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am >= m - 1:
    count -= 1
print(count)

Submission status: Runtime Error

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

one = A.index(1)

ans = None
if one == 0 or one == N-1:
  ans = -(-(N-1) // (K-1))
else:
  left = -(-i // (K-1))
  right = -(-(N - i - 1 - (i % (K-1)))//(K-1))
  ans = left + right
  
print(ans)

Submission status: Runtime Error

Solution code:
import math
k, m = map(int, input().split())
x = math.ceil((k-1)/(n-1))

print(x)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k == n:
    print(1)
else:
    print(1+math.ceil((n-k)/(k-1)))

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=list(map(int,input().split()))
    cnt=0
    if n<=k:
        print(1)
    else:

        while True:
            n-=k
            n+=1
            cnt+=1
            if n<=k:
                cnt+=1
                print(cnt)
                break
reso

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
h.sort()

ans=9999999999999
for i in range(n-k+1):
    ans=min(ans,h[i+k-1]-h[i])
print(ans)

Submission status: Runtime Error

Solution code:
N,M=map(int,input())
print(N//2)

Submission status: Runtime Error

Solution code:
print(int(open(0)[0][0])//2)

Submission status: Runtime Error

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

if A.index(1) + N - A.index(1) - 1 < K:
    print(1)
else:
    print(int(np.ceil(A.index(1)/(K-1))+np.ceil((N - A.index(1) - 1)/(K-1))))

Submission status: Runtime Error

Solution code:
import sys
import os

def file_input():
    f = open('ARC099/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,K=map(int, input().split())
    A_li=list(map(int, input().split()))
    # print(min)

    print(-(-N//(K-1))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,K = map(int,input().split())
arrA = list(map(int,input().split()))
ans = ceil((N-1)/(K-1))
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
print(math.ceil((N-1)/(K-1)))

Submission status: Runtime Error

Solution code:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    lena = len(a)
    if (lena-k) % (k-1) == 0:
        print(((lena-k) // (k-1))+1)
    else :
        print(((lena-k) // (k-1))+2)
 resolve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def ceil(x,y):
  return (x-1)//y+1

n,k = map(int,input().split())
A = list(map(int,input().split()))
for i,ai in enumerate(A):
  if ai == 1:
    ind1 = i
print(ceil(n-1,k-1)))

Submission status: Runtime Error

Solution code:
n, k = map(int, input())

if (n-1)%(k-1)==0:
    print((n-1)//(k-1))
else:
    print((n-1)//(k-1)+1)

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
a=[int(i) for in input().split()]
if n==k:
    print(1)
else:
    k-=1
    print((n+k-1)//k)

Submission status: Runtime Error

Solution code:
n,k,*_=open(0);print(((int(n)-2)//(int(k)-1))+1)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  if a[i]==1:
    x=i
    y=n-1-i
import math

print(math.ceil(n-1,k))

Submission status: Runtime Error

Solution code:
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)
        else:
            print(M-i)
            print(now-(M-i))
            break

Submission status: Runtime Error

Solution code:
import sys
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

if N == K:
    print(1)
    sys.exit(0)

minimum = min(A)
count = 0
for i in range(N-K+1):
    if A[i+K] == [minimum] * K:
        count += 0

ans = math.ceil(N/K) - count
print(ans)

Submission status: Runtime Error

Solution code:
import math

N,K=map(int, inp[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, inp[0].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき


if N==K:
    print(1)
else:
    print(math.ceil((N-1)/(K-1)))

Submission status: Runtime Error

Solution code:
import math

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

#print(A)
#print(A.index(min(A)))
m=min(A)
a=A.index(m)

i=a
tmp=0
while(i<N):
    while(A[i]==m):
        if(i>=N):
            break
        i+=1
    if(i>=N):
        break
    #for k in range(K-1):
        #A[i+k]=m
    tmp+=1
    i+=K-1

tmp+=math.ceil(a/(K-1))

print(tmp)

Submission status: Runtime Error

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
w = a.index(1)
if w<k or n-w-1<k:
  print( math.ceil((n-1)/(k-1)) )
else:
  print( math.seil((w)/(k-1)) + math.ceil((n-w-1)/(k-1)) )

Submission status: Runtime Error

Solution code:
n,k = map(int(),input().split())
print((n+k-3)/(k-1))

Submission status: Runtime Error

Solution code:
n,k = int(input().split())
print((n+k-3)/(k-1))

Submission status: Runtime Error

Solution code:
n,k = int(input().split)
print((n+k-3)/(k-1))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split(' '))
A=list(map(int,input.split(' ')))
count=0
sum=0
while sum<N:
	if count==0:
		sum+=K
	else:
		sum+=(K-1)
	count+=1
print(count)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=a.find(1)
ans=m//(k-1)+(n-m-1)//(k-1)
kk=m%(k-1)+(n-m-1)%(k-1)+1
ans+=1+(kk>k)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = input().split()
count = 0
if N = K:
    print(1)
else:
    count += 1
    rem = N-K
    add = 1 if (N-K)%(K-1) else 0
    count += (N-K)//(K-1) + add
    print(count)

Submission status: Runtime Error

Solution code:
def Ask(x):
    return sum(int(c) for c in str(x))

def Check(x, y):
    return x * Ask(y) > y * Ask(x)

k = int(input())
no = st = 1
for i in range(k):
    print(no)
    if (Check(no + st, no + st * 10)): st *= 10
    no += st

Submission status: Runtime Error

Solution code:
def Ask(x):
    ans = 0
    while (x):
        ans += x % 10
        x //= 10
    return ans

def Check(x, y):
    return x * Ask(y) > y * Ask(x)


k = int(input())
no = st = 1
while (k):
    k -= 1
    print(no)
    if (Check(no + st, no + st * 10)): st *= 10
    no += st

Submission status: Runtime Error

Solution code:
k = input()
n=1
if k =< 9:
    for cnt in range(1,k+1):
        print(cnt)
else:
    for cnt in range(1,10):
        print(cnt)
    for cnt in range(19,19+10*(k-9),10):
        print(cnt)

Submission status: Runtime Error

Solution code:



def n_snuke(n):
    return n /sum(map(int,str(n)))


# (100o+10x+y)/(o+x+y) > (100o+99)/(o+9+9)
#  100o*18+(10x+y)(o+18) > 100o(x+y) +99(o+x+y)


#
#1 - 10 , 19,29,39,49,59,69,79,89,99

#for i in range(1,1115):
#    print(i,n_snuke(i))


K = int(input())
tmp =0

tmp_list = []
for i in range(K*3):
    tmp = tmp+ 10**(len(str(tmp+1))-1)
    tmp_list.append(tmp)
    #print(tmp,n_snuke(tmp))
r_list = [tmp_list[-1]]
for i in reversed(range(len(tmp_list)-1)):
    if n_snuke(r_list[-1]) >= n_snuke(tmp_list[i]):
        r_list.append(tmp_list[i])

for i in reversed(r_list[-K:]):
    print(i)

Submission status: Runtime Error

Solution code:
from fractions import Fraction
from collections import Counter

K = input()
A = range(1, 10) + range(19, 100, 10)
N = K - len(A)
diff = 100
target = 19
count = 0

while N > 0:
    N -= 1
    A.append(A[-1]+diff)
    count += 1
    if count == target:
        diff *= 10
        target += 9
        count = 0

for i in xrange(K):
    print A[i]

Submission status: Runtime Error

Solution code:
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_list = []
min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 100)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        if min_sunuke_div >= sunuke_div:
            sunuke_list.append(i)
            min_sunuke_div = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    if min_sunuke_div >= sunuke_div:
        sunuke_list.append(i)
        min_sunuke_div = sunuke_div

sunuke_list.reverse()

for i in range(0, input_num):
    print(sunuke_list[i])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
print((n - 2) // (k - 2) + 1)

Submission status: Runtime Error

Solution code:
print(-(-(N-1)//(K-1)))

Submission status: Runtime Error

Solution code:
N = int(input())
a =[1,2,3,4,5,6,7,8,9]
for i in range(1,10000):
  b = 10**i - 1
  for j in range(1,10):
    a.append(b + j * 10 ** i)
  
for i in range(N):
  print(a[i])

Submission status: Runtime Error

Solution code:

K = int(input())
aaa = 1
ans_array = []

def sunuke(n):
    re = 0
    tmp = n
    while n:
        re += n % 10
        n = n//10
    re = tmp/re
    print(re)

def print_sunuke():
    global aaa
    num = aaa % 10
    if num == 0:
        aaa += 1
        print_sunuke()
        return
    nine = aaa // 10
    ans = str(num) + "9" * nine
    aaa += 1
    ans_array.append(int(ans))




for i in range(10000):

    print_sunuke()

ans_array.append(1899)
ans_array.append(2899)
ans_array.append(3899)
ans_array.append(4899)
ans_array.append(5899)
ans_array.append(6899)
ans_array.append(7899)
ans_array.append(8899)
ans_array.append(9899)
ans_array.append(18999)
ans_array.append(28999)
ans_array.append(38999)
ans_array.append(48999)
ans_array.append(58999)
ans_array.append(68999)
ans_array.append(78999)
ans_array.append(88999)
ans_array.append(98999)
ans_array.append(189999)
ans_array.append(289999)
ans_array.append(389999)
ans_array.append(489999)
ans_array.append(589999)
ans_array.append(689999)
ans_array.append(789999)
ans_array.append(889999)
ans_array.append(989999)
ans_array.append(1899999)
ans_array.append(2899999)
ans_array.append(3899999)
ans_array.append(4899999)
ans_array.append(5899999)
ans_array.append(6899999)
ans_array.append(7899999)
ans_array.append(8899999)
ans_array.append(9899999)

ans_array.append(18999999)
ans_array.append(28999999)
ans_array.append(38999999)
ans_array.append(48999999)
ans_array.append(58999999)
ans_array.append(68999999)
ans_array.append(78999999)
ans_array.append(88999999)
ans_array.append(98999999)

ans_array.append(189999999)
ans_array.append(289999999)
ans_array.append(389999999)
ans_array.append(489999999)
ans_array.append(589999999)
ans_array.append(689999999)
ans_array.append(789999999)
ans_array.append(889999999)
ans_array.append(989999999)
ans_array.append(1899999999)
ans_array.append(2899999999)
ans_array.append(3899999999)
ans_array.append(4899999999)
ans_array.append(5899999999)
ans_array.append(6899999999)
ans_array.append(7899999999)
ans_array.append(8899999999)
ans_array.append(9899999999)

ans_array.append(18999999999)
ans_array.append(28999999999)
ans_array.append(38999999999)
ans_array.append(48999999999)
ans_array.append(58999999999)
ans_array.append(68999999999)
ans_array.append(78999999999)
ans_array.append(88999999999)
ans_array.append(98999999999)


ans_array.sort()

for i in range(K):
    print(ans_array[i])

Submission status: Runtime Error

Solution code:
args = int(input().rstrip())

def snuke(number):
    temp = list(str(number))
    arr = [ int(t) for t in temp] 
    return sum(arr)

def find_snuke(args):
    result = []
    i = 1
    while len(result) < args:
        push = True
        for power in range(0,len(str(i))):
            if((i+10**power)/snuke(i+10**power))<(i/snuke(i)):
                push = False
                break
        if push:
            result.append(i)
        i=i+1
            
    return result

arr = find_snuke(args)
for a in arr:
   print(a)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
p = A.index(1)

if p+1<=K or N-p<=K:
    print(N//(K-1))
    exit(0)
if K%2==1:
    print(1+((p+1)-(K-1)//2)//(K-1) + (N-(p+(K-1)//2))//(K-1))
else:
    print(1+min(((p+1)-K//2-1)//(K-1) + (N-(p+K//2))//(K-1)),((p+1)-K//2)//(K-1) + (N-(p+K//2-1))//(K-1))

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
n = A.index(min(A))
n2 = N-1-n
a,b = divmod(n,K-1)
c,d = divmod(n2,K-1)
if b == d == 0:
    print(a+c)
elif b+d < K
    print(a+c+1)
else:
    print(a+c+2)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())

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

b = min(a)

lft = 0
rgt = 0
for i in range(len(a)):
    if a[i] == b:
        lft = i
        break

ret = 0
i = 0
for i in range(len(a)):
    if a[i] == b:
        continue
    flag = False
    for j in range(k - 1):
        if not i + j < n:
            break
        if a[i+j] == b:
            flag = True
        a[i+j] = b
    if flag:
        a[i+k-1] = b
    ret += 1

print(ret)