there n chest the ith chest contain a_i coin you need open n chest order chest 1 chest nThere type key use open chest good key cost k coin use bad key cost coin halve coin unopene chest include chest open the halve operation round near integer chest halve in word bad key open chest a_i lfloorfraca_i2rfloor a_i1 lfloorfraca_i12rfloor dot a_n lfloor fraca_n2rfloor key good bad break usage onetime use you need use total n key chest Initially coin key if want use good key need buy itduring process allow debt example 1 coin allow buy good key worth k3 coin balance 2 coinsfind maximum number coin open n chest order chest 1 chest n