Cod sursa(job #578604)
| Utilizator | Data | 11 aprilie 2011 13:37:54 | |
|---|---|---|---|
| Problema | Medie | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include <cstdio>
#include <fstream>
using namespace std;
#define N 7005
int c[N];
int main ()
{
ifstream in ("medie.in");
int n,x,m=0;
for(in>>n;n;--n){
in>>x;
++c[x];
if(x>m)
m=x;
}
in.close ();
long long S=0;
for(int i=1;i<=m;++i)
if(c[i]){
if(c[i]>2)
S+=(((c[i]-2)*(c[i]-1)*c[i])>>1);
for(int j=i-1,k=i+1;j&&k<=m;++k,--j)
S+=c[i]*c[j]*c[k];
}
freopen ("medie.out","w",stdout);
printf("%lld\n",S);
return 0;}
