Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
long long a[100000+10];
bool cmp(long long x,long long y)
{
	return x>y;
} 
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
    	int i;
    	map<long long,long long>ss;
    	scanf("%lld",&a[0]);
    	for(i=1;i<n;i++)
    	scanf("%lld",&a[i]);
    	sort(a,a+n,cmp); 
    	ss[a[0]]=1;
    	for(i=1;i<n;i++)
    	{
    		if(a[i]==a[i-1]) ss[a[i]]++;
			else ss[a[i]]=1; 
		}
		int s1[3];
		int k=0,t=0;
    	map<long,long>::reverse_iterator it;
    	for(it=ss.rbegin();it!=ss.rend();it++)
    	{
    		if(it->second>=4&&k==0) 
			{
				printf("%lld\n",(it->second)*(it->second));
				break;
			}
    		else if(it->second>=2)
    		{
    			s1[k]=it->first;
    			k++;
			}
			if(k>=2) 
			{
				t=1;
				break;
			}
		}
        if(t) printf("%lld\n",s1[0]*s1[1]);
        else printf("%lld\n",0);	
	}
}

Compiler output:
In file included from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of 'constexpr std::reverse_iterator<_Iterator>& std::reverse_iterator<_Iterator>::operator=(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 long int, long int> >]':
a.cc:32:23:   required from here
   32 |         for(it=ss.rbegin();it!=ss.rend();it++)
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:229:9: error: no match for 'operator=' (operand types are 'std::_Rb_tree_iterator<std::pair<const long int, long int> >' and 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >')
  229 |         _GLIBCXX_NOEXCEPT_IF(noexcept(current = __x.current))
      |         ^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:62,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long int, long int> >& std::_Rb_tree_iterator<std::pair<const long int, long int> >::operator=(const std::_Rb_tree_iterator<std::pair<const long int, long 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 long int, long int> >&'
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long int, long int> >& std::_Rb_tree_iterator<std::pair<const long int, long int> >::operator=(std::_Rb_tree_iterator<std::pair<const long int, long 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 long int, long int> >&&'
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/stl_iterator.h: In instantiation of 'constexpr std::reverse_iterator<_Iterator>& std::reverse_iterator<_Iterator>::operator=(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 long int, long int> >]':
a.cc:32:23:   required from here
   32 |         for(it=ss.rbegin();it!=ss.rend();it++)
      |                          ^
/usr/include/c++/14/bits/stl_iterator.h:231:19: error: no match for 'operator=' (operand types are 'std::_Rb_tree_iterator<std::pair<const long int, long int> >' and 'const std::_Rb_tree_iterator<std::pair<const long long int, long long int> >')
  231 |           current = __x.current;
      |           ~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long int, long int> >& std::_Rb_tree_iterator<std::pair<const long int, long int> >::operator=(const std::_Rb_tree_iterator<std::pair<const long int, long 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 long int, long int> >&'
/usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long int, long int> >& std::_Rb_tree_iterator<std::pair<const long int, long int> >::operator=(std::_Rb_tree_iterator<std::pair<const long int, long 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 long int, long 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 long int, long int> >; _IteratorR = _Rb_tree_iterator<pair<const long long int, long long int> >]':
a.cc:32:37:   required from here
   32 |         for(it=ss.rbegin();it!=ss.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 long int, long 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/iosfwd:42,
                 from /usr/include/c++/14/ios:40:
/usr/include/c++/14/bits/postypes.h:197:5: note: candidate: 'template<class _StateT> bool std::operator!=(const fpos<_StateT>&, const fpos<_StateT>&)'
  197 |     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:197: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 long int, long int> > >::iterator_type' is not derived from 'const std::fpos<_StateT>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/allocator.h:243:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const allocator<_CharT>&, const allocator<_T2>&)'
  243 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:243: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 long int, long int> > >::iterator_type' is not derived from 'const std::allocator<_CharT>'
  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 long int, long 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 long int, long 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/map:64:
/usr/include/c++/14/bits/stl_multimap.h:1179:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>&, const multimap<_Key, _Tp, _Compare, _Allocator>&)'
 1179 |     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_multimap.h:1179: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 long int, long int> > >::iterator_type' is not derived from 'const std::multimap<_Key, _Tp, _Compare, _Allocator>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:63:
/usr/include/c++/14/bits/stl_map.h:1557:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator!=(const map<_Key, _Tp, _Compare, _Allocator>&, const map<_Key, _Tp, _Compare, _Allocator>&)'
 1557 |     operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1557: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 long int, long int> > >::iterator_type' is not derived from 'const std::map<_Key, _Tp, _Compare, _Allocator>'
  502 |     { return __x.base() != __y.base(); }
      |              ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46:
/usr/include/c++/14/bits/streambuf_iterator.h:242:5: note: candidate: 'template<class _CharT, class _Traits> bool std::operator!=(const istreambuf_iterator<_CharT, _Traits>&, const istreambuf_iterator<_CharT, _Traits>&)'
  242 |     operator!=(const istreambuf_iterator<_CharT, _Trait