All problems

Problem 897

Number of Students Unable to Eat Lunch

Easy · 10 pts · Array, Queue, Simulation

Problem

Students stand in a queue and sandwiches lie in a stack; each is type 0 (circular) or 1 (square). The student at the front takes the top sandwich if they like it and leaves; otherwise they go to the back of the queue. This stops when no student in the queue wants the top sandwich. Count the students who cannot eat. Only the counts matter: serve sandwiches from the top while a student of that type remains.

Input

The first line contains N. The second line contains the students' preferences from the front of the queue. The third line contains the sandwiches from the top of the stack.

Output

Print the number of students unable to eat.

Constraints

1 <= N <= 100; every value is 0 or 1

Example input

4
1 1 0 0
0 1 0 1

Example output

0

Explanation

With students 1 1 0 0 and sandwiches 0 1 0 1, the students keep rotating until everyone finds their sandwich type on top, so all four eat and the answer is 0.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Build an Array With Stack Operations Next: Time Needed to Buy Tickets