Hi.

There are `n<=100`

customers round a table. i'th of them wants food of type `a[i]`

but waiter has brought food of type `b[i]`

for him! ( note that `[b]`

is a permutation of `[a]`

).

Now customers want to move foods such that each of them get his favorite food. At each second each of them can perform one of these :

1 : pick one of the foods in front of him and give it to the person on his LEFT side

2 : pick one of the foods in front of him and give it to the person on his RIGHT side

3 : (1 + 2) simultaneously

There is one additional limitation that at each second no one can have more than 5 foods in front of him. We want to know the minimum time needed to do the job. ( each customer get his favorite food )

Sample : ( Squares are customers with their favorite food and Circles are foods on table. )

We need 2 seconds.

Can you help me to solve this problem ? It's kind of you :)