#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            int cur[26];
            memset(cur, 0, sizeof cur);
            int last = 0;
            for (int j = 0; j < m; j++) {
                int c = a[i][j] - 'a';
                while (last < m && get(i, j, k, last) <= abc) {
                    if (a[i][last] == a[k][last]) {
                        cur[a[i][last] - 'a']++;
                    }
                    last++;
                }
                if (last > j && a[i][j] == a[k][j]) {
                    cur[c] -= (get(i, j, k, j)) <= abc;
                    ans += cur[c];
                }
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, j + 1);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            int cur[26];
            memset(cur, 0, sizeof cur);
            int last = 0;
            for (int j = 0; j < m - 1; j++) {
                int c = a[i][j] - 'a';
                while (last < m && get(i, j, k, last) <= abc) {
                    if (a[i][last] == a[k][last]) {
                        cur[a[i][last] - 'a']++;
                    }
                    last++;
                }
                if (a[i][j] == a[k][j]) {
                    cur[c] -= (get(i, j, k, j)) <= abc;
                    ans += cur[c];
                }
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = m - 1;
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                vector <int> t;
                queue <int> p = cur[c];
                while (p.size()) {
                    t.push_back(p.front());
                    p.pop();
                }
                for (int c = 0; c < (int) t.size(); c++) {
                    int r = t[c];
                    if (r > j && a[i][r] == a[k][r] && a[i][r] == a[i][j] && get(i, j, k, c) <= abc) {
                        ans++;
                    } else {
                        assert(0);
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            //queue <int> cur[26];
            //int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                //int c = a[i][j] - 'a';
                /*
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                */
                for (int t = m - 1; t > j; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) > abc) {
                        ans++;
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            //queue <int> cur[26];
            //int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                //int c = a[i][j] - 'a';
                /*
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                */
                for (int t = m - 1; t > j; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, j);
                /*
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                */
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, min(m - 1, j + 1));
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, min(m - 1, j + 7));
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                vector <int> t;
                queue <int> p = cur[c];
                while (p.size()) {
                    t.push_back(p.front());
                    p.pop();
                }
                for (int c = 0; c < (int) t.size(); c++) {
                    int r = t[c];
                    if (r == j) continue;
                    if (a[i][r] == a[k][r] && a[i][r] == a[i][j] && get(i, j, k, c) <= abc) {
                        ans++;
                    } else {
                        assert(0);
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];
vector <int> pos[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
            pos[i][(int) a[i][j]].pb(j);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                if (last != j) ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define cin(n) scanf("%d",&n)
#define cind(n) scanf("%lf",&n)
#define pb push_back
#define mp make_pair
#define ll long long
#define MAXN 401

int col[MAXN][MAXN];
int a[MAXN][MAXN],m,n,d;
int cnt[27][27];

void inp()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

    cin>>(m);
    cin>>(n);cin>>(d);

    for(int i=1;i<=m;i++)
    {
        string s;
        cin>>s;
        for(int j=1;j<=n;j++)
        {
            if(s[j-1]=='a')
                col[i][j]=col[i-1][j]+1;
            else
                col[i][j]=col[i-1][j];
            a[i][j]=s[j-1]-'a';
            //cout<<a[i][j]<<" ";
        }
        //cout<<"\n";
    }
}

void pre()
{
    memset(col,0,sizeof(col));
    memset(a,0,sizeof(a));
}

void solve()
{
    int i,j,k;

    long long ans=0;

    //fixing upper end point of row
    for(i=1;i<=m;i++){
    //fixing lower end point of row
        for(j=i+1;j<=m;j++){
            memset(cnt,0,sizeof(cnt));
            int sum=0;
            int idx=1;
            //end points initial (i,1) (j,1)
            for(k=1;k<=n;k++){
            if(a[i][k]==a[j][k]&&(col[j][k]-col[i-1][k])<=d)
            ans--;
                while(idx<=n&&sum<=d){
                    sum+=(col[j][idx]-col[i-1][idx]);
                    cnt[a[i][idx]][a[j][idx]]++;
                    idx++;
                }
                if(sum>d){
                    idx--;
                    if(idx>0&&a[i][idx]==a[j][idx]&&a[i][idx]==a[i][k]&&a[i][k]==a[j][k])
                        ans--;
                    idx++;
                }

                if(a[i][k]==a[j][k])
                    ans+=cnt[a[i][k]][a[i][k]];
                cnt[a[i][k]][a[j][k]]--;
                sum-=(col[j][k]-col[i-1][k]);
                //cout<<i<<" "<<j<<" "<<k<<" "<<ans<<"\n";
            }
        }
    }
    cout<<ans<<"\n";
}
int main()
{
    int t,i,j,k,l;

    pre();
    inp();

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cin(n) scanf("%d",&n)
#define cind(n) scanf("%lf",&n)
#define pb push_back
#define mp make_pair
#define ll long long
#define MAXN 401

int col[MAXN][MAXN];
int a[MAXN][MAXN],m,n,d;
int cnt[27][27];

void inp()
{
    cin>>(m);
    cin>>(n);cin>>(d);

    for(int i=1;i<=m;i++)
    {
        string s;
        cin>>s;
        for(int j=1;j<=n;j++)
        {
            if(s[j-1]=='a')
                col[i][j]=col[i-1][j]+1;
            else
                col[i][j]=col[i-1][j];
            a[i][j]=s[j-1]-'a';
            //cout<<a[i][j]<<" ";
        }
        //cout<<"\n";
    }
}

void pre()
{
    memset(col,0,sizeof(col));
    memset(a,0,sizeof(a));
}

void solve()
{
    int i,j,k;

    long long ans=0;

    //fixing upper end point of row
    for(i=1;i<=m;i++){
    //fixing lower end point of row
        for(j=i+1;j<=m;j++){
            memset(cnt,0,sizeof(cnt));
            int sum=0;
            int idx=1;
            //end points initial (i,1) (j,1)
            for(k=1;k<=n;k++){
            if(a[i][k]==a[j][k]&&(col[j][k]-col[i-1][k])<=d)
            ans--;
                while(idx<=n&&sum<=d){
                    sum+=(col[j][idx]-col[i-1][idx]);
                    cnt[a[i][idx]][a[j][idx]]++;
                    idx++;
                }
                if(sum>d){
                    idx--;
                    if(idx>0&&a[i][idx]==a[j][idx]&&a[i][idx]==a[i][k]&&a[i][k]==a[j][k])
                        ans--;
                    idx++;
                }

                if(a[i][k]==a[j][k])
                    ans+=cnt[a[i][k]][a[i][k]];
                cnt[a[i][k]][a[j][k]]--;
                sum-=(col[j][k]-col[i-1][k]);
                //cout<<i<<" "<<j<<" "<<k<<" "<<ans<<"\n";
            }
        }
    }
    cout<<ans<<"\n";
}
int main()
{
    int t,i,j,k,l;

    pre();
    inp();

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cin(n) scanf("%d",&n)
#define cind(n) scanf("%lf",&n)
#define pb push_back
#define mp make_pair
#define ll long long
#define MAXN 401

int col[MAXN][MAXN];
int a[MAXN][MAXN],m,n,d;
int cnt[27][27];

void inp()
{
    cin(m);
    cin(n);cin(d);

    for(int i=1;i<=m;i++)
    {
        string s;
        cin>>s;
        for(int j=1;j<=n;j++)
        {
            if(s[j-1]=='a')
                col[i][j]=col[i-1][j]+1;
            else
                col[i][j]=col[i-1][j];
            a[i][j]=s[j-1]-'a';
            //cout<<a[i][j]<<" ";
        }
        //cout<<"\n";
    }
}

void pre()
{
    memset(col,0,sizeof(col));
    memset(a,0,sizeof(a));
}

void solve()
{
    int i,j,k;

    long long ans=0;

    //fixing upper end point of row
    for(i=1;i<=m;i++){
    //fixing lower end point of row
        for(j=i+1;j<=m;j++){
            memset(cnt,0,sizeof(cnt));
            int sum=0;
            int idx=1;
            //end points initial (i,1) (j,1)
            for(k=1;k<=n;k++){
            if(a[i][k]==a[j][k]&&(col[j][k]-col[i-1][k])<=d)
            ans--;
                while(idx<=n&&sum<=d){
                    sum+=(col[j][idx]-col[i-1][idx]);
                    cnt[a[i][idx]][a[j][idx]]++;
                    idx++;
                }
                if(sum>d){
                    idx--;
                    if(idx>0&&a[i][idx]==a[j][idx]&&a[i][idx]==a[i][k]&&a[i][k]==a[j][k])
                        ans--;
                    idx++;
                }

                if(a[i][k]==a[j][k])
                    ans+=cnt[a[i][k]][a[i][k]];
                cnt[a[i][k]][a[j][k]]--;
                sum-=(col[j][k]-col[i-1][k]);
                //cout<<i<<" "<<j<<" "<<k<<" "<<ans<<"\n";
            }
        }
    }
    cout<<ans<<"\n";
}
int main()
{
    int t,i,j,k,l;

    pre();
    inp();

    solve();

    return 0;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1-1][y2]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
        }
    }

    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
        for(int x2 = x1+1; x2 <= n; x2++) {
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
                if(y1 > y2) y2 = y1;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 < y2 && board[x1][y1] == board[x2][y1]) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

    #ifdef FSOCIETY
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1] << " " << acc[i][j] << " " << board[i][j] << endl;
//            cout << acc[i][j];
        }
//        cout << endl;
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << "  fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                cout << y1 << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " " << y2 << endl;
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 != y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
//                cout << y1 << " " << y2 << endl;
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1] << " " << acc[i][j] << " " << board[i][j] << endl;
//            cout << acc[i][j];
        }
//        cout << endl;
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << "  fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                cout << y1 << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " " << y2 << endl;
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 != y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
//                cout << y1 << " " << y2 << endl;
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1] << " " << acc[i][j] << " " << board[i][j] << endl;
//            cout << acc[i][j];
        }
//        cout << endl;
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << "  fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                cout << y1 << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " " << y2 << endl;
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 != y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
//                cout << y1 << " " << y2 << endl;
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1] << " " << acc[i][j] << " " << board[i][j] << endl;
//            cout << acc[i][j];
        }
//        cout << endl;
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << "  fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                cout << y1 << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " " << y2 << endl;
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 != y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
//                cout << y1 << " " << y2 << endl;
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1-1][y2]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
     cin.tie(0);

//    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
        }
    }

    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
        for(int x2 = x1+1; x2 <= n; x2++) {
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 < y2 && board[x1][y1] == board[x2][y1]) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
        }
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
        for(int x2 = x1+1; x2 <= n; x2++) {
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 < y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1][y2-1]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1] << " " << acc[i][j] << " " << board[i][j] << endl;
//            cout << acc[i][j];
        }
//        cout << endl;
    }
    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << "  fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                cout << y1 << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " " << y2 << endl;
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 != y2 && board[x1][y1] == board[x2][y1] ) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
//                cout << y1 << " " << y2 << endl;
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1-1][y2]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
        }
    }

    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
        for(int x2 = x1+1; x2 <= n; x2++) {
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
//                if(y1 > y2) y2 = y1;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
                    if(board[x1][y2] == board[x2][y2]) {
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 < y2 && board[x1][y1] == board[x2][y1]) {
                    ans += cnt[ board[x1][y1]-'a' ];
                }
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 405;
const double EPS = 1e-5;
const int INF = INT_MAX;

char board[MAX][MAX];
int acc[MAX][MAX];
int cnt[27];

int get_acc(int x1, int y1, int x2, int y2) {
    return acc[x2][y2]-acc[x2][y1-1]-acc[x1-1][y2]+acc[x1-1][y1-1];
}

int main( ) {
     ios_base::sync_with_stdio(0);
//     cin.tie(0);

//    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    #endif

    int n, m, k; cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> board[i][j];
            acc[i][j] = acc[i-1][j]+acc[i][j-1]-acc[i-1][j-1]+(board[i][j] == 'a');
//            cout << acc[i][j];
        }
//        cout << endl;
    }

//    cout << get_acc(1, 2, 2, 2) << endl;

    ll ans = 0;
    for(int x1 = 1; x1 <= n; x1++) {
//        cout << "fila " << x1 << endl;
        for(int x2 = x1+1; x2 <= n; x2++) {
//            cout << " fila " << x2 << endl;
            memset(cnt, 0, sizeof cnt);
            for(int y1 = 1, y2 = 1; y1 <= m; y1++) {
                if(y1 > y2) y2 = y1;
//                cout << "from " << y1 <<  " and " << y2 << endl;
//                cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                while(y2 <= m && get_acc(x1, y1, x2, y2) <= k) {
//                    cout << " -> " << get_acc(x1, y1, x2, y2) << endl;
                    if(board[x1][y2] == board[x2][y2]) {
//                        cout << "cuento una " << board[x1][y2] << endl;
                        cnt[ board[x1][y2]-'a' ]++;
                    }
                    y2++;
                }
//                cout << "to " << y2 << endl;
                if(board[x1][y1] == board[x2][y1]) {
                    cnt[ board[x1][y1]-'a' ]--;
                }
                if(y1 < y2 && board[x1][y1] == board[x2][y1] && get_acc(x1, y1, x2, y2-1) <= k) {
//                    cout << " cnt = " << cnt[ board[x1][y1]-'a' ] << endl;
                    ans += cnt[ board[x1][y1]-'a' ];
                }
            }
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    int ca[n+1][m];
    for(j=0;j<m;j++){
        ca[0][j]=0;
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            ca[i+1][j] = ca[i][j];
            if(s[i][j]=='a')ca[i+1][j]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                //if(s[j][r]=='a')ca[r]++;
                aux = ca[j+1][r] - ca[i][r];
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;
int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(ckon[s[i][l]-'a']>1)res+=ckon[s[i][l]-'a'] - 1;
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l])ckon[s[i][l] - 'a']--;
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pll pair<long long, long long>
#define vll vector<long long>

using namespace std;

int main(){

    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(ckon[s[i][l]-'a']>1)res+=ckon[s[i][l]-'a'] - 1;
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l])ckon[s[i][l] - 'a']--;
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){

    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][r])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll int
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    int ca[n+1][m];
    for(j=0;j<m;j++){
        ca[0][j]=0;
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i+1][j] = c[i][j];
            if(s[i][j]=='a')ca[i+1][j]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                //if(s[j][r]=='a')ca[r]++;
                aux = ca[j+1][r] - ca[i][r];
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][r])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;
int main(){
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(ckon[s[i][l]-'a']>1)res+=ckon[s[i][l]-'a'] - 1;
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l])ckon[s[i][l] - 'a']--;
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll int
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    int ca[n+1][m];
    for(j=0;j<m;j++){
        ca[0][j]=0;
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            ca[i+1][j] = ca[i][j];
            if(s[i][j]=='a')ca[i+1][j]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                //if(s[j][r]=='a')ca[r]++;
                aux = ca[j+1][r] - ca[i][r];
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][r])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll int
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    int ca[n+1][m];
    for(j=0;j<m;j++){
        ca[0][j]=0;
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i+1][j] = c[i][j];
            if(s[i][j]=='a')ca[i+1][j]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                //if(s[j][r]=='a')ca[r]++;
                aux = ca[j+1][r] - c[i][r];
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll int
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        int ca[m];
        for(j=0;j<m;j++){
            ca[j]=0;
            if(s[i][j]=='a')ca[j]=1;
        }
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                if(s[j][r]=='a')ca[r]++;
                aux = ca[r];
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0){
                                if(s[i][r] == s[i][l] && s[j][r] == s[j][l])res+=ckon[s[i][l]-'a'] - 1;
                                else res+=ckon[s[i][l]-'a'];
                            }
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l]){
                            ckon[s[i][l] - 'a']--;
                            if(ckon[s[i][l]-'a']>0)res+=ckon[s[i][l]-'a'];
                        }
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define cd complex<double>
#define pll pair<long long, long long>
#define vll vector<long long>
using namespace std;
int main(){
    fropen("input.txt","r",stdin);
    fropen("output.txt","w",stdout);
    ll n,m,k,i,j,t,l,r,con,aux,res,ckon[26];
    cin>>n>>m>>k;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    res=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            l=0;
            while(l<m && s[i][l]!=s[j][l])l++;
            r=l;
            con = 0;
            memset(ckon, 0, sizeof ckon);
            queue<ll> q;
            while(r<m){
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                aux=0;
                for(t=i;t<=j;t++){
                    if(s[t][r]=='a')aux++;
                }
                con+=aux;
                //cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<con<<" "<<res<<endl;
                q.push(aux);
                if(con>k){
                    if(ckon[s[i][l]-'a']>1)res+=ckon[s[i][l]-'a'] - 1;
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                    while(l<m && (s[i][l]!=s[j][l] || con>k)){
                        if(!q.empty() && s[i][l]==s[j][l])ckon[s[i][l] - 'a']--;
                        l++;
                        if(!q.empty()){
                            con-=q.front();
                            q.pop();
                        }
                        else{
                            r=l-1;
                        }
                    }
                }
                else{
                    if(s[i][r] == s[j][r])ckon[s[i][r]-'a']++;
                }
                r++;
            }
            for(int kk = 0; kk<26; kk++)res+=ckon[kk]*(ckon[kk]-1)/2;
            //cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
#define d(i,j) a[i][j]-'a'
using namespace std;
int read()
{
    register int a(0),p(1);register char ch=0;
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') p=-1,ch=getchar();
    while(ch>='0'&&ch<='9') a=a*10+ch-48,ch=getchar();
    return a*p;
}
const int N=550;
int n,m,num,s[N][N];
ll ans,cnt[100];
char a[N][N];
int main()
{
	n=read(),m=read(),num=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++)
		{
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			if(a[i][j]=='a') ++s[i][j];
		}
	}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int temp=1;memset(cnt,0,sizeof(cnt));
			for(int k=1;k<=m;k++) if(a[j][k]==a[i][k])
			{
				--cnt[d(i,k)];
				while(temp<=m&&s[j][temp]-s[i-1][temp]-s[j][k-1]+s[i-1][k-1]<=num)
				{
					if(a[i][temp]==a[j][temp]) ++cnt[d(i,temp)];
					++temp;
				}
				if(cnt[d(i,k)]>0) ans+=cnt[d(i,k)];
			}
		}
	 cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
#define d(i,j) a[i][j]-'a'
using namespace std;
int read()
{
    register int a(0),p(1);register char ch=0;
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') p=-1,ch=getchar();
    while(ch>='0'&&ch<='9') a=a*10+ch-48,ch=getchar();
    return a*p;
}
const int N=550;
int n,m,num,s[N][N];
ll ans,cnt[100];
char a[N][N];
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	n=read(),m=read(),num=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++)
		{
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			if(a[i][j]=='a') ++s[i][j];
		}
	}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int temp=1;memset(cnt,0,sizeof(cnt));
			for(int k=1;k<=m;k++) if(a[j][k]==a[i][k])
			{
				--cnt[d(i,k)];
				while(temp<=m&&s[j][temp]-s[i-1][temp]-s[j][k-1]+s[i-1][k-1]<=num)
				{
					if(a[i][temp]==a[j][temp]) ++cnt[d(i,temp)];
					++temp;
				}
				if(cnt[d(i,k)]>0) ans+=cnt[d(i,k)];
			}
		}
	 cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
#define d(i,j) a[i][j]-'a'
using namespace std;
int read()
{
    register int a(0),p(1);register char ch=0;
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') p=-1,ch=getchar();
    while(ch>='0'&&ch<='9') a=a*10+ch-48,ch=getchar();
    return a*p;
}
const int N=550;
int n,m,num,s[N][N];
ll ans,cnt[100];
char a[N][N];
int main()
{
	n=read(),m=read(),num=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++)
		{
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			if(a[i][j]=='a') ++s[i][j];
		}
	}
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int temp=1;memset(cnt,0,sizeof(cnt));
			for(int k=1;k<=m;k++) if(a[j][k]==a[i][k])
			{
				--cnt[d(i,k)];
				while(temp<=m&&s[j][temp]-s[i-1][temp]-s[j][k-1]+s[i-1][k-1]<=num)
				{
					if(a[i][temp]==a[j][temp]) ++cnt[d(i,temp)];
					++temp;
				}
				if(cnt[d(i,k)]>0) ans+=cnt[d(i,k)];
			}
		}
	printf("%I64d",ans);
    return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,columns[maxn],letters[maxa];
long long res;
int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++)
            if(a[i][j]=='a')
                columns[j]++;
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++)
                if(a[j][l]=='a')
                    columns[l]++;
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1])
                letters[a[i][1]-'a']++;
            while(idx1<m){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 400+100
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,res,columns[maxn],letters[maxa];

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++)
            if(a[i][j]=='a')
                columns[j]++;
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++)
                if(a[j][l]=='a')
                    columns[l]++;
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1])
                letters[a[i][1]-'a']++;
            while(idx1<m){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,res,columns[maxn],letters[maxa];

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++)
            if(a[i][j]=='a')
                columns[j]++;
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++)
                if(a[j][l]=='a')
                    columns[l]++;
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1])
                letters[a[i][1]-'a']++;
            while(idx1<n){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,res,columns[maxn],letters[maxa];

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++)
            if(a[i][j]=='a')
                columns[j]++;
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++)
                if(a[j][l]=='a')
                    columns[l]++;
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1])
                letters[a[i][1]-'a']++;
            while(idx1<m){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,res,columns[maxn],letters[maxa];

int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%s",a[i]+1);
    }
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++){
            if(a[i][j]=='a'){
                columns[j]++;
            }
        }
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++){
                if(a[j][l]=='a'){
                    columns[l]++;
                }
            }
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1]){
                letters[a[i][1]-'a']++;
            }
            while(idx1<m){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n,m,k,res,columns[maxn],letters[maxa];

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%s",a[i]+1);
    }
    for(int i=1;i<=n-1;i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++){
            if(a[i][j]=='a'){
                columns[j]++;
            }
        }
        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1;l<=m;l++){
                if(a[j][l]=='a'){
                    columns[l]++;
                }
            }
            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1]){
                letters[a[i][1]-'a']++;
            }
            while(idx1<m){
                counter-=columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout<<res;
    return 0;
}


import java.io.*;
import java.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        File f=new File("input.txt");
        File f2=new File("output.txt");
        BufferedReader bu=new BufferedReader(new FileReader(f));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int i,c[]=new int[5001],k;
        for(i=0;i<n;i++)
        {
            k=Integer.parseInt(s[i]);
            c[k]++;
        }
        int ans=Integer.MAX_VALUE;
        for(i=1;i<=5000;i++)
        c[i]+=c[i-1];
        for(i=1;i<=2500;i++)
        ans=Math.min(ans,n-(c[2*i]-c[i-1]));
        PrintStream p=new PrintStream(f2);
        System.out.print(ans);
    }
}


import java.io.*;
import java.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        File f=new File("input.txt");
        File f2=new File("output.txt");
        BufferedReader bu=new BufferedReader(new FileReader(f));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int i,c[]=new int[5001],k;
        for(i=0;i<n;i++)
        {
            k=Integer.parseInt(s[i]);
            c[k]++;
        }
        int ans=Integer.MAX_VALUE;
        for(i=1;i<=5000;i++)
        c[i]+=c[i-1];
        for(i=1;i<=2500;i++)
        ans=Math.min(ans,n-(c[2*i]-c[i-1]));
        PrintStream p=new PrintStream(f2);
        System.out.print(ans+"\n");
    }
}


import java.io.*;
import java.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        FastReader fr=new FastReader("input.txt","output.txt");
        int n=ni();
        int i,c[]=new int[5001],k;
        for(i=0;i<n;i++)
        {
            k=ni();
            c[k]++;
        }
        int ans=Integer.MAX_VALUE;
        for(i=1;i<=5000;i++)
        c[i]+=c[i-1];
        for(i=1;i<=2500;i++)
        ans=Math.min(ans,n-(c[2*i]-c[i-1]));
        pn(ans);
    }
    static FastReader sc;
    static PrintWriter out;

    static void pn(Object o){ out.println(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        PrintWriter out;

        public FastReader(String in_file, String out_file)throws FileNotFoundException
        {
            br=new BufferedReader(new FileReader(in_file));
            out=new PrintWriter(out_file);
        }

        PrintWriter op()
        {
            return out;
        }

        String next()
        {
            while(st==null || !st.hasMoreElements())
            {
                try
                {st=new StringTokenizer(br.readLine());}
                catch(IOException e) {e.printStackTrace();}
            }
            return st.nextToken();
        }

    }
}


import java.io.*;
import java.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        File f=new File("input.txt");
        File f2=new File("output.txt");
        BufferedReader bu=new BufferedReader(new FileReader(f));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        String s[]=bu.readLine().split(" ");
        int i,c[]=new int[5001],k;
        for(i=0;i<n;i++)
        {
            k=Integer.parseInt(s[i]);
            c[k]++;
        }
        int ans=Integer.MAX_VALUE;
        for(i=1;i<=5000;i++)
        c[i]+=c[i-1];
        for(i=1;i<=2500;i++)
        ans=Math.min(ans,n-(c[2*i]-c[i-1]));
        PrintStream p=new PrintStream(f2);
        System.out.println(ans);
    }
}