Close Enough Computations
Time limit1sMemory limit128 MB
Decide whether printed grams of fat, carbohydrate, and protein can come from true amounts whose calorie total rounds to the printed calories.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Brute force
- Solved
- No attempts yet
Problem

Nutritional food labels are everywhere; a sample label is shown above. On the label, the number of calories and the number of grams of fat, carbohydrate, and protein are all given as integers.
Reading a label carefully can reveal apparent inconsistencies. One gram of fat provides calories, one gram of carbohydrate provides calories, and one gram of protein provides calories. For the sample label, a direct computation gives calories, yet the label reports calories.
Sometimes such a difference comes from other factors (for example alcohol or soluble fiber), but here we consider only round-off error. This food actually contains grams of fat ( calories), grams of carbohydrate ( calories), and grams of protein ( calories), for a true total of calories — which indeed rounds to the printed .
Write a program that decides whether the values on a nutritional label are consistent: that is, whether there exist true nutrient amounts that round to the printed grams and whose total calories round to the printed calorie count.
Assume standard rounding: any value below rounds down, and any value of or more rounds up. Because a nutrient amount cannot be negative, a printed value of grams corresponds to a true amount in .
Input
The input contains one or more data sets, one per line. Each data set consists of non-negative integers separated by one or more spaces: the number of calories, the grams of fat, the grams of carbohydrate, and the grams of protein, in that order. The number of calories is at most , and the grams of any single component is at most .
Input ends with a line containing four zeros; that line is not processed.
Output
For each data set, print yes or no on its own line, indicating whether the printed grams of the three nutrients can yield the printed number of calories.