# Code

``````#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <queue>
#define rep(i, st, ed) for (int i = st; i <= ed; i  = 1)
#define drp(i, st, ed) for (int i = st; i >= ed; i -= 1)
#define erg(i, st) for (int i = ls[st]; i; i = e[i].next)
#define fill(x, t) memset(x, t, sizeof(x))
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
#define abs(x) ((x)<(0)?(-(x)):(x))
#define N 202000
#define E 1001
#define L 1001
using std:: pair;
std:: priority_queue<pair <int, int> > heap;
int pre[N], nex[N], t[N];
bool vis[N];
int x = 0, v = 1; char ch = getchar();
for(; ch<'0'||ch>'9'; v=(ch=='-')?(-1):(v),ch=getchar());
for(; ch<='9'&&ch>='0'; (x*=10) =ch-'0',ch=getchar());
return x * v;
}
int main(void) {
rep(i, 1, n) {
pre[i] = i - 1;
nex[i] = i   1;
pair <int, int> p(t[i], i);
heap.push(p);
}
pre[1] = n;
nex[n] = 1;
int ans = 0;
rep(i, 1, m) {
pair <int, int> top(heap.top());
heap.pop();
while (vis[top.second]) {
top = heap.top();
heap.pop();
if (heap.empty()) {
puts("Error!");
return 0;
}
}
ans  = top.first;
t[top.second] = t[pre[top.second]]   t[nex[top.second]] - t[top.second];
vis[pre[top.second]] = vis[nex[top.second]] = 1;
nex[pre[pre[top.second]]] = top.second;
pre[top.second] = pre[pre[top.second]];
pre[nex[nex[top.second]]] = top.second;
nex[top.second] = nex[nex[top.second]];
heap.push(std:: make_pair(t[top.second], top.second));
}
printf("%d\n", ans);
return 0;
}``````