#P6367. Food Taking Reminder Count

    ID: 19583 Type: Default 1000ms 256MiB

Food Taking Reminder Count

Food Taking Reminder Count

At lunch, children sit around a table and take food in sequence from 1 to \(n\). There are \(n\) food items, and the children take them one by one in the given order. When a child takes an item, if the number of items he had taken previously (not including the current item) is greater than the sum of the items taken by all the other children, his mother issues a reminder about his impolite behavior. Note that even after the reminder, the child still takes the food item.

In mathematical terms, when a child with identifier \(k\) takes an item, let \(c_{k}\) denote the number of items he has taken before and \(T\) be the total number of items taken so far. A reminder is issued if:

\(c_{k} > T - c_{k}\).

Given the sequence in which the \(n\) food items were taken, compute the total number of reminders given.

inputFormat

The input consists of two lines:

  • The first line contains an integer \(n\) representing the total number of food items.
  • The second line contains \(n\) integers, where each integer indicates the identifier of the child who takes that food item, in order.

outputFormat

Output a single integer, which is the total number of reminders issued by the mothers.

sample

5
1 2 1 2 1
0

</p>