COCI '16 Contest 6 #5 Sirni
View as PDFLittle Daniel has a bag of candy and  cards.
Each of the cards has a positive integer  written on it. While Daniel was eating his candy, he thought of a fun game. He can tie together two cards with labels 
 and 
, and then he must eat 
 of candy, where operation 
 denotes the remainder when dividing 
 with 
.
He wants to tie together pairs of cards in a way that, when he lifts one of them, all the rest are also lifted up. Each card can be directly connected with a tie to any number of other cards. As Daniel is watching his figure, he doesn't want to consume too much, so he is asking you to calculate the minimal number of candy he must eat so all cards are connected.
Input Specification
The first line of input contains the positive integer  
.
Each of the following  lines contains a positive integer 
 
.
Output Specification
The first and only line of output must contain the required value from the task.
Scoring
In test cases worth  of total points, it will hold 
.
In test cases worth  of total points, it will hold 
.
In test cases worth  of total points, at least one of the two conditions will hold.
Sample Input 1
4
2
6
3
11
Sample Output 1
1
Explanation for Sample Output 1
Daniel can connect the first and second card and eat  candy, the second and third and eat 
 candy, and the first and fourth and eat 
 candy.
Sample Input 2
4
1
2
3
4
Sample Output 2
0
Sample Input 3
3
4
9
15
Sample Output 3
4
Comments