fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin>>n;
  9. long long a[100005];
  10. for(int i = 0;i <n; i++) {
  11. cin>>a[i];
  12. }
  13. sort(a, a+n);
  14. unsigned long long ans = 0;
  15. for(int i = n-1; i>=3; i--) {
  16. if(a[i] - a[i-1] <= 1 && a[i-2] - a[i-3] <= 1) {
  17. ans += (a[i-1] * a[i-3]);
  18. i-=3;
  19. }
  20. }
  21. cout<<ans;
  22. return 0;
  23. }
Success #stdin #stdout 0s 3812KB
stdin
14
5 5 5 5 5 5 4 4 4 4 2 2 2 2
stdout
53