Let's Play Billiards Already
Time limit1sMemory limit1024 MB
Given N rain flags, anger rises by 1 on rainy days and falls by 1 otherwise, starting from 0. Print the sum of the anger over all N days.
- Level
Easy1 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Dongwoo wants to play billiards with Suho. However, Suho is an extreme homebody and refuses to leave the house.
Dongwoo: Hyung, please come out already
Suho: I'll go if it doesn't rain lol
Dongwoo checks the weather for the next days. On a rainy day, Dongwoo cannot play billiards with Suho, so his anger builds up. Dongwoo's current anger is . Each day, Dongwoo checks whether it rains. If it rains, his anger increases by . If it does not, his anger decreases by . His anger can become negative.
Find the sum of Dongwoo's anger from day to day , so that he can avoid getting sick from bottled-up anger.
Input
The first line contains an integer .
The second line contains the weather for the days, separated by spaces. A rainy day is , and a day without rain is .
Output
Print the sum of Dongwoo's anger from day to day .
Hint
The sum can overflow 32-bit integers. Use the following types:
- C, C++:
long long - Java:
long