Cheongrin wanted to develop a game, but repeated abandoned projects and uncertainty had kept him from starting a new one. After some thought, he hired Sion to work on the project.
The game project currently has tasks. Task has progress . If Sion works on this task for one day, its progress increases by .
Each day, Sion chooses exactly distinct tasks to work on. The progress of each chosen task increases by , and the progress of every other task stays unchanged. There is no upper limit on progress.
Cheongrin plans to have Sion work every day until all tasks have equal progress.
Find the minimum number of days needed to make the progress of all tasks equal. If all tasks already have equal progress, the answer is . If it is impossible, the answer is -1.
The input is given in the following format:
Print the minimum number of days needed to make all tasks have equal progress. If it is impossible, print -1.
On the first day, choose tasks and . Their progress increases by and , respectively, so the progress values become .
The first line contains the number of tasks and the number of tasks chosen each day . The second line contains the initial progress values . The third line contains the daily increases .
__int128 in C++.| 2 |
| 22 |
, , (). |
| 3 | 65 | No additional constraints. |
The progress of task is always even, while the progress of task is always odd. Thus, their progress cannot become equal.