#line 1 "/opt/library/template.hpp" #include <bits/stdc++.h> using namespace std; using ll = long long; using i64 = long long; using u32 = unsigned int; using u64 = unsigned long long; using i128 = __int128; using u128 = unsigned __int128; using f128 = __float128; template <class T> constexpr T infty = 0; template <> constexpr int infty<int> = 1'000'001'000; template <> constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2; template <> constexpr u32 infty<u32> = infty<int>; template <> constexpr u64 infty<u64> = infty<ll>; template <> constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>; template <> constexpr double infty<double> = infty<ll>; template <> constexpr long double infty<long double> = infty<ll>; #define inf infty<ll> using pi = pair<ll, ll>; using vi = vector<ll>; using vvi = vector<vector<ll>>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vc<T>>; template <class T> using vvvc = vector<vvc<T>>; template <class T> using vvvvc = vector<vvvc<T>>; template <class T> using vvvvvc = vector<vvvvc<T>>; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; #define vv(type, name, h, ...) \ vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) \ vector<vector<vector<type>>> name( \ h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) #define vvvv(type, name, a, b, c, ...) \ vector<vector<vector<vector<type>>>> name( \ a, vector<vector<vector<type>>>( \ b, vector<vector<type>>(c, vector<type>(__VA_ARGS__)))) #define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_) #define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i) #define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i) #define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c)) #define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i) #define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i) #define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i) #define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define len(x) (ll)(x.size()) #define elif else if #define bit(x, i) (((x)>>(i))&1) #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define stoi stoll #define abs llabs #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define UNIQUE(x) \ sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit() ll popcnt(ll x) { return __builtin_popcountll(x); } ll popcnt(u64 x) { return __builtin_popcountll(x); } ll popcnt_mod_2(ll x) { return __builtin_parityll(x); } ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); } ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } template <typename T> T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); } template <typename T> T ceil(T x, T y) { return floor(x + y - 1, y); } template <typename T> T bmod(T x, T y) { return x - y * floor(x, y); } template <typename T> pair<T, T> divmod(T x, T y) { T q = floor(x, y); return {q, x - q * y}; } template<typename T> T SUM(const vector<T> &A) { T s = 0; for (auto &&a: A) s += a; return s; } template <typename T> T POP(queue<T> &que) { T a = que.front(); que.pop(); return a; } template <typename T> T POP(deque<T> &que) { T a = que.front(); que.pop_front(); return a; } template <typename T> T POP(pq<T> &que) { T a = que.top(); que.pop(); return a; } template <typename T> T POP(pqg<T> &que) { T a = que.top(); que.pop(); return a; } template <typename T> T POP(vc<T> &que) { T a = que.back(); que.pop_back(); return a; } template <typename F> ll binary_search(F check, ll ok, ll ng, bool check_ok = true) { if (check_ok) assert(check(ok)); while (abs(ok - ng) > 1) { auto x = (ng + ok) / 2; (check(x) ? ok : ng) = x; } return ok; } template <typename F> f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) { rep(iter) { f128 x = (ok + ng) / 2; (check(x) ? ok : ng) = x; } return (ok + ng) / 2; } // ? は -1 vc<int> s_to_vi(const string &S, char first_char) { vc<int> A(S.size()); rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); } return A; } template <typename T, typename U> vc<T> cumsum(vc<U> &A, ll off = 1) { ll N = A.size(); vc<T> B(N + 1); rep(i, N) { B[i + 1] = B[i] + A[i]; } if (off == 0) B.erase(B.begin()); return B; } // stable sort template <typename T> vi argsort(const vector<T> &A) { vi ids(len(A)); iota(all(ids), 0); sort(all(ids), [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); }); return ids; } // A[I[0]], A[I[1]], ... template <typename T> vc<T> rearrange(const vc<T> &A, const vi &I) { vc<T> B(len(I)); rep(i, len(I)) B[i] = A[I[i]]; return B; } template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));} template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));} inline void wt(const char c) { cout << c; } inline void wt(const string s) { cout << s; } inline void wt(const char *s) { cout << s; } template <typename T> void wt_integer(T x) { cout << (x); } template <typename T> void wt_real(T x) { cout << fixed << setprecision(15) << (long double)(x); } template <typename T> void wt_integer128(T x) { char buf[64]; char *d = end(buf); d--; *d = '\0'; __uint128_t tmp = ((x < 0)? -x : x); do { d--; *d = char(tmp%10 + '0'); tmp /= 10; } while (tmp); if (x < 0) { d--; *d = '-'; } cout << d; } inline void wt(int x) { wt_integer(x); } inline void wt(ll x) { wt_integer(x); } inline void wt(i128 x) { wt_integer128(x); } inline void wt(u32 x) { wt_integer(x); } inline void wt(u64 x) { wt_integer(x); } inline void wt(u128 x) { wt_integer128(x); } inline void wt(double x) { wt_real(x); } inline void wt(long double x) { wt_real(x); } inline void wt(f128 x) { wt_real(x); } template <class T, class U> void wt(const pair<T, U> val) { wt(val.first); wt(' '); wt(val.second); } template <size_t N = 0, typename T> void wt_tuple(const T t) { if constexpr (N < std::tuple_size<T>::value) { if constexpr (N > 0) { wt(' '); } const auto x = std::get<N>(t); wt(x); wt_tuple<N + 1>(t); } } template <class... T> void wt(tuple<T...> tpl) { wt_tuple(tpl); } template <class T, size_t S> void wt(const array<T, S> val) { auto n = val.size(); for (size_t i = 0; i < n; i++) { if (i) wt(' '); wt(val[i]); } } template <class T> void wt(const vector<T> val) { auto n = val.size(); for (size_t i = 0; i < n; i++) { if (i) wt(' '); wt(val[i]); } } void print() { wt('\n'); } template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) { wt(head); if (sizeof...(Tail)) wt(' '); print(forward<Tail>(tail)...); } void YES(bool t = 1) { print(t ? "YES" : "NO"); } void NO(bool t = 1) { YES(!t); } void Yes(bool t = 1) { print(t ? "Yes" : "No"); } void No(bool t = 1) { Yes(!t); } void yes(bool t = 1) { print(t ? "yes" : "no"); } void no(bool t = 1) { yes(!t); } void onez(bool t = 1) { print(t ? 1 : 0); } #define endl '\n' #define dump(x) {cerr << #x " = " << x << '\n';} #line 2 "/opt/library/graph/base.hpp" template <typename T> struct Edge { ll frm, to; T cost; ll id; }; template <typename T = ll, bool directed = false> struct Graph { static constexpr bool is_directed = directed; ll N, M; using cost_type = T; using edge_type = Edge<T>; vector<edge_type> edges; vi indptr; vc<edge_type> csr_edges; vc<ll> vc_deg, vc_indeg, vc_outdeg; bool prepared; class OutgoingEdges { public: OutgoingEdges(const Graph* G, ll l, ll r) : G(G), l(l), r(r) {} const edge_type* begin() const { if (l == r) { return 0; } return &G->csr_edges[l]; } const edge_type* end() const { if (l == r) { return 0; } return &G->csr_edges[r]; } private: const Graph* G; ll l, r; }; bool is_prepared() { return prepared; } Graph() : N(0), M(0), prepared(0) {} Graph(ll N) : N(N), M(0), prepared(0) {} void build(ll n) { N = n, M = 0; prepared = 0; edges.clear(); indptr.clear(); csr_edges.clear(); vc_deg.clear(); vc_indeg.clear(); vc_outdeg.clear(); } void add(ll frm, ll to, T cost = 1, ll i = -1) { assert(!prepared); assert(0 <= frm && 0 <= to && to < N); if (i == -1) i = M; auto e = edge_type({frm, to, cost, i}); edges.eb(e); ++M; } #ifdef FASTIO // wt, off void read_tree(bool wt = false, ll off = 1) { read_graph(N - 1, wt, off); } void read_graph(ll M, bool wt = false, ll off = 1) { for (ll m = 0; m < M; ++m) { LL(a, b); a -= off, b -= off; if (!wt) { add(a, b); } else { T c; read(c); add(a, b, c); } } build(); } #endif void build() { assert(!prepared); prepared = true; indptr.assign(N + 1, 0); for (auto&& e: edges) { indptr[e.frm + 1]++; if (!directed) indptr[e.to + 1]++; } for (ll v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; } auto counter = indptr; csr_edges.resize(indptr.back() + 1); for (auto&& e: edges) { csr_edges[counter[e.frm]++] = e; if (!directed) csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id}); } } OutgoingEdges operator[](ll v) const { assert(prepared); return {this, indptr[v], indptr[v + 1]}; } vi deg_array() { if (vc_deg.empty()) calc_deg(); return vc_deg; } pair<vi, vi> deg_array_inout() { if (vc_indeg.empty()) calc_deg_inout(); return {vc_indeg, vc_outdeg}; } ll deg(ll v) { if (vc_deg.empty()) calc_deg(); return vc_deg[v]; } ll in_deg(ll v) { if (vc_indeg.empty()) calc_deg_inout(); return vc_indeg[v]; } ll out_deg(ll v) { if (vc_outdeg.empty()) calc_deg_inout(); return vc_outdeg[v]; } #ifdef FASTIO void debug() { print("Graph"); if (!prepared) { print("frm to cost id"); for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id); } else { print("indptr", indptr); print("frm to cost id"); rep(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id); } } #endif vi new_idx; vc<bool> used_e; // G における頂点 V[i] が、新しいグラフで i になるようにする // {G, es} Graph<T, directed> rearrange(vi V, bool keep_eid = 0) { if (len(new_idx) != N) new_idx.assign(N, -1); if (len(used_e) != M) used_e.assign(M, 0); ll n = len(V); rep(i, n) new_idx[V[i]] = i; Graph<T, directed> G(n); vi history; rep(i, n) { for (auto&& e: (*this)[V[i]]) { if (used_e[e.id]) continue; ll a = e.frm, b = e.to; if (new_idx[a] != -1 && new_idx[b] != -1) { history.eb(e.id); used_e[e.id] = 1; ll eid = (keep_eid ? e.id : -1); G.add(new_idx[a], new_idx[b], e.cost, eid); } } } rep(i, n) new_idx[V[i]] = -1; for (auto&& eid: history) used_e[eid] = 0; G.build(); return G; } private: void calc_deg() { assert(vc_deg.empty()); vc_deg.resize(N); for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++; } void calc_deg_inout() { assert(vc_indeg.empty()); vc_indeg.resize(N); vc_outdeg.resize(N); for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; } } }; #line 3 "main.cpp" int solve(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll T = 1; while (!solve()) if (--T == 0) break; return 0; } int solve() { ll X, Y; cin >> X >> Y; ll XY = X*Y; Graph<ll> G(XY); rep(i, X) G.add(i, (i+1)%X); rep(i, X) rep(j, Y-1) G.add(j*X+i, (j+1)*X+i); G.build(); print(XY, XY); rep(i, XY) { for (auto e : G[i]) { if (e.frm > e.to) continue; print(e.frm+1, e.to+1); } } return 0; }