#include using namespace std; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main(){ int T,R; cin >> T >> R; int p=0; UnionFind uf(5555); vector S(5555); vector ma(5555),mi(5555); for(int i=0;i> n; vector> act; for(int j=0;j> S[p]; ma[p]=S[p]; mi[p]=S[p]; for(int k=p-1;k>=1;k--){ if(uf.size(p)==R){break;} if(uf.findSet(k,p)){continue;} if(uf.size(k)+uf.size(p)>R){continue;} int rk=uf.root(k); int rp=uf.root(p); if(max(ma[rk],ma[rp])-min(mi[rk],mi[rp])>6){continue;} uf.unionSet(rk,rp); act.push_back({rk,rp}); ma[uf.root(rk)]=max(ma[rk],ma[rp]); mi[uf.root(rk)]=min(mi[rk],mi[rp]); } } cout << act.size() << '\n'; for(auto &nx : act){cout << nx.first << ' ' << nx.second << '\n';} fflush(stdout); } return 0; }