Problem:
Problem K
Min-Max Distance Game
Alice and Bob are playing the following game. Initially, $n$ stones are placed in a straight line on a table. Alice and Bob take turns alternately. In each turn, the player picks one of the stones and removes it. The game continues until the number of stones on the straight line becomes two. The two stones are called
result stones
. Alice's objective is to make the result stones as distant as possible, while Bob's is to make them closer.
You are given the coordinates of the stones and the player's name who takes the first turn. Assuming that both Alice and Bob do their best, compute and output the distance between the result stones at the end of the game.
Input
The input consists of a single test case with the following format.
$n$ $f$
$x_1$ $x_2$ ... $x_n$
$n$ is the number of stones $(3 \leq n \leq 10^5)$. $f$ is the name of the first player, either Alice or Bob. For each $i$, $x_i$ is an integer that represents the distance of the $i$-th stone from the edge of the table. It is guaranteed that $0 \leq x_1 < x_2 < ... < x_n \leq 10^9$ holds.
Output
Output the distance between the result stones in one line.
Sample Input 1
5 Alice
10 20 30 40 50
Sample Output 1
30
Sample Input 2
5 Bob
2 3 5 7 11
Sample Output 2
2

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template<class T>using V = vector<T>;


void testcase(){
    ll N; cin >> N;
    string S; cin >> S;
    V<ll> A(N); REP(i,N) cin >> A[i];

    if(N % 2 == 0 && S == "Alice"){
        ll ans = INF;
        ll ok = A.back(), ng = 0;
        while(ng + 1 < ok){
            ll wt = (ng + ok) / 2, k = 0, p = 0;
            while(p < N){
                ll q = p + 1;
                while(q < N && A[q] <= A[p] + wt) q++;
                //ll q = upper_bound(B.begin(), B.end(), B[p] + wt) - B.begin();
                p = q; k++;
            }
            if(k <= N/2) ok = wt; else ng = wt;
        }
        ans = ok;
        cout << ans << "\n";
    }
    else if(N % 2 == 0 && S == "Bob"){
        ll ans = INF;
        REP(i,N/2) ans = min(ans, A[i+N/2] - A[i]);
        cout << ans << "\n";
    }
    else if(N % 2 == 1 && S == "Bob"){
        ll ans = INF;
        ll ok = A.back(), ng = 0;
        while(ng + 1 < ok){
            ll wt = (ng + ok) / 2, k = 0, p = 0;
            while(p < N){
                ll q = p + 1;
                while(q < N && A[q] <= A[p] + wt) q++;
                //ll q = upper_bound(B.begin(), B.end(), B[p] + wt) - B.begin();
                p = q; k++;
            }
            if(k <= N/2+1) ok = wt; else ng = wt;
        }
        ans = ok;
        cout << ans << "\n";
    }
    else {
        ll ans = INF;
        REP(i,N/2) ans = min(ans, A[i+N/2+1] - A[i]);
        cout << ans << "\n";
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    testcase();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4096
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n; 
char st[10]; 
int x[200000]; 
int g[200000]; 
int f[200000]; 

int main() {
	scanf( "%d%s", &n, st ); 
	for (int i = 1; i <= n; ++i) scanf( "%d", &x[i] ); 
	if ( n % 2 == 0 && st[0] == 'B' ) {
		int ans = x[1+n/2] - x[1]; 
		for (int i = 2; i <= n/2; ++i) ans = min( ans, x[i+n/2] - x[i] );
		cout<<ans<<endl; 
	}
	else if ( n % 2 == 1 && st[0] == 'A' ) {
		int ans = x[1+n/2+1] - x[1]; 
		for (int i = 2; i <= n/2; ++i) ans = min( ans, x[i+n/2+1] - x[i] );
		cout<<ans<<endl; 
	}
	else if ( n % 2 == 0 && st[0] == 'A' ) {
		int l = 0, r = x[n] - x[1] + 1; 
		while ( l + 1 < r ) {
			int m = ( l + r ) / 2; 
			f[1] = 1; 
			int j = 1; 
			for (int i = 1; i <= n; ++i) {
				while ( x[i]-x[j] > m ) ++j; 
				f[i] = f[j-1] + 1; 
			}
			if ( f[n] <= n / 2 ) r = m; 
			else l = m; 
		}
		cout<<r<<endl; 
	}
	else {
		int l = 0, r = x[n] - x[1] + 1; 
		while ( l + 1 < r ) {
			int m = ( l + r ) / 2; 
			f[0] = 0; 
			int j = 1; 
			for (int i = 1; i <= n; ++i) {
				while ( x[i]-x[j] > m ) ++j; 
				f[i] = f[j-1] + 1; 
			}
			g[n+1] = 0; 
			j = n; 
			for (int i = n; i >= 1; --i) {
				while ( x[j]-x[i] > m ) --j; 
				g[i] = g[j+1] + 1; 
			}
			int buf = f[0] + g[2]; 
			for (int i = 2; i <= n; ++i) 
				buf = min( buf, f[i-1] + g[i+1] ); 
			if ( buf <= n / 2 ) r = m; 
			else l = m; 
		}
		cout<<r<<endl; 
	}
}
accuracy: 1
time_ms: 40
memory_kb: 4660
final_rank: 19

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <bitset>
using namespace std;

const int MAXN = 100005;
int stones[MAXN], del[MAXN], n;
bool aliceFirst;

// even number of stones, and bob first, will Alice win?
bool check1(int length) {
  vector<int> arr;
  for (int i = 1; i <= n; i++) {
    if (del[i] == length) continue;
    arr.push_back(stones[i]);
  }
  int sz = int(arr.size()) >> 1;
  for (int i = 0, j = i + sz; j < arr.size(); i++, j++) {
    // puts("Fuck 1!");
    if (arr[j] - arr[i] < length) return false;
  }
  return true;
}

// even number of stones, and alice first, will Bob win?
bool check2(int length) {
  vector<int> arr;
  for (int i = 1; i <= n; i++) {
    if (del[i] == length) continue;
    arr.push_back(stones[i]);
  }
  int sz = int(arr.size()) >> 1, ans = 0, start = 0, end = 0;
  int lim = int(arr.size());
  while (start < lim) {
    // printf("Size is %d\n", lim);
    // printf("Start is %d\n", start);
    end = start + 1;
    ans++;
    while (end < lim && arr[end] - arr[start] < length) end++;
    // printf("End is %d\n", end);
    // printf("Fuck 2!\n");
    start = end;
  }
  return ans <= sz;
}

// check whether Alice will win
bool check(int length) {
  if (!(n & 1) && !aliceFirst)
    return check1(length);
  else if ((n & 1) && aliceFirst) {
    del[(n + 1) / 2] = length;
    return check1(length);
  } else if (!(n & 1) && aliceFirst) {
    return !check2(length);
  } else {
    int lneed[MAXN] = {}, rneed[MAXN] = {};
    int lfa[MAXN] = {}, rfa[MAXN] = {};
    lfa[0] = 1;
    lneed[0] = 1;
    for (int i = 1; i <= n; i++) {
      lfa[i] = lfa[i - 1];
      lneed[i] = lneed[i - 1];
      if (abs(stones[i] - stones[lfa[i]]) >= length) {
        lfa[i] = i;
        lneed[i]++;
      }
    }
    rfa[n + 1] = n;
    rneed[n + 1] = 1;
    for (int i = n; i >= 1; i--) {
      rfa[i] = rfa[i + 1];
      rneed[i] = rneed[i + 1];
      if (abs(stones[i] - stones[rfa[i]]) >= length) {
        rfa[i] = i;
        rneed[i]++;
      }
    }
    
    // printf("Now Length is %d\n", length);
    // for(int i=1;i<=n;i++) printf("%d ", lneed[i]); puts("");
    // for(int i=1;i<=n;i++) printf("%d ", lfa[i]); puts("");
    // for(int i=1;i<=n;i++) printf("%d ", rneed[i]); puts("");
    // for(int i=1;i<=n;i++) printf("%d ", rfa[i]); puts("");
    
    for (int i = 1; i <= n; i++) {
      del[i - 1] = length - 1;
      del[i] = length;
      int pos = i + 1;
      int fa = lfa[i - 1];
      while (pos <= n && abs(stones[pos] - stones[fa]) < length) pos++;
      int want = lneed[i - 1] + ((pos <= n) ? (lneed[n] - lneed[pos - 1]) : 0);
      // printf("want %d segments\n", want);
      // int want = lneed[i-1] + rneed[i+1];
      // if(abs(stones[lfa[i-1]] - stones[rfa[i+1]]) <= length) want--;
      if (want <= (n >> 1)) return false;
    }
    
    return true;
  }
}

int main() {
  char ss[10];
  while (~scanf("%d%s", &n, ss)) {
    memset(del, false, sizeof(del));
    if (strcmp(ss, "Alice") == 0)
      aliceFirst = true;
    else
      aliceFirst = false;
    for (int i = 1; i <= n; i++) scanf("%d", &stones[i]);
    int ans = -1, left = 1, right = stones[n] - stones[1];
    while (left <= right) {
      int mid = (left + right) >> 1;
      // printf("MID is %d\n", mid);
      if (check(mid)) {
        ans = mid;
        left = mid + 1;
      } else
        right = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 4524
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int BobEven(int n, int *A) {
  int M = n / 2;
  int res = INT_MAX;
  for (int i = 1; i <= M; i++)
    res = min(res, A[M + i] - A[i]);
  return res;
}
int AliceOdd(int n, int *A) {
  int M = n / 2;
  for (int i = M + 1; i < n; i++)
    A[i] = A[i + 1];
  return BobEven(n - 1, A);
}
bool check(int n, int *A, int M) {
  int cnt = 0;
  int last = 1;
  for (int i = 1; i <= n; i++)
    if (A[i] - A[last] > M)
      cnt++, last = i;
  return cnt >= n / 2;
}
int AliceEven(int n, int *A) {
  int L = 1, H = A[n] - A[1];
  while (L < H) {
    int M = L + H >> 1;
    if (check(n, A, M))
      L = M + 1;
    else
      H = M;
  }
  return L;
}
int BobOdd(int n, int *A) {
  return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}
int n, A[MAXN + 10];
int main() {
  string name;
  cin >> n >> name;
  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]);
  if (name == "Alice") {
    if (n & 1)
      cout << AliceOdd(n, A) << endl;
    else
      cout << AliceEven(n, A) << endl;
  } else {
    if (n & 1)
      cout << BobOdd(n, A) << endl;
    else
      cout << BobEven(n, A) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3628
final_rank: 8

code_snippet: #include <cstdio>
#include <iostream>
using namespace std;
const int MaxN = (int)1e5 + 7;
int n, a[MaxN], ans;
char str[10];
int main() {
  int i, j, le, ri, mi, cnt;
  scanf("%d", &n);
  scanf("%s", str + 1);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i);
  if ((str[1] == 'A' && (n & 1)) || (str[1] == 'B' && (!(n & 1)))) {
    ans = 1 << 30;
    j = (n + 1) / 2;
    for (i = 1; i + j <= n; i++)
      ans = min(ans, a[i + j] - a[i]);
  } else {
    le = 0, ri = a[n];
    while (le <= ri) {
      mi = (le + ri) >> 1;
      cnt = 1;
      for (i = j = 1; i <= n; i++)
        if (a[i] - a[j] > mi)
          cnt++, j = i;
      if (cnt > (n + 1) / 2)
        le = mi + 1;
      else
        ri = mi - 1;
    }
    ans = le;
  }
  printf("%d\n", ans);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3608
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
inline int BobEven(int n, int *A) {
  int mid = n / 2;
  int Ans = A[mid + 1] - A[1];
  for (int i = 2; i <= mid; i++)
    Ans = min(Ans, A[mid + i] - A[i]);
  return Ans;
}
inline int AliceOdd(int n, int *A) {
  int mid = n / 2;
  for (int i = mid + 1; i < n; i++)
    A[i] = A[i + 1];
  return BobEven(n - 1, A);
}
inline bool Check(int n, int *A, int v) {
  int cnt = 0;
  for (int i = 1, j = 1; i <= n; i = j + 1, j = i, cnt++)
    while (j < n && A[j + 1] - A[i] < v)
      j++;
  return (cnt > (n / 2));
}
inline int AliceEven(int n, int *A) {
  int L = 1, R = A[n] - A[1];
  while (L + 1 < R) {
    int mid = (L + R) >> 1;
    if (Check(n, A, mid))
      L = mid;
    else
      R = mid - 1;
  }
  return Check(n, A, R) ? R : L;
}
inline int BobOdd(int n, int *A) {
  return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}
int n;
int A[maxn];
int main() {
  int n, Ans;
  string S;
  cin >> n >> S;
  for (int i = 1; i <= n; i++)
    cin >> A[i];
  if (S[0] == 'A')
    Ans = n & 1 ? AliceOdd(n, A) : AliceEven(n, A);
  else
    Ans = n & 1 ? BobOdd(n, A) : BobEven(n, A);
  cout << Ans << endl;
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3596
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; string first; cin >> N >> first;
	V<int> A(N); rep(i,N) cin >> A[i];
	auto Awin = [&](int t){
		if((N%2==1) == (first == "Alice")){
			// Awin  <=>  max ind <= (N+1)/2
			int j = 0;
			int mx = 0;
			rep(i,N){
				while(j != N-1 && A[j+1]-A[i] < t) j++;
				chmax(mx,j-i+1);
			}
			return mx <= (N+1)/2;
		}else{
			// Bwin  <=>  max clq <= (N+1)/2
			int pre = -1;
			int mx = 0;
			rep(i,N){
				if(pre == -1 || A[i]-A[pre] >= t){
					mx++;
					pre = i;
				}
			}
			return mx > (N+1)/2;
		}
	};
	int lb = 0, ub = TEN(9)+1;
	while(ub-lb>1){
		int m = (ub+lb)/2;
		if(Awin(m)) lb = m;
		else ub = m;
	}
	cout << lb << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
int a[maxn];

int main() {
    int n; 
    char s[10];
    scanf("%d%s", &n, s);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

    if (n % 2 == 0 && s[0] == 'B') {
        int ans = 2e9;
        for (int i = 0; i < n / 2; ++i) ans = min(ans, a[i + n / 2] - a[i]);
        printf("%d\n", ans);
        return 0;
    }
    if (n % 2 == 1 && s[0] == 'A') {
        int ans = 2e9;
        for (int i = 0; i < n / 2; ++i) ans = min(ans, a[i + n / 2 + 1] - a[i]);
        printf("%d\n", ans);
        return 0;
    }

    auto Check = [&](int z) {
        int ans = 0;
        for (int i = 0, j; i < n; i = j) {
            for (j = i; j < n && a[j] - a[i] <= z; ++j);
            ans += j - i - 1;
        }
        return ans >= n / 2;
    };

    int ans = 1e9 + 10;
    for (int d = 30; d >= 0; --d) {
        if (ans - (1 << d) >= 0 && Check(ans - (1 << d))) ans -= (1 << d);
    }
    printf("%d\n", ans);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 4

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
#define SIZE 100005
 
enum Type{
    Alice,
    Bob,
};
 
enum Which{
    pre_DEL,
    pre_REST,
};
 
int N;
int table[SIZE];
bool dp[SIZE][2];
char name[10];
Type last_turn;
 
 
bool is_OK_Alice(int dist){  //辺【距離がdist未満なら張る】を全て消せるか
 
    int L,R,mid;
 
    int max_qlique = 0;
 
    for(int left = 0; left < N; left++){
        //leftを始点とした、dist未満に収まる最大の頂点数を数える
        L = left,R = N-1,mid = (L+R)/2;
        int tmp_max_qlique = 0;
 
        while(L <= R){
 
            if(table[mid]-table[left] < dist){
 
                tmp_max_qlique = mid-left+1;
                L = mid+1;
 
            }else{
 
                R = mid-1;
            }
            mid = (L+R)/2;
        }
        max_qlique = max(max_qlique,tmp_max_qlique);
    }
 
    if(max_qlique >= (N+1)/2+1){ //どうやっても辺が残るのでBob勝ち
 
        return false;
 
    }else{
 
        return true;
    }
}
 
bool is_OK_Bob(int dist){ //辺を少なくとも1本残せるか
 
    int count = 0;
 
    for(int left = 0,right = 0; right < N; right++){
 
        if(table[right]-table[left] > dist){
 
            count++;
            left = right;
        }
    }
 
    if(count >= (N+1)/2){
 
        return true;
 
    }else{ //全ての辺を消されるので不可
 
        return false;
    }
}
 
int main(){
 
    scanf("%d %s",&N,name);
 
    for(int i = 0; i < N; i++){
 
        scanf("%d",&table[i]);
    }
 
    if(name[0] == 'A'){
 
        if(N%2 == 0){
 
            last_turn = Bob;
 
        }else{
 
            last_turn = Alice;
        }
 
    }else{ //name[0] == 'B'
 
        if(N%2 == 0){
 
            last_turn = Alice;
 
        }else{
 
            last_turn = Bob;
        }
    }
 
    int L = 0,R = table[N-1],mid = (L+R)/2;
 
    int ans;
    if(last_turn == Alice){
 
        ans = L;
 
        while(L <= R){
 
            if(is_OK_Alice(mid)){
 
                ans = mid;
                L = mid+1;
 
            }else{
 
                R = mid-1;
            }
            mid = (L+R)/2;
        }
 
 
    }else{ //last_turn == Bob
 
        ans = R;
 
        while(L<=R){
 
            if(is_OK_Bob(mid)){
                ans = mid;
                L = mid+1;
 
            }else{
 
                R = mid-1; //midが小さくなるほど、辺が増えるのでBobが有利になるはず
            }
            mid = (L+R)/2;
        }
        ans++;
    }
 
    printf("%d\n",ans);
 
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3628
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

enum Type{
	Alice,
	Bob,
};

enum Which{
	pre_DEL,
	pre_REST,
};

int N;
int table[SIZE];
bool dp[SIZE][2];
char name[10];
Type last_turn;


bool is_OK_Alice(int dist){  //辺【距離がdist未満なら張る】を全て消せるか

	int L,R,mid;

	int max_qlique = 0;

	for(int left = 0; left < N; left++){
		//leftを始点とした、dist未満に収まる最大の頂点数を数える
		L = left,R = N-1,mid = (L+R)/2;
		int tmp_max_qlique = 0;

		while(L <= R){

			if(table[mid]-table[left] < dist){

				tmp_max_qlique = mid-left+1;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}
		max_qlique = max(max_qlique,tmp_max_qlique);
	}

	if(max_qlique >= (N+1)/2+1){ //どうやっても辺が残るのでBob勝ち

		return false;

	}else{

		return true;
	}
}

bool is_OK_Bob(int dist){ //辺を少なくとも1本残せるか

	int count = 0;

	for(int left = 0,right = 0; right < N; right++){

		if(table[right]-table[left] > dist){

			count++;
			left = right;
		}
	}

	if(count >= (N+1)/2){

		return true;

	}else{ //全ての辺を消されるので不可

		return false;
	}
}

int main(){

	scanf("%d %s",&N,name);

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
	}

	if(name[0] == 'A'){

		if(N%2 == 0){

			last_turn = Bob;

		}else{

			last_turn = Alice;
		}

	}else{ //name[0] == 'B'

		if(N%2 == 0){

			last_turn = Alice;

		}else{

			last_turn = Bob;
		}
	}

	int L = 0,R = table[N-1],mid = (L+R)/2;

	int ans;
	if(last_turn == Alice){

		ans = L;

		while(L <= R){

			if(is_OK_Alice(mid)){

				ans = mid;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}


	}else{ //last_turn == Bob

		ans = R;

		while(L<=R){

			if(is_OK_Bob(mid)){
				ans = mid;
				L = mid+1;

			}else{

				R = mid-1; //midが小さくなるほど、辺が増えるのでBobが有利になるはず
			}
			mid = (L+R)/2;
		}
		ans++;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3628
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

enum Type{
	Alice,
	Bob,
};

enum Which{
	pre_DEL,
	pre_REST,
};

int N;
int table[SIZE];
bool dp[SIZE][2];
char name[10];
Type last_turn;


bool is_OK_Alice(int dist){  //辺【距離がdist未満なら張る】を全て消せるか

	int L,R,mid;

	int max_qlique = 0;

	for(int left = 0; left < N; left++){
		//leftを始点とした、dist未満に収まる最大の頂点数を数える
		L = left,R = N-1,mid = (L+R)/2;
		int tmp_max_qlique = 0;

		while(L <= R){

			if(table[mid]-table[left] < dist){

				tmp_max_qlique = mid-left+1;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}
		max_qlique = max(max_qlique,tmp_max_qlique);
	}

	if(max_qlique >= (N+1)/2+1){ //どうやっても辺が残るのでBob勝ち

		return false;

	}else{

		return true;
	}
}

bool is_OK_Bob(int dist){ //辺【距離がdist未満なら張る】を少なくとも1本残せるか

	int count = 0;

	for(int left = 0,right = 0; right < N; right++){

		if(table[right]-table[left] > dist){

			count++;
			left = right;
		}
	}

	if(count >= (N+1)/2){

		return true;

	}else{ //全ての辺を消されるので不可

		return false;
	}
}

int main(){

	scanf("%d %s",&N,name);

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
	}

	if(name[0] == 'A'){

		if(N%2 == 0){

			last_turn = Bob;

		}else{

			last_turn = Alice;
		}

	}else{ //name[0] == 'B'

		if(N%2 == 0){

			last_turn = Alice;

		}else{

			last_turn = Bob;
		}
	}

	int L = 0,R = table[N-1],mid = (L+R)/2;

	int ans;
	if(last_turn == Alice){ //距離の最大化を図る

		ans = L;

		while(L <= R){

			if(is_OK_Alice(mid)){

				ans = mid;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}


	}else{ //last_turn == Bob:距離の最小化を図る

		ans = R;

		while(L <= R){

			if(is_OK_Bob(mid)){
				ans = mid;
				L = mid+1;

			}else{

				R = mid-1; //midが小さくなるほど、辺が増えるのでBobが有利になる
			}
			mid = (L+R)/2;
		}
		ans++;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3612
final_rank: 16

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

enum Type{
	Alice,
	Bob,
};

enum Which{
	pre_DEL,
	pre_REST,
};

int N;
int table[SIZE];
bool dp[SIZE][2];
char name[10];
Type last_turn;


bool is_OK_Alice(int dist){  //辺【距離がdist未満なら張る】を全て消せるか

	int L,R,mid;

	int max_qlique = 0;

	for(int left = 0; left < N; left++){
		//leftを始点とした、dist未満に収まる最大の頂点数を数える
		L = left,R = N-1,mid = (L+R)/2;
		int tmp_max_qlique = 0;

		while(L <= R){

			if(table[mid]-table[left] < dist){

				tmp_max_qlique = mid-left+1;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}
		max_qlique = max(max_qlique,tmp_max_qlique);
	}

	if(max_qlique >= (N+1)/2+1){ //どうやっても辺が残るのでBob勝ち

		return false;

	}else{

		return true;
	}
}

bool is_OK_Bob(int dist){ //辺【距離がdist未満なら張る】を少なくとも1本残せるか

	int count = 0;

	for(int left = 0,right = 0; right < N; right++){

		if(table[right]-table[left] > dist){

			count++;
			left = right;
		}
	}

	if(count >= (N+1)/2){

		return true;

	}else{ //全ての辺を消されるので不可

		return false;
	}
}

int main(){

	scanf("%d %s",&N,name);

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
	}

	if(name[0] == 'A'){

		if(N%2 == 0){

			last_turn = Bob;

		}else{

			last_turn = Alice;
		}

	}else{ //name[0] == 'B'

		if(N%2 == 0){

			last_turn = Alice;

		}else{

			last_turn = Bob;
		}
	}

	int L = 0,R = table[N-1],mid = (L+R)/2;

	int ans;
	if(last_turn == Alice){ //距離の最大化を図る

		ans = L;

		while(L <= R){

			if(is_OK_Alice(mid)){

				ans = mid;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}


	}else{ //last_turn == Bob:距離の最小化を図る

		ans = 0;

		while(L <= R){

			if(is_OK_Bob(mid)){

				ans = mid;
				L = mid+1;

			}else{

				R = mid-1;
			}
			mid = (L+R)/2;
		}
		ans++;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3608
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

const int Nmax=100010;
int n,x[Nmax];
bool alice;

int Snuke(int l){
	int res=0,j=0;
	REP(i,n){
		while(j<n&&x[j]-x[i]<l)j++;
		chmax(res,j-i);
	}
	return res;
}

pi Rng(int l){
	int q=0,p=0;
	for(int i=0;i<n;){
		int j=i;
		while(j<n&&x[j]-x[i]<l)j++;
		int w=j-i;
		if(w>=2)q+=w-2;
		else p++;
		i=j;
	}
	return pi(q,p);
}

bool Wafrelka(int l){
	if((n%2==0)^alice){
		int s=Snuke(l);
		if(alice){
			if(s>=n/2+2)return false;
			else return true;
		}else{
			if(s>=n/2+1)return false;
			else return true;
		}
	}else{
		pi r=Rng(l);
		if(alice){
			if(r.first>=r.second)return false;
			else return true;
		}else{
			if(r.first>=r.second-1)return false;
			else return true;
		}
	}
	
}

signed main(){
	n=read();
	alice=readString()=="Alice";
	REP(i,n)x[i]=read();
	int l=1,r=1000000001;
	while(r-l>1){
		int m=(r+l)/2;
		if(Wafrelka(m))l=m;
		else r=m;
	}
	cout<<l<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4048
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int MAXN = 100000;

int BobEven(int n, int *A) {
    int M = n / 2;
    int res = INT_MAX;
    for(int i = 1; i <= M; i++)
        res = min(res, A[M+i]-A[i]);
    return res;
}

int AliceOdd(int n, int *A) {
    int M = n / 2;
    for(int i = M + 1; i < n; i++) A[i] = A[i + 1];
    return BobEven(n - 1, A);
}
bool check(int n, int *A, int M) {
    int cnt = 0;
    int last = 1;
    for(int i = 1; i <= n; i++)
        if(A[i] - A[last] >= M)
            cnt++, last = i;
    return cnt >= n / 2;
}
int AliceEven(int n, int *A) {
    int L = 1, H = A[n] - A[1];
    while(L<H) {
        int M = L + H + 1 >> 1;
        if(check(n, A, M))
            L = M;
        else H = M-1;
    }
    return L;
}
int BobOdd(int n, int *A) {
    return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}

int n, A[MAXN + 10];

int main() {

    string name;
    cin >> n >> name;
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    if(name == "Alice") {
        if(n & 1) cout << AliceOdd(n, A) << endl;
        else cout << AliceEven(n, A) << endl;
    }
    else {
        if(n & 1) cout << BobOdd(n, A) << endl;
        else cout << BobEven(n, A) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1644
final_rank: 2

code_snippet: #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n, N, a[100010];
char s[10];

int main(){
	scanf("%d%s", &n, s+1);
	N = (n+1)/2;
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	if (((s[1] == 'A') && (n%2 != 0)) || ((s[1] == 'B') && (n%2 == 0))){
		int ans = a[n];
		for(int i = 1; i <= n-N; i++)
			ans = min(ans,a[i+N]-a[i]);
		cout << ans << endl;
	} else {
		int l = 0, r = a[n], ans = 0;
		while (l <= r) {
			int mid = (l+r)/2, cnt = 1;
			for(int i = 1, j = 1; i <= n; i++)
				if (a[i]-a[j] > mid) cnt++, j = i;
			if (cnt > N) ans = mid, l = mid+1;
			else r = mid-1;
		}
		cout << ans+1 << endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1596
final_rank: 1

code_snippet: #include <iostream>
#include <cstdio>
using namespace std;

const int MaxN = (int)1e5+7;

int n,a[MaxN],ans; char str[10];


int main()
{
	//freopen("K.in","r",stdin);
	//freopen("K.out","w",stdout);

	int i,j,le,ri,mi,cnt;

	scanf("%d",&n);
	scanf("%s",str+1);
	for(i=1;i<=n;i++)
		scanf("%d",a+i);

	if((str[1]=='A' && (n&1)) || (str[1]=='B' && (!(n&1))))
	{
		ans = 1<<30; j =(n+1)/2;
		for(i=1;i+j<=n;i++)
			ans = min(ans , a[i+j]-a[i]);
	}
	else
	{
		le = 0, ri = a[n];
		while(le<=ri)
		{
			mi = (le+ri)>>1;
			cnt = 1;
			for(i=j=1;i<=n;i++)
				if(a[i]-a[j]>mi) cnt++,j=i;
			//printf("%d %d\n",mi,cnt);
			if(cnt>(n+1)/2) le = mi+1;
			else ri = mi-1;
		}
		ans = le;
	}

	printf("%d\n",ans);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3612
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int MAXN = 100000;

int BobEven(int n, int *A) {
    int M = n / 2;
    int res = INT_MAX;
    for(int i = 1; i <= M; i++)
        res = min(res, A[M+i]-A[i]);
    return res;
}

int AliceOdd(int n, int *A) {
    int M = n / 2;
    for(int i = M + 1; i < n; i++) A[i] = A[i + 1];
    return BobEven(n - 1, A);
}
bool check(int n, int *A, int M) {
    int cnt = 0;
    int last = 1;
    for(int i = 1; i <= n; i++)
        if(A[i] - A[last] > M)
            cnt++, last = i;
    return cnt >= n / 2;
}
int AliceEven(int n, int *A) {
    int L = 1, H = A[n] - A[1];
    while(L<H) {
        int M = L + H >> 1;
        if(check(n, A, M))
            L = M+1;
        else H = M;
    }
    return L;
}
int BobOdd(int n, int *A) {
    return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}

int n, A[MAXN + 10];

int main() {

    string name;
    cin >> n >> name;
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    if(name == "Alice") {
        if(n & 1) cout << AliceOdd(n, A) << endl;
        else cout << AliceEven(n, A) << endl;
    }
    else {
        if(n & 1) cout << BobOdd(n, A) << endl;
        else cout << BobEven(n, A) << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1644
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
inline int BobEven(int n,int *A)
{
    int mid=n/2;
    int Ans=A[mid+1]-A[1];
    for(int i=2;i<=mid;i++)
        Ans=min(Ans,A[mid+i]-A[i]);
    return Ans;
}
inline int AliceOdd(int n,int *A)
{
    int mid=n/2;
    for(int i=mid+1;i<n;i++)A[i]=A[i+1];
    return BobEven(n-1,A);
}
inline bool Check(int n,int *A,int v)
{
    int cnt=0;
    for(int i=1,j=1;i<=n;i=j+1,j=i,cnt++)
        while(j<n && A[j+1]-A[i]<v)j++;
    return (cnt>(n/2));
}
inline int AliceEven(int n,int *A)
{
    int L=1,R=A[n]-A[1];
    while(L+1<R)
    {
        int mid=(L+R)>>1;
        if(Check(n,A,mid))L=mid;
        else R=mid-1;
    }
    return Check(n,A,R)?R:L;
}
inline int BobOdd(int n,int *A)
{
    return min(AliceEven(n-1,A),AliceEven(n-1,A+1));
}
int n;
int A[maxn];
int main()
{
// 233
    int n,Ans;
    string S;
    cin>>n>>S;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    if(S[0]=='A')Ans=n&1?AliceOdd(n,A):AliceEven(n,A);
    else Ans=n&1?BobOdd(n,A):BobEven(n,A);
    cout<<Ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3612
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
inline int BobEven(int n,int *A)
{
    int mid=n/2;
    int Ans=A[mid+1]-A[1];
    for(int i=2;i<=mid;i++)
        Ans=min(Ans,A[mid+i]-A[i]);
    return Ans;
}
inline int AliceOdd(int n,int *A)
{
    int mid=n/2;
    for(int i=mid+1;i<n;i++)A[i]=A[i+1];
    return BobEven(n-1,A);
}
inline bool Check(int n,int *A,int v)
{
    int cnt=0;
    for(int i=1,j=1;i<=n;i=j+1,j=i,cnt++)
        while(j<n && A[j+1]-A[i]<v)j++;
    return (cnt>(n/2));
}
inline int AliceEven(int n,int *A)
{
    int L=1,R=A[n]-A[1];
    while(L+1<R)
    {
        int mid=(L+R)>>1;
        if(Check(n,A,mid))L=mid;
        else R=mid-1;
    }
    return Check(n,A,R)?R:L;
}
inline int BobOdd(int n,int *A)
{
    
    return min(AliceEven(n-1,A),AliceEven(n-1,A+1));
}
int n;
int A[maxn];
int main()
{
    int n,Ans;
    string S;
    cin>>n>>S;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    if(S[0]=='A')Ans=n&1?AliceOdd(n,A):AliceEven(n,A);
    else Ans=n&1?BobOdd(n,A):BobEven(n,A);
    cout<<Ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3584
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N;
vector<int> ip;
bool fs = false;

bool test(int a) {
  int id = 0;
  int t = 0;
  while (id < N) {
    int j = id;
    while (ip[j] - ip[id] < a and j < N) {
      j ++;
    }
    t += (j - id - 1);
    id = j;
  }
  int n = N - 2;
  int want = fs ? (n - n / 2) : n / 2;
  if (t <= want) return true;
  else return false;
}

bool test2(int a) {
  int z = N/2, q = N/2;
  int r = 0;
  for (int i=0; i<z; i++) {
    int t = ip[i+q] - ip[i];
    if (t < a) {
      if (r) return false;
      r = 1;
      q ++;
      t = ip[i+q] - ip[i];
      if (t < a) return false;
    }
  }
  return true;
}

int main() {
  cin >> N;
  string s;
  cin >> s;
  if (s == "Alice") fs = true;
  for (int i=0; i<N; i++) {
    int a; cin >> a;
    ip.push_back(a);
  }
  sort(ip.begin(), ip.end());
  
  if ((N&1) and !fs or !(N&1) and fs) {
    int l = 0, r = ip.back();
    while (l < r) {
      int md = (l+r+1) / 2;
      if (test(md)) {
        l = md;
      } else {
        r = md - 1;
      }
    }
    cout << l << endl;
  } else if (!(N&1)) {
    int ans = 1029384756;
    int z = N/2;
    for (int i=0; i<z; i++) {
      ans = min(ans, ip[z+i] - ip[i]);
    }
    cout << ans << endl;
  } else {
    int l = 0, r = ip.back();
    while (l < r) {
      int md = (l+r+1) / 2;
      if (test2(md)) {
        l = md;
      } else {
        r = md - 1;
      }
    }
    cout << l << endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 3576
final_rank: 9