#include #if __has_include() #endif using namespace std; #define done(...) return pp(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);i{}) #define defpp templatevoid pp(const auto&...a){[[maybe_unused]]const char*c="";((o<(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ namespace my{ void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} templateconstexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} const string newline{char(10)}; const string space{char(32)}; void lin(auto&...a){(cin>>...>>a);} templatestruct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} auto operator<=>(const pair&)const=default; }; templateusing pack_back_t=tuple_element_t>; } namespace my{ templateconcept vectorial=is_base_of_v::value_type>,remove_cvref_t>; templateostream&operator<<(ostream&o,const vector&v){ll n=v.size();fo(i,n)o<ostream&operator<<(ostream&o,const vector&v){ll n=v.size();fo(i,n)o<constexpr int depth=0; templateconstexpr int depth =depth+1; templatestruct core_t_helper{using type=T;}; templatestruct core_t_helper{using type=typename core_t_helper::type;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);} void resizes(const auto&...a){if constexpr(sizeof...(a)==D){ }else*this=make(a...);} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else return vec(n,make(a...)); } ll size()const{return vector::size();} templateauto fold(auto&&f)const{ pairres{}; fe(*this,e){ if constexpr(!vectorial){ if(res.b)f(res.a,e); else res={e,1}; }else if(auto t=e.fold(f);t.b){ if(res.b)f(res.a,t.a); else res=t; } } return res; } templateauto sum()const{return fold([](auto&a,const auto&b){a+=b;}).a;} inline ll row()const{return size();} inline ll col()const{return (*this)[0].size();} auto transpose()const{ assert(col()); vec r(col()); fe(r,e)e.resize(row()); fo(i,row())fo(j,col())r[j][i]=(*this)[i][j]; return r; } }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; } namespace my{entry void main(){ LL(H,W); if(H==1||W==1){ pp(0); done(vec(H,W,0)); } vec a(H,W,1); if(H%2==0){ if(W%2==0); else fo(i,H)a[i][W-1]=0; } else{ if(W%2==0)fo(j,W)a[H-1][j]=0; else{ bool sw=0; if(H>W)sw=1,swap(H,W),a=a.transpose(); fo(i,H)a[i][i]=0; fo(j,H,W)a[H-1][j]=0; if(sw)a=a.transpose(); } } pp(a.sum()); pp(a); }}