/*

Level element       Character	ASCII Code
Wall	                #	   0x23
Player	                @	   0x40
Player on goal square	+	   0x2b
Box	                $	   0x24
Box on goal square	*	   0x2a
Goal square	        .	   0x2e
Floor	              (Space)	   0x20
 */

#include <stdio.h>
#include <stdlib.h>

char map[64][64];

int main(int argc, char **argv)
{
  int width, height;
  int c;
  int x, y;
  int icons;

  c = fgetc(stdin);
  if (c == EOF) exit(1);
  for (;;) { // all problems
    // fprintf(stderr, "next problem......................................\n");
    icons = 0;
    width = 0; height = 0;
    for (y = 0; y < 64; y++) {
      for (x = 0; x < 64; x++) {
	map[x][y] = ' ';
      }
    }
    x = 0; y = 0;
    if (c == ';') {
      // fprintf(stderr, "Drain title...\n");
      do { c = fgetc(stdin); /*fputc(c, stderr);*/ } while (c != '\n');
    }
    for (;;) { // all lines in one problem
      // fprintf(stderr, "next line...\n");
      x = 0;
      for (;;) { // one line
        if (c == '\r') { x = 0; c = fgetc(stdin); /*fputc(c, stderr);*/ continue; }
        if ((c == '\n') && (x == 0)) { x = 0; c = fgetc(stdin); /*fputc(c, stderr); */continue; }
        if (c == '\n') break;
        if (c == ';') break;
	// fprintf(stderr, "map[%d][%d] = %d\n", x, y, c);
        map[x++][y] = c; if (x >= 64) exit(1);
        if ((c != '+') && (c != '|') && (c != '-') && (c != ' ')) icons += 1;
        if ((c == '?') || (c == '*')) icons += 1; // X on Y  Oops - reused '+' by accident
	c = fgetc(stdin);
	// fputc(c, stderr);
      }
      if (x > width) width = x;
      y++;
      if (y > height) height = y;
      if ((c == EOF) || (c == ';')) {
	if ((height-2 <= 16) && (width-2 <= 16) && (icons <= 38)) {
          fprintf(stdout, "; Problem is %d by %d and needs %d icons\n\n", height-2, width-2, icons);
          for (y = 0; y < height; y++) {
	    for (x = 0; x < width; x++) {
	      fputc(map[x][y], stdout);
	    }
	    fputc('\n', stdout);
          }
          fputc('\n', stdout);
	}
        x = y = width = height = icons = 0;
        if (c == EOF) exit(0);
	fflush(stdout);
	break; // go on to next block
      }
    }
  }
}
