dans

For our school's 150 year celebration we had a show and the most spectacular part of it was a dance in which the students aligned themselves in concentric circles, one circle for each class, and started spinning to the music. The number of students in a class, n, is the same for every class, but the number of boys and girls, as well as how they are lined up in the circles varies, so the IT teacher that's sitting on the side asks himself the following question: could we, by rotating the circles of students, obtain an alignment in which we had only boys or only girls on one radius and, if not, which is the maximum number of such radiuses we could obtain.

Task

Knowing the initial student line-up on each circle, and taking as a reference the innermost circle, establish how many positions the students on each circle must move to the right in order to obtain a maximum number of radiuses with students of the same gender. By rotating one position to the right the student from position i will move to position i+1, for i=1,2,...,n-1, and the one on position n moves to position 1.

Input Data

Line one of input file dans.in contains  two positive integers, m and n, representing the number of classes, and respectively the number of students in a class. The following m lines each contain n numbers 0 or 1 (0 for girls, 1 for boys), representing the students' initial line-up, in ascending radius order. The numbers on the same line will be separated by a space.

Output Data

Line one of input file dans.out will contain the maximum number of radiuses formed by only boys or only girls that can be obtained. On the next line there will be m-1 numbers separated by a space, representing how many positions each circle, starting with the second, rotates in order to obtain said configuration. If there is more than one possible solution, the one in which the circle that is closer to the center has to rotate less will be selected. If there is more than one rotation possibility for a circle, the one in which it rotates less will be selected.

Restrictions

Example

dans.in

dans.out

Explanation

5 4
1 0 1 0
0 1 1 0
1 0 1 0
1 0 0 0
1 0 1 1

2
0 0 2 2

rotating circles 3 and 4 two positions to the right we get
1 0 1 0
0 1 1 0
1 0 1 0
0 0 1 0
1 1 1 0

Time limit: 3.5 seconds/test

prof. Nistor Mot
Brăila "N.Balcescu" National High School
Contact:emotz_ro@yahoo.co.uk