Calendar
InterviewTime limit2sMemory limit1024 MB
Count, across all months, the day numbers from 1 to each month's length that contain at least one broken digit.
- Level
Easy3 of 10
- Topics
- Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Aman Robramovich, a wealthy magnate on Mars, decided to order a series of calendars from the Flatland-Print typography, with his own profile on every page. The Great Financial Crisis reached Mars too, so the print shop had too little ink for good-quality printing. The dates were printed the old way, on a typewriter instead.
The staff took out the Lysach typewriter and found that some of its type heads were broken. Printing a digit requires its matching head to work. For example, printing the digit 4 requires the head for 4 to be intact.
The staff want to know how many dates will need some digits added by hand in pencil.
Input
The first line contains two integers (the number of months on Mars) and (the number of broken heads) (, ). The second line contains integers , the number of days in each month (). The third line contains distinct digits that cannot be printed.
Output
Print the number of dates that need at least one digit added in pencil.
Hint
The calendar below shows the state before the masters repaired the typewriter, for the first test case.
Январь Февраль Март
Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс
1 2 1 2 4 5 6 7 1 2 4 5 6 7
4 5 6 7 8 9 1 8 9 1 11 12 1 14 8 9 1 11 12 1 14
11 12 1 14 15 16 17 15 16 17 18 19 2 21 15 16 17 18 19 2 21
18 19 2 21 22 2 24 22 2 24 25 26 27 28 22 2 24 25 26 27 28
25 26 27 28 29 1 29 1
Апрель Май Июнь
Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс
1 2 4 1 2 1 2 4 5 6
5 6 7 8 9 1 11 4 5 6 7 8 9 7 8 9 1 11 12 1
12 1 14 15 16 17 18 1 11 12 1 14 15 16 14 15 16 17 18 19 2
19 2 21 22 2 24 25 17 18 19 2 21 22 2 21 22 2 24 25 26 27
26 27 28 29 24 25 26 27 28 29 28 29
1
Июль Август Сентябрь
Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс
1 2 4 1 1 2 4 5
5 6 7 8 9 1 11 2 4 5 6 7 8 6 7 8 9 1 11 12
12 1 14 15 16 17 18 9 1 11 12 1 14 15 1 14 15 16 17 18 19
19 2 21 22 2 24 25 16 17 18 19 2 21 22 2 21 22 2 24 25 26
26 27 28 29 1 2 24 25 26 27 28 29 27 28 29
1
Октябрь Ноябрь Декабрь
Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс Пн Вт Ср Чт Пт Сб Вс
1 2 1 2 4 5 6 7 1 2 4 5
4 5 6 7 8 9 1 8 9 1 11 12 1 14 6 7 8 9 1 11 12
11 12 1 14 15 16 17 15 16 17 18 19 2 21 1 14 15 16 17 18 19
18 19 2 21 22 2 24 22 2 24 25 26 27 28 2 21 22 2 24 25 26
25 26 27 28 29 1 29 27 28 29 1