#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T &x, const T &y) {return (x bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=1000000007; constexpr ll INF=2e18; int main(){ int h, w; cin >> h >> w; if(h%2==0&&w%2==0){ cout << h*w << endl; REP(i,h)REP(j,w) cout << 1 << " \n"[j==w-1]; } else if(h%2==1&&w%2==1){ cout << h*w-max(h,w) << endl; REP(i,h)REP(j,w){ int f=1; if(i==j) f=0; else if(i==h-1&&j>=h) f=0; else if(j==w-1&&i>=w) f=0; cout << f << " \n"[j==w-1]; } } else if(h%2==1){ cout << h*w-w << endl; REP(i,h-1)REP(j,w) cout << 1 << " \n"[j==w-1]; REP(j,w) cout << 0 << " \n"[j==w-1]; } else{ cout << h*w-h << endl; REP(i,h){ REP(j,w-1) cout << 1 << " "; cout << 0 << endl; } } return 0; }