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: Runtime Error

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

if n <= k:
  print(1)
else:
  print(n//k+1

Submission status: Runtime Error

Solution code:
N = int(input())
dsum = 0
tmp = N
while tmp > 0:
  dsum += tmp % 10
  tmp /=  10
  tmp  = int(tmp)
if N % dsum != 0:
  print ("No")
else:
  print ("Yes")

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
count = 0
for i in range(int(N / (K - 1))):
    if i * (K - 1) + K <= N - 1:
        m = min(A[i * (K - 1):i * (K - 1) + K])
        for j in range(i * (K - 1), i * (K - 1) + K):
            A[j] = m
        count += 1
    else:
        m = min(A[N - K:N])
        for j in range(N - K, N):
            A[j] = m
    print(A)
count += 1
A.reverse()
a = 0
for i in range(1, N):
    if A[i] != A[0]:
        a = i
        break
if a != 0:
    count += int((N - a) / (K - 1))
print(count)

Submission status: Runtime Error

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

left = len(A[0:min_in])

right = len(A[min_in+1:])
#print(left,  right)
if N ==K:
    ans = 1
    
else:
    if (min(left, right) + 1) < K:
        ans += 1
        tuyoi = len(A-K)
        
        ans += tuyoi//K
        
        if tuyoi % K !=0:
            ans +=1
    
    else:
        if left != 0:
            ans += left//(K-1)
            
            if left%(K-1) != 0:
                ans += 1
        
        if right != 0:
            ans += right//(K-1)
            
            if right%(K-1) != 0:
                ans += 1
print(ans)

Submission status: Runtime Error

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

left = len(A[0:min_in])

right = len(A[min_in+1:])

if N ==K:
    ans = 0
    
else:
    if (min(left, right) + 1) < K:
        ans += 1
        tuyoi = len(A-K)
        
        ans += tuyoi//K
        
        if tuyoi % K !=0:
            ans +=1
    
    else:
        if left != 0:
            ans += left//(K-1)
            
            if left%(K-1) != 0:
                ans += 1
        
        if right != 0:
            ans += right//(K-1)
            
            if right%(K-1) != 0:
                ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
def kiriage(a, b): #切り上げ
    return (a + b - 1) // b

print(kiriage((N - 1, K - 1)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
li = list(map(int, input().split()))
#左から最小値を探していく
#最小値を見つけたら、左側を最小値にしていく
#ないなら(１は１個しかない！！)最小値エリアの右端の値から最小値にしていく

mn = 1#min値を取得
mnix = li.index(1)
mnix0 =mnix #min値の最初のindex
sum = 0 #操作の回数
# li
f=[False]
#左側をまず1へ
while(1):
    if f[0]==True:
        break
    if (mnix+1-k) >0:
        for i in range(mnix+1-k,mnix+1):
            li[i] = mn
        sum +=1
        mnix=li.index(1)
    else:
        for i in range(0,k):
            li[i] = mn
        f[0]=True
        sum +=1

# li
#次に右側を1へ
if (mnix0+1-k) >0:
    #mnix0が右端
    migi = mnix0
if (mnix0+1-k) <=0:
    #k-1が右端
    migi = k-1
# migi

    
f[0]=False
if li[n-1]==1:
    f[0]=True
while(1):
    if f[0]==True:
        break
    if (migi+2)>(n-1):
        for i in range(migi,n):
            li[i] = mn
        sum +=1
        f[0]=True
    else:
        for i in range(migi,migi+k):
            li[i] = mn
        sum +=1
        migi = migi+k-1

 
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
K = int(input())

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

i = A.index(1)

lt = i // (K - 1)
rt = (N - i) // (K - 1)

print(lt + rt)

Submission status: Runtime Error

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

amin = min(a)

if len(myarr) == myarr.count(amin) :
    print("0")
else :
    if K == 1 : 
        print(N - myarr.count(amin))
    else :
        if (N - a.count(amin)) % (K - 1) == 0 :
            print((N - a.count(amin)) // (K - 1))
        else :
            print((N - a.count(amin)) // (K - 1) + 1)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(K,min(A[:K]))
    print(A)
    del A[0:K]
print(sum)

Submission status: Runtime Error

Solution code:
from math import ceil
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
from math import ceil
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
from math import ceil
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
from math import ceil
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
def solve(array, k):
    if len(array) <= 1:
        return 0
    if array[0] == array[1]:
        return solve(array[1:], k)
    if len(array) <= k:
        return 1
    return 1 + solve([min(array[:k])] + array[k:], k)

if __name__ == "__main__":
    n, k = map(int, input().split())
    array = [int(s) for s in input().split()]
    print(solve(array, k))

Submission status: Runtime Error

Solution code:
import math


n, k = input().split(' ')
n, k = int(n), int(k)
a = [int(n) for n in input().split(' ')]
print(int(math.ceil(n / (k - 1)))

Submission status: Runtime Error

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

if n==k:
	print(1)
elif n//(k-1)=1:
	print(2)
else:
	print(n//(k-1))

Submission status: Runtime Error

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

print(n//(k-1))

Submission status: Runtime Error

Solution code:
import math
a, b = map(int, input().split())
c = b - 1

d = a / c

print(math.ceil(d)

Submission status: Runtime Error

Solution code:
NK = input()
Ain = input()
N = int(NK[0:1])
K = int(NK[2:3])
n = N-1
k = K-1
a = int(n/k)
if n%k > 0:
    a += 1
print(a)

Submission status: Runtime Error

Solution code:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n, k, as):
    if (n-1)%(k-1)==0:
        return (n-1)/(k-1)
    else:
        return round((n-1)/(k-1))

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as])

def main():
    n, k, as = readQuestion()
    answer = solve(n, k, as)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

def solve(n, k, as):
        return n/(k-1)

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as])

def main():
    n, k, as = readQuestion()
    answer = solve(n, k, as)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
li=list(map(int,input()split())
ans=0
n-=1
while n>0:
        n+=1
        n-=k
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
li=list(map(int,input()split())
ans=0
while n>0:
        n+=1
        n-=k
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
li=list(map(int,input()split())
ans=0
while n>0:
        n-=(k-1)
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
I = raw_input()
A = I.split(" ")
X = N / K
Y = N % K
ans = X + Y
print ans

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
I = raw_input()
A = I.split(" ")
X = N / K
Y = N % K
ans X + Y + A[1]
print ans

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
I = raw_input()
A = I.split(" ")
X = N / K
Y = N % K
ans X + Y
print ans

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
I = raw_input()
A = I.split(" ")
X = N / K
Y = N % K
print X + Y

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
for i in range(N):
    A[i] = int(raw_input())
A = N / A
B = N % A
print A + B

Submission status: Runtime Error

Solution code:
N = int(raw_input())
K = int(raw_input())
A = N / A
B = N % A
print A + B

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
a = input()
print(math.celi(n-1/k-1))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
b=map(int,input().split())
a=b.index(1)
ans1=-int(-a/(k-1))
ans2=-int((-(k-a-1))/(k-1))
print(int((ans1+ans2)))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
b=map(int,input().split())
a=b.index(1)
ans1=-(-a//(k-1))
ans2=-((-(k-a-1))//(k-1))
print(int((ans1+ans2)))

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
b=map(int,input().split())
a=b.index(1)
ans1=math.ceil(a/(k-1))
ans2=math.ceil((k-a-1)/(k-1))
print(int((ans1+ans2)))

Submission status: Runtime Error

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

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

min_idx = A.index(min(A))

if K >= N:
    print(1)
else:
    if (n-1)%(k-1):
        print((N - 1) // (K - 1) + 1)
    else:
        print((N - 1)// (K - 1))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
ans = (N + (N % K)) // K

def aaaaa(k):
    if k % 2 == 0:
        return k + 1
    else:
        return k - 1
    
if N != k:
    for k in range(K):
        if ans % K == k and N % K != def(k):
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
count = 0
k -= 1

left = a.index(1) 
right = len(a) - left - 1

if left % k == 0:
    count += left // k
else:
    count += left // k + 1

if right % k == 0:
    count += right // k
else:
    count += right // k + 1

amari = left % k + right % k

if left % k != 0 and right % k != 0 and amari = k - 1:
    count -= 1

print(count)

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
 
a = list(map(int, input().split()))
plus = 0
minus = 0
 
for i in range(len(a)):
  if a[i] == 1:
    min = i + 1
 
if (min-1)%(K-1) + (N-min)%(K-1) >= (K-1):
  minus += 1
  
if (min-1)%(K-1) > 0:
  plus += 1
if (N-min)%(K-1) > 0:
  plus += 1
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1
  
print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)
N,K = map(int, input().split())

a = list(map(int, input().split()))
plus = 0
minus = 0

for i in range(len(a)):
  if a[i] == 1:
    min = i + 1

if (min-1)%(K-1) + (N-min)%(K-1) >= (K-1):
  minus += 1
  
if (min-1)%(K-1) > 0:
  plus += 1
if (N-min)%(K-1) > 0:
  plus += 1
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1

if N == K:
  print(1)
else:  
  print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split(" "))
#A,B = input().split(" ")
A = list(map(int,input().split(" ")))
min = min(A)
i = A.index(min)
 bot = i -int((M-1)*(i/(i+N-1-i)))
 up = i + (M-1) - int((M-1)*(i/(i+N-1-i)))
 cou = 1

if(N-1-i<=M):
    up = N-1
    bot = i - (M-1-N-1-i)
    cou = 1
if(i<=M):
    bot = 0
    up = i + (M-1-i)
    cou = 1
    
while(up<N-1):
    up = up + M-1
    cou = cou + 1
while(bot>0):
    bot = bot - M-1
    cou = cou + 1

print(cou)

Submission status: Runtime Error

Solution code:
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif n%2 != 0 k%2 == 0 and (n-k)%(k-1) != 0:
  	print(n//(k-1) + 1)
else:
    print(n//(k-1))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
start = [i for i,x in enumerate(a) if x == min(a)]
m = 10000000
for i in start:
    if math.ceil(i/(k-1))+math.ceil(((n-1)-i)/(k-1)) < m:
        m = math.ceil(i/(k-1))+math.ceil(((n-1)-i)/(k-1))
print(m)

Submission status: Runtime Error

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
index1=a.index(1)
if k>=index1+1 or n-(index1+1)<=k:
    print(round((len(a)-1)/(k-1)))
else:
    ans=float("inf")
    for i in range(k):
        ans=min(ans,1+round((index1+1-k+i)/k)+round(n-(index1+1+i))/k))
    print(ans)

Submission status: Runtime Error

Solution code:
8 3
7 3 1 8 4 6 2 5

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
if (N-K) % (K-1) == 0:
    out = (N-K) // (K-1) + 1
else:
    out = (N-K) // (K-1) + 2
print(out)

Submission status: Runtime Error

Solution code:
from math import ceil

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

if i==0:left=0
elif i-k<0:left=1
elif i%(k-1)==0:
    left=i//(k-1)
else:
    left=ceil(i/(k-1))
    
if i==n-1:right=0
elif n-k<i:left=1
elif (n-i-1)%(k-1)==0:
    right=(n-i-1)//(k-1)
else:
    right=ceil((n-i-1)/(k-1))
print(left+right)

Submission status: Runtime Error

Solution code:
import sys
N,K = map(int, input().split())
lis = [int(i) for i in input().split()]
if N == 1:
  print(1)
  sys.exit()
ind = lis.index(1)+1
print(ind)
pre = ind-1
pos = l-ind-1
if pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  int temp;
  int m=0;
  for(int i=0;i<N;i++){
    cin>>temp;
    if(temp==1)m=i+1;
  }
  if(m<=K || (N-m)<K)cout<<(N-1+K-2)/(K-1)<<endl;
  else cout<<(m-1+K-2)/(K-1)+(N-m+K-2)/(K-1)<<endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
from math import floor
nk = input()
n, k = nk.split()
n = int(n)
k = int(k)

an = input()
an_list = an.split()
min = min(an_list)

min_ind = an_list.index(min) + 1
after = (n - min_ind) / (k-1)
before = (min_ind - 1) / (k-1)

res = 0

if min_ind < k or (n - min_ind) > (k-1):
    res = floor(n/(k-1)) 

else:
    if after.is_integer():
    res = res + after
    else:
    res = res + floor(after) + 1

    if before.is_integer():
    res = res + before
    else:
    res = res + floor(before) + 1


print(int(res))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
one_index = A.index(1)
for i in range(K):
    if (N - 1 - (one_index + i)) % (K-1) == 0  and one_index - (K - i - 1) % (K-1) == 0:
        out = (N - K)//(K-1) + 1
    else:
        out = (N - K)//(K-1) + 2
print(out)

Submission status: Runtime Error

Solution code:
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ')]
"""
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)
"""
ans =0
if (N-1)%(k-1) ==0:
    ans = (N-1)//(k-1)
else:
    ans = (N-1)//(k-1) +1
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
one_index = A.index(1)
for i in range(K):
    if (N - (one_index + i)) % (K-1) == 0  and one_index - (K - i - 1) % (K-1) == 0:
        out = (N - K)//(K-1) + 1
    else:
        out = (N - K)//(K-1) + 2
print(out)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
m = 0
if a[0] == 1 or a[1]==1 or a[2]==1:
    for i in range(n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue

        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
else:
    for i in range(n):
        if a[i]==1:
            m = i
            break
    for i in range(m,n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue
        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
    for i in reversed(range(m)):
        if a[i] == a[i-1] == a[i-2] or a[i] == a[i-1]:
            if a[i-2] == a[0]:
                a[i] = min(a[i],a[i-1],a[i-2])
                a[i+1] = min(a[i],a[i-1],a[i-2])
                a[i+2] = min(a[i],a[i-1],a[i-2])
                ans+= 1
            else:
                continue
        else:
            a[i] = min(a[i],a[i-1],a[i-2])
            a[i+1] = min(a[i],a[i-1],a[i-2])
            a[i+2] = min(a[i],a[i-1],a[i-2])
            ans+= 1
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
one_index = A.index(1)
for i in range(K):
    if (N - one_index + i) % (K-1) == 0  and one_index - (K - i - 1) % (K-1) == 0:
        out = (N - K)//(K-1) + 1
    else:
        out = (N - K)//(K-1) + 2
print(out)

Submission status: Runtime Error

Solution code:
n = np.argmin(A)
m = N - n - 1
if n < m:
    res = int(n/(K-1))
    reminder= n % (K-1)
    if reminder != 0:
        m_new = m - (reminder)
        res = res + 1
    else:
        m_new = m
    res += int(m_new/(K-1))
    reminder = m_new % (K-1)
    if reminder != 0:
        res = res + 1
else:
    temp = n
    n = m
    m = temp
    res = int(n/(K-1))
    reminder= n % (K-1)
    if reminder != 0:
        m_new = m - (reminder)
        res = res + 1
    else:
        m_new = m
    res += int(m_new/(K-1))
    reminder = m_new % (K-1)
    if reminder != 0:
        res = res + 1
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
i = np.argmin(a)
m = math.ceil(i/(k-1))+math.ceil(((n-1)-i)/(k-1))
if a[0]==min(a) or a[n-1]==min(a):
    h = math.ceil((n-1)/(k-1))
print(min(h,m))

Submission status: Runtime Error

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

center = A.index(1)
left_block = center + 1
right_block = len(A) - center

left_num = 0
if left_block > K:
    tmp = left_block
    while tmp > 0:
        tmp = tmp - K + 1
        left_num += 1
        if tmp == K:
            left_num -= 1
elif 2 <= left_block <= K:
    left_num = 1

right_num = 0
if right_block > K:
    tmp = right_block
    while tmp > 0 :
        tmp = tmp - K + 1
        right_num += 1
        if tmp == K:
            right_num -= 1
elif 2 <= right_block <= K:
    right_num = 1

print(left_num + right_num)

# D
K = int(input())

Submission status: Runtime Error

Solution code:
n, k = LI()
a = LI()
l = len(a[:a.index(1)]) + 1
r = len(a[a.index(1):])

if l == 1:
    left = 0
elif l < k:
    left = 1
else:
    left = math.ceil((l - k) / (k - 1)) + 1

if r == 1:
    right = 0
elif r < k:
    right = 1
else:
    right = math.ceil((r - k) / (k - 1)) + 1

print(left + right)

Submission status: Runtime Error

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

#len(a) == n

#print(n//(k-1))
long_pla =  a.index(min(a)) + 1
if (n - long_pla) % (k-1) + long_pla) % (k-1)>= (k-1):
    print(n//(k-1)+1)
else:
    print(n//(k-1))

Submission status: Runtime Error

Solution code:
def main15():
    strbuf1 = input('');
    strbuf2 = input('');
    strbufs1 = strbuf1.split();
    strbufs2 = strbuf2.split();
    buf1 = [];
    buf2 = [];
    ba = 0;
    for i in range(2):
        buf1.append(int(strbufs1[i]));
    for i in range(buf1[0]):
        buf2.append(int(strbufs2[i]));
        if(buf2[i] == 1):
            ba = i;
            break;
    are = buf1[1] - 1;
    kai1 = math.ceil(ba/are);
    kk = ba - are * kai1;
    kai2 = math.ceil((buf1[0] -(ba+1+kk))/are)
    print(int(kai1+kai2));

def main16():
    strbuf = input('');
    num = int(strbuf);
    kazu = 0;
    number = 1;
    while(kazu<num):


        kazu = kazu + 1;

        number = number + 1;


if __name__ == '__main__':
    main15()

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split(" "))
#A,B = input().split(" ")
A = list(map(int,input().split(" ")))
min = min(A)
i = A.index(min)
bot = i
up = i
cou = 0
while(up<N-1):
    up = up + M-1
    cou = cou + 1
while(bot>0):
    bot = bot - M-1
    cou = cou + 1


if(M%2!=0):
    bot = i-int(M/2)
    up = i+int(M/2)
    cou2 = 1
    while(up<N-1):
        up = up + M-1
        cou2 = cou2 + 1
    while(bot>0):
        bot = bot - M-1
        cou2 = cou2 + 1

if(cou2<cou):cou = cou2

print(cou)

Submission status: Runtime Error

Solution code:
import math
def main15():
    strbuf1 = input('');
    strbuf2 = input('');
    strbufs1 = strbuf1.split();
    strbufs2 = strbuf2.split();
    buf1 = [];
    buf2 = [];
    ba = 0;
    for i in range(2):
        buf1.append(int(strbufs1[i]));
    for i in range(buf1[0]):
        buf2.append(int(strbufs2[i]));
        if(buf2[i] == 1):
            ba = i;
            break;
    are = buf1[1] - 1;
    kai1 = ceil(ba/are);
    kk = ba - are * kai1;
    kai2 = ceil((buf1[0] -(ba+1+kk))/are)
    print(int(kai1+kai2));

def main16():
    strbuf = input('');
    num = int(strbuf);
    kazu = 0;
    number = 1;
    while(kazu<num):


        kazu = kazu + 1;

        number = number + 1;


if __name__ == '__main__':
    main15()

Submission status: Runtime Error

Solution code:


def main():
    import math
    n, k = list(map(int, input().split()))
    #print(n, k)
    row = list(map(int, input().split()))
    #print(row.index(11))
    if row.index(1) == 0: 
        migigawa = 0
        hidarigawa = math.ceil((n - 1) / (k - 1))
    elif row.index(1) == n - 1:
        hidarigawa = math.ceil((n - 1) / (k - 1))
        hidarigawa = 0
    else: 
        migigawa = math.ceil(row.index(1) / (k-1))
        hidarigawa = math.ceil((n - migigawa * k) / (k-1))
    #print(row.index(1)+1 , k)
    #print(migigawa)
    
    #print(hidarigawa)
    print(migigawa + hidarigawa)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, k = LI()
a = LI()
l = len(a[:a.index(1)])
r = len(a[a.index(1):])

if l == 0:
    left = 0
elif l < k:
    left = 1
else:
    left = math.ceil((l - k) / (k - 1)) + 1

if r == 0:
    right = 0
elif r < k:
    right = 1
else:
    right = math.ceil((r - k) / (k - 1)) + 1

print(left + right)

Submission status: Runtime Error

Solution code:
def endo(N, K):
    result=(N-1)//(K-1)
    if not (N-1)%(K-1)==0:
        result+=1

    return result

N,K=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
i=A.index(1)+1
if i==1 or i==N:
    result=endo(N,K)
else
    result=max([endo(i,K)+endo(N-i+1,K), endo(i-1,K)+endo(N-i,K)+1])
print(result)

Submission status: Runtime Error

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

X = 0
for i in range(0,N-K +2,2):
    if(i+3 > N):
        M = min(A[i-1:i+2])
        A[i-1] = M
        A[i] = M
        A[i+1] = M

    else:
        M = min(A[i:i+3])
        A[i] = M
        A[i+1] = M
        A[i+2] = M

    #print(A)
    X = X + 1

print(X)

Submission status: Runtime Error

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

X = 0
for i in range(0,N-K +2,2):
    if(i+3 > N):
        M = min(A[i-1:i+2])
        A[i-1] = M
        A[i] = M
        A[i+1] = M

    else:
        M = min(A[i:i+3])
        A[i] = M
        A[i+1] = M
        A[i+2] = M

    print(A)
    X = X + 1

print(X)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_tmp = input().split()
a = [[] for i in range(n)]
for i in range(n):
    a[i] = int(a_tmp[i])
if n != k:
a1 = a.index(1)
sol = 0
a_left = a1
a_right = len(a)-1-a1
if a_left % (k-1) == 0:
    sol += int(a_left / (k-1))
else:
    sol += int(a_left / (k-1)) + 1
if a_right % (k-1) == 0:
    sol += int(a_right / (k-1))
else:
    sol += int(a_right / (k-1)) + 1

if sol != 0:
    print(sol)
else:
    print(1)

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
K = int(l[1])

l1 = raw_input().split()

print(int(math.ceil(N/(K-1))))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
m = min(A)
res = 0
for i in range(N):
    min_num = i
    if m == A[i]:
        break
    
        
n1 = min_num 
n2 = N - min_num - 1

if n1 == 0:
    res = math.ceil(n2/2)
elif n2 == 0:
    res = math.ceil(n1/2)
else:
    res = math.ceil(n1/2) + math.ceil(n2/2)
    
print(res)

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
K = int(l[1])

l1 = raw_input().split()

print(int(ath.ceil(N/(K-1))))

Submission status: Runtime Error

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

#len(a) == n

#print(n//(k-1))
long_pla =  a.index(min(a))) + 1
if n - long_pla % (k-1):
    print(n//(k-1)+1)
else:
    print(n//(k-1))

Submission status: Runtime Error

Solution code:
N, K = input().split()
lines = []
for i in range(int(N)):
    lines.append(input())
if int(K)%int(N) ==0:
    a = int(K)/int(N)
else:
    a = int(K)/int(N)+1
print(a)

Submission status: Runtime Error

Solution code:
import math

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

inde = A.index(1)

if inde == 0 or inde == N-1:
	print(math.ceil((N - 1) / (K-1)))
elif inde < K or N - idex - 1 < K:
	print(1 + math.ceil((N-K)/(K-1)))
else:
	a = math.ceil(inde / (K-1)) + math.ceil((N - inde - 1) / (K-1))
	b = math.ceil((inde-1) / (K-1)) + math.ceil((N - inde - 2) / (K-1)) + 1
	print(min(a,b))

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
K = int(l[1])

l1 = raw_input().split()

print(math.ceil(N/(K-1)))

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
K = int(l[1])

l1 = raw_input().split()

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

Submission status: Runtime Error

Solution code:
import math

def LI(): return [int(x) for x in sys.stdin.readline().split()]

n, k = LI()
a = LI()
l = len(a[:a.index(1)])
r = len(a[a.index(1):])

left = math.ceil((l - k) / (k - 1)) + 1
right = math.ceil((r - k) / (k - 1)) + 1

print(left + right)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
out = (N) // (K-1)
print(out)

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
list = []
for i in range(N):
    list.append(int(input()))

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

Submission status: Runtime Error

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

while(True):
	Kc = K
	temp = []
	while(i+K > len(A)):
		K -= 1
	if(K == 0):
		break
	for j in range(i+K):
		temp.append(A[j])
	target = min(temp)
	for j in range(i+K):
		A[j] = target
	count += 1
	i += Kc - 1

print(A)
print(count)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
i=a.index(1)
(i+1)//(k-1)+(n-i)//(k-1)print()