#P1534. Accumulated Unhappiness Calculation
Accumulated Unhappiness Calculation
Accumulated Unhappiness Calculation
Tianjin has just started middle school. His mother believes that he should study harder, so besides regular classes, he also attends various review classes. In addition, every day his mother sends him to lessons for recitation, dance, and piano. However, if he attends classes for more than 8 hours in a day, he becomes unhappy, and the longer he attends, the unhappier he gets.
This problem is different from the first problem of NOIp2004 Pupil Group. Assume that Tianjin does not get unhappy for anything else, but his unhappiness (or happiness) will carry over to the next day. Specifically, if we denote the unhappiness level on day i by \(u_i\), and the total class time on day i by \(t_i\), then the recurrence is given by:
\[ u_i = u_{i-1} + (t_i - 8), \quad \text{for } i=1,2,\dots,n, \quad \text{with } u_0=0. \]Your task is to determine the accumulated unhappiness after n days, i.e. the value of \(u_n\).
inputFormat
The first line contains an integer n (\(1 \leq n \leq 10^5\)) representing the number of days. The second line contains n integers \(t_1, t_2, \ldots, t_n\) (each \(t_i\) is the number of class hours on day i), where each \(t_i\) is a non-negative integer.
outputFormat
Output a single integer representing the accumulated unhappiness after n days.
sample
3
8 8 8
0