Language: C++

//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

template <class T> T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}


#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<u32> a(n);
	u32 sum = 0;
	for (auto &e : a) {
		::std::cin >> e;
		sum += e;
	}
	usize ans;
	u32 dist = 1000000;
	for (const auto i : rep<>(0, n)) {
		const u32 dif = difference(sum, a[i] * n);
		if (smini(dist, dif)) ans = i;
	}
	::std::cout << ans << ::std::endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:43: error: no matching function for call to 'difference(u32&, usize)'
   93 |                 const u32 dif = difference(sum, a[i] * n);
      |                                 ~~~~~~~~~~^~~~~~~~~~~~~~~
a.cc:72:22: note: candidate: 'template<class T> T difference(const T&, const T&)'
   72 | template <class T> T difference(const T &a, const T &b) {
      |                      ^~~~~~~~~~
a.cc:72:22: note:   template argument deduction/substitution failed:
a.cc:93:43: note:   deduced conflicting types for parameter 'const T' ('unsigned int' and 'usize' {aka 'long unsigned int'})
   93 |                 const u32 dif = difference(sum, a[i] * n);
      |                                 ~~~~~~~~~~^~~~~~~~~~~~~~~