NOI Contest Archive

Archive / 2022 / February 2022

No Electricity Hour

Medium · National Olympiad in Informatics Sri Lanka - February 2022

There’s a distant island named Ãkkåy Island, that uses a different timing convention. Unlike ours, this island has D days per month and H hours per day. The island is divided into S number of sections. This island is having a hard time finding fuel for electricty generation. So, to overcome this, they have decided to stop providing power for various sections of the island to control the fuel usage for power generation. So, the smart people in this island have come up with a plan, to stop power for different sections in different intervals. So, every section would loose power for one hour, after different number of hours(Ys). Due to this, there are some hours, where the whole island looses power. And the people on this island have begun to call this hour as “No Electricity Hour”.

Given a time of a no electricy hour(T1), you are supposed to find whether a given time(T2) is a no electricity hour. If it’s not a no electricity hour, find X, the number of hours to the closest no electricity hour.

Input Format

First line contains 3 integers, D, H & S describing the number of days per month, number of hours per day and number of sections in the island respectively.
Next line contains S integers, Y1, Y2, …, Xn, describing the number of hours between a power cut for each section.
Next line contains 3 integers, m1, d1, h1. The month, date and hour of T1 respectively.
Last line contains 3 integers, m2, d2, h2. The month, date and hour of T2 respectively.

Output Format

If T2 is a Full Moon Day, print “NO ELECTRICITY HOUR”.
If not, print a single positive integer X, the number of hours to the closest no electricity hour.

Constraints

If the number of hours between T1 & T2 is D,

Limits

Sample Input 0

30 24 1
26
2 24 8
2 25 10

Sample Output 0

NO ELECTRICITY HOUR

Sample Input 1

20 12 2
3 2
2 1 1
2 1 12

Sample Output 1

1