TORONTO KIDS COMPUTER CLUB | PMCA Sunday 12:00 Java Homework 20.03.08.
17204
post-template-default,single,single-post,postid-17204,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

PMCA Sunday 12:00 Java Homework 20.03.08.

12 Mar PMCA Sunday 12:00 Java Homework 20.03.08.

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 (P, Q), 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

No Comments

Sorry, the comment form is closed at this time.