Problem:
Score : 500 points

Problem Statement

We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.

The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1.

We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.

How many times do we need to cut the bar so that every block after the cuts has K or less white squares?

Constraints

1 \leq H \leq 10

1 \leq W \leq 1000

1 \leq K \leq H \times W

S_{i,j} is 0 or 1.

Input

Input is given from Standard Input in the following format:

H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W}

Output

Print the number of minimum times the bar needs to be cut so that every block after the cuts has K or less white squares.

Sample Input 1

3 5 4
11100
10001
00111

Sample Output 1

2

For example, cutting between the 1-st and 2-nd rows and between the 3-rd and 4-th columns - as shown in the figure to the left - works.

Note that we cannot cut the bar in the ways shown in the two figures to the right.

Sample Input 2

3 5 8
11100
10001
00111

Sample Output 2

0

No cut is needed.

Sample Input 3

4 10 4
1110010010
1000101110
0011101001
1101000111

Sample Output 3

3

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var HWK = CinTAr();
            int max = (int)Math.Ceiling(Math.Log(HWK[0] * HWK[1] / HWK[2] , 2));
            if (HWK[0] * HWK[1] <= 32)
            {
                Cout(max);
            }else if(HWK[0] * HWK[1] <= 64)
            {
                Cout(max - 1);
            }
            else if (HWK[0] * HWK[1] <= 128)
            {
                Cout(max - 2);
            }
            else
            {
                Cout(max - 3);
            }

            Cin();
        }

        //static long GET(int startH, List<int> blocks, int co = 0)
        //{
            
        //}

        static Random Rand = new Random();
        static string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        static int GetDigits(long num)
        {
            return (int)Math.Floor(Math.Log10(num)) + 1;
        }
        static int GetNumByDigit(long num, int digit)
        {
            return (int)((num / ((int)Math.Pow(10, digit - 1))) % 10);
        }
        static int loop(int num, int max)
        {
            if (num > max)
            {
                return num % max;
            }
            else if (num < 0)
            {
                return max - (-num) % max;
            }
            else
            {
                return num;
            }
        }
        static long GCD(long a, long b)
        {
            if (a < b) { swap(ref a, ref b); }
            if (a % b == 0) { return b; }
            else { return GCD(b, a % b); }
        }

        static long LCM(long a, long b)
        {
            return a * b / GCD(a, b);
        }

        static void swap<T>(ref T a, ref T b)
        {
            T t = a;
            a = b;
            b = t;
        }

        static readonly int MOD10_9_7 = (1000000000 + 7);
        static bool IsInt(double d) { return (int)d == d; }
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void Cout(object s) { WriteLine(s); }
        static long[] yakusuu(long n)
        {
            if (n == 1) { return new long[] { 1 }; }
            List<long> res = new List<long>();
            res.Add(1);
            for (long i = 2; i <= n / 2 + 1; i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                }
            }
            res.Add(n);
            return res.ToArray();
        }
        static bool isPrime(long num)
        {
            if (num == 1) { return false; }
            for (long i = 2; i <= Math.Sqrt(num) + 1; i++)
            {
                if (num % i == 0) { return false; }
            }
            return true;
        }

        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            WriteLine(string.Join(" ", types));
        }

        public static long nCr(int n, int r)
        {
            // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
            return nPr(n, r) / Factorial(r);
        }

        public static long nPr(int n, int r)
        {
            // naive: return Factorial(n) / Factorial(n - r);
            return FactorialDivision(n, n - r);
        }

        private static long FactorialDivision(int topFactorial, int divisorFactorial)
        {
            long result = 1;
            for (int i = topFactorial; i > divisorFactorial; i--)
                result *= i;
            return result;
        }

        private static long Factorial(int i)
        {
            if (i <= 1)
                return 1;
            return i * Factorial(i - 1);
        }
    }

    public struct Pair<T>
    {
        public T a;
        public T b;
        public T c;
        public Pair(T _a, T _b) { a = _a; b = _b; c = default(T); }
        public Pair(T _a, T _b, T _c) { a = _a; b = _b; c = _c; }
    }
}