Cod sursa(job #894283)
{element majoritar-infoarena}
program elem_maj;
type vect=array[0..1000000]of longint;
var a:vect;
i,n,x,nra:longint;
f,g:text;
function majoritar(n:longint; a:vect; var nra:longint):longint;
var k,cand,i,nr:longint;
begin
cand:=-1; k:=0;
for i:=1 to n do if k=0 then begin
cand:=a[i]; k:=1;
end
else if a[i]=cand then inc(k)
else dec(k);
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 begin
majoritar:=cand;
nra:=nr;
end
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,nra);
if x>0 then writeln(g,x,' ',nra)
else writeln(g,-1);
close(f); close(g);
end.