Malatang Tanghulu (hard)
Time limit2sMemory limit1024 MB
Decide whether inserting P strawberries and Q grapes per minute can equalize every skewer's counts, and output the insert counts if so.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Implementation
- Solved
- No attempts yet
Problem

그럼 제가 선배 맘에
<서이브/남동현, 마라탕후루, 2024>
Chito, the mascot of Ajou University, opened a malatang tanghulu shop by combining malatang and tanghulu, two snacks that are popular these days. On the first day, however, a wrong order left boxes of strawberries and Shine Muscat grapes piled up. Fruit has to be fresh, so today Chito decided to give tanghulu to customers for free.
Chito made tanghulu skewers in advance. While busy, Chito stuck fruit on whatever was at hand, and only later realized that the number of strawberries and Shine Muscat grapes on each skewer could differ. To keep the flavor balanced, each skewer must have the same number of strawberries and Shine Muscat grapes. However, different skewers do not need to have the same count as each other. Chito hired a robot to even out the counts of strawberries and grapes, because the shop is too busy for that.
Skewer currently has strawberries and Shine Muscat grapes. The robot has one flaw: it always inserts a fixed number of each fruit at a time. Every minute, the robot performs the following action once.
- Choose skewer and skewer . Here and may be the same.
- Insert strawberries into skewer and Shine Muscat grapes into skewer at the same time.
Chito realized after some thought that the robot might not be able to make the strawberry and grape counts equal on every skewer.
Check whether the robot can make the number of strawberries and Shine Muscat grapes equal on every skewer.
Input
The first line contains the number of skewers , the number of strawberries and the number of Shine Muscat grapes that the robot inserts every minute, separated by spaces.
The second line contains the number of strawberries on each skewer , separated by spaces.
The third line contains the number of Shine Muscat grapes on each skewer , separated by spaces.
Output
On the first line, print YES if the robot can make the strawberry and grape counts equal on every skewer, and NO otherwise.
If the robot can make the counts equal on every skewer, print on the second line the number of times the robot inserted strawberries into each skewer, separated by spaces. On the third line, print the number of times the robot inserted Shine Muscat grapes into each skewer, separated by spaces. If several answers are possible, print any one of them.
The strawberries and grapes are not unlimited, so the number of times the robot inserts strawberries and grapes into each skewer must each be within .