// ---


function q(x) { return document.querySelector(x); }
function qa(x) { return [...document.querySelectorAll(x)]; }

function range(x) { return Array.from({length: x}, (v, i) => i); }

function rand(x) { return x[Math.floor(Math.random() * x.length)]; }
function randpop(x) { return x.splice(Math.floor(Math.random() * x.length), 1)[0]; }

function shuffle(x) { return x.map(i => [Math.random(), i]).sort().map(i => i[1]); }
function capitalize(x) { return x.charAt(0).toUpperCase() + x.slice(1); }


// ---


function html(x) {
	var h = document.createElement('div'); 
	h.innerHTML = x; 
	return h.children[0];
}

function onenter(ele, f) {
	ele.addEventListener('keydown', function (e) {
		if (e.keyCode === 13) { f(e); e.preventDefault(); }
	})
}


// ---


class Random {
	constructor(seed) { this.seed = BigInt(seed); this.next(); }
	next() {
		this.seed = (this.seed * 0x5DEECE66Dn + 0xBn) & 0xFFFFFFFFFFFFn;
		return Number((this.seed >> 10n) & 0xFFFFFFFFn) / 0x100000000;
	}
}


// ---


Array.prototype.rand = function() {
	return this[Math.floor(Math.random() * this.length)];
}
Array.prototype.randpop = function() {
	return this.splice(Math.floor(Math.random() * this.length), 1)[0];
}
Array.prototype.uniq = function() {
	return this.filter((i, index, array) => array.indexOf(i) == index);
}
Array.prototype.shuffle = function() {
	var n = this.length;
	while (n) {
		var i = Math.floor(Math.random() * n--);
		var t = this[n]; this[n] = this[i]; this[i] = t;
	}
	return this;
}

Object.prototype.values = function() {
	return Object.values(this);
}
Object.prototype.keys = function() {
	return Object.keys(this);
}


// ---
// new version


const q = (x) => document.querySelector(x);
const qa = (x) => [...document.querySelectorAll(x)];

const qs = (sub, x) => sub.querySelector(x);
const qsa = (sub, x) => [...sub.querySelectorAll(x)];


const range = (x) => Array.from({length: x}, (v, i) => i);
const shuffle = (x) => x.map(i => [Math.random(), i]).sort().map(i => i[1]);
const uniq = (x) => x.filter((i, index, array) => array.indexOf(i) == index);

const rand = (x) => x[Math.floor(Math.random() * x.length)];
const randpop = (x) => x.splice(Math.floor(Math.random() * x.length), 1)[0];

const capitalize = (x) => x.charAt(0).toUpperCase() + x.slice(1);


const isArray = (x) => Array.isArray(x);
const isFunc = (x) => typeof (x) === "function";
const isObject = (x) => x && typeof (x) === "object";


const objectGet = (o, [head, ...tail]) => tail.length == 0 ? o[head] : objectGet(o[head], tail, value)
const objectSet = (o, [head, ...tail], value) => tail.length == 0 ? o[head] = value : objectSet(o[head], tail, value)


const now = () => (performance.timeOrigin + performance.now());
const nows = () => (performance.timeOrigin + performance.now()) / 1000;



function html(x) {
	var h = document.createElement('div'); 
	h.innerHTML = x; 
	return h.children[0];
}

function onenter(ele, f) {
	ele.addEventListener('keydown', function (e) {
		if (e.keyCode === 13) { f(e); e.preventDefault(); }
	})
}



class Random {
	constructor(seed) { this.seed = BigInt(seed); this.next(); }
	next() {
		this.seed = (this.seed * 0x5DEECE66Dn + 0xBn) & 0xFFFFFFFFFFFFn;
		return Number((this.seed >> 10n) & 0xFFFFFFFFn) / 0x100000000;
	}
}