Malatang Tanghulu
Time limit1sMemory limit1024 MB
Given skewers with strawberry and grape counts and fixed insert amounts P and Q, decide whether every skewer can be balanced and print the insert counts.
- Level
Easy2 of 10
- Topics
- 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 trending these days. But on the first day, a wrong order left boxes of strawberries and Shine Muscat grapes piled up. Fresh fruit spoils quickly, so today Chito decided to give the tanghulu away free to customers.
Chito made tanghulu skewers in advance. While busy, Chito stuck fruit onto the skewers as it came to 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 as Shine Muscat grapes. However, different skewers do not need to match each other. Chito was too busy running the shop, so Chito hired a robot to make the counts equal.
Skewer currently has strawberries and Shine Muscat grapes. The robot has one problem: every time, it inserts a fixed number of fruits. Each minute, the robot performs the following action once.
- Choose skewer .
- Insert strawberries and Shine Muscat grapes into skewer .
Chito thought it over and realized that the robot might not be able to make the counts equal on every skewer.
Check whether the robot can make the strawberry and Shine Muscat counts equal on every skewer.
Input
The first line contains the number of skewers , the number of strawberries the robot inserts each minute, and the number of Shine Muscat grapes it inserts each 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.
All numbers in the input are integers.
Output
On the first line, print YES if the robot can make the strawberry and Shine Muscat counts equal on every skewer, and NO otherwise.
If the robot can do so, print on the second line the number of times the robot inserted strawberries and Shine Muscat grapes into each skewer, separated by spaces. If there are several possible answers, print any one of them.
Since the supply of strawberries and Shine Muscat grapes is not unlimited, the number of times the robot performs the action of inserting strawberries and Shine Muscat grapes must each be within 10,000.