Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func max(l, r int64) int64 {
	if l > r {
		return l
	}
	return r
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)
	input := arr[1]
	sort.Slice(input, func(i, j int) bool { return input[i] < input[j] })

	var costMin int64 = math.MaxInt64
	nMin := input[0]
	nMax := input[len(input)-1]
	for x := nMin; x <= nMax; x++ {
		costCurrent := max(x - nMin, nMax - x)
		if costCurrent < costMin {
			costMin = costCurrent
		}
	}

	fmt.Println(costMin)
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; cin >> n;
    int a[n]; rep(i,0,n) cin >> a[i];

    int ans = MOD;
    rep(i,0,2001){
        int sum = 0;
        rep(j,0,n){
            sum = max(sum, abs((int)i-a[j]));
        }
        if(sum < ans) ans = sum;
    }
    cout << ans << "\n";
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, pii > piii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N;
int a[1010];

int abss(int A){
    if(A < 0)return -A;
    return A;
}

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a + N);
    cout << a[N - 1] - (a[N - 1] + a[0]) / 2 << endl;

    return 0;
}

/*

*/

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> xs(n);
  for(int i=0;i<n;i++) cin>>xs[i];
  sort(xs.begin(),xs.end());
  cout<<(xs.back()-xs.front()+1)/2<<endl;
  return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	auto V=vecin(N);
	auto R=minmax_element(ALL(V));
	auto P=((*R.second)+(*R.first))/2;
	out(max((*R.second)-P,(*R.first)-P));
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int>home(N);
    for(int i=0;i<N;i++){
        cin >> home[i];
    }
    sort(home.begin(),home.end());
    int s =(home[0]+home[N-1])/2;
    int ans = 0;
    for(int i=0;i<N;i++){
        if(home[i]<=s && ans<s-home[i]){
            ans = s-home[i];
        }else if(home[i]>=s && ans<home[i]-s){
            ans = home[i]-s;
        }
    }
    cout << ans <<endl;
}

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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	ll n;
	cin >> n;
	int tmp;
	int Max = -100;
	int Min = 10000;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp > Max) Max = tmp;
		if (tmp < Min) Min = tmp;
	}
	if ((Max - Min) % 2 == 0)	cout << (Max - Min) / 2 << endl;
	else cout << (Max - Min) / 2 + 1 << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int min=10000;
  int max=0;
  int n,x,home;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x;
    if(min>=x) min=x;
    if(max<=x) max=x;
  }
    home=(max+min)/2;
    cout<<max-home<<endl;
}

C++: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> x(N);
    for(int i=0; i<N; i++) cin >> x[i];

    int ans = INF;
    for(int i=0; i<2010; i++) {
        int cand = 0;
        for(int j=0; j<N; j++) {
            int d = abs(i - x[j]);
            chmax(cand, d);
        }
        chmin(ans, cand);
    }
    cout << ans << endl;
    return 0;
}