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 vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
int main() {
    IN(int, n);
    VIN(int, a, n);
    SORT(a);
    int aja = (a[n-1]-a[0]+1)/2;
    COUT(aja);
}

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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    int n;
    cin>>n;
    int a[n];
    bool used[2222]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans = 1e9;
    for(int i=0;i<=2000;i++){
        ans = min(ans,max(i-a[0],a[n-1]-i));
    }
    cout << ans<< endl;
    
}

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

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

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

int main() {
	int N, x, a = 0, b = INT_MAX;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x;
		a = max(a, x);
		b = min(b, x);
	}
	cout << (1 + a - b) / 2 << endl;
}

C++: #include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll mn = 1000000000,mx = 0 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		if(a>mx) mx = a ;
		if(a<mn) mn = a ;
	}
	ll d = mx-mn ;
	if(d&1) cout << d/2+1 << endl ;
	else cout << d/2 << endl ;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int n, t, minv=2001, maxv=-1, diff;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        minv = min(minv, t);
        maxv = max(maxv, t);
    }
    diff = maxv - minv;
    diff = (diff % 2 == 0) ? diff/2 : diff/2+1;
    printf("%d\n", diff);
    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.front() + 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> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  int now=(v[0]+v[n-1]+1)/2;
  cout << now-v[0] << endl;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n);
    for(int i = 0; n > i; i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    if(A[n-1]==A[0])cout << 0 << endl;
    else cout << (A[n-1]-A[0]-1)/2+1 << endl;
}

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

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define all(x) (x).begin(), (x).end()

int main(){
    int N;
    cin >> N;
    int x[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<iostream>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int x[n];
    for(int i = 0; i < n; i++)  cin >> x[i];
    sort(x, x+n);
    cout << (x[n-1]-x[0]+1)/2 << endl;
    return 0;
}

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


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

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

using namespace std;

int N;
vector<int> HomeId;

int main() {
	int x;

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

	return 0;
}