Pagini recente » Cod sursa (job #183339) | Cod sursa (job #2888107) | Cod sursa (job #2547484) | Cod sursa (job #2740823) | Cod sursa (job #2698674)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
InParser fin("medie.in");
ofstream fout("medie.out");
int n, v[9005], fv[7005], rez;
int main()
{
ios::sync_with_stdio(false);
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> v[i];
++fv[v[i]];
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if ((v[i] + v[j]) % 2 == 0 && fv[(v[i] + v[j]) / 2])
{
rez += fv[(v[i] + v[j]) / 2];
if (v[i] == v[j])
rez -= 2;
}
fout << rez;
return 0;
}