#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

void paint_grids(vector<int> &a, vector<vector<int>> &g);

void set_next_direction(size_t &row, size_t &col, int &direction, vector<vector<int>> &g);

void set_next_position(size_t &row, size_t &col, int &direction);

bool cannot_step(size_t &row, size_t &col, int &direction, vector<vector<int>> &g);

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    vector<int> row_of_g(w, 0);
    vector<vector<int>> g(h, row_of_g);
    paint_grids(a, g);

    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            char c = (j == w - 1)? '\n' : ' ';
            cout << g[i][j] << c;
        }
    }
    return 0;
}

const int DOWN = 0;
const int RIGHT = 1;
const int UP = 2;
const int LEFT = 3;

void paint_grids(vector<int> &a, vector<vector<int>> &g){
    int direction = DOWN;
    size_t row = 0;
    size_t col = 0;
    for(size_t i = 1; i < a.size(); ++i){
        // cout << endl << "a[" << i << "] = " << a[i] << endl;
        /* 個数分塗る処理 */
        int cnt = 0;
        while (cnt < a[i]){
            /* 今いる位置のマスを塗る */
            g[row][col] = i;
            // cout << "g[" << row << "][" << col << "] = " << g[row][col] << endl;

            /* 塗った個数に1加算 */
            cnt++;
            // cout << "cnt = " << cnt << endl;

            /* 必要ならば方向を変える */
            set_next_direction(row, col, direction, g);
            // cout << "direction = " << direction << endl;

            /* 次のマスに変更 */
            set_next_position(row, col, direction);
            // cout << "row = " << row << ", col = " << col << endl;
        }       
    }
}

void set_next_direction(size_t &row, size_t &col, int &direction, vector<vector<int>> &g){
    if(cannot_step(row, col, direction, g)){
        direction = (direction == DOWN)? RIGHT :
                    (direction == RIGHT)? UP :
                    (direction == UP)? LEFT : DOWN;
    }
}

void set_next_position(size_t &row, size_t &col, int &direction){
    if(direction == DOWN){
        row++;
    }else if(direction == RIGHT){
        col++;
    }else if(direction == UP){
        row--;
    }else{
        col--;
    }
}

bool cannot_step(size_t &row, size_t &col, int &direction, vector<vector<int>> &g){
    switch (direction){
    case DOWN:
        if(row + 1 == g.size()){
            return true;
        }

        if(g[row + 1][col] > 0){
            return true;
        }
        return false;
    case RIGHT:
        if(col + 1 == g[0].size()){
            return true;
        }

        if(g[row][col + 1] > 0){
            return true;
        }
        return false;
    case UP:
        if(row == 0){
            return true;
        }

        if(g[row - 1][col] > 0){
            return true;
        }
        return false;
    default:
        if(col == 0){
            return true;
        }

        if(g[row][col - 1] > 0){
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 384