/// 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 main = (input: Input, output: any[]): void => { // const [N, M] = input.getInts(2); // const A: int[][] = []; // for (const _ of range(N)) { // const a = input.getInts(N); // if (sumNumber(a) !== M) { // output.push(-1); // return; // } // A.push(a); // } // // 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); // } // do { // let ps: int[][] = []; // for (const p of perms) ps.push([...p]); // let ok = true; // for (const i of range(M)) { // if (ps[i].includes(cs[i])) { // ok = false; // break; // } // ps[i].push(cs[i]); // } // 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) { // output.push(p.map(x => x + 1).join(' ')); // } // } // }; // // const input = new InputStdin(); // input.setup().then(_ => { // const output = []; // main(input, output); // console.log(output.join('n')); // }); // /// The code above transpiles as follows: var F=Object.create;var z=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var R=t=>z(t,"__esModule",{value:!0});var q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var L=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O(e))!C.call(t,i)&&i!=="default"&&z(t,i,{get:()=>e[i],enumerable:!(r=k(e,i))||r.enumerable});return t},w=t=>L(R(z(t!=null?F(W(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var S=q((nt,I)=>{"use strict";var Q=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};u.prototype.heapify=function(t){this.array=t,this.size=t.length;var e;for(e=this.size>>1;e>=0;e--)this._percolateDown(e)};u.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};u.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()};u.prototype.remove=function(t){for(var e=0;e1?(this.array[0]=this.array[--this.size],this._percolateDown(0)):this.size-=1,t}};u.prototype.replaceTop=function(t){if(this.size!=0){var e=this.array[0];return this.array[0]=t,this._percolateDown(0),e}};u.prototype.trim=function(){this.array=this.array.slice(0,this.size)};u.prototype.isEmpty=function(){return this.size===0};u.prototype.forEach=function(t){if(!(this.isEmpty()||typeof t!="function"))for(var e=0,r=this.clone();!r.isEmpty();)t(r.poll(),e++)};u.prototype.kSmallest=function(t){if(this.size==0)return[];t=Math.min(this.size,t);var e=new u(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=N(t),this._length=0,this._front=0,E(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 h=i-1;h>=0;h--){this._checkCapacity(r+1);var o=this._capacity,s=(this._front-1&o-1^o)-o;this[s]=arguments[h],r++,this._length=r,this._front=s}return r}else{for(var n=this._front,h=i-1;h>=0;h--){var s=(n-1&o-1^o)-o;this[s]=arguments[h],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,h=(this._front-1&o-1^o)-o;return this[h]=e,this._length=r+1,this._front=h,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;H(this,0,this,r,n)}};var E=Array.isArray;function H(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 N(t){if(typeof t!="number")if(E(t))t=t.length;else return 16;return J(Math.min(Math.max(16,t),1073741824))}T.exports=a});var _=w(require("fs"));var b=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 d=(t,e=null,r=null)=>e===null?Z(t):r===null?B(t,e):B(t,e,r);var x=t=>{let e=0;for(let r of t)e+=r;return e};var tt=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,h=-1;n>o;n+=h)if(!(t[n]<=t[r])){e(r,n);for(let p=0,l=t.length-r-1;pg)break;e(f,g)}break}return!0}return!1},et=(t,e)=>{let[r,i]=t.getInts(2),s=[];for(let h=0,p=r;h{if(h===r)return p;let l=[];for(let f=0,g=r;f[]));if(o===!1)e.push(-1);else for(let h of o)e.push(h.map(p=>p+1).join(" "))},D=new v;D.setup().then(t=>{let e=[];et(D,e),console.log(e.join(` `))});