Problem:
Score : 200 points

Problem Statement

Niwango-kun is an employee of Dwango Co., Ltd.

One day, he is asked to generate a thumbnail from a video a user submitted.

To generate a thumbnail, he needs to select a frame of the video according to the following procedure:

Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video.

Select t-th frame whose representation a_t is nearest to the average of all frame representations.

If there are multiple such frames, select the frame with the smallest index.

Find the index t of the frame he should select to generate a thumbnail.

Constraints

1 \leq N \leq 100

1 \leq a_i \leq 100

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N
a_{0} a_{1} ... a_{N-1}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

1

Since the average of frame representations is 2, Niwango-kun needs to select the index 1, whose representation is 2, that is, the nearest value to the average.

Sample Input 2

4
2 5 2 5

Sample Output 2

0

The average of frame representations is 3.5.

In this case, every frame has the same distance from its representation to the average.

Therefore, Niwango-kun should select index 0, the smallest index among them.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template<typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using ll = long long int;
using i64 = long long int;
#define all(vec) (vec).begin(),(vec).end()
template <typename T> inline void ckmax(T &x, T y) {if (y > x) x = y; }
template <typename T> inline void ckmin(T &x, T y) {if (y < x) x = y; }
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " =: " << a << endl;
	err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& buf) {
    return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v) {
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++) {
        if(!first) os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::set<T>& v) {
    bool first = true;
    os << "{";
    for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii;
        first = false;
    }
    return os << "}";
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v) {
    bool first = true;
    os << "{";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
        if(!first) os << ", ";
        os << *ii ;
        first = false;
    }
    return os << "}";
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::unordered_set<T>& v) {
    return os << std::set<T>(v.begin(), v.end());
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::multiset<T,greater<T>>& v) {
    return os << std::vector<T>(v.begin(), v.end());
}
template<typename T>
inline std::ostream &operator << (std::ostream & os,const ordered_set<T>& v) {
    return os << std::set<T>(v.begin(), v.end());
}
template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os,const std::unordered_map<T1, T2>& v) {
    return os << std::map<T1, T2>(v.begin(), v.end());
}

const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
/***********************************************************************/
struct rec {
    i64 x1, y1, x2, y2;
    rec(i64 a, i64 b, i64 c, i64 d) {
        x1 = a;
        y1 = b;
        x2 = c;
        y2 = d;
    }
    rec() {};
};
bool ins(const rec &a, const rec &b) {
    // a in b?
    return (a.x1 >= b.x1 && a.x2 <= b.x2 && a.y1 >= b.y1 && a.y2 <= b.y2);
}
vector<rec> cut(rec a, rec b) {
    vector<rec> ret;
    if (a.x2 < b.x1 || a.y2 < b.y1 || a.x1 > b.x2 || a.y1 > b.y2) {
        ret.push_back(b);
        return ret;
    }
    a.x2 = min(a.x2, b.x2);
    a.y2 = min(a.y2, b.y2);
    a.x1 = max(a.x1, b.x1);
    a.y1 = max(a.y1, b.y1);
    if (a.x2 + 1 <= b.x2) {
        ret.emplace_back(a.x2 + 1, a.y1, b.x2, a.y2);
    }
    if (a.y2 + 1 <= b.y2) {
        ret.emplace_back(a.x1, a.y2 + 1, a.x2, b.y2);
    }
    if (a.x1 - 1 >= b.x1) {
        ret.emplace_back(b.x1, a.y1, a.x1 - 1, a.y2);
    }
    if (a.y1 - 1 >= b.y1) {
        ret.emplace_back(a.x1, b.y1, a.x2, a.y1 - 1);
    }
    if (a.x2 + 1 <= b.x2 && a.y2 + 1 <= b.y2) {
        ret.emplace_back(a.x2 + 1, a.y2 + 1, b.x2, b.y2);
    }
    if (a.x2 + 1 <= b.x2 && a.y1 - 1 >= b.y1) {
        ret.emplace_back(a.x2 + 1, b.y1, b.x2, a.y1 - 1);
    }
    if (a.x1 - 1 >= b.x1 && a.y2 + 1 <= b.y2) {
        ret.emplace_back(b.x1, a.y2 + 1, a.x1 - 1, b.y2);
    }
    if (a.x1 - 1 >= b.x1 && a.y1 - 1 >= b.y1) {
        ret.emplace_back(b.x1, b.y1, a.x1 - 1, a.y1 - 1);
    }
    return ret;
}
i64 get(i64 x, i64 y) {
    if (x * y % 2 == 0) {
        return x * y / 2;
    }
    return x * y / 2 + 1;
}
i64 getw(const rec &a) {
    assert(a.x1 <= a.x2 && a.y1 <= a.y2);
    i64 ret = get(a.x2, a.y2);
    ret -= get(a.x1 - 1, a.y2);
    ret -= get(a.x2, a.y1 - 1);
    ret += get(a.x1 - 1, a.y1 - 1);
    return ret;
}
i64 getb(const rec &a) {
    assert(a.x1 <= a.x2 && a.y1 <= a.y2);
    return (a.x2 - a.x1 + 1) * (a.y2 - a.y1 + 1) - getw(a);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int &i: a) {
        cin >> i;
        i *= n;
        sum += i;
    }
    sum /= n;
    int best = MOD, ans;
    for (int i = 0; i < n; ++i) {
        if (abs(a[i] - sum) < best) {
            best = abs(a[i] - sum);
            ans = i;
        }
    }
    cout << ans << '\n';

    return 0;
}