Cod sursa(job #927001)

Utilizator crisbodnarCristian Bodnar crisbodnar Data 25 martie 2013 15:21:55
Problema Medie Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("medie.in");
ofstream fout("medie.out");

int n, a[9007], v[7007];
long long rez;


void Med(short a, short b){
    if((a+b)&1 != 0) return ;
    int x =(a+b)>>1;
    v[x]++;
    if(a == x) rez--;
    if(b == x) rez--;
}

void Citire(){
    fin>>n;
    for(int i=1; i<=n; i++){
        fin>>a[i];
        for(int j=1; j<i; j++)
            Med(a[j], a[i]);
    }
}

int main()
{
    Citire();
    for(int i=1; i<=n; i++)
        rez += v[a[i]];
    fout<<rez;
    return 0;
}