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;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = upper;
	rep(i, 2001) {
		int tmp = 0;
		rep(j, n) {
			chmax(tmp, abs(i - a[j]));
		}
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>

int main() {
  int n;
  int t;

  std::cin >> n;

  int w_index = -1;
  int e_index = -1;

  for (int i = 0; i < n; ++i) {
    std::cin >> t;

    if (w_index == -1) {
      w_index = t;
    }

    if (e_index == -1) {
      e_index = t;
    }

    if (t < w_index) {
      w_index = t;
    }

    if (e_index < t) {
      e_index = t;
    }
  }

  t = (e_index - w_index) % 2 == 0 ? ((e_index - w_index) / 2) : ((e_index - w_index) / 2 + 1);
  std::cout << std::max(w_index + t - w_index, e_index - w_index - t) << std::endl;

  return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
    sum+=x[i];
  }
  sum/=n;
  int ans=100000000;
  for(int i=-500;i<500;i++){
    int tmp=0;
    for(int j=0;j<n;j++){
      tmp=max(tmp,abs((sum+i)-x[j]));
    }
    ans=min(ans,tmp);
  }
  cout<<ans<<'\n';
  return(0);
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	int n;
    cin >> n;
    vector<int> x(n);
    int mx = -1;
    int mn = 2001;
    rep(i,0,n){
        cin >> x[i];
        if(mx < x[i]){
            mx = x[i];
        }
        if(mn > x[i]){
            mn = x[i];
        }
    }

    if((mx - mn)%2 == 0){
        cout << (mx - mn) / 2 << endl;
        return 0;
    }else{
        cout << (mx - mn) / 2 + 1 << endl;
        return 0;
    }
}

C++: 
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0;i < (n);i++)
using namespace std;

int main() {
	long long N;
	long long n = 2001;

	cin >> N;
	vector<long long> x(N);
	rep(i, N) cin >> x[i];
	sort(x.begin(), x.end());
	if(N == 1) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, x[N-1]) {
		long long a = 0;
		rep(j, N) a = max(a, abs(i - x[j]));
		if(a < n) {
			n = a ;

		}
	}
	cout << n << endl;
}

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

int main(){
    
    int i, n, t, t1=2000, t2=0;
    
    cin >> n;
    
    for(i=0;i<n;i++){
        cin >> t;
        if(t<t1){
            t1=t;
        }
        if(t2<t){
            t2=t;
        }
    }
    cout << (t2-t1+1)/2 << endl;
    
}

C++: #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 1005

int N;

int main(){

	scanf("%d",&N);

	int tmp;
	int minimum = BIG_NUM,maximum = -BIG_NUM;

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

		scanf("%d",&tmp);

		minimum = min(minimum,tmp);
		maximum = max(maximum,tmp);
	}

	if((maximum-minimum)%2 == 0){

		printf("%d\n",(maximum-minimum)/2);

	}else{

		printf("%d\n",(maximum-minimum)/2+1);
	}

	return 0;
}

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

int main()
{

    int N, minv = 2001, maxv = 0, h;
    std::scanf("%d", &N);
    for (int i = 0; i < N; i ++) {
        std::scanf("%d", &h);
        minv = std::min(minv, h), maxv = std::max(maxv, h);
    }
    ((maxv - minv) % 2 == 0) ? std::printf("%d\n", (maxv-minv)/2) : std::printf("%d\n", (maxv-minv)/2+1);

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i = 0; i < N; ++i) cin >> X[i];
  sort(X.begin(), X.end());
  cout << (X.back()-X[0]+1)/2 << endl;
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	
	int N;
	cin >> N;
	vector<int> x(N);
	int num = 1000000, sum = -1;
	rep(i, N) {
		cin >> x[i];
		if (x[i] < num) {
			num = x[i];
		}
		if (x[i] > sum) {
			sum = x[i];
		}
	}

	int d = (num + sum) / 2;
	int ans;
	if (sum - d >= d - num) {
		 ans = sum - d;
	}
	else {  ans = d - num; }

	cout << ans << endl;

	return 0;
}