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>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int x[1001];
	cin>>n;

	int mi=2001,ma=0;
	rep(i,n){
		cin>>x[i+1];
		mi=min(mi,x[i+1]);
		ma=max(ma,x[i+1]);
	}

	int ans=3001;
	for(int i=0; i<ma+1; i++){
		int t=max(i-mi,ma-i);
		ans=min(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int x[1000];
  int sum=0;
  rep(i,n){cin>>x[i];sum+=x[i];}
  sort(x,x+n);
  sum=x[0]+x[n-1];
  sum/=2;
  cout<<max(sum-x[0],x[n-1]-sum)<<endl;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int beg,fin,none;
    cin >>beg;
    fin=beg;
    for(int i=0;i<n-1;i++){
        cin >> none;
        if(fin<none) fin=none;
        if(beg>none) beg=none;
    }
    cout << (fin-beg+1)/2 << endl;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int ma = 0, mi = INF;
    rep(i, N) {
        int x;
        cin >> x;
        ma = max(x, ma);
        mi = min(x, mi);
    }
    cout << (ma - mi + 1) / 2 << endl;
    return 0;
}

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

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

  vector<int>vec(N);
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(),vec.end());

  sa=vec.at(N-1)-vec.at(0);

  if(sa%2==1){
    cout << sa/2+1 <<endl;
  }
  else {
    cout << sa/2 <<endl;
  }

  
}

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

#define MAXPOS 2000

int main(void){
    int num;    cin >> num;
    int pos[num];   for(int i = 0; i < num; i++)    cin >> pos[i];
    int minpos = MAXPOS, maxpos = 0;
    for(int i = 0; i < num; i++){
        if(pos[i] < minpos) minpos = pos[i];
        if(pos[i] > maxpos) maxpos = pos[i];
    }
    if(!((maxpos - minpos) % 2))   cout << (maxpos - minpos) / 2 << endl;
    else    cout << (maxpos - minpos) / 2 + 1 << endl;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, X[1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> X[i];

    int ans = inf;
    rep(shukaijo, 0, 2001) {
        int ma = 0;
        rep(i, 0, N) chmax(ma, abs(shukaijo - X[i]));
        chmin(ans, ma);
    }
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<cmath>
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
signed main() {
	int n, a[1234]; cin >> n; for0(i, n)cin >> a[i]; sort(a, a + n); cout << (a[n - 1] - a[0] + 1) / 2 << endl;
}

C++: #include <iostream>
using namespace std;
int main() {

    int n; 
    cin >> n;

    int x, xmin = 2000, xmax = 0;
    for ( int i=0; i<n; ++i ) {
	cin >> x;
	if ( x < xmin ) xmin = x;
	if ( x > xmax ) xmax = x;
    }

    cout << xmax - (xmin + xmax)/2 << endl;
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int N, tmp;
    int n[1010];

    cin >> N;
    int max = 0, min = 2010;
    for(int i = 0; i < N; i++){
        cin >> n[i];
        if(n[i] > max) max = n[i];
        if(n[i] < min) min = n[i];
    }
    if((max - min) % 2 == 1) cout << (max - min + 1) / 2 << endl;
    else cout << (max - min) / 2 << endl;
}

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

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> x(n);
  for(auto &a:x) cin >> a;
  int ans=1e9;
  for(int i=0;i<=2000;++i) {
    int tmp=0;
    for(int j=0;j<n;++j) tmp=max(tmp,abs(i-x[j]));
    ans=min(ans,tmp);
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
    int N; cin >> N;
    int mx = -1, mn = 2020;
    for(int i = 0; i < N; ++i) {
        int x; cin >> x;
        mx = max(mx, x);
        mn = min(mn, x);
    }
    cout << (mx - mn + 1) / 2 << '\n';
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, sum = 0, num = 2001; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; sum = max(sum, a); num = min(num, a);
	}
	cout << max(sum - (abs(sum - num) / 2 + min(sum, num)), num - (abs(sum - num) / 2 + min(sum, num))) << endl;
	cin >> n;
}