Cod sursa(job #60582)

Utilizator cezar305Mr. Noname cezar305 Data 15 mai 2007 15:10:10
Problema Medie Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.29 kb
var f1,f2:text; i,j,caut,n,h,r:longint;
    y,z,v,a:array[-9000..9000] of longint;
    nr:int64;
begin
        assign(f1,'medie.in');
        reset(f1);
        assign(f2,'medie.out');
        rewrite(f2);
        read(f1,n);
        r:=0;
        for i:=1 to n do
        begin
                read(f1,a[i]);
                h:=1;
                for j:=1 to r do
                begin
                        if y[j]=a[i] then
                        begin
                                h:=0;
                                inc(z[j]);
                        end;
                end;
                if h=1 then
                begin
                        inc(r);
                        y[r]:=a[i];
                        inc(z[r]);
                end;
        end;
        for i:=1 to n do
        begin
                for j:=1 to r do
                begin
                        v[y[j]]:=z[j];
                end;
                caut:=2*a[i];
                dec(v[a[i]]);
                for j:=1 to n do
                begin
                        if j<>i then dec(v[a[j]]);
                        if (j<>i)and(caut-a[j]>0) then nr:=nr+v[caut-a[j]];
                end;
        end;
        writeln(f2,nr);
        close(f1);
        close(f2);
end.