#include #include #define rep(i,n) for(int i=0;i> n >> m; bool FLIP = false; if(n % 4 == 0 && m % 2 == 0){ swap(n, m); FLIP = true; } if(n % 2 == 0 && m % 4 == 0){ int k = n * m / 4; int n2 = n / 2; int m2 = m / 4; vector> a(n, vector(m)); int cnt = 0; rep(i, n2) rep(j, m2){ a[2 * i][4 * j] = cnt + 1; a[2 * i][4 * j + 1] = cnt + 1; a[2 * i][4 * j + 2] = cnt + 1; a[2 * i][4 * j + 3] = cnt + 2; a[2 * i + 1][4 * j] = cnt + 1; a[2 * i + 1][4 * j + 1] = cnt + 2; a[2 * i + 1][4 * j + 2] = cnt + 2; a[2 * i + 1][4 * j + 3] = cnt + 2; cnt += 2; } cout << k << "\n"; if(FLIP){ vector> a_old(m, vector(n)); swap(a, a_old); rep(i, n) rep(j, m) a[j][i] = a_old[i][j]; swap(n, m); } rep(i, n){ rep(j, m) cout << a[i][j] << (j == m - 1 ? "\n" : " "); } }else cout << "-1\n"; return 0; }