Language: C++

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 100001

void solve()
{
    lli n,k;
    cin>>n>>k;

    lli a[n],id;
    loopl(i,0,n) {cin>>a[i]; if(a[i]==1) id=i; }

    lli ans=0;


    ans += (id/(k-1)) + (id%(k-1) != 0);

    id = n-id-1;
    ans += (id/(k-1)) + (id%(k-1) != 0);

    cout<<ans; 

    
}   

int main()
{
////////////////////////////////////////////   
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
////////////////////////////////////////////
    
    lli t;
    t=1;
    while(t--)
    {
        solve();
    }
}
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 100001

void solve()
{
    lli n,k;
    cin>>n>>k;

    lli a[n],id;
    loopl(i,0,n) {cin>>a[i]; if(a[i]==1) id=i; }

    lli ans=0;


    ans += (id/(k-1)) + (id%(k-1) != 0);

    id = n-id-1;
    ans += (id/(k-1)) + (id%(k-1) != 0);

    cout<<ans; 

    
}   

int main()
{
////////////////////////////////////////////   
    fastio;
////////////////////////////////////////////
    
    lli t;
    t=1;
    while(t--)
    {
        solve();
    }
}


Compiler output:
a.cc:120:11: error: redefinition of 'const long long int dx4 []'
  120 | const lli dx4[] = {-1, 0, 1, 0};
      |           ^~~
a.cc:35:11: note: 'const long long int dx4 [4]' previously defined here
   35 | const lli dx4[] = {-1, 0, 1, 0};
      |           ^~~
a.cc:121:11: error: redefinition of 'const long long int dy4 []'
  121 | const lli dy4[] = {0, 1, 0, -1};
      |           ^~~
a.cc:36:11: note: 'const long long int dy4 [4]' previously defined here
   36 | const lli dy4[] = {0, 1, 0, -1};
      |           ^~~
a.cc:122:11: error: redefinition of 'const long long int dx8 []'
  122 | const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
      |           ^~~
a.cc:37:11: note: 'const long long int dx8 [8]' previously defined here
   37 | const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
      |           ^~~
a.cc:123:11: error: redefinition of 'const long long int dy8 []'
  123 | const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
      |           ^~~
a.cc:38:11: note: 'const long long int dy8 [8]' previously defined here
   38 | const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
      |           ^~~
a.cc:128:9: error: redefinition of 'std::mt19937 rng'
  128 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
a.cc:43:9: note: 'std::mt19937 rng' previously declared here
   43 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
a.cc:129:12: error: redefinition of 'std::mt19937_64 mt'
  129 | mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
      |            ^~
a.cc:44:12: note: 'std::mt19937_64 mt' previously declared here
   44 | mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
      |            ^~
a.cc:133:6: error: redefinition of 'void solve()'
  133 | void solve()
      |      ^~~~~
a.cc:48:6: note: 'void solve()' previously defined here
   48 | void solve()
      |      ^~~~~
a.cc:154:5: error: redefinition of 'int main()'
  154 | int main()
      |     ^~~~
a.cc:69:5: note: 'int main()' previously defined here
   69 | int main()
      |     ^~~~