Woburn Challenge 2017-18 Finals Round - Senior Division
The Party of Extraterrestrial Gangsters has begun its invasion of Earth! Vast armies of PEG soldiers have been deployed down to the surface throughout Scarberia, and the cows and monkeys have engaged them in battle.
Amidst the fighting, however, the aliens have also transported something else to the planet's surface — a bomb with devastating nuclear power! All life in Scarberia, and perhaps the rest of Earth, would surely cease if the bomb were to detonate. Fortunately, the PEG leaders are honourable enough to give their enemies a fighting chance. As such, they've set the bomb to go off after a period of three hours, and implanted a system for defusing it. They've even included an instruction manual along with it!
On the surface of the bomb, there are
Bo Vine and the Head-Monkey have gotten their hands on the bomb and its accompanying instruction manual. According to the manual, the bomb will turn itself off if the following conditions are all met:
- Each terminal
receives an electrical current with some voltage , such that is a positive integer. - For each black wire
(such that ), the greatest common divisor (GCD) of and is equal to . - For each white wire
(such that ), the GCD of and is greater than .
Bo Vine has ordered his cow engineers to prepare the necessary
electrical equipment as quickly as possible. Meanwhile, the Head-Monkey
has personally taken it upon herself to come up with a set of voltages
Subtasks
In test cases worth
Input Specification
The first line of input consists of a single integer,
Output Specification
Output a single integer, the minimum possible total voltage required to defuse the bomb.
Sample Input
7
4 1 1
4 5 0
7 6 1
3 6 1
1 7 0
2 4 1
Sample Output
16
Sample Explanation
It's optimal to send
- a
-volt current to terminal ; -volt currents to terminals , , and ; and -volt currents to terminals , , and .
Comments