Under construction

Still being built. Things may change

Let's Play Billiards Already

Time limit1sMemory limit1024 MB

Summary
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 NN days. On a rainy day, Dongwoo cannot play billiards with Suho, so his anger builds up. Dongwoo's current anger is 00. Each day, Dongwoo checks whether it rains. If it rains, his anger increases by 11. If it does not, his anger decreases by 11. His anger can become negative.

Find the sum of Dongwoo's anger from day 11 to day NN, so that he can avoid getting sick from bottled-up anger.

Input

The first line contains an integer NN. (1≤N≤200 000)(1 \le N \le 200\,000)

The second line contains the weather for the NN days, separated by spaces. A rainy day is 11, and a day without rain is 00.

Output

Print the sum of Dongwoo's anger from day 11 to day NN.

Hint

The sum can overflow 32-bit integers. Use the following types:

  • C, C++: long long
  • Java: long

Examples2

  1. Example 1

    Input
    5
    0 0 0 0 0
    
    Expected output
    -15
    
  2. Example 2

    Input
    6
    1 1 0 0 1 0
    
    Expected output
    5