CF383A.Milking cows

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Iahub helps his grandfather at the farm. Today he must milk the cows. There are nn cows sitting in a row, numbered from 11 to nn from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).

Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

输入格式

The first line contains an integer nn (1<=n<=200000)(1<=n<=200000) . The second line contains nn integers a1a_{1} , a2a_{2} , ..., ana_{n} , where aia_{i} is 00 if the cow number ii is facing left, and 11 if it is facing right.

输出格式

Print a single integer, the minimum amount of lost milk.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

  • 输入#1

    4
    0 0 1 0
    

    输出#1

    1
  • 输入#2

    5
    1 0 1 0 1
    

    输出#2

    3

说明/提示

In the first sample Iahub milks the cows in the following order: cow 33 , cow 44 , cow 22 , cow 11 . When he milks cow 33 , cow 44 loses 11 unit of milk. After that, no more milk is lost.

首页