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"
#pragma GCC optimize("Ofast")

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(size_t, N);

    vector<intmax_t> x(N);
    input(x);

    intmax_t minv = INF;
    reps(c, 0, 2000) {
        intmax_t maxv = 0;
        for (const auto xi: x) chmax(maxv, diff(c, xi));
        chmin(minv, maxv);
    }

    output(minv);

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    
    int N , Max = 0 , min = 2000 ;
    cin >> N ;
    
    int x[N] ;
    
    for(int i = 1 ; i <= N ; i++){
        cin >> x[i] ;
    }
    
    for(int j = 1 ; j <= N ; j++){
        if(Max <= x[j]){
            Max = x[j] ;
        }
        if(min >= x[j]){
            min = x[j] ;
        }
    }
    
    int S ;
    S = (Max - min + 1) / 2 ;
    
    cout << S << endl ;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  int x[1100];
  for (int i = 0; i < N; i++) cin >> x[i];

  int ans = 1000000;
  for (int i = 0; i <= 2000; i++) {
    int time = 0;
    for (int j = 0; j < N; j++) {
      time = max(time, abs(i - x[j]));
    }
    ans = min(ans, time);
  }

  cout << ans << endl;
  
  return 0;
}

C++: // 2020/07/13 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;

	int x_max = -1;			// 最も東の地点
	int x_min = 2001;		// 最も西の地点

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

		x_max = max(x, x_max);
		x_min = min(x, x_min);
	}

	cout << (x_max-x_min+1)/2 << endl;	// .5を切り上げるために

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n;
    cin >>n;
    int a[n];
    for(int i=0;i<=n-1;i++){
        cin >>a[i];
    }
    int min=a[0],max=a[0];
    for(int j=0;j<=n-1;j++){
        if(min>=a[j]) min=a[j];
    }
    for(int j=0;j<=n-1;j++){
           if(max<=a[j]) max=a[j];
       }
    int ave=(max-min+1)/2;
    
    cout<<ave<<endl;
    
}

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

int N;
int x[1000];
int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> x[i];
	int m = INT_MAX;
	for(int i=0; i<=2000; i++){
		int tmp = 0;
		for(int j=0; j<N; j++){
			tmp = max(tmp, abs(x[j]-i));
		}
		m = min(m, tmp);
	}
	cout << m << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N,ans;cin>>N;
    VI x(N,-1);
    REP(i,N)cin>>x[i];
    sort(All(x));
    ans=x[N-1]-x[0];
    if(ans%2!=0){
        ans=int(ans/2);
        ans++;
    }else{
        ans=int(ans/2);
    }
    cout<<ans<<endl;
}