#include using namespace std; using ll = long long; int main() { ll n,k; cin >> n >> k; vector a(k+1); for (size_t i=0; i> a[i]; a[k] = a[0] + 2*n; vector an(k+1); for (size_t i=0; i bool { ll x = 2 * mid; ll t = s; for (size_t i=0; i= an[i+2]) return false; t = max(t+x, an[i+1]+1); } return true; }; while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (is_ok(mid)) ok = mid; else ng = mid; } ans = max(ans, 2*ok); } cout << ans << endl; }