A radio station plays songs in a fixed order, repeating the playlist forever. The song durations are seconds. There are no gaps between songs, including between song and song .
You turn on the radio at an arbitrary moment, possibly in the middle of a song. This moment is not necessarily an integer number of seconds.
Find the smallest integer such that listening continuously for seconds guarantees that you hear at least one complete song, regardless of when you turn on the radio.
A song counts only if you hear one playback of it from its beginning to its end. A playback starting exactly when you turn on the radio or ending exactly when you stop listening also counts.
The first line contains the number of songs .
The second line contains their durations in playback order.
Print the smallest integer listening duration that guarantees hearing a complete song.