Problem K. Kode work?

Author:Антон Карабанов,Игорь Блинов   Time limit:1 sec
Input file:Standard input   Memory limit:512 Mb
Output file:Standard output  

Statement

A group of students decided to create a startup to replace QR codes with new improved system. They decided to represent binary data as a string of digit patterns for 0 and 1, displayed on a picture below. Picture also contains a representation of a binary string 1001.

Digits in the code are separated by one column of '.' characters, first and last digit are located right on the edges of the code. If the image taken by camera does not exactly coincide with the digit patterns, then the number of differing pixels is called recognition error.

System must determine the minimal recognition error which can be obtained by picking the bit string most closely resembling given image.

Input format

First line of input contains integer n — image width. Following three lines contain the image. Each character is either '#' (ASCII 35), or '.' (ASCII 46).

Output format

Output single integer — minimum possible recognition error.

Constraints

2 ≤ n ≤ 100000

Sample tests

No. Standard input Standard output
1
5
.#..#
##.##
.#..#
0
2
14
.#.#.#.##.#..#
##.#.#.##.#.##
.#####.####..#
14

0.149s 0.030s 17