//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=37;

int n, m, k;

char wcz[nax];

struct plan
{
	vector <int> wek[nax];
	int kogo[nax][nax];
	plan()
	{
		czys();
	}
	void czys()
	{
		for (int i=0; i<nax; i++)
			for (int j=0; j<nax; j++)
				kogo[i][j]=0;
	}
	ll oznacz()
	{
		ll ret=0;
		for (int i=0; i<nax; i++)
		{
			int ost=-1;
			int ile=0;
			for (int j=0; j<nax; j++)
			{
				int x=-1;
				if ((int)wek[j].size()>i)
					x=wek[j][i];
				if (x==-1)
				{
					ost=-1;
					ile=0;
				}
				else
				{
					if (x!=ost)
					{
						ile=1;
						ost=x;
					}
					else
					{
						ile++;
						if (ile>=k)
						{
							for (int l=0; l<k; l++)
								kogo[j-l][i]=1;
						}
					}
				}
			}
		}
		for (int i=0; i<nax; i++)
			for (int j=0; j<(int)wek[i].size(); j++)
				ret+=kogo[i][j]*wek[i][j];
		return ret;
	}
	void puszuj()
	{
		for (int i=0; i<nax; i++)
		{
			vector <int> wez;
			for (int j=0; j<(int)wek[i].size(); j++)
				if (!kogo[i][j])
					wez.push_back(wek[i][j]);
			wek[i]=wez;
		}
		//~ int g=0;
		//~ for (int i=0; i<nax; i++)
		//~ {
			//~ if (!wek[i].empty())
			//~ {
				//~ wek[g]=wek[i];
				//~ if (i!=g)
					//~ wek[i].clear();
				//~ g++;
			//~ }
		//~ }
		czys();
	}
};

ll wyn;

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	plan start;
	for (int i=0; i<n; i++)
	{
		scanf("%s", wcz);
		for (int j=0; j<m; j++)
			start.wek[j].push_back(wcz[j]-'0');
	}
	for (int i=0; i<m; i++)
		reverse(start.wek[i].begin(), start.wek[i].end());
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<m; j++)
		{
			plan wez=start;
			wez.kogo[j][i]=1;
			wez.puszuj();
			ll ter=0;
			for (int h=0; 1; h++)
			{
				ll x=wez.oznacz();
				if (!x)
					break;
				ter+=(x<<h);
				wez.puszuj();
			}
			wyn=max(wyn, ter);
		}
	}
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 256