Timetable Trouble


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Congratulations! After years of hard work, you have finally landed your dream role as an intern managing your university's merger. Just as you're about to head home after your first day, your manager assigns you an urgent task that must be completed today, or you will be fired!

Due to inadequate planning and a lack of foresight from the university, there is now a mismatch between the number of students enrolled in a subject and the number of available classes. To make matters more complicated, every subject can hold a different number of students in its class.

Your task as the new intern is to determine how the class counts should be adjusted, so that every student is accommodated for. As the university is very stingy, subjects are cancelled if all students can not be accommodated for in 100 classes or if they go over budget. There must also be no unnecessary empty classes, as the university is trying to minimise the total cost.

For each subject, calculate how many classes need to be added or removed based on the number of enrolled students, the capacity of each class, and the current number of classes, all while considering the class budget.

After adjusting all the classes, you need to let your manager know the total cost of running all the subjects before you can go home for the day.

Input

The first line contains an integer n (1 \leq n \leq 100), the number of subjects.

For each subject, the input consists of three lines.

The first line contains a string s (1 \leq s.length \leq 10), representing the name of the subject the university is offering. It is guaranteed that s consists only of lowercase English letters.

The second line consists of three integers x, y and z (0 \leq x, y\leq 10^9, 0 \leq z\leq 100), where x represents the number of students enrolled in the subject, y represents the maximum number of students each class can accommodate, and z represents the current number of classes.

The third line consists of two integers b and c (0 \leq b, c\leq 10^9), where b represents the total budget of the class and c represents the cost of each class.

Output

For each subject, output a line containing the subject name s, and an integer representing the change in the number of classes, separated by a space.

The integer should be positive if the number of classes needs to increase, negative if it needs to decrease, and 0 if no change is required.

If the university is not able to accommodate all the students, whether because all students can not be fit into 100 classes, or it costs more than the budget to run all the classes, replace the integer representing the change with the phrase is cancelled!.

After outputting all the subjects, output the phrase Total cost is:, followed by an integer representing the total cost of running all the subjects.

Example

Input 1
3
oop
115 10 7
1000 20
math
13 3 19 
30 6
ethics
1357 13 27
98765 23
Output 1
oop 5
math -14
ethics is cancelled!
Total cost is: 270
  • oop: Increase from 7 to 12 classes to accommodate all students, so the subject costs 240.
  • math: Reduce from 19 to 4 classes, so the subject costs 30.
  • ethics: Needs over 100 classes so the subject is cancelled and costs 0.

Total cost: It costs 270 to run all of the subjects (240 + 30 + 0).

Input 2
2
data
625 25 25
53 2
securities
10 2 3
100 49
Output 2
data 0
securities is cancelled!
Total cost is: 50
  • data: No class change is required, so the subject costs 50.
  • securities: The 5 classes required are over budget so the subject is cancelled and costs 0.

Total cost: It costs 50 to run all of the subjects (50 + 0).


Comments

There are no comments at the moment.