Cod sursa(job #1382935)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 9 martie 2015 19:13:29
Problema Medie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>

using namespace std;

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

const int vmax = 7000;
int f[ vmax + 1 ];

inline long long max2( long long a, long long b ) {
    if ( a > b ) {
        return a;
    }
    return b;
}
int main() {
    int n, x;
    long long ans;
    fin >> n;
    for( int i = 0; i < n; ++ i ) {
        fin >> x;
        ++ f[ x ];
    }
    ans = 0;
    for( int i = 1; i <= vmax; ++ i ) {
        ans += max2( 0, f[ i ] * (f[ i ] - 1) * (f[ i ] - 2) / 2 * 1LL );
        for( int j = i + 2; j <= vmax; j += 2 ) {
            ans += max2( 0, f[ i ] * f[ j ] * f[ (i + j) / 2 ] * 1LL );
        }
    }
    fout << ans << "\n";
    fin.close();
    fout.close();
    return 0;
}