import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;

import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;

public class Visualizer {
	static class SegmentsTree {
		int[] a;
		int two;
		
		public SegmentsTree(int[] data) {
			for (two = 1; two < data.length; two *= 2);
			a = new int[2 * two];
			for (int i = 0; i < data.length; i++) {
				a[two + i] = data[i];
			}
			for (int i = two - 1; i > 0; i--) {
				a[i] = Math.max(a[2 * i], a[2 * i + 1]);
			}
		}
		
		public int leftmostAtLeast(int value) {
			if (a[1] < value)
				return -1;
			int cur = 1;
			while (cur < two) {
				cur *= 2;
				if (a[cur] < value)
					cur++;
			}
			return cur - two;
		}
		
		public int get(int index) {
			return a[two + index];
		}
		
		public void set(int index, int value) {
			int cur = two + index;
			a[cur] = value;
			while (cur > 1) {
				cur /= 2;
				a[cur] = Math.max(a[2 * cur], a[2 * cur + 1]);
			}
		}
	}
	
	static class Banner {
		int x, y, wid, id;

		public Banner(int x, int y, int wid, int id) {
			this.x = x;
			this.y = y;
			this.wid = wid;
			this.id = id;
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new FileReader(args[0]));
		int hei = in.nextInt();
		int wid = in.nextInt();
		int w = 800 / wid;
		int h = 600 / hei;
		if (w <= 0 || h <= 0)
			return;
		int n = in.nextInt();
		int[] free = new int[Math.min(hei, n)];
		int[] x = new int[hei];
		Arrays.fill(free, wid);
		SegmentsTree st = new SegmentsTree(free);
		ArrayList<Banner> banners = new ArrayList<Banner>();
		for (int i = 0; i < n; i++) {
			int banner = in.nextInt();
			int pos = st.leftmostAtLeast(banner);
			if (pos == -1) {
				continue;
			}
			banners.add(new Banner(x[pos], pos, banner, i));
			st.set(pos, st.get(pos) - banner);
			x[pos] += banner;
		}

		BufferedImage img = new BufferedImage(wid * w, hei * h, BufferedImage.TYPE_INT_RGB);
		Graphics g = img.getGraphics();
		int f = Math.min(w, h);
		if (f < 5)
			f = 0;
		g.setFont(new Font("", 0, f));
		g.setColor(Color.YELLOW);
		g.fillRect(0, 0, wid * w, hei * h);
		for (Banner b: banners) {
			int c = 255 * b.id / n;
			g.setColor(new Color(c, c, c));
			g.fillRect(b.x * w, b.y * h, b.wid * w, h);
			if (f == 0)
				continue;
			g.setColor(Color.RED);
			String s = "" + (b.id + 1);
			int ws = (int) g.getFontMetrics().getStringBounds(s, g).getWidth();
			int hs = (int) g.getFontMetrics().getStringBounds(s, g).getHeight() / 3;
			if (ws > b.wid * w || hs > h)
				continue;
			g.drawString(s, b.x * w + b.wid * w / 2 - ws / 2, b.y * h + h / 2 + hs * 3 / 4);
		}
		ImageWriter iw = ImageIO.getImageWritersByFormatName("bmp").next();
		iw.setOutput(ImageIO.createImageOutputStream(new File(args[0] + ".bmp")));
		iw.write(img);
//		iw.write(img.getSubimage(border, border, wid - 2 * border, hei - 2 * border));
	}
}
