Write a program based on the following assumptions/rules:

For example, for the first example,
Examples:
INPUT OUTPUT
1 6 2 10 20 -1 3 4 6 10 16
2 5 10 2 20 30 -1 -1 3 4 5 10 15
1 5 3 3 3 4 5 5 10 20
1 2 2 20 40 3 -1 -1 4 2 20


Important issues about all exams/projects/quizzes: