3515 {
3516 int n;
3517 int m;
3518 int arr[100][100] = {};
3519 int x = 0;
3520 int y = 0;
3521 int v = 1;
3522 int dir = 1;
3523 cin >> n >> m;
3524 while(v <= n * m) {
3525 arr[x][y] = v++;
3526 move:;
3527 if(v > m * n) {
3528 break;
3529 }
3530 switch(dir) {
3531 case 3:
3532 {
3533 const int next_y = y - 1;
3534 if(arr[x][next_y] != 0 || next_y < 0) {
3535
3536 dir = (dir + 1) % 4;
3537 goto move;
3538 }
3539 y--;
3540 break;
3541 }
3542 case 2:
3543 {
3544 const int next_x = x + 1;
3545 if(arr[next_x][y] != 0 || next_x >= n) {
3546 dir = (dir + 1) % 4;
3547 goto move;
3548 }
3549 x++;
3550 break;
3551 }
3552 case 1:
3553 {
3554 const int next_y = y + 1;
3555 if(arr[x][next_y] != 0 || next_y >= m) {
3556 dir = (dir + 1) % 4;
3557 goto move;
3558 }
3559 y++;
3560 break;
3561 }
3562 case 0:
3563 {
3564 const int next_x = x - 1;
3565 if(arr[next_x][y] != 0 || next_x < 0) {
3566 dir = (dir + 1) % 4;
3567 goto move;
3568 }
3569 x--;
3570 break;
3571 }
3572 }
3573 }
3574 for(int i = 0; i < n; i++) {
3575 for(int j = 0; j < m; j++) {
3576 cout << arr[i][j] << " ";
3577 }
3578 cout << endl;
3579 }
3580 return 0;
3581 }