Cod sursa(job #894274)
{element majoritar-infoarena}
program elem_maj;
type vect=array[0..1000000]of longint;
var a:vect;
i,n,x:longint;
f,g:text;
function majoritar(n:longint; a:vect):longint;
var k,cand,i,nr:longint;
begin
cand:=-1; k:=0;
for i:=1 to n do begin
if k=0 then begin
cand:=a[i]; k:=1;
end
else if a[i]=cand then begin
inc(k);
end
else dec(k);
end;
if cand<0 then majoritar:=cand;
nr:=0;
for i:=1 to n do if a[i]=cand then inc(nr);
if nr>n div 2 then majoritar:=cand
else majoritar:=-1;
end;
begin
assign(f,'elmaj.in');reset(f);
assign(g,'elmaj.out');rewrite(g);
readln(f,n);
for i:=1 to n do read(f,a[i]);
x:=majoritar(n,a);
writeln(g,x);
close(f); close(g);
end.