#P8537. Sequence Transformation

    ID: 21704 Type: Default 1000ms 256MiB

Sequence Transformation

Sequence Transformation

You are given two sequences of integers, a and b, each of length \( n \). You can perform two types of operations on sequence a:

  • Reverse the entire sequence.
  • Add an arbitrary integer (which may be negative) to any one element of the sequence.

Your task is to determine the minimum number of operations required to transform sequence a into sequence b.

Note: The reversal operation flips the order of the sequence, and an addition operation can be used to match an individual element to the corresponding value in sequence b.

It is optimal to consider at most one reversal because performing two reversals is equivalent to doing nothing. In summary, you need to check the number of mismatches in two scenarios:

  • Without reversal: Count mismatches between a[i] and b[i].
  • With one reversal: Reverse sequence a and then count mismatches between a[n-1-i] and b[i], then add one for the reversal operation.

The answer is the minimum of these two counts.

inputFormat

The input begins with an integer n (\( 1 \leq n \leq 10^5 \)), the length of the sequences.

The second line contains n space-separated integers representing sequence a.

The third line contains n space-separated integers representing sequence b.

outputFormat

Output a single integer which is the minimum number of operations required to transform sequence a into sequence b.

sample

3
1 2 3
1 2 3
0