#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, K; cin >> N >> K; vector A(K*2+1); for (int i=0; i> A[i]; A[i+K] = A[i]+N*2; } A[K*2] = 1e9; ll l=0, r=N+1, c; auto f=[&](ll X){ //dp(i):iで切ったとき次の切れ目 //dp(i)=(2i+1~2i+2X-1にいちごがあるなら2i+2X, ないなら2i+2X以上の最小のA+1) //dp(i)=max(2i+1以上の最小の(A+1)/2, i+X) int k=0, L; vector dp(N*2+2), v(N*2+2); dp[N*2+1] = N*2+1; for (int i=1; i<=N*2; i++){ while (k pd(N*2+2); if (L & 1){ for (int i=1; i<=N*2+1; i++) v[i] = dp[v[i]]; } for (int i=1; i<=N*2+1; i++) pd[i] = dp[dp[i]]; swap(pd, dp); L >>= 1; } //for (int i=1; i<=N; i++) cout << v[i] << " "; //cout << endl; for (int i=1; i<=N; i++){ if (v[i] <= i+N) return 1; } return 0; }; while(r-l>1){ c = (l+r)/2; if (f(c)) l=c; else r=c; } cout << l*2 << endl; return 0; }