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 = int(input())
K = int(input())
l = list(map(int, input().split()))
index = l.index(1)

ans = 0
if index != 0:
    p = index - K + 1
    ans += 1
    if p < 0:
        index = index + (-1 * p)
    elif p > 0:
        while p > 0:
            p = p - K + 1
            ans += 1
if index < (N - 1):
    ans += 1
    index = index + K - 1
    while index < (N - 1):
        index = index + K - 1
        ans += 1

print(ans)

Submission status: Runtime Error

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

min_an_index = np.argmin(an)

count = 0
a = min_an_index
b = N - min_an_index - 1

if K-1 > a:
    b -= K - 1 - a
    if b < 0:
        b = 0
        count += 1
if K-1 > b:
    a -= K - 1 - b
    if a < 0:
        a = 0
        count += 1
if a > 0:        
    a1 = a // (K-1)
    if a % (K-1) != 0:
        a1 += 1
if a <= 0:
    a1 = 0
    
if b > 0:    
    b1 = b // (K-1)
    if b % (K-1) != 0:
        b1 += 1
if b <= 0:
    b1 = 0

count += a1 + b1
print(count)

Submission status: Runtime Error

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

Solution code:
a,b=map(int, input().split())
c=list(map(int, input().split()))
d -= 1
print(a//d)

Submission status: Runtime Error

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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:
//#define _GLIBCXX_DEBUG
//#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int a[n]; for (int i = 0; i<n; i++) cin >> a[i];
    cout << (((n-k)+(k-2))/(k-1))+1 << "\n";
}

Submission status: Runtime Error

Solution code:
//#define _GLIBCXX_DEBUG
//#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int a[n];
    cout << (((n-k)+(k-2))/(k-1))+1 << "\n";
}

Submission status: Runtime Error

Solution code:
    n, k = [ int(x) for x in input().split(' ') ]
    xs = [  int(x) for x in input().split(' ') ]
    i0 = xs.index(min(xs))
    print(1 + min([ (i + k - 2) // (k - 1) + (n - i - 2) // (k - 1)
      for i in range(max(i0 - k + 1, 0),  min(i0, n - k) + 1)  ]))

Submission status: Runtime Error

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

print(floor((n - 1) / (k - 1)))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
 
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数
 
    assert N % 3 == 0

Submission status: Runtime Error

Solution code:
import math

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

if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数

    assert l < r

    print(114514)

Submission status: Runtime Error

Solution code:
import math

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

if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数

    assert r % 3 == 1
    
    print(114514)

Submission status: Runtime Error

Solution code:
import math

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

if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数

    assert r % 3 == 0
    
    print(114514)

Submission status: Runtime Error

Solution code:
import math

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

if N == K:
    print(1)
    quit()
else:
    one_index = A.index(1)
    l = one_index #1の左側にある数字の数
    r = N - one_index - 1 #1の右側にある数字の数

    assert l % 3 == 0
    
    print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K == 3
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K == 3
assert N < 100
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K > 3
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K > 2
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K > 5
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K > 10
 
print(114514)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
assert K > 50
 
print(114514)

Submission status: Runtime Error

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

assert K > 100

print(114514)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

idx = As.index(i)
left = idx
right = n - idx - 1

n_l = (left + k - 1) // (k - 1)
n_r = (right + k - 1) // (k - 1)

print(n_l + n_r)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-N-1//k-1))

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
n = 0
l = 0
r = o
for i in range(N):
    if Alist[i] == 1:
        p = i
n = n -(-p//(K-1))
n = n -(-(N-p-1)//(K-1))
print(-(-N-1//k-1))

Submission status: Runtime Error

Solution code:
 N,K=map(int,input().split())
a=list(map(int,input().split()))
index=a.index(1)
l=index
r=index
cnt=0
if index<=(N//2-1 if N%2==0 else N//2):
  while l!=0:
    if cnt==0:
      if l-K+1<0:
        r=K-1
    l=max(0,l-K+1)
    cnt+=1
  while r!=N-1:
    r=min(N-1,r+K-1)
    cnt+=1
  print(cnt)
else:
  while r!=N-1:
    if cnt==0:
      if r+K-1>N-1:
        l=N-K
    r=min(N-1,r+K-1)
    cnt+=1
  while l!=0:
    l=max(0,l-K+1)
    cnt+=1
  print(cnt)

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
c=0
mn=min(l)
while len(l)>=1:
  if mn==min(l):
    m=l.index(min(l))
    if m==0:
      l=l[m+1:]
    elif m+l[k-1::-1].index(min(l))==len(l):
      c+=m//(k-1)
      if m%(k-1)!=0:
        c+=1
      l=l[m+1:]
    else:
      c+=1
      l=l[k:]
  else:
    c+=len(l)//(k-1)
    if len(l)%(k-1)!=0:
      c+=1
    l=[]
print(c)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
c=0
mn=min(l)
while len(l)>=1:
  if mn==min(l):
    m=l.index(min(l))
    if m==0: # count == 0
      l=l[m+1:]
    elif m+l[k-1::-1].index(min(l))==len(l):
      c+=m//(k-1)
      if m%(k-1)!=0:
        c+=1
      l=l[m+1:]
    else: # count >= 2
      #print(l[k-1::-1])
      c+=1
      l=l[k:]
  else:
    c+=len(l)//(k-1)
    if len(l)%(k-1)!=0:
      c+=1
    l=[]
print(c)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
c=0
mn=min(l)
while len(l)>=1:
  if mn==min(l):
    m=l.index(min(l))
    if m==0:
      l=l[m+1:]
    elif m+l[k-1::-1].index(min(l))==len(l):
      c+=m//(k-1)
      if m%(k-1)!=0:
        c+=1
      l=l[m+1:]
    else:
      c+=1
      l=l[k:]
  else:
    c+=len(l)//(k-1)
    if len(l)%(k-1)!=0:
      c+=1
    l=[]

Submission status: Runtime Error

Solution code:
import math

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

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

print(ans)

Submission status: Runtime Error

Solution code:
#n=6 k=4
#
# 3 1 2 4 5 6


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

id_of_one = lst.index(1) #リスト内の最小値1のインデックスを取得

left = len(lst[0:id]) #1より左側にある数列の長さ
right = len(lst[id+1:]) #1より右側にある数列の長さ
total = left + right

amari = max(left%(k-1),right%(k-1))
total -= amari



counter = 0
while total > 0:
    counter += 1
    total -= k - 1

print(counter)

Submission status: Runtime Error

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

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

id_one = lst.index(1)
left_length = len(lst[0:id_one]-1)
right_length = len(lst[id_one:]-1)

counter = 0

if left_length > 0:
    left_length -= k
    counter += 1

while left_length > 0:
    counter += 1
    left_length -= k-1

if right_length > 0:
    counter += 1
    right_length -= k

while right_length > 0:
    counter += 1
    right_length -= k-1

print(counter)

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())
A=list(map(int,input.split()))

ans=1
X=N-K

while X>0:
  X-=K-1
  ans+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

cnt = 0
for i in range(N):
    if A[i] == 1:
        L = i
        R = (N - i - 1)
        if L == 0:
            cnt += 0
        elif L < K:
            cnt += 1
        else:
            #cnt += (math.ceil(L / (K - 1)))
            cnt += (L / (K - 1))
        if R == 0:
            cnt += 0
        elif R < K:
            cnt += 1
        else:            
　           #cnt += (math.ceil(R / (K - 1)))  
            cnt += (R / (K - 1))
#print(L,R)
print(cnt)

Submission status: Runtime Error

Solution code:

import math

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

cnt = 0
for i in range(N):
    if A[i] == 1:
        L = i
        R = (N - i - 1)
        if L == 0:
            cnt += 0
        elif L < K:
            cnt += 1
        else:
            #cnt += (math.ceil(L / (K - 1)))
            cnt += (L / (K - 1))
        if R == 0:
            cnt += 0
        elif R < K:
            cnt += 1
        else:
　           #cnt += (math.ceil(R / (K - 1)))  
             cnt += (R / (K - 1))
#print(L,R)
print(cnt)

Submission status: Runtime Error

Solution code:
import math

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

cnt = 0
for i in range(N):
    if A[i] == 1:
        L = i
        R = (N - i - 1)
        if L == 0:
            cnt += 0
        elif L < K:
            cnt += 1
        else:
            #cnt += (math.ceil(L / (K - 1)))
            cnt += (L / (K - 1))
        if R == 0:
            cnt += 0
        elif R < K:
            cnt += 1
        else:
　           c#nt += (math.ceil(R / (K - 1)))  
             cnt += (R / (K - 1))
#print(L,R)
print(cnt)

Submission status: Runtime Error

Solution code:
n,k =int(x) for x in input().split()
s = list(int(y) for y in input().split())
def min(a):
  min = 1000000
  for i in range(len(a)):
    if min > a[i]:
      min = a[i]
      index = i
  return index
c = min(s)
num = (c-1)//k + (len(s)-c)//k +2
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N , K = (int(i) for i in input().split())
A = list(int(i) for i in range(input().split(),N))

count = 1
s  = K

while s < N:
    s = s + (K - 1)
    count = count + 1
    print(s)
print(count)

Submission status: Runtime Error

Solution code:
N,K=map(int,input.split())
TMP=K
ANS=1
if N <= K:
  ANS=1
else:
  TMP+=(K-1)
  ANS+=1
  if N <= K:
    break
print(ANS)

Submission status: Runtime Error

Solution code:
N,K=map(int,input.split())
TMP=K
ANS=1
if N <= K:
  ANS=1
else:
  TMP=(K-1)
  ANS+=1
  if N <= K:
    break
print(ANS)

Submission status: Runtime Error

Solution code:
N,K=map(int,input.split())
TMP=K
ANS=1
if N =< K:
  ANS=1
else:
  TMP=(K-1)
  ANS+=1
  if N <= K:
    break
print(ANS)

Submission status: Runtime Error

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

import math

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

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

Submission status: Runtime Error

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

import numpy as np
import sys

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

arg = 0
op_l = 0
while(True):
    arg_new = arg + K - 1
    op_l += 1
    if np.any(A[arg:arg_new+1] == 1):
        last_arg = (arg, arg_new)
        break
    arg = arg_new

if arg_new == N-1:
    print(op_l)
    sys.exit()

arg = N-1
op_r = 0
while(True):
    arg_new = arg - K + 1
    op_r += 1
    if np.any(A[arg_new:arg+1] == 1):
        if (arg_new, arg) == last_arg:
            op_r -= 1
        break
    if arg_new = last_arg[1]+1:
        break
    arg = arg_new

print(op_l+op_r)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
A = input()
ans = (n-1)//(k-1)
print(ans if (n-1) % (k-1) ==

Submission status: Runtime Error

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

def minus(N, K,count):
    if N>K:
        N=N - (K - 1)
        count += 1
        return minus(N, K, count)
        
    elif N <= K:
        count += 1
        return count

print(minus(N,K,0))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    int A;
    int m = 0
    for (int i = 1; i < N+1; i++){
        cin >> A;
        if (A == 1){
            m = i;
            break;
        }
    }
    int l = (i - 1) / K;
    int r = (N - i) / K;
    if ((i - 1) % K == 0){
        l++;
    }
    if ((N - i) % K == 0){
        r++;
    }
    cout << l + r << endl;

}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, input().split(" "))
A = (list(map(int, input().split(" ")))
list=[i-1 for i, v in enumerate(A) if v == max(A)]

list_.insert(0, 0)
list_.append(N-1)
     
array = np.array(list_)

print(array)

total = 0

for i in range(len(list)-1):
  if (array[i+1] - array[i]) % (K - 1) == 0 or (array[i+1] - array[i]) // (K - 1)==0:
    total = total + (array[i+1] - array[i]) // (K - 1)
  else:
    total = total + (array[i+1] - array[i]) // (K - 1) + 1
    
print(total)

Submission status: Runtime Error

Solution code:
def function(n,k,a):
    ind1 = a.index(1)
    pre = len(a[:ind1])
    ex = len(a[ind1:])    
    ans = -(-pre//(k-1)) + -(-ex//(k-1))
    if n == k:
        ans = 1
    return int(ans)

print(function(n,k,a))

Submission status: Runtime Error

Solution code:
import sys
from math import ceil
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))

if n == k:
    print(1)
else:
    former = index_min(A)[0]
    latter = n - 1 - former
    ceil(former / (k-1)), ceil(latter / (k-1))
    print(ceil(former / (k-1)) + ceil(latter / (k-1)))

Submission status: Runtime Error

Solution code:
3 3
1 2 3

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  int ans = (n-1+k-2)/(k-1);
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
def ceil(n,m):
  if n%m==0:
    return n//m
  else:
    return (n//m)+1
a=ls.index(1)
if K==N:
  print(1)
elif (K==N-1 and (a==0 or a==N-1)):
  print(1):
else:
  print(ceil(a,K-1)+ceil(N-a-1,K-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import math

id_1 = a.index(1)

if n == k:
  print(1)
elif id_1 > k - 1 and n - id_1 - 1 > k - 1:
  print( math.ceil(id_1 / (k - 1)) + math.ceil((n - id_1 - 1) / (k - 1)) )
else:
  print( 1 + math.floor((n - k) / (k - 1))

Submission status: Runtime Error

Solution code:
import math

n,k = map(int,input().split())
li = [int(i) for i in input().split()]
a = li.index(4)
k -= 1
n -= 1
left = math.ceil(a/k)
right = math.ceil((n-a)/k)
print(left+right)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    a = s.count("-")
    b = s.count("+")
    print(b-a)
    return

#B
def B():
    n = S()
    num = sum(map(int, n))
    n = int("".join(n))
    print(["Yes", "No"][n % num > 0])
    return

#C
def C():
    n, k = LI()
    a = LI()
    one = a.index(a, 1)
    if k == n:
        print(1)
        return
    ans = 0
    i = one
    while i < n:
        ans += 1
        i += k - 1
    i = one
    while i >= 0:
        ans += 1
        i -= k - 1
    print(ans)
    return

#D
def D():
    return


#Solve
if __name__ == '__main__':
    C()

Submission status: Runtime Error

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

min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 10**5
for idx in range(K):
  left = min_idx - K + idx
  right = min_idx + idx
  if min_idx - K + idx < 0:
    continue
  if min_idx - K + idx >= N:
    break
  sum_cnt = 1
  if (N-right)%(K-1) == 0:
    sum_cnt += (N-right)//(K-1)
  else:
    sum_cnt += (N-mright)//(K-1)+1
  if left%(K-1) == 0:
    sum_cnt += left//(K-1)
  else:
    sum_cnt += left//(K-1) + 1
  ans = min(ans, sum_cnt)
print(ans)

Submission status: Runtime Error

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

min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-min_idx)%(K-1) == 0:
  ans += (N-min_idx)//(K-1)
else:
  ans += (N-min_idx)//(K-1)+1
if min_idx%(K-1) == 0:
  ans += min_idx//(K-1)
else:
  ans += min_idx//(K-1) + 1
print(ans)

Submission status: Runtime Error

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

min_idx = 10**5
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-idx)%(K-1) == 0:
  ans += (N-idx)//(K-1)
else:
  ans += (N-idx)//(K-1)+1
if idx%(K-1) == 0:
  ans += idx//(K-1)
else:
  ans += idx//(K-1) + 1
print(ans)

Submission status: Runtime Error

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

A = 10**5
min_idx = 0
for idx in range(N):
  if A[idx] < A[min_idx]:
    min_idx = idx
ans = 0
if (N-idx)%(K-1) == 0:
  ans += (N-idx)//(K-1)
else:
  ans += (N-idx)//(K-1)+1
if idx%(K-1) == 0:
  ans += idx//(K-1)
else:
  ans += idx//(K-1) + 1
print(ans)

Submission status: Runtime Error

Solution code:
#coding: utf-8
 
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
if(N==K):
    ans = 1
 
print(ans)

Submission status: Runtime Error

Solution code:
#coding: utf-8

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

for i in range(K):
    if(A[i] == 1):
        one = i
        #print('1は',one + 1,'番目')

ans = []

for i in range(K):
    start = one - (K - 1) + i
    end = one + i
    
    before = start
    after = N - (end+1)
    
    before_num = before//(K-1)
    if(before%(K-1) != 0):
        before_num += 1
        
    after_num = after//(K-1)
    if(after%(K-1) != 0):
        after_num += 1
    
    answer = before_num + after_num + 1
    ans.append(answer)

print(min(ans))

Submission status: Runtime Error

Solution code:
import math

N,K=map(int,input().split())
A=[*map(int,input().split())]

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

Submission status: Runtime Error

Solution code:
import math
n.k=map(int,input().split())
A=[int(i) for i in input().split()]
print(math.ceil(n/k))

Submission status: Runtime Error

Solution code:
n = int(input())
blue_list = [ input() for i in range(n)]
m = int(input())
red_list = [ input() for i in range(m)]

card_list = list(set(blue_list+red_list))

point = 0

for i in card_list:
	point = max(point,blue_list.count(i)-red_list.count(i))

print(point)

Submission status: Runtime Error

Solution code:
import math
N, K = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]

idx = A.index(1)
left = A[:idx+1]
right = A[idx:]


def get_cnt(L):
    return math.ceil((len(L) - 1) / (K-1))


if left + 1 < K or N - right < K:
    print(get_cnt(A))
else:
    print(get_cnt(left) + get_cnt(right))

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
one_p=a.index(1)
ans=0
if n!=k:
  ans=ans+(one_p)//(k-1) if (one_p)%(k-1)==0 else ans+(one_p)//(k-1)+1
  ans=ans+(n-one_p)//(k-1) if (n-one_p)%(k-1)==0: else ans+(n-one_p)//(k-1)+1
else:
  ans=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
one_p=a.index(1)
ans=0
if n!=k:
  ans=ans+(one_p)//(k-1) if (one_p)%(k-1)==0 else ans=ans+(one_p)//(k-1)+1
  ans=ans+(n-one_p)//(k-1) if (n-one_p)%(k-1)==0: else ans=ans+(n-one_p)//(k-1)+1
else:
  ans=1
print(ans)

Submission status: Runtime Error

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

def dfs(N,ans):
    if N < 0:
        return ans
    return dfs(N-(K -1),ans+1)

print(dfs(N-K,1))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    std::vector<char> a(n);

    for (int i =0;i<n;i++)
        cin >> a[i];
    int ans =-(-n/(k-1));
    cout << ans<<endl;


}

Submission status: Runtime Error

Solution code:
def calculate_median(lst):
    lst.sort()
    median_right = lst[int(len(lst)/2)]
    median_left = lst[int(len(lst)/2)-1]
    return median_right, median_left


N = int(input())
X = list(map(int, input().split()))
X_copy = X.copy()
median_right, median_left = calculate_median(X)
for i in range(N):
    if X_copy[i] >= median_right:
        print(median_left)
    elif X_copy[i] < median_right:
        print(median_right)

Submission status: Runtime Error

Solution code:
import statistics


def calculate_median(lst):
    lst.sort()
    median_right = lst[int(len(lst)/2)]
    median_left = lst[int(len(lst)/2)-1]
    return median_right, median_left


N = int(input())
X = list(map(int, input().split()))
X_copy = X.copy()
median_right, median_left = calculate_median(X)
for i in range(N):
    if X_copy[i] >= median_right:
        print(median_left)
    elif X_copy[i] < median_right:
        print(median_right)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=(a.index(1)+k-2)//(k-1)
if (a.index(1))%(k-1)!=0:
  x+=1
  y=(n-a.index(1)-1+(a.index(1)+k-2)%(k-1))//(k-1)
else:
  y=(n-a.index(1)-1+k-2)//(k-1)
x2=(n-a.index(1)-1+k-2)//(k-1)
if (n-a.index(1)-1)%(k-1)!=0:
  x2+=1
  y2=(a.index(1)+(n-a.index(1)-1)%(k-1))//(k-1)
print(min(x+y,x2+y2))

Submission status: Runtime Error

Solution code:
実装無理
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ind = A.index(1)
if (ind%(K-1) + (N-ind-1)%(K-1)) <= K-1:
    print(math.floor(ind/(K-1)) + math.floor((N-ind-1)/(K-1))+1)
else:
    print(math.ceil(ind/(K-1)) + math.ceil((N-ind-1)/(K-1)))

Submission status: Runtime Error

Solution code:
実装無理
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ind = A.index(1)
if (ind%(K-1) + (N-ind-1)%(K-1))%(K-1) == 0:
    print(math.floor(ind/(K-1)) + math.floor((N-ind-1)/(K-1))+1)
else:
    print(math.ceil(ind/(K-1)) + math.ceil((N-ind-1)/(K-1)))

Submission status: Runtime Error

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

inf = 10 ** 18

for i in range(1,inf):
  N -= (K - 1)a
  if N <= 1:
    print(i)
    break

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
tmp=min(a)
count_min=Counter(a)[tmp]
kazu=n-count_min
if kazu%(k-1)==0:
    print(kazu//(k-1))
else:
    print(kazu//(k-1)+1)

Submission status: Runtime Error

Solution code:
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split())) #A[0]〜A[N-1]

m = min(A)
answer = N

for i in range(N-K+1): #A[i:i+K]〜A[N-K:N]
  if not k in A[i:i+K]:
    continue
  answer = min(answer,
              (1 + math.ceil(i/(K-1)) + math.ceil((N-K-i)/(K-1))))
print(answer)

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
input()
solve():
  for i in rnge(100000):
    if(N<K+i*(K-1)):
      print(i+1)
      return

solve()

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
solve():
  for i in rnge(100000):
    if(N<K+i*(K-1)):
      print(i+1)
      return

solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def f(m,n):
    ret=m/n
    ret_=int(ret)
    if ret_==ret:
        return ret_
    else:
        return ret_+1
      
N,K=list(map(int,input().split()))
a=np.array(list(map(int,input().split())))
print(f(np.sum(a!=min(a)),K-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if n == k:
    print(1)
    exit()

l = 0
r = 0
one = False
for i in range(n):
    if a[i] == 1:
        one = True
        continue
    if one == False:
        l += 1
    else:
        r += 1

if k >= min(l+1,r+1):
    n -= k
    if n%(k-1) == 0:
        n //= k-1
    else:
        n //= k-1
        n += 1
    pritn(n+1)
else:
    if l % (k-1) == 0:
        l //= k-1
    else:
        l //= k-1
        l += 1
        
    if r % (k-1) == 0:
        r //= k-1
    else:
        r //= k-1
        r += 1
    print(l+r)

Submission status: Runtime Error

Solution code:
print((int(input()) - 2) / (int(input()) - 1) + 1)

Submission status: Runtime Error

Solution code:
n,k=map(int, input().split())
a=map(int, input().split())
print(N-K+1)

Submission status: Runtime Error

Solution code:
from collections import deque
k = int(input())

digsum = lambda x: sum(map(int, list(str(x))))
dignorm = lambda x: x/digsum(x)

n = 1
order = 1
while k > 0:
    print(n)
    k -= 1
    if dignorm(n+10**(order-1)) > dignorm(n+10**order):
        order += 1
    n += 10**(order-1)