polycarp play computer game in game fight monster magic spellsthere type spell fire spell power x deal x damage monster lightning spell power y deal y damage monster double damage spell Polycarp cast each spell cast battle Polycarp cast orderfor example suppose Polycarp know spell fire spell power 5 lightning spell power 1 lightning spell power 8 there 6 way choose order cast spell second this order deal 5 1 2 cdot 8 22 damage second this order deal 5 8 2 cdot 1 15 damage second this order deal 1 2 cdot 5 8 19 damage second this order deal 1 2 cdot 8 2 cdot 5 27 damage second this order deal 8 2 cdot 5 1 19 damage second this order deal 8 2 cdot 1 2 cdot 5 20 damage Initially Polycarp know 0 spell his spell set change n time time learn new spell forget know after change calculate maximum possible damage polycarp deal spell know