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<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,x[1000],i,j,sa,MAX,MIN;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	  MIN=2001;
	for(i=0;i<=2000;i++){
		MAX=-1;
		for(j=0;j<n;j++){
			sa=i-x[j];
			if(sa<0){
				sa=-sa;
			}
			MAX=max(MAX,sa);
		}
		MIN=min(MAX,MIN);
	}
	printf("%d\n",MIN);
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int ans = (int)1e29;
    for (int i = 0; i < 2007; i++) {
        int cur_max = 0;
        for (int j = 0; j < n; j++) {
            cur_max = max(cur_max, abs(x[j] - i));
        }
        ans = min(ans, cur_max);
    }
    cout << ans << '\n';
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <math.h>
#include <limits>

using namespace std;

int main(void) {
	int N, tmp, min = 2000, max = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		if (min > tmp) min = tmp;
		if (max < tmp) max = tmp;
	}
	cout << (max - min + 1) / 2 << endl; //小数点以下切り上げ
	
	return 0;
}

C++: #include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x[i];
  lint ans = INF;
  for(int i = 0; i <= 2000; i++) {
    lint cost = 0;
    for(int j = 0; j < n; j++) cost = max(cost, (lint)abs(i - x[j]));
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main() {
	int N; cin >> N;
	vector<int>A(N);
	int Min = 3000, Max = 0;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		Min = min(Min, A.at(i));
		Max = max(Max, A.at(i));
	}
	if (Min == Max) cout << 0 << endl;
	else {
		int sum = 0, ans = 9999;
		for (int j = Min; j <= Max; j++) {
			sum = 0;
			for (int k = 0; k < N; k++) {
				sum = max(sum, abs(A.at(k) - j));
			}
			ans = min(ans, sum);
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
int main() {
    int n,sum,ans = 1e9,mx=0,mi=1e9; cin >> n; vector<int> v(n);
    rep(i, n) {
        cin >> v[i];
        mx = max(mx, v[i]);
        mi = min(mi, v[i]);
    }
    for(int i = mi;i <=mx;i++) {
        sum = 0;
        rep(j, n) {
            sum = max(abs(i - v[j]),sum);
        }
        ans = min(ans, sum);
    }cout << ans << endl;
}

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

using namespace std;

void solve()
{
    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;
}

int main()
{
    solve();
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int N,maxnum=-1,minnum=2001;
  cin>>N;
  vector<int> x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
    if(x[i]<minnum) minnum=x[i];
    if(x[i]>maxnum) maxnum=x[i];
  }
  int dis=maxnum-minnum;
  if(dis%2==1) dis+=1;
  cout<<dis/2<<endl;
  return 0;
}