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;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n;
    cin >> n;
    V<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = inf;
    sort(all(a));
    for(int i = 0; i <= 2000; i++) {
        int tmp = 0;
        rep(j,n) chmax(tmp, abs(a[j]-i));
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};



int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int x = INF, y = 0;
  rep(i, n) {
    chmin(x, a[i]);
    chmax(y, a[i]);
  }
  cout << (y - x + 1) / 2 << endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
int fabs(int x){
    if(x<0) return -x;
    return x;
}
int main(){
    int n; cin>>n;
    int data[1001];
    for(int i=1;i<=n;++i) cin>>data[i];
    int maxv=0,minv=1000000000;
    for(int i=1;i<=2000;++i){
	maxv=0;
	for(int j=1;j<=n;++j)
	    maxv=max(maxv,fabs(i-data[j]));
	minv=min(minv,maxv);
    }
    cout<<minv<<endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a,Imax = 0,Imin = 3000;
    for(int i = 0;i < N;i++){
        cin >> a;
        Imax = max(Imax,a);
        Imin = min(Imin,a);
    }
    int I;
    I = Imax - Imin;
    //cout << Imax << endl;
    //cout << Imin << endl;
    if(I % 2 == 1){
        cout << I/2+1 << endl;
    }else{
        cout << I/2 << endl;
    }
    
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> ie(n);
    rep(i,n){
        cin >> ie[i];
    }
    int mi = 2005;
    int mx = 0;
    rep(j,n){
        mi = min(mi, ie[j]);
        mx = max(mx, ie[j]);
    }
    int ans;
    if ((mx - mi) % 2 == 0){
        ans = (mx - mi) / 2;
    }
    else{
        ans = (mx - mi + 1) / 2;
    }
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int ans = INF;
    rep(i,2001){
        int t = 0;
        rep(j,n)t = max(t, abs(a[j]-i));
        ans = min(ans, t);
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
llong x[1005];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i];

    llong ans = 1ll << 60ll;
    for (llong p = 0; p <= 2000; p++) {
        llong mv = -1;
        for (llong i = 0; i < n; i++) {
            mv = max(mv, llabs(x[i] - p));
        }

        ans = min(mv, ans);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
  int banti[2000];
  int N,num,saisyo=20000,saigo=0;
  cin >> N;
  
  for(int i = 1 ; i < 2001 ; i++){
    banti[i] = 0;
  }
  
  for(int i = 0;i < N ; i++){
    cin >> num;
    banti[num] = 1;
    if(saisyo > num){
      saisyo = num;
    }
    if(saigo < num){
    saigo = num;
    }
  }

  //cout << "saisyo is " << saisyo << endl;
  //cout << "saigo is " << saigo << endl;

  cout << (saigo - (saisyo-1)) / 2   << endl;

}

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

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

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

int main(){
    int n;
    cin >> n;

    int s(1000000),b(0);
    for(int i=0;i<n;i++){
        int x;  cin >> x;

        s = min(s,x);
        b = max(b,x);
    }

    if((b-s)%2==0)
        cout << (b-s)/2 << endl;
    else
        cout << (b-s)/2+1 << endl;

    return 0;
}