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<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//17:00~

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int n,a=0,b=99999;cin>>n;
	while(n--){int x;cin>>x;maxeq(a,x);mineq(b,x);}
	cout<<(a+1-b)/2<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    SORT(a);
    int x = a.front() + a.back() >> 1;
    cout << max(x - a.front(), a.back() - x) << "\n";
}

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

vector<int> input(int N){
    int i;
    vector<int> output(N);
    for(i=0;i<N;i++)cin>>output[i];
    return output;
}

int main(){
    int N,i,result,x_min,x_max;
    vector<int> X;

    cin>>N;
    X=input(N);
    x_min=*min_element(X.begin(),X.end());
    x_max=*max_element(X.begin(),X.end());
    
    result=(x_max-x_min)/2+(x_max-x_min)%2;

    cout<<result<<endl;
    return 0;
}

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

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

int main(){
	int n, x, min, max;
	cin >> n;
	cin >> x;
	min = x;
	max = x;
	for(int i=1; i<n; ++i){
		cin >> x;
		if(x>max){max=x;}
		if(x<min){min=x;}
	}

	cout << (max-min)/2 + (max-min)%2 << 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];
    int MIN = *min_element(begin(X), end(X));
    int MAX = *max_element(begin(X), end(X));
    int m = (MIN + MAX) / 2;
    cout << max(abs(MIN - m), abs(MAX - m)) << endl;
}

C++: #include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, n, max = 0, min = 2000, x;
  scanf("%lld", &n);
  for(i = 0; i < n; i++) {
    scanf("%lld", &x);
    if(max < x) max = x;
    if(min > x) min = x;
  }
  printf("%lld\n", (max - min + 1) / 2);
  return 0;
}

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

int main(){
	int n;
	int xmax=0,xmin=2000;
	cin>>n;
	for(int i=0; i < n;i++){
		int a;
		cin>>a;
		xmax = max(xmax,a);
		xmin = min(xmin,a);
	}
	cout<<(xmax-xmin+1)/2<<endl;
}