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>
#define ll long long

using namespace std;

int main(){
	ll n, le=2021, ri=0, i;
	
	cin>>n;
	
	vector <ll> a(n+1);
	
	for(i=1;i<=n;i++){
		cin>>a[i];
		le=min(le, a[i]);
		ri=max(ri, a[i]);
	}
	
	ri=ri-le;
	le=0;
	
	
	cout<<(ri+le)/2+(ri+le)%2<<"\n";
}

C++: #include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int N,x,syu=0,xmax=0,xmin=2000;
int main(void)
{
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>x;
		if(x<xmin){
			xmin=x;
		}
		if(x>xmax){
			xmax=x;
		}
	}
	syu+=(double)0.5+(xmax-xmin)/2.0;
	cout<<syu<<endl;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	cout << a[n-1]-(a[0]+a[n-1])/2 << endl;
}

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

void Solve(){
    UL n; cin >> n;
    UL x[1000]; rep(i, n) cin >> x[i];
    sort(x, x+n);
    cout << (x[n-1] - x[0] + 1) / 2 << endl;
}

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

C++: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int updivide(int a,int b){
    if(b==1) return a;
    else if(a%b==0) return a/b;
    else return (a/b)+1;
}

int main(){
    int n;
    in(n);
    vector<int> vec(n);
    in(vec);
    sort(all(vec));
    out(updivide(vec[n-1]-vec[0],2));
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) {
        cin >> x.at(i);
    }
    int shuukai = (*max_element(x.begin(), x.end())+*min_element(x.begin(), x.end()))/2;
    int longest = 0;
    rep(i,n) {
        int time = abs(shuukai-x.at(i));
        if (time > longest) {
            longest = time;
        }
    }
    cout << longest << endl;
}