Pagini recente » Cod sursa (job #2501965) | Cod sursa (job #2613490) | Cod sursa (job #2776747) | Cod sursa (job #871057) | Cod sursa (job #1101762)
program el_maj;
const nmax=1000005;
var a:array[1..nmax] of longint;
b:array[1..1 shl 16] of char;
n,i,k,cand,nr:longint;
begin
assign(input,'elmaj.in');
reset(input);
assign(output,'elmaj.out');
rewrite(output);
settextbuf(input,b);
readln(n);
for i:=1 to n do read(a[i]);
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 k:=k+1
else k:=k-1;
end;
nr:=0;
for i:=1 to n do if a[i]=cand then nr:=nr+1;
if nr>=n div 2+1 then write(cand,' ',nr)
else write(-1);
CLOSE(OUTPUT);
END.