TORONTO KIDS COMPUTER CLUB | Markham Saturday 14:00 Java Homework 20.09.05.
18290

# Markham Saturday 14:00 Java Homework 20.09.05.

## 10 Sep Markham Saturday 14:00 Java Homework 20.09.05.

Question:
Count the number of cars passing each other on the street.

The goal is to count passing cars. We say that a pair of cars (PQ), where 0 ≤ P < Q < N, is passing when car P is traveling to the east and car Q is traveling to the west.

Input Description
The first line of the input is N (0<N<10000000) which contains the number of cars on the street. The next N lines of input represents the position of the car on the street. Each line of input contains number 0 and 1 where 0 represents a car traveling east and 1 means the car is traveling west.

●      0 represents a car traveling east,

●      1 represents a car traveling west.

Output Description
Output the number of cars passing each other.

Samples:

Input
5
0
1
0
1
1

Output
5

Explanation:
We have 5 cars passing each others. The car at 2nd place will pass car at 1st place. The car at 4th and 5th place will pass cars at position 1st and 3rd.

Input
6
0
0
0
0
1
1

Output
8

Explanation:
We have 8  cars passing each other. The cars at 5th and 6th place will pass the cars at 1st,2nd,3rd and 4th place as they are moving in opposite direction