#include #include using namespace std; int main() { freopen("pooh.in", "r", stdin); freopen("pooh.out", "w", stdout); int n; scanf("%d", &n); int a; map M; for(int i = 0; i < n; i++) { scanf("%d", &a); M[a]++; } int total, best_total = 0, best_cnt = 0, best_pos; for(map::const_iterator it = M.begin(); it != M.end(); it++) { total = (*it).first * (*it).second; if(total > best_total) { best_total = total; best_cnt = (*it).second; best_pos = (*it).first; } else if(total == best_total && (*it).second < best_cnt) { best_total = total; best_cnt = (*it).second; best_pos = (*it).first; } } printf("%d\n", best_pos); return 0; }