F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem C. Shuffle And Modify

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 331    Accepted Submission(s): 27


Problem Description
Give A and B, both are permutations of [1, 2 × n]. You want to change A to B in minimal moves.
For each move, you can do one of these two operations:
1. Shuffle the A. We define the shuffle as shuffle(A) = $A_1$ $A_{n+1}$ $A_2$ $A_{n+2}$ ... $A_n$$A_{2×n}$
2. Modify one element in A to any number.
 

Input
Input is given from Standard Input in the following format:
n
$A_1$ $A_2$ ... $A_{2×n}$
$B_1$ $B_2$ ... $B_{2×n}$
Constraints
1 ≤ n ≤ 100000
1 ≤$A_i$, $B_i$ ≤ 2 × n. All $A_i$ are distinct, so do B.
 

Output
Print one number denotes the minimal moves.
 

Sample Input
2 1 2 3 4 1 3 2 4
 

Sample Output
1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 15:00:43, Gzip enabled