On an IT lesson Valera studied data compression. The teacher told about a new method, which we shall now describe to you.
Let {a _{1}, a _{2}, ..., a _{ n}} be the given sequence of lines needed to be compressed. Here and below we shall assume that all lines are of the same length and consist only of the digits 0 and 1. Let's define the compression function:
Valera faces a real challenge: he should divide the given sequence {a _{1}, a _{2}, ..., a _{ n}} into two subsequences {b _{1}, b _{2}, ..., b _{ k}} and {c _{1}, c _{2}, ..., c _{ m}}, m + k = n, so that the value of S = |f(b _{1}, b _{2}, ..., b _{ k})| + |f(c _{1}, c _{2}, ..., c _{ m})| took the minimum possible value. Here |p| denotes the length of the string p.
Note that it is not allowed to change the relative order of lines in the subsequences. It is allowed to make one of the subsequences empty. Each string from the initial sequence should belong to exactly one subsequence. Elements of subsequences b and c don't have to be consecutive in the original sequence a, i. e. elements of b and c can alternate in a (see samples 2 and 3).
Help Valera to find the minimum possible value of S.
The first line of input data contains an integer n — the number of strings (1 ≤ n ≤ 2·10^{5}). Then on n lines follow elements of the sequence — strings whose lengths are from 1 to 20 characters, consisting only of digits 0 and 1. The i + 1-th input line contains the i-th element of the sequence. Elements of the sequence are separated only by a newline. It is guaranteed that all lines have the same length.
Print a single number — the minimum possible value of S.
3
01
10
01
4
4
000
111
110
001
8
5
10101
01010
11111
01000
10010
17
Detailed answers to the tests:
Name |
---|