Program tournament;
const
MAXN = 131072;
var
N, i, h,k, numeroconcorrenti,runnerup, winner : LongInt;
P,tabellone : Array[0..MAXN-1] of LongInt;
begin
{
uncomment the two following lines if you want to read/write from files
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);
}
ReadLn(N);
for i:=0 to N-1 do
begin
Read(P[i]);
tabellone[i]:=i;
end;
ReadLn();
numeroconcorrenti:=N;
winner := 0;
runnerup := 0;
while numeroconcorrenti>2 do
begin
i:=0; h:=0;
while i< numeroconcorrenti-1 do
begin
if P[tabellone[i]]>P[tabellone[i+1]] then tabellone[h]:=tabellone[i]
else tabellone[h]:=tabellone[i+1];
h:=h+1; i:=i+2;
end;
numeroconcorrenti:=numeroconcorrenti div 2;
end;
if P[tabellone[0]]>P[tabellone[1]] then begin winner:= tabellone[0];runnerup:=tabellone[1]; end
else begin winner:= tabellone[1];runnerup:=tabellone[0]; end;
writeLn(winner, ' ', runnerup);
end.
UHJvZ3JhbSB0b3VybmFtZW50OwoKY29uc3QKICAgIE1BWE4gPSAxMzEwNzI7Cgp2YXIKICAgIE4sIGksIGgsaywgbnVtZXJvY29uY29ycmVudGkscnVubmVydXAsIHdpbm5lciA6IExvbmdJbnQ7CiAgICBQLHRhYmVsbG9uZSAgICAgICAgICAgICAgICAgICAgICA6IEFycmF5WzAuLk1BWE4tMV0gb2YgTG9uZ0ludDsKCmJlZ2luCnsKICAgIHVuY29tbWVudCB0aGUgdHdvIGZvbGxvd2luZyBsaW5lcyBpZiB5b3Ugd2FudCB0byByZWFkL3dyaXRlIGZyb20gZmlsZXMKICAgIGFzc2lnbihpbnB1dCwgICdpbnB1dC50eHQnKTsgIHJlc2V0KGlucHV0KTsKICAgIGFzc2lnbihvdXRwdXQsICdvdXRwdXQudHh0Jyk7IHJld3JpdGUob3V0cHV0KTsKfQoKICAgIFJlYWRMbihOKTsKCiAgICBmb3IgaTo9MCB0byBOLTEgZG8gCiAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgIFJlYWQoUFtpXSk7CiAgICAgICAgICAgICAgICAgICB0YWJlbGxvbmVbaV06PWk7CiAgICAgICAgICAgICAgICAgZW5kOyAgCiAgICBSZWFkTG4oKTsKICAgIG51bWVyb2NvbmNvcnJlbnRpOj1OOwogICAgd2lubmVyIDo9IDA7CiAgICBydW5uZXJ1cCA6PSAwOwogICAgd2hpbGUgbnVtZXJvY29uY29ycmVudGk+MiBkbwogICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgaTo9MDsgaDo9MDsKICAgICAgICAgICAgICB3aGlsZSBpPCBudW1lcm9jb25jb3JyZW50aS0xIGRvCiAgICAgICAgICAgICAgICAgICAgICBiZWdpbgogICAgICAgICAgICAgICAgICAgICAgICBpZiBQW3RhYmVsbG9uZVtpXV0+UFt0YWJlbGxvbmVbaSsxXV0gIHRoZW4gdGFiZWxsb25lW2hdOj10YWJlbGxvbmVbaV0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIHRhYmVsbG9uZVtoXTo9dGFiZWxsb25lW2krMV07CiAgICAgICAgICAgICAgICAgICAgICAgIGg6PWgrMTsgaTo9aSsyOwogICAgICAgICAgICAgICAgICAgICAgZW5kOwogICAgICAgICAgICAgIG51bWVyb2NvbmNvcnJlbnRpOj1udW1lcm9jb25jb3JyZW50aSBkaXYgMjsKICAgICAgICAgIGVuZDsgICAgCiAgICBpZiBQW3RhYmVsbG9uZVswXV0+UFt0YWJlbGxvbmVbMV1dIHRoZW4gYmVnaW4gd2lubmVyOj0gdGFiZWxsb25lWzBdO3J1bm5lcnVwOj10YWJlbGxvbmVbMV07IGVuZAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGJlZ2luIHdpbm5lcjo9IHRhYmVsbG9uZVsxXTtydW5uZXJ1cDo9dGFiZWxsb25lWzBdOyBlbmQ7CiAgICB3cml0ZUxuKHdpbm5lciwgJyAnLCBydW5uZXJ1cCk7CiBlbmQuCg==