NOI Contest Archive

Archive / 2022 / March 2022

Bags O' Money

Medium · National Olympiad in Informatics Sri Lanka - March 2022

Big Bank stores their money in bags, each containing a distinct amount of money. A gang of thieves are planning to rob the bank. The loot has to be distributed evenly between them to not risk the thieves snitching on each other. In that sense, they will not perform the heist if the money they loot cannot be divided evenly. The thieves can only carry exactly two bags with them so that there is minimal risk involved in the heist, and atleast two to make the heist worthwhile.

The Bank Manager receives word of this. He plans to transport bags of money to a different branch so that the thieves cannot pull their plan off. Take the transportation cost of one bag to be one unit. What is the maximum number of bags he can keep in the bank so that the number of transportation units are minimal and the thieves will not attempt the heist?

Input Format

Output Format

Constraints

Sample Input 0

5 5
2 7 12 17 22

Sample Output 0

5