#include <iostream> using namespace std; int main(){ int i,j,h,w; cin >> h >> w; if(h==1){ cout << 0 << endl; for(i=0;i<w;i++) cout << 0 << " "; cout << endl; return 0; } if(w==1){ cout << 0 << endl; for(i=0;i<h;i++) cout << 0 << "\n"; return 0; } if(h&1 && w&1){ int ans = 0; if(h>=w){ cout << h*(w - 1) << endl; for(i=0;i<w;i++){ for(j=0;j<w;j++){ if(i==j) cout << 0 << " "; else cout << 1 << " "; } cout << endl; } for(i=w;i<h;i++){ for(j=0;j<w - 1;j++){ cout << 1 << " "; } cout << 0 << " "; cout << endl; } }else{ cout << w*(h - 1) << endl; for(i=0;i<h;i++){ for(j=0;j<h;j++){ if(i==j) cout << 0 << " "; else cout << 1 << " "; } for(j=h;j<w;j++){ if(i<h - 1) cout << 1 << " "; else cout << 0 << " "; } cout << "\n"; } } }else if(h&1){ cout << (h - 1)*w << endl; for(i=0;i<h - 1;i++){ for(j=0;j<w;j++) cout << 1 << " "; cout << endl; } for(i=0;i<w;i++) cout << 0 << " "; cout << endl; }else if(w&1){ cout << h*(w - 1) << endl; for(i=0;i<h;i++){ for(j=0;j<w - 1;j++) cout << 1 << " "; cout << 0 << "\n"; } }else{ cout << h*w << endl; for(i=0;i<h;i++){ for(j=0;j<w;j++) cout << 1 << " "; cout << endl; } } }