Language: C++

#include<bits/stdc++.h>

using namespace std;


int main(){
	int n;
	cin >> n;
	int a[n];
	map<long long, long long>maap;
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i=n-1; i>=0; i--){
		maap[a[i]]++;
	}
	long long cnt=0;
	for(map<int, int>::reverse_iterator it=maap.rbegin(); it!=maap.rend(); it++){
		if(cnt==0 && it->second>=2){
			cnt=it->first;
		}
		else if(cnt!=0 && it->second>=2){
			cout << cnt*it->first;
			return 0;
		}
	}
	cout << 0;
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of 'constexpr std::reverse_iterator<_Iterator>::reverse_iterator(const std::reverse_iterator<_Iter>&) [with _Iter = std::_Rb_tree_iterator<std::pair<const long long int, long long int> >; _Iterator = std::_Rb_tree_iterator<std::pair<const int, int> >]':
a.cc:19:53:   required from here
   19 |         for(map<int, int>::reverse_iterator it=maap.rbegin(); it!=maap.rend(); it++){
      |                                                            ^
/usr/include/c++/14/bits/stl_iterator.h:216:9: error: no matching function for call to 'std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >&)'
  216 |         _GLIBCXX_NOEXCEPT_IF(noexcept(_Iterator(__x.current)))
      |         ^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152:
/usr/include/c++/14/bits/stl_tree.h:269:7: note: candidate: 'std::_Rb_tree_iterator<_Tp>::_Rb_tree_iterator(_Base_ptr) [with _Tp = std::pair<const int, int>; _Base_ptr = std::_Rb_tree_node_base*]'
  269 |       _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:269:35: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'std::_Rb_tree_iterator<std::pair<const int, int> >::_Base_ptr' {aka 'std::_Rb_tree_node_base*'}
  269 |       _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |                         ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_tree.h:265:7: note: candidate: 'std::_Rb_tree_iterator<_Tp>::_Rb_tree_iterator() [with _Tp = std::pair<const int, int>]'
  265 |       _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:265:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(const std::_Rb_tree_iterator<std::pair<const int, int> >&)'
  252 |     struct _Rb_tree_iterator
      |            ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'const std::_Rb_tree_iterator<std::pair<const int, int> >&'
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(std::_Rb_tree_iterator<std::pair<const int, int> >&&)'
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'std::_Rb_tree_iterator<std::pair<const int, int> >&&'
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of 'constexpr std::reverse_iterator<_Iterator>::reverse_iterator(const std::reverse_iterator<_Iter>&) [with _Iter = std::_Rb_tree_iterator<std::pair<const long long int, long long int> >; _Iterator = std::_Rb_tree_iterator<std::pair<const int, int> >]':
a.cc:19:53:   required from here
   19 |         for(map<int, int>::reverse_iterator it=maap.rbegin(); it!=maap.rend(); it++){
      |                                                            ^
/usr/include/c++/14/bits/stl_iterator.h:217:11: error: no matching function for call to 'std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >&)'
  217 |         : current(__x.current)
      |           ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:269:7: note: candidate: 'std::_Rb_tree_iterator<_Tp>::_Rb_tree_iterator(_Base_ptr) [with _Tp = std::pair<const int, int>; _Base_ptr = std::_Rb_tree_node_base*]'
  269 |       _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:269:35: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'std::_Rb_tree_iterator<std::pair<const int, int> >::_Base_ptr' {aka 'std::_Rb_tree_node_base*'}
  269 |       _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |                         ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_tree.h:265:7: note: candidate: 'std::_Rb_tree_iterator<_Tp>::_Rb_tree_iterator() [with _Tp = std::pair<const int, int>]'
  265 |       _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:265:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(const std::_Rb_tree_iterator<std::pair<const int, int> >&)'
  252 |     struct _Rb_tree_iterator
      |            ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'const std::_Rb_tree_iterator<std::pair<const int, int> >&'
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const int, int> >::_Rb_tree_iterator(std::_Rb_tree_iterator<std::pair<const int, int> >&&)'
/usr/include/c++/14/bits/stl_tree.h:252:12: note:   no known conversion for argument 1 from 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >' to 'std::_Rb_tree_iterator<std::pair<const int, int> >&&'
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of 'constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&) [with _IteratorL = _Rb_tree_iterator<pair<const int, int> >; _IteratorR = _Rb_tree_iterator<pair<const long long int, long long int> >]':
a.cc:19:70:   required from here
   19 |         for(map<int, int>::reverse_iterator it=maap.rbegin(); it!=maap.rend(); it++){
      |                                                                             ^
/usr/include/c++/14/bits/stl_iterator.h:502:25: error: no match for 'operator!=' (operand types are 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >::iterator_type' and 'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const long long int, long long int> > >::iterator_type')
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator.h:502:25: note:   'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >::iterator_type' is not derived from 'const std::pair<_T1, _T2>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator.h:502:25: note:   'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >::iterator_type' is not derived from 'const std::reverse_iterator<_Iterator>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  500 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator.h:502:25: note:   'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >::iterator_type' is not derived from 'const std::reverse_iterator<_Iterator>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1132 |     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1132:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator.h:502:25: note:   'std::reverse_iterator<std::_Rb_tree_iterator<std::pair<const int, int> > >::iterator_type' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1212 |     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/u