Cod sursa(job #2530181)

Utilizator ApostolIlieDanielApostol Daniel ApostolIlieDaniel Data 24 ianuarie 2020 14:57:06
Problema Medie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << ": " << x << "\n"

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

int main () {
    freopen ("medie.in", "r", stdin);
    freopen ("medie.out", "w", stdout);

    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    int n;
    cin >> n;
    int ans = 0;
    int x;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        f[x]++;
    }
    for (int i = 1; i <= V; i++) {
        int j = i - 1,  k = i + 1;
        ans += f[i] * (f[i] - 1) * (f[i] - 2) / 2;
        while (k <= V && j > 0)
            ans += f[i] * f[j] * f[k], k++, j--;
    }
    cout << ans << "\n";
    return 0;
}