#B4044. Homework Submission Deadline
Homework Submission Deadline
Homework Submission Deadline
Little L has a busy college life. It is the Saturday morning of the first week at 8:00 and she is checking her homework. In her university, every course has a designated weekday \(w\) (with \(1 \le w \le 5\)) when classes are held and a recurrence period \(d\) weeks. That is, after the class in the first week, the class will be held every \(d\) weeks on the same weekday \(w\). For example, if a course has \(w=4\) and \(d=2\), the classes will be held on Thursday in week 1, week 3, week 5, and so on.
Except for the first class, every class requires the students to submit the homework from the previous class. Given that Little L has enrolled in \(n\) courses (each with homework), your task is to compute how many days from now (Saturday of the first week at 8:00) she will have to submit her first homework assignment.
For each course, the first lecture is held in the first week on day \(w\). The homework for the first lecture is due on the day of the second lecture, which is held in week \(1+d\) on the same weekday \(w\). Considering that the current day is Saturday (day 6 of the week), the number of days to wait for a given course is:
[ \text{waiting days} = 7 \times d + w - 6 ]
Your program should find the minimum waiting days among all courses.
inputFormat
The first line contains a single integer \(n\) (the number of courses). Each of the following \(n\) lines contains two integers \(w\) and \(d\) where \(1 \le w \le 5\) and \(d\) is the recurrence period of the course in weeks.
outputFormat
Output a single integer representing the minimum number of days from the current time (Saturday of the first week at 8:00) until the first homework submission is due.
sample
1
4 2
12