/* Array.js v0.0.3 | https://github.com/iwind/Array.js */
Array.$nil = {};
Array.prototype.$contains = function (a) {
	var c = this;
	if (c == null) {
		return false
	}
	for (var b = 0; b < c.length; b++) {
		if (c[b] == a) {
			return true
		}
	}
	return false
};
Array.prototype.$include = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	return b.$contains(a)
};
Array.prototype.$removeValue = function (b) {
	var d = this;
	if (d == null) {
		return true
	}
	var a = [];
	for (var c = 0; c < d.length; c++) {
		if (d[c] != b) {
			a.push(d[c])
		}
	}
	d.$clear();
	d.$pushAll(a);
	return true
};
Array.prototype.$remove = function (a) {
	var b = this;
	if (b == null) {
		return true
	}
	b.splice(a, 1);
	return true
};
Array.prototype.$removeIf = function (b) {
	var c = this;
	if (c == null) {
		return 0
	}
	var a = c.length;
	var d = c.$reject(b);
	c.$replace(d);
	return a - c.length
};
Array.prototype.$drop = function (a) {
	a = parseInt(a, 10);
	if (isNaN(a) || a <= 0) {
		return []
	}
	if (a > this.length) {
		a = this.length
	}
	return this.splice(this.length - a, a)
};
Array.prototype.$keepIf = function (b) {
	var c = this;
	if (c == null) {
		return 0
	}
	var a = c.length;
	var d = c.$findAll(b);
	c.$replace(d);
	return a - c.length
};
Array.prototype.$replace = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	if (!Array.isArray(a)) {
		return false
	}
	b.splice.apply(b, [0, b.length].concat(a));
	return true
};
Array.prototype.$clear = function () {
	var a = this;
	if (a == null) {
		return true
	}
	if (a.length == 0) {
		return true
	}
	a.splice(0, a.length);
	return true
};
Array.prototype.$each = function (b) {
	var d = this;
	if (d == null) {
		return true
	}
	if (typeof (b) != "function") {
		return true
	}
	var c = d.length;
	for (var a = 0; a < c; a++) {
		b.call(d, a, d[a])
	}
	return true
};
Array.prototype.$unique = function (d) {
	var e = this;
	if (e == null) {
		return true
	}
	var a = [];
	var b = [];
	e.$each(function (h, g) {
		if (typeof (d) == "function") {
			g = d.call(e, h, g)
		}
		if (!a.$contains(g)) {
			a.push(g);
			b.push(h)
		}
	});
	var f = e.$copy();
	e.$clear();
	for (var c = 0; c < b.length; c++) {
		e.push(f[b[c]])
	}
	return true
};
Array.prototype.$get = function (a) {
	var b = this;
	if (b == null) {
		return null
	}
	if (a > b.length - 1) {
		return null
	}
	return b[a]
};
Array.prototype.$getAll = function (e) {
	var d = this;
	if (d == null) {
		return []
	}
	var b = [];
	for (var c = 0; c < arguments.length; c++) {
		var a = arguments[c];
		if (Array.$isArray(a)) {
			b.$pushAll(d.$getAll.apply(d, a))
		} else {
			if (typeof (a) == "number" && a < d.length) {
				b.$push(d.$get(a))
			} else {
				if (typeof (a) == "string" && /^\\d+$/.test(a)) {
					a = parseInt(a);
					if (a < d.length) {
						b.$push(d.$get(a))
					}
				}
			}
		}
	}
	return b
};
Array.prototype.$set = function (a, c) {
	var b = this;
	if (b == null) {
		return false
	}
	if (a > b.length - 1) {
		return false
	}
	b[a] = c;
	return true
};
Array.prototype.$copy = function () {
	var c = this;
	if (c == null) {
		return c
	}
	var a = [];
	for (var b = 0; b < c.length; b++) {
		a.push(c[b])
	}
	return a
};
Array.prototype.$isEmpty = function () {
	var a = this;
	if (a == null) {
		return true
	}
	return (a.length == 0)
};
Array.prototype.$all = function (b) {
	var c = this;
	if (c == null) {
		return false
	}
	for (var a = 0; a < c.length; a++) {
		if (!b.call(c, a, c[a])) {
			return false
		}
	}
	return true
};
Array.prototype.$any = function (b) {
	var c = this;
	if (c == null) {
		return false
	}
	for (var a = 0; a < c.length; a++) {
		if (b.call(c, a, c[a])) {
			return true
		}
	}
	return false
};
Array.prototype.$map = function (d) {
	var e = this;
	if (e == null) {
		return []
	}
	var b = [];
	for (var c = 0; c < e.length; c++) {
		var a = d.call(e, c, e[c]);
		if (a === Array.$nil) {
			continue
		}
		b.push(a)
	}
	return b
};
Array.prototype.$reduce = function (a) {
	var b = this;
	if (b == null) {
		return null
	}
	var c = null;
	b.$each(function (e, d) {
		c = a.call(b, e, d, c)
	});
	return c
};
Array.prototype.$collect = function (a) {
	var b = this;
	if (b == null) {
		return []
	}
	return b.$map(a)
};
Array.prototype.$find = function (c) {
	var d = this;
	if (d == null) {
		return -1
	}
	if (typeof (c) == "undefined") {
		return d.$get(0)
	}
	var b = -1;
	var a = null;
	d.$each(function (f, e) {
		if (b > -1) {
			return
		}
		if (c.call(d, f, e)) {
			b = f;
			a = e
		}
	});
	return a
};
Array.prototype.$findAll = function (b) {
	var c = this;
	if (c == null) {
		return []
	}
	if (typeof (b) == "undefined") {
		return c.$copy()
	}
	var a = [];
	c.$each(function (e, d) {
		if (b.call(c, e, d)) {
			a.push(d)
		}
	});
	return a
};
Array.prototype.$filter = function (a) {
	var b = this;
	if (b == null) {
		return []
	}
	return b.$findAll(a)
};
Array.prototype.$exist = function (a) {
	return this.$findAll(a).length > 0
};
Array.prototype.$reject = function (b) {
	var c = this;
	if (c == null) {
		return []
	}
	if (typeof (b) == "undefined") {
		return []
	}
	var a = [];
	c.$each(function (e, d) {
		if (!b.call(c, e, d)) {
			a.push(d)
		}
	});
	return a
};
Array.prototype.$grep = function (b) {
	var a = this;
	if (a == null) {
		return []
	}
	return a.$findAll(function (d, c) {
		if (c == null) {
			return false
		}
		return b.test(c.toString())
	})
};
Array.prototype.$keys = function (e, a) {
	var d = this;
	if (d == null) {
		return []
	}
	if (arguments.length == 0) {
		return Array.$range(0, d.length - 1)
	}
	var c = [];
	if (typeof (a) == "undefined") {
		a = false
	}
	for (var b = 0; b < d.length; b++) {
		if ((a && e === d[b]) || (!a && e == d[b])) {
			c.push(b)
		}
	}
	return c
};
Array.prototype.$indexesOf = function (c, a) {
	var b = this;
	if (b == null) {
		return []
	}
	if (arguments.length == 0) {
		return Array.$range(0, b.length - 1)
	}
	return b.$keys(c, a)
};
Array.prototype.$indexOf = function (c, a) {
	var b = this;
	if (b == null) {
		return -1
	}
	if (arguments.length == 0) {
		return -1
	}
	const keys = b.$keys(c, a)
	return (keys.length > 0) ? keys[0] : -1
};
Array.prototype.$sort = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	if (typeof (a) == "undefined") {
		a = function (d, c) {
			if (d > c) {
				return 1
			} else {
				if (d == c) {
					return 0
				} else {
					return -1
				}
			}
		}
	}
	b.sort(a);
	return true
};
Array.prototype.$rsort = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	this.$sort(a);
	b.reverse();
	return true
};
Array.prototype.$asort = function (a) {
	var e = this;
	if (e == null) {
		return []
	}
	var c = [];
	for (var d = 0; d < e.length; d++) {
		c.push(d)
	}
	if (typeof (a) == "undefined") {
		a = function (g, f) {
			if (g < f) {
				return -1
			}
			if (g > f) {
				return 1
			}
			return 0
		}
	}
	for (d = 0; d < e.length; d++) {
		for (var b = 0; b < e.length; b++) {
			if (b > 0 && a(e[b - 1], e[b]) > 0) {
				e.$swap(b, b - 1);
				c.$swap(b, b - 1)
			}
		}
	}
	return c
};
Array.prototype.$arsort = function (a) {
	var c = this;
	if (c == null) {
		return []
	}
	var b = c.$asort(a);
	c.reverse();
	b.reverse();
	return b
};
Array.prototype.$diff = function (c) {
	var b = this;
	if (b == null) {
		return []
	}
	var a = [];
	b.$each(function (e, d) {
		if (!c.$contains(d)) {
			a.push(d)
		}
	});
	return a
};
Array.prototype.$intersect = function (c) {
	var b = this;
	if (b == null) {
		return []
	}
	var a = [];
	b.$each(function (e, d) {
		if (c.$contains(d)) {
			a.push(d)
		}
	});
	return a
};
Array.prototype.$max = function (a) {
	var c = this;
	if (c == null) {
		return null
	}
	if (c.length > 0) {
		var b = c.$copy();
		b.$rsort(a);
		return b.$get(0)
	}
	return null
};
Array.prototype.$min = function (a) {
	var c = this;
	if (c == null) {
		return null
	}
	if (c.length > 0) {
		var b = c.$copy();
		b.$sort(a);
		return b.$get(0)
	}
	return null
};
Array.prototype.$swap = function (e, d) {
	var c = this;
	if (c == null) {
		return false
	}
	var b = c.$get(e);
	var a = c.$get(d);
	c.$set(e, a);
	c.$set(d, b);
	return true
};
Array.prototype.$sum = function (b) {
	var c = this;
	if (c == null) {
		return 0
	}
	var a = 0;
	c.$each(function (e, d) {
		if (typeof (b) == "function") {
			d = b.call(c, e, d)
		}
		if (typeof (d) == "number") {
			a += d
		} else {
			if (typeof (d) == "string") {
				var f = parseFloat(d);
				if (!isNaN(f)) {
					a += f
				}
			}
		}
	});
	return a
};
Array.prototype.$product = function (b) {
	var c = this;
	if (c == null) {
		return 0
	}
	var a = 1;
	c.$each(function (e, d) {
		if (typeof (b) == "function") {
			d = b.call(c, e, d)
		}
		if (typeof (d) == "number") {
			a *= d
		} else {
			if (typeof (d) == "string") {
				var f = parseFloat(d);
				if (!isNaN(f)) {
					a *= f
				}
			}
		}
	});
	return a
};
Array.prototype.$chunk = function (c) {
	var d = this;
	if (d == null) {
		return []
	}
	if (typeof (c) == "undefined") {
		c = 1
	}
	c = parseInt(c);
	if (isNaN(c) || c < 1) {
		return []
	}
	var a = [];
	for (var b = 0; b < d.length / c; b++) {
		a.$push(d.slice(b * c, (b + 1) * c))
	}
	return a
};
Array.prototype.$combine = function (f) {
	var e = this;
	if (e == null) {
		return []
	}
	var b = e.$chunk(1);
	for (var d = 0; d < arguments.length; d++) {
		var a = arguments[d];
		if (Array.$isArray(a)) {
			for (var c = 0; c < e.length; c++) {
				b[c].$push(a.$get(c))
			}
		}
	}
	return b
};
Array.prototype.$pad = function (d, b) {
	var c = this;
	if (c == null) {
		return false
	}
	if (typeof (b) == "undefined") {
		b = 1
	}
	if (b < 1) {
		return false
	}
	for (var a = 0; a < b; a++) {
		c.push(d)
	}
	return true
};
Array.prototype.$fill = function (e, d) {
	var c = this;
	if (c == null) {
		return false
	}
	if (typeof (d) == "undefined") {
		d = c.length
	}
	if (d < c.length) {
		return false
	}
	if (d == c.length) {
		return true
	}
	var b = d - c.length;
	for (var a = 0; a < b; a++) {
		c.push(e)
	}
	return true
};
Array.prototype.$shuffle = function () {
	var a = this;
	if (a == null) {
		return false
	}
	a.$sort(function () {
		return Math.random() - 0.5
	});
	return true
};
Array.prototype.$rand = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	if (typeof (a) == "undefined") {
		a = 1
	}
	var c = b.$copy();
	c.$shuffle();
	return c.slice(0, a)
};
Array.prototype.$size = function (a) {
	if (typeof a == "function") {
		return this.$findAll(a).length
	}
	var b = this;
	if (b == null) {
		return 0
	}
	return b.length
};
Array.prototype.$count = function (a) {
	return this.$size(a)
};
Array.prototype.$first = function () {
	var a = this;
	if (a == null) {
		return null
	}
	if (a.length == 0) {
		return null
	}
	return a.$get(0)
};
Array.prototype.$last = function () {
	var a = this;
	if (a == null) {
		return null
	}
	if (a.length == 0) {
		return null
	}
	return a[a.length - 1]
};
Array.prototype.$push = function () {
	var a = this;
	if (a == null) {
		return 0
	}
	return Array.prototype.push.apply(a, arguments)
};
Array.prototype.$pushAll = function (b) {
	var a = this;
	if (a == null) {
		return 0
	}
	return Array.prototype.push.apply(a, b)
};
Array.prototype.$insert = function (b, e) {
	var d = this;
	if (d == null) {
		return false
	}
	var a = [];
	if (arguments.length == 0) {
		return false
	}
	for (var c = 1; c < arguments.length; c++) {
		a.push(arguments[c])
	}
	if (b < 0) {
		b = d.length + b + 1
	}
	d.splice.apply(d, [b, 0].concat(a));
	return true
};
Array.prototype.$asc = function (b) {
	var a = this;
	if (a == null) {
		return false
	}
	return a.$sort(function (d, c) {
		if (typeof (d) == "object" && typeof (c) == "object") {
			if (d[b] > c[b]) {
				return 1
			}
			if (d[b] == c[b]) {
				return 0
			}
			return -1
		}
		return 0
	})
};
Array.prototype.$desc = function (b) {
	var a = this;
	if (a == null) {
		return false
	}
	return a.$sort(function (d, c) {
		if (typeof (d) == "object" && typeof (c) == "object") {
			if (d[b] > c[b]) {
				return -1
			}
			if (d[b] == c[b]) {
				return 0
			}
			return 1
		}
		return 0
	})
};
Array.prototype.$equal = function (c) {
	var b = this;
	if (b == null) {
		return false
	}
	if (!Array.$isArray(c)) {
		return false
	}
	if (b.length != c.length) {
		return false
	}
	for (var a = 0; a < b.length; a++) {
		if (b[a] != c[a]) {
			return false
		}
	}
	return true
};
Array.prototype.$loop = function (a) {
	var b = this;
	if (b == null) {
		return false
	}
	if (b.length == 0) {
		return false
	}
	a.call(b, 0, b[0], {
		index: 0, next: function () {
			this.index++;
			if (this.index > b.length - 1) {
				this.index = 0
			}
			a.call(b, this.index, b[this.index], this);
			return this.index
		}, sleep: function (c) {
			var d = this;
			setTimeout(function () {
				d.next()
			}, c)
		}
	});
	return true
};
Array.prototype.$asJSON = function () {
	return JSON.stringify(this)
};
Array.$range = function (e, a, c) {
	var d = [];
	if (typeof (c) == "undefined") {
		c = 1
	}
	if (e < a) {
		for (var b = e; b <= a; b += c) {
			d.push(b)
		}
	} else {
		for (var b = e; b >= a; b -= c) {
			d.push(b)
		}
	}
	return d
};
Array.$isArray = function (a) {
	return Object.prototype.toString.call(a) === "[object Array]"
};
if (!Array.from) {
	Array.from = (function () {
		var d = Object.prototype.toString;
		var e = function (g) {
			return typeof g === "function" || d.call(g) === "[object Function]"
		};
		var c = function (h) {
			var g = Number(h);
			if (isNaN(g)) {
				return 0
			}
			if (g === 0 || !isFinite(g)) {
				return g
			}
			return (g > 0 ? 1 : -1) * Math.floor(Math.abs(g))
		};
		var b = Math.pow(2, 53) - 1;
		var a = function (h) {
			var g = c(h);
			return Math.min(Math.max(g, 0), b)
		};
		return function f(p) {
			var g = this;
			var o = Object(p);
			if (p == null) {
				throw new TypeError("Array.from requires an array-like object - not null or undefined")
			}
			var m = arguments.length > 1 ? arguments[1] : void undefined;
			var i;
			if (typeof m !== "undefined") {
				if (!e(m)) {
					throw new TypeError("Array.from: when provided, the second argument must be a function")
				}
				if (arguments.length > 2) {
					i = arguments[2]
				}
			}
			var n = a(o.length);
			var h = e(g) ? Object(new g(n)) : new Array(n);
			var j = 0;
			var l;
			while (j < n) {
				l = o[j];
				if (m) {
					h[j] = typeof i === "undefined" ? m(l, j) : m.call(i, l, j)
				} else {
					h[j] = l
				}
				j += 1
			}
			h.length = n;
			return h
		}
	}())
}