Pagini recente » Cod sursa (job #1132059) | Cod sursa (job #361847) | Cod sursa (job #3184431) | Cod sursa (job #3283059) | Cod sursa (job #60060)
Cod sursa(job #60060)
var f1,f2:text;
n,i,j,k,max,pos:longint;
sol,aux:int64;
v:array[0..9000] of longint;
s,se,ct,v1,ctv:array[1..7000] of longint;
begin
assign(f1,'medie.in');
reset(f1);
assign(f2,'medie.out');
rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,v[i]);
close(f1);
if n<=200 then
begin
//n^3
for i:=1 to n do
for j:=1 to n do
for k:=j+1 to n do
if (i<>j) and (i<>k) then
if v[i]<<1=v[j]+v[k] then
inc(sol);
end
else
begin
//valmax^2
for i:=1 to n do
inc(ctv[v[i]]);
max:=-1;
for i:=1 to n do
if max<v[i] then
max:=v[i];
for i:=1 to max do
begin
aux:=(ctv[i]*(ctv[i]-1) div 2);
aux:=aux*(ctv[i]-2);
inc(sol,aux);
pos:=1;
while (i-pos>0) and (i+pos<=max) do
begin
inc(sol,ctv[i-pos]*ctv[i+pos]*ctv[i]);
inc(pos);
end;
end;
end;
writeln(f2,sol);
close(f2);
end.