Language: C++

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class Solve
{
    static void Main(string[] args)
    {
        new ABC_E();
    }
}
public class ABC_A
{
    public ABC_A()
    {
        var inn = Ex.ReadIntArray();
        int n = inn[0];
        int m = inn[1];
        Console.WriteLine(n * (n - 1) / 2 + m * (m - 1) / 2);
    }
}
public class ABC_B
{
    public ABC_B()
    {
        string s = Ex.Read;
        int n = s.Length;
        Console.WriteLine((c1(s, 1, n) && c1(s, 1, (n - 1) / 2) && c1(s, (n + 3) / 2, n)) ? "Yes" : "No");
    }

    bool c1(string s, int ss, int ee)
    {
        int i = 0;
        while ((ss + i - 1) <= (ee / 2))
        {
            if (s[ss + i - 1] != s[ee - i - 1]) return false;
            i++;
        }

        return true;
    }
}
public class ABC_C
{
    public ABC_C()
    {
        string s = Ex.Read;
        ulong l = ulong.Parse(s);
        var d = (l / 3.0);
        Console.WriteLine(d * d * d);
    }
}
public class ABC_D
{
    public ABC_D()
    {
        var n = Ex.ReadInt;
        var inn = Ex.ReadIntArray();
        long[] arr = new long[n + 1];
        foreach (int i in inn)
        {
            arr[i]++;
        }
        ulong all = 0;
        foreach (long i in arr)
        {
            long j = i;
            if (j >= 2)
                all += (ulong)(j * (j - 1) / 2);
        }
        foreach (int i in inn)
        {
            long j = arr[i] - 1;
            if (j >= 2)
                Console.WriteLine(all - (ulong)((j * (j + 1) / 2) - (j * (j - 1) / 2)));
            else if (j == 1)
                Console.WriteLine(all - 1);
            else
                Console.WriteLine(all);
        }
    }
}
public class ABC_E
{
    int h, w, k;
    char[,] s;
    int[,] c = new int[10, 1005];

    public ABC_E()
    {
        In();
        int res = int.MaxValue;

        for (int div = 0; div < (1 << (h - 1)); div++)
        {
            int g = 0;
            int[] id = new int[h];
            for (int i = 0; i < h; i++)
            {
                id[i] = g;
                if ((div >> i & 1) == 1) ++g;
            }
            ++g;

            for (int i = 0; i < g; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    c[i, j] = 0;
                }
            }

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    c[id[i], j] += (s[i, j] - '0');
                }
            }

            int num = g - 1;
            int[] now = new int[g];
            Func<int, bool> add = j =>
            {
                for (int i = 0; i < g; i++) now[i] += c[i, j];
                for (int i = 0; i < g; i++) if (now[i] > k) return false;
                return true;
            };
            for (int j = 0; j < w; j++)
            {
                if (!add(j))
                {
                    num++;
                    now = new int[g];
                    if (!add(j))
                    {
                        num = int.MaxValue;
                        break;
                    }
                }
            }
            res = Math.Min(res, num);
        }
        Console.WriteLine(res);
    }
    void In()
    {
        var line1 = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line1[0]);
        w = int.Parse(line1[1]);
        k = int.Parse(line1[2]);
        s = new char[h, w];

        for (int i = 0; i < h; i++)
        {
            var line2 = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
            {
                s[i, j] = line2[j];
            }
        }

    }
}
public class ABC_F
{
    public ABC_F()
    {

    }
}
public static class Ex
{
    public static string Read { get { return Console.ReadLine().Trim(); } }
    public static int ReadInt { get { return int.Parse(Read); } }
    public static long ReadLong { get { return long.Parse(Read); } }
    public static double ReadDouble { get { return double.Parse(Read); } }
    public static string[] ReadArray() { return Read.Split(' '); }
    public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
    public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
    public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Linq;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Collections;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:6:1: error: expected unqualified-id before 'public'
    6 | public class Solve
      | ^~~~~~
a.cc:13:1: error: expected unqualified-id before 'public'
   13 | public class ABC_A
      | ^~~~~~
a.cc:23:1: error: expected unqualified-id before 'public'
   23 | public class ABC_B
      | ^~~~~~
a.cc:44:1: error: expected unqualified-id before 'public'
   44 | public class ABC_C
      | ^~~~~~
a.cc:54:1: error: expected unqualified-id before 'public'
   54 | public class ABC_D
      | ^~~~~~
a.cc:84:1: error: expected unqualified-id before 'public'
   84 | public class ABC_E
      | ^~~~~~
a.cc:166:1: error: expected unqualified-id before 'public'
  166 | public class ABC_F
      | ^~~~~~
a.cc:173:1: error: expected unqualified-id before 'public'
  173 | public static class Ex
      | ^~~~~~