#include "gap.h"
#include <bits/stdc++.h>
// Skyqwq
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
long long findGap(int T, int n)
{
if (T == 1) {
int x = n;
LL mx, mn;
vector<LL> a;
LL L = 0, R = 1e18;
while (x > 0) {
MinMax(L, R, &mn, &mx);
if (x == 1) {
a.pb(mx);
x--;
break;
}
L = mn + 1, R = mx - 1;
a.pb(mn), a.pb(mx);
x -= 2;
}
sort(a.begin(), a.end());
LL ans = 0;
for (int i = 0; i + 1 < a.size(); i++)
chkMax(ans, a[i + 1] - a[i]);
return ans;
} else {
LL mx, mn;
LL L = 0, R = 1e18;
MinMax(L, R, &mn, &mx);
LL o = (mx - mn + 1 + n - 2) / (n - 1);
LL la = -1, ans = 0;
LL now = mn;
while (now <= mx) {
LL rt = min(mx, now + o - 1);
LL p, q;
MinMax(now, rt, &p, &q);
if (p != -1) {
if (la != -1) chkMax(ans, p - la);
la = q;
chkMax(ans, q - p);
}
now = rt + 1;
}
return ans;
}
return 0;
}