Under construction

Still being built. Things may change

Course Swap

Time limit4sMemory limit512 MB

Summary
Each student holds course A_i and wants B_i; two students can swap their courses, and chains of swaps are allowed. Find the minimum number of students who cannot get their desired course.
Level

Medium6 of 10

Topics
Graph, Greedy, Hash map, Implementation
Solved
No attempts yet

Problem

In 20XX, Yonsei University, the only university in the country using a mileage based course registration system, plans to introduce a new system for course changes as well.

Starting in 20XX, "course swaps" are allowed during the course change period.

A course swap is when two people exchange different courses, and it is only possible with the consent of both people.

Three-way swaps are not possible, but after two people swap courses, one of them may swap that course with yet another person.

When the system was first introduced there was much discussion, but good cases are increasing, such as students who want to take each other's major courses swapping courses, or graduating students with leftover mileage handing courses down to juniors.

As always, the course change period has begun. Given one course each student wants to take and one course each student wants to swap, find the minimum number of students who fail to take the course they want after all course swaps are finished.

Input

The first line gives the number of students NN. (1≤N≤1 000 0001 \leq N \leq 1\ 000\ 000)

The second line gives integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N. AiA_i is the course student ii is currently enrolled in and also the number of the course they want to swap. (1≤Ai≤1 000 0001 \leq A_i \leq 1\ 000\ 000)

The third line gives integers B1,B2,⋯ ,BNB_1, B_2, \cdots, B_N. BiB_i is the number of the course student ii wants to take through a swap. (1≤Bi≤1 000 0001 \leq B_i \leq 1\ 000\ 000)

All input is separated by spaces.

Output

Print the number of students who fail to take the course they want when all students finish course swaps using the optimal method.

Examples2

  1. Example 1

    Input
    5
    2 2 3 3 3
    3 3 1 2 2
    
    Expected output
    1
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    6 5 2 7 3
    
    Expected output
    2