The CTF Mafia wants to remove the competition (i.e.you) to again have monopoly over flags. Bribe the Mafia to get away unscathed and with the flag.
This problem is an application of binary search. The value of amount is binary searched with a lower bound as 1 and upper bound as 1000000.
In each iteration, the current amount is queried against the current set of friends. All friends with amount greater than the current amount is taken as the set of friends for the next iteration. If no friend has amount greater than current but some friend has equal to current amount, that value is displayed. Otherwise, the same set of friends are taken for a lower amount.
from pwn import *