#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};   const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},                   Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   long long in() {     long long x;     cin >> x;     return x;   }   void print() { cout <<   n ; }   template <class Head, class... Tail>   void print(Head &&head, Tail &&...tail) {     cout << head;     if (sizeof...(tail) != 0) cout <<    ;     print(forward<Tail>(tail)...);   }   template <class T>   void print(vector<T> &vec) {     for (auto &a : vec) {       cout << a;       if (&a != &vec.back()) cout <<    ;     }     cout <<   n ;   }   template <class T>   void print(set<T> &set) {     for (auto &a : set) {       cout << a <<    ;     }     cout <<   n ;   }   template <class T>   void print(vector<vector<T>> &df) {     for (auto &vec : df) {       print(vec);     }   }   long long power(long long x, long long n) {     long long ret = 1;     while (n > 0) {       if (n & 1) ret *= x;       x *= x;       n >>= 1;     }     return ret;   }   long long comb(long long n, long long k) {     vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));     for (long long i = 0; i < (long long)((v).size()); i++) {       v[i][0] = 1;       v[i][i] = 1;     }     for (long long k = 1; k < (long long)((v).size()); k++) {       for (long long j = 1; j < k; j++) {         v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);       }     }     return v[n][k];   }   void add(long long &a, long long b) {     a += b;     if (a >= MOD) a -= MOD;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   long long ceildiv(long long a, long long b) {     if (b < 0) a = -a, b = -b;     if (a >= 0)       return (a + b - 1) / b;     else       return a / b;   }   long long floordiv(long long a, long long b) {     if (b < 0) a = -a, b = -b;     if (a >= 0)       return a / b;     else       return (a - b + 1) / b;   }   long long floorsqrt(long long x) {     assert(x >= 0);     long long ok = 0;     long long ng = 1;     while (ng * ng <= x) ng <<= 1;     while (ng - ok > 1) {       long long mid = (ng + ok) >> 1;       if (mid * mid <= x)         ok = mid;       else         ng = mid;     }     return ok;   }   template <class T>   bool contain(const std::string &s, const T &v) {     return s.find(v) != std::string::npos;   }   __attribute__((constructor)) void faster_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   long long n, m, p;   vector<string> fld;   vector<long long> s;   vector<vector<long long>> vis;   vector<queue<pair<pair<long long, long long>, long long>>> q(9);   void bfs() {     bool changed = true;     while (changed) {       changed = false;       for (long long ni = 0; ni < (long long)(9); ni++) {         while ((!q[ni].empty()) and (q[ni].front().second < s[ni])) {           auto current_pos = q[ni].front();           long long x = current_pos.first.first;           long long y = current_pos.first.second;           long long step = current_pos.second;           q[ni].pop();           for (long long dir = 0; dir < 4; ++dir) {             long long nx = x + dx[dir];             long long ny = y + dy[dir];             if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;             if (fld[nx][ny] ==  # ) continue;             if (vis[nx][ny] == -1) {               q[ni].push(make_pair(make_pair(nx, ny), step + 1));               vis[nx][ny] = ni;               changed = true;             }           }         }         long long sz = (long long)((q[ni]).size());         vector<pair<long long, long long>> tmp;         for (long long si = 0; si < (long long)(sz); si++) {           auto current_pos = q[ni].front();           long long x = current_pos.first.first;           long long y = current_pos.first.second;           long long step = current_pos.second;           q[ni].pop();           tmp.push_back(make_pair(x, y));         }         for (auto i : tmp) {           q[ni].push(make_pair(i, 0LL));         }       }     }   }   signed main() {     cin >> n >> m >> p;     s.assign(p, 0);     vis.assign(n, vector<long long>(m, -1));     for (long long pi = 0; pi < (long long)(p); pi++) {       cin >> s[pi];     }     for (long long ni = 0; ni < (long long)(n); ni++) {       string ss;       cin >> ss;       fld.push_back(ss);     }     for (long long ni = 0; ni < (long long)(n); ni++) {       for (long long mi = 0; mi < (long long)(m); mi++) {         if (fld[ni][mi] !=  .  and fld[ni][mi] !=  # ) {           q[fld[ni][mi] -  1 ].push(make_pair(make_pair(ni, mi), 0LL));           vis[ni][mi] = fld[ni][mi] -  1 ;         }       }     }     bfs();     vector<long long> ans(p);     for (long long ni = 0; ni < (long long)(n); ni++) {       for (long long mi = 0; mi < (long long)(m); mi++) {         if (vis[ni][mi] != -1) ans[vis[ni][mi]]++;       }     }     print(ans);     return 0;   }