Given two cyclic sequences A and B each of length n, consisting of 0 and 1. In cyclic sequence \(a_{i+1}\) comes after \(a_i\) and \(a_0\) comes after \(a_{n-1}\). In a single turn you can flip three consecutive elements: \(a_i\), \(a_{(i+1)\bmod n}\) and \(a_{(i+2) \bmod n}\). Flipping element is altering its value: if it is 0, it becomes 1, and vice versa. What is the minimum number of turns you need to make to obtain sequence B from A?
Input format
First line of input contains single integer n (\(3 \leq n \leq 2 \cdot 10^5\)) — the length of A and B.
The second line of input contains n integers \(a_i\) (\(0 \leq a_i \leq 1\)) — sequence A.
The third line of input contains n integers \(b_i\) (\(0 \leq b_i \leq 1\)) — sequence B.
Output format
Print single integer — number of operations if it is possible to obtain B from A. Otherwise print "Impossible" (without quotes).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial