Cod sursa(job #2181165)

Utilizator Vlad3108Tir Vlad Ioan Vlad3108 Data 21 martie 2018 15:02:25
Problema Medie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <bits/stdc++.h>
using namespace std;
int ap[7005];
int main(){
    int n,Max=-1;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int x;
        scanf("%d",&x);
        ++ap[x];
        if(x>Max) Max=x;
    }
    long long S=0;
    for(int i=1;i<=7000;++i){
        if(ap[i]==0) continue;
        int P=1;
        for(int j=1;j<=ap[i];++j)
            P*=j;
        S+=P/4;
        int st=i-1,dr=i+1;
        while(st>=1&&dr<=7000){
            S+=ap[st]*ap[dr]*ap[i];
            --st;
            ++dr;
        }
    }
    printf("%lld\n",S);
    return 0;
}