WOSS Dual Olympiad 2022 Team Round P2: Bobby's Studying Schedule
View as PDFAfter getting his integration test successfully delayed by  days, Bobby wants to create a schedule to study. He checks his calendar and realizes that on the 
th day, he has 
 hours available to study. However, Bobby is weird and wants to study for exactly a multiple of 
 hours each day, where 
 cannot equal 
. For example, if 
, Bobby could only study for 
 or 
 hours on any particular day as long as that number is less than 
. Find the most amount of hours Bobby can study given his schedule, for an optimal 
 value.
Constraints
Input Specification
The first line will contain a single integer, , giving the number of days Bobby has to study.
The second line will contain  space-separated integers, with the 
th integer being the value 
, or the amount of study time Bobby has available on the 
th day.
Output Specification
Output should consist of a single line, containing a single integer: the maximum amount of hours Bobby can study with an optimal  value.
Sample Input 1
5
5 10 15 5 6
Sample Output 1
40
Explanation of Sample 1
In this case, it is optimal to choose . This means that on any given day 
, Bobby must study for a number of hours that is a multiple of 
, but is less than or equal to 
. On day one, Bobby studies for 
 hours. On day two he studies for 
 hours. On day three he studies for 
 hours. On day four he studies for 
 hours. On day five he studies for 
 hours. This yields a total of 
 hours.
Sample Input 2
10
24 23 24 24 23 17 15 24 24 24
Sample Output 2
218
Comments