/// source code (in typescript) // // @kariay1975/atcoder-tslib is a private package: // import { // Input, // InputStdin, // sortAsNumber, // sumNumber, // } from '@kariya1975/atcoder-tslib'; // // use babel-plugin-macros for speed. // import { // range, // arrayWith, // } from '@kariya1975/atcoder-tslib/macro'; // // // type int = number; // // const nextPerm = (xs: int[]): boolean => { // const swap = (i: int, j: int): void => { // const t = xs[i]; // xs[i] = xs[j]; // xs[j] = t; // }; // for (const i of range(xs.length - 2, -1, -1)) { // if (xs[i] >= xs[i + 1]) continue; // for (const j of range(xs.length -1, -1, -1)) { // if (xs[j] <= xs[i]) continue; // swap(i, j); // for (const k of range(xs.length - i - 1)) { // const l = i + 1 + k; // const m = xs.length - 1 - k; // if (l > m) break; // swap(l, m); // } // break; // } // return true; // } // return false; // }; // // const gcd = (n: int, m: int): int => { // if (m === 0) return n; // return gcd(m, n % m); // }; // // const gcds = (xs: int[]): int => { // const [x, ...rest] = xs; // if (rest.length === 0) return x; // return gcd(x, gcds(rest)); // }; // // const main = (input: Input, output: any[]): void => { // let [N, M] = input.getInts(2); // let g = M; // const A: int[][] = []; // for (const _ of range(N)) { // const a = input.getInts(N); // if (sumNumber(a) !== M) { // output.push(-1); // return; // } // A.push(a); // g = gcd(g, gcds(a)); // } // // M /= g; // for (const a of A) { // for (let i of range(N)) { // a[i] /= g; // } // } // // const dfs = (i: int, perms: int[][]): int[][] | false => { // // console.error(i, perms) // if (i === N) return perms; // const cs: int[] = []; // for (const j of range(N)) { // for (const _ of range(A[i][j])) cs.push(j); // } // let ps: int[][] = []; // for (const p of perms) { // ps.push([...p]); // } // const sets = arrayWith(M, (i) => new Set(perms[i])); // do { // // console.error(cs.join(' ')) // let ok = true; // for (const j of range(M)) { // if (sets[j].has(cs[j])) { // ok = false; // break; // } // ps[j][i] = cs[j]; // } // if (!ok) continue; // const result = dfs(i + 1, ps); // if (result !== false) return result; // } while (nextPerm(cs)); // return false; // }; // // const result = dfs(0, arrayWith(M, () => [])); // if (result === false) { // output.push(-1); // } else { // for (const p of result) { // const t = p.map(x => x + 1).join(' '); // for (const _ of range(g)) { // output.push(t); // } // } // } // }; // // const input = new InputStdin(); // input.setup().then(_ => { // const output = []; // main(input, output); // console.log(output.join('n')); // }); // /// The code above transpiles as follows: var C=Object.create;var b=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var P=t=>b(t,"__esModule",{value:!0});var M=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var G=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!Q.call(t,i)&&i!=="default"&&b(t,i,{get:()=>e[i],enumerable:!(r=R(e,i))||r.enumerable});return t},x=t=>G(P(b(t!=null?C(L(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var N=M((ut,E)=>{"use strict";var U=function(t,e){return t0&&(r=e-1>>1,i=this.array[r],!!this.compare(t,i));)this.array[e]=i,e=r;this.array[e]=t};h.prototype.heapify=function(t){this.array=t,this.size=t.length;var e;for(e=this.size>>1;e>=0;e--)this._percolateDown(e)};h.prototype._percolateUp=function(t,e){for(var r=this.array[t],i,s;t>0&&(i=t-1>>1,s=this.array[i],!(!e&&!this.compare(r,s)));)this.array[t]=s,t=i;this.array[t]=r};h.prototype._percolateDown=function(t){for(var e=this.size,r=this.size>>>1,i=this.array[t],s,n,o;tthis.size-1||t<0))return this._percolateUp(t,!0),this.poll()};h.prototype.remove=function(t){for(var e=0;e1?(this.array[0]=this.array[--this.size],this._percolateDown(0)):this.size-=1,t}};h.prototype.replaceTop=function(t){if(this.size!=0){var e=this.array[0];return this.array[0]=t,this._percolateDown(0),e}};h.prototype.trim=function(){this.array=this.array.slice(0,this.size)};h.prototype.isEmpty=function(){return this.size===0};h.prototype.forEach=function(t){if(!(this.isEmpty()||typeof t!="function"))for(var e=0,r=this.clone();!r.isEmpty();)t(r.poll(),e++)};h.prototype.kSmallest=function(t){if(this.size==0)return[];t=Math.min(this.size,t);var e=new h(this.compare);let r=Math.min((t>0?Math.pow(2,t-1):0)+1,this.size);e.size=r,e.array=this.array.slice(0,r);for(var i=new Array(t),s=0;s{"use strict";function a(t){if(this._capacity=B(t),this._length=0,this._front=0,A(t)){for(var e=t.length,r=0;r1){var s=this._capacity;if(i+r>s){for(var o=0;o1){var o=this._capacity;if(r+i>o){for(var u=i-1;u>=0;u--){this._checkCapacity(r+1);var o=this._capacity,s=(this._front-1&o-1^o)-o;this[s]=arguments[u],r++,this._length=r,this._front=s}return r}else{for(var n=this._front,u=i-1;u>=0;u--){var s=(n-1&o-1^o)-o;this[s]=arguments[u],n=s}return this._front=n,this._length=r+i,r+i}}if(i===0)return r;this._checkCapacity(r+1);var o=this._capacity,u=(this._front-1&o-1^o)-o;return this[u]=e,this._length=r+1,this._front=u,r+1};a.prototype.peekBack=function(){var e=this._length;if(e!==0){var r=this._front+e-1&this._capacity-1;return this[r]}};a.prototype.peekFront=function(){if(this._length!==0)return this[this._front]};a.prototype.get=function(e){var r=e;if(r===(r|0)){var i=this._length;if(r<0&&(r=r+i),!(r<0||r>=i))return this[this._front+r&this._capacity-1]}};a.prototype.isEmpty=function(){return this._length===0};a.prototype.clear=function(){for(var e=this._length,r=this._front,i=this._capacity,s=0;sr){var n=i+s&r-1;Y(this,0,this,r,n)}};var A=Array.isArray;function Y(t,e,r,i,s){for(var n=0;n>>0,t=t-1,t=t|t>>1,t=t|t>>2,t=t|t>>4,t=t|t>>8,t=t|t>>16,t+1}function B(t){if(typeof t!="number")if(A(t))t=t.length;else return 16;return Z(Math.min(Math.max(16,t),1073741824))}D.exports=a});var y=x(require("fs"));var q=class{constructor(e){this.data=e!=null?e:"",this.index=0}isSpace(e){return e===" "||e===` `}getString(){for(;this.index{let r=new Array(t);for(let i=0;i0)for(let i=t;ie;i+=r)yield i}var _=(t,e=null,r=null)=>e===null?it(t):r===null?F(t,e):F(t,e,r);var I=t=>{let e=0;for(let r of t)e+=r;return e};var st=t=>{let e=(r,i)=>{let s=t[r];t[r]=t[i],t[i]=s};for(let r=t.length-2,i=-1,s=-1;r>i;r+=s)if(!(t[r]>=t[r+1])){for(let n=t.length-1,o=-1,u=-1;n>o;n+=u)if(!(t[n]<=t[r])){e(r,n);for(let p=0,c=t.length-r-1;pg)break;e(f,g)}break}return!0}return!1},S=(t,e)=>e===0?t:S(e,t%e),k=t=>{let[e,...r]=t;return r.length===0?e:S(e,k(r))},nt=(t,e)=>{let[r,i]=t.getInts(2),s=i,n=[];for(let p=0,c=r;p{if(p===r)return c;let f=[];for(let l=0,v=r;lnew Set(c[l]));do{let l=!0;for(let d=0,w=i;d[]));if(u===!1)e.push(-1);else for(let p of u){let c=p.map(f=>f+1).join(" ");for(let f=0,g=s;f{let e=[];nt(O,e),console.log(e.join(` `))});