"use strict"; // start var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const readline_1 = require("readline"); const fs = __importStar(require("fs")); function main() { // ここに処理を記述して let T = nextNum(); while (T--) { let [N, K] = nextNums(2); let A = nextBigInts(N); let ans = 10n ** 18n; for (let i = 0; i < N; i++) { let sum = 1n; for (let j = 0; j < N; j++) { if (i == j) { sum *= (A[j] - BigInt(K)); } else { sum *= A[j]; } } ans = bigIntMin(ans, sum); } println(ans); } // 処理終了 } Array.prototype.last = function () { return this.length === 0 ? undefined : this[this.length - 1]; }; Array.prototype.isEmpty = function () { return this.length === 0; }; const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1); const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1); const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m)); const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m)); const bigIntAbs = (arg) => (arg < 0 ? -arg : arg); const bigIntSqrt = (n) => { if (n == 0n) { return 0n; } let x = n; let y = (x + 1n) / 2n; while (x !== y) { x = y; y = (x + n / x) / 2n; } return x; }; let inputs = ""; let inputArray; let currentIndex = 0; let outputBuffer = ""; let yes = "Yes"; let no = "No"; let MOD998244353 = 998244353; let dxy4 = [[-1, 0], [0, 1], [1, 0], [0, -1]]; let dxy8 = [[-1, 0], [-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1]]; // // インタラクティブ用 // // お決まりのインプットはコメントアウト、main関数にasync、最後にrl.close()を忘れない // // 詳しくはABC244-Cをチェック // const rl = createInterface({ // input: process.stdin, // output: process.stdout, // }); // const input: string[] = []; // rl.on("line", (line: string) => { // input.push(line); // }); // const gl = async (): Promise => { // while (!input.length) { // await new Promise((resolve) => setTimeout(resolve, 0)); // } // return input.shift()!.trim(); // }; function next() { return inputArray[currentIndex++]; } function nextNum() { return +next(); } function nextBigInt() { return BigInt(next()); } function nexts(length) { const arr = []; for (let i = 0; i < length; ++i) arr[i] = next(); return arr; } function nextNums(length) { const arr = []; for (let i = 0; i < length; ++i) arr[i] = nextNum(); return arr; } function nextBigInts(length) { const arr = []; for (let i = 0; i < length; ++i) arr[i] = nextBigInt(); return arr; } function print(out, separator) { if (Array.isArray(out)) { outputBuffer += out.join(separator); } else { outputBuffer += out; } } function println(out, separator) { if (Array.isArray(out)) { print(out, separator || ""); } else { print(out); } print("\n"); } function flush() { console.log(outputBuffer); } function intDiv(a, b) { return Math.trunc(a / b); } function lowerBound(list, value, less = (l, r) => l < r) { let count = list.length; let first = 0; while (0 < count) { const count2 = count / 2 | 0; const mid = first + count2; if (less(list[mid], value)) { first = mid + 1; count -= count2 + 1; } else { count = count2; } } return first; } function upperBound(list, value, less = (l, r) => l < r) { return lowerBound(list, value, (l, r) => !less(r, l)); } function nextPermutation(arr) { const len = arr.length; let left = len - 2; while (left >= 0 && arr[left] >= arr[left + 1]) { left--; } if (left < 0) { return false; } let right = len - 1; while (arr[left] >= arr[right]) { right--; } const t = arr[left]; arr[left] = arr[right]; arr[right] = t; left++; right = len - 1; while (left < right) { const t = arr[left]; arr[left] = arr[right]; arr[right] = t; left++; right--; } return true; } function gcd(a, b) { if (b == 0 || b == BigInt(0)) { return a; } if (typeof a === 'number' && typeof b === 'number') { const r = a % b; return gcd(b, r); } else if (typeof a === 'bigint' && typeof b === 'bigint') { const r = a % b; return gcd(b, r); } return 0; } function lcm(a, b) { try { return a / gcd(a, b) * b; } catch (e) { return -1n; } } function eratosthenesPrime(N = 10 ** 6) { let b = Array(N + 1).fill(true); b[0] = false; b[1] = false; let prime = [2]; for (let i = 4; i <= N; i += 2) { b[i] = false; } for (let i = 3; i <= N; i += 2) { if (b[i]) { prime.push(i); for (let j = i * 3; j <= N; j += i * 2) { b[j] = false; } } } return prime; } function enumDiv(n) { let set = new Set(); for (let i = 1; i * i <= n; i++) { if (n % i == 0) { set.add(i); set.add(intDiv(n, i)); } } return [...set]; } function useModint(M) { Number.prototype.add = function (a) { const t = (+this + a) % M; return t < 0 ? t + M : t; }; Number.prototype.sub = function (a) { const t = (+this - a) % M; return t < 0 ? t + M : t; }; Number.prototype.mul = function (a) { const s = +this; const t = s * a; return t <= Number.MAX_SAFE_INTEGER ? t % M : ((((s >> 16) * a) % M) * 65536 + (s & 65535) * a) % M; }; Number.prototype.pow = function (n) { let x = +this; if (x % M === 0) return 0; let r = 1; for (; n; x = x.mul(x), n >>>= 1) if (n & 1) r = r.mul(x); return r; }; Number.prototype.div = function (a) { return this.mul(a.pow(M - 2)); }; } function bigint_mod_pow(x, n, p) { if (x % p === 0n) return 0n; let r = 1n; for (x %= p; n; x = (x * x) % p, n >>= 1n) { if (n & 1n) r = (r * x) % p; } return r; } function z_algorithm(S) { let A = Array(S.length).fill(0); A[0] = S.length; let i = 1, j = 0; while (i < S.length) { while (i + j < S.length && S[j] == S[i + j]) j++; A[i] = j; if (j == 0) { i++; continue; } let k = 1; while (i + k < S.length && k + A[k] < j) { A[i + k] = A[k]; k++; } i += k; j -= k; } return A; } // 最長増加部分列(長さを返す) function LIS(arr) { let dp = []; for (let num of arr) { let lb = lowerBound(dp, num); if (lb == dp.length) { dp.push(num); } else { dp[lb] = num; } } return dp.length; } function combinations(arr, k) { const result = []; const combo = []; function dfs(start) { if (combo.length === k) { result.push([...combo]); return; } for (let i = start; i < arr.length; i++) { combo.push(arr[i]); dfs(i + 1); combo.pop(); } } dfs(0); return result; } function builtin_popcount(n) { n |= 0; let count = 0; while (n != 0) { n &= (n - 1); count++; } return count; } class UnionFind { constructor(edge) { this.Parent = Array(edge).fill(-1); } root(node) { if (this.Parent[node] < 0) return node; return this.Parent[node] = this.root(this.Parent[node]); } size(node) { return -this.Parent[this.root(node)]; } same(A, B) { A = this.root(A); B = this.root(B); return A == B; } connect(A, B) { A = this.root(A); B = this.root(B); if (A == B) { return false; } if (this.size(A) < this.size(B)) { let tmp = A; A = B; B = tmp; } this.Parent[A] += this.Parent[B]; this.Parent[B] = A; return true; } } class PriorityQueue { constructor(compare) { this.compare = compare; this.list = new Array(); } push(v) { this.list.push(v); const back = this.list.length - 1; this.against(back); } against(child) { if (child === 0) return; const parent = Math.ceil(child / 2) - 1; const childValue = this.list[child]; const parentValue = this.list[parent]; if (this.compare(childValue, parentValue)) { this.swap(child, parent); this.against(parent); } } swap(a, b) { const tmp = this.list[a]; this.list[a] = this.list[b]; this.list[b] = tmp; } top() { if (this.list.length === 0) throw new Error("empty"); return this.list[0]; } pop() { if (this.list.length === 0) throw new Error("empty"); if (this.list.length === 1) { const ans = this.top(); this.list.pop(); return ans; } const ans = this.top(); this.list[0] = this.list.pop(); this.flow(0); return ans; } flow(parent) { const parentValue = this.list[parent]; const left = parent * 2 + 1; const right = parent * 2 + 2; if (!this.inRange(left)) { return; } if (!this.inRange(right)) { // 左子はいるが右子はいない const leftValue = this.list[left]; if (this.compare(leftValue, parentValue)) { this.swap(parent, left); } return; } const leftValue = this.list[left]; const rightValue = this.list[right]; const target = this.compare(leftValue, rightValue) ? left : right; const targetValue = this.list[target]; if (this.compare(targetValue, parentValue)) { this.swap(parent, target); this.flow(target); } } inRange(index) { return index < this.list.length; } size() { return this.list.length; } } // 01-bfsのときは無理にdequeを使わず、2つの配列を使う方が速い(ABC431-E) class Deque { constructor(capacity = 1 << 20) { this.capacity = capacity; this.data = new Array(capacity); this.head = capacity >> 1; this.tail = capacity >> 1; } push(value) { this.data[this.tail++] = value; } unshift(value) { this.data[--this.head] = value; } shift() { return this.head < this.tail ? this.data[this.head++] : undefined; } pop() { return this.head < this.tail ? this.data[--this.tail] : undefined; } peekHead() { return this.head < this.tail ? this.data[this.head] : undefined; } peekHeadIdx(idx) { return this.head + idx < this.tail ? this.data[this.head + idx] : undefined; } peekTail() { return this.head < this.tail ? this.data[this.tail - 1] : undefined; } peekTailIdx(idx) { return this.head < this.tail - idx ? this.data[this.tail - idx - 1] : undefined; } getLength() { return this.tail - this.head; } } // オイラーツアーのメモ // let E; // let L = Array.from({length: 101010},() => 0); // let R = Array.from({length: 101010},() => 0); // let idx = 0; // function euler(cu, pa = -1) { // L[cu] = idx; // idx++; // for (let to of E[cu]) if (to != pa) euler(to, cu); // R[cu] = idx; // } // https://atcoder.jp/users/nanana1o class SegmentTree { constructor(lenOrArray) { this.len = typeof lenOrArray === 'number' ? lenOrArray : lenOrArray.length; this.n = 1; while (this.n < this.len) { this.n *= 2; } const bufsize = this.n * 2; this.tree = Array(bufsize); this.tree[0] = this.getDefaultValue(); if (Array.isArray(lenOrArray)) { for (let i = 0; i < this.len; i++) this.tree[this.n + i] = lenOrArray[i]; for (let i = this.len; i < this.n; i++) this.tree[this.n + i] = this.getDefaultValue(); for (let i = this.n - 1; i >= 1; i--) this.tree[i] = this.merger(this.tree[i * 2], this.tree[i * 2 + 1]); } else { for (let i = 1; i < bufsize; i++) this.tree[i] = this.getDefaultValue(); } } get length() { return this.len; } update(index, value) { let k = index + this.n; this.tree[k] = this.updater(this.tree[k], value); while (k > 1) { k >>= 1; this.tree[k] = this.merger(this.tree[2 * k], this.tree[2 * k + 1]); } } get(left, right) { let res = this.getDefaultValue(); for (left += this.n, right += this.n; left < right; left >>= 1, right >>= 1) { if (left & 1) { res = this.merger(res, this.tree[left++]); } if (right & 1) { res = this.merger(res, this.tree[--right]); } } return res; } } class MaxSegmentTree2 extends SegmentTree { getDefaultValue() { return -Infinity; } merger(a, b) { return Math.max(a, b); } updater(oldV, newV) { return newV; } } class MinSegmentTree2 extends SegmentTree { getDefaultValue() { return Infinity; } merger(a, b) { return Math.min(a, b); } updater(oldV, newV) { return newV; } } class SumSegmentTree2 extends SegmentTree { getDefaultValue() { return 0; } merger(a, b) { return a + b; } updater(oldV, newV) { return newV; } } class XorSegmentTree2 extends SegmentTree { getDefaultValue() { return 0; } merger(a, b) { return a ^ b; } updater(oldV, newV) { return oldV ^ newV; } } class ArraySegmentTree2 extends SegmentTree { getDefaultValue() { return []; } merger(a, b) { return a[0] > b[0] ? a : b; } updater(oldV, newV) { return newV; } } class LazySegmentTree { constructor(size) { this.size = 1; while (this.size < size) { this.size *= 2; } this.tree = Array(2 * this.size - 1).fill(0); this.lazy = Array(2 * this.size - 1).fill(0); } query(left, right) { return this.querySub(left, right, 0, 0, this.size); } update(left, right, value) { this.updateSub(left, right, value, 0, 0, this.size); } querySub(queryLeft, queryRight, index, nodeLeft, nodeRight) { if (nodeRight <= queryLeft || queryRight <= nodeLeft) { return 0; } this.applyLazyUpdate(index); if (queryLeft <= nodeLeft && nodeRight <= queryRight) { return this.tree[index]; } const mid = Math.floor((nodeLeft + nodeRight) / 2); const leftValue = this.querySub(queryLeft, queryRight, index * 2 + 1, nodeLeft, mid); const rightValue = this.querySub(queryLeft, queryRight, index * 2 + 2, mid, nodeRight); return Math.max(leftValue, rightValue); } updateSub(queryLeft, queryRight, value, index, nodeLeft, nodeRight) { if (nodeRight <= queryLeft || queryRight <= nodeLeft) { return; } if (queryLeft <= nodeLeft && nodeRight <= queryRight) { this.lazy[index] = value; this.applyLazyUpdate(index); return; } const mid = Math.floor((nodeLeft + nodeRight) / 2); this.updateSub(queryLeft, queryRight, value, index * 2 + 1, nodeLeft, mid); this.updateSub(queryLeft, queryRight, value, index * 2 + 2, mid, nodeRight); this.tree[index] = Math.max(this.tree[index * 2 + 1], this.tree[index * 2 + 2]); } applyLazyUpdate(index) { if (this.lazy[index] === 0) { return; } this.tree[index] = this.lazy[index]; if (index < this.size - 1) { this.lazy[index * 2 + 1] = this.lazy[index]; this.lazy[index * 2 + 2] = this.lazy[index]; } this.lazy[index] = 0; } } class Trie { constructor() { this.next = new Map(); this.nextSet = new TreeMultiSet(); this.idx = []; } } // https://atcoder.jp/users/mst40 class TreeSetNode { constructor(n) { this.value = n; this.left = null; this.right = null; this.height = 1; this.count = 1; } incCnt() { this.count++; } decCnt() { this.count--; } } class TreeMultiSet { constructor() { this.root = null; } add(val) { this.root = this._addHelper(this.root, val); } delete(val) { const newTree = this._deleteHelper(this.root, val); this.root = newTree; if (!newTree) { return false; } return true; } count(value) { return this._getCountHelper(this.root, value); } min() { if (!this.root) { return undefined; } return this._findMin(this.root).value; } max() { if (!this.root) { return undefined; } return this._findMax(this.root).value; } lower_bound(val) { return this._lower_boundHelper(this.root, val); } upper_bound(val) { return this._upper_boundHelper(this.root, val); } prev(val) { return this._prevHelper(this.root, val); } next(val) { return this._nextHelper(this.root, val); } /** private */ _addHelper(node, val) { if (!node) { return new TreeSetNode(val); } if (val < node.value) { node.left = this._addHelper(node.left, val); } else if (node.value < val) { node.right = this._addHelper(node.right, val); } else { node.incCnt(); return node; } node.height = this._newHeight(node); return this._balancing(node, val); } _getBalanceFactor(node) { return this._getHeight(node.right) - this._getHeight(node.left); } _getHeight(node) { return node ? node.height : 0; } _newHeight(node) { return Math.max(this._getHeight(node.left), this._getHeight(node.right)) + 1; } _balancing(node, val) { const factor = this._getBalanceFactor(node); if (factor < -1) { if (val < node.left.value) { return this._rightRotate(node); } else { node.left = this._leftRotate(node.left); return this._rightRotate(node); } } else if (1 < factor) { if (val > node.right.value) { return this._leftRotate(node); } else { node.right = this._rightRotate(node.right); return this._leftRotate(node); } } return node; } _leftRotate(node) { const pivot = node.right; node.right = pivot ? pivot.left : null; if (pivot) pivot.left = node; node.height = this._newHeight(node); if (pivot) pivot.height = this._newHeight(pivot); return pivot || node; } _rightRotate(node) { const pivot = node.left; node.left = pivot ? pivot.right : null; if (pivot) pivot.right = node; node.height = this._newHeight(node); if (pivot) pivot.height = this._newHeight(pivot); return pivot || node; } _getCountHelper(node, value) { // value is not exsists. if (!node) { return 0; } // binary search(recursive) if (value < node.value) { return this._getCountHelper(node.left, value); } else if (value > node.value) { return this._getCountHelper(node.right, value); } else { return node.count; } } _deleteHelper(node, val) { if (!node) { return null; } if (val < node.value) { node.left = this._deleteHelper(node.left, val); } else if (val > node.value) { node.right = this._deleteHelper(node.right, val); } else { if (1 < node.count) { node.decCnt(); return node; } if (!node.left) { node = node.right; } else if (!node.right) { node = node.left; } else { const min = this._findMin(node.right); node.value = min.value; node.right = this._deleteHelper(node.right, min.value); } if (node) { node.height = this._newHeight(node); return this._balancing(node, val); } } return node; } _findMin(node) { let curr = node; while (curr.left) { curr = curr.left; } return curr; } _findMax(node) { let curr = node; while (curr.right) { curr = curr.right; } return curr; } _lower_boundHelper(node, val) { if (!node) { return undefined; } if (val <= node.value) { const left = this._lower_boundHelper(node.left, val); return left !== undefined ? left : node.value; } else { return this._lower_boundHelper(node.right, val); } } _upper_boundHelper(node, val) { if (!node) { return undefined; } if (val < node.value) { const left = this._upper_boundHelper(node.left, val); return left !== undefined ? left : node.value; } else { return this._upper_boundHelper(node.right, val); } } _prevHelper(node, val) { if (!node) { return undefined; } if (val <= node.value) { return this._prevHelper(node.left, val); } else { const right = this._prevHelper(node.right, val); return right !== undefined ? right : node.value; } } _nextHelper(node, val) { if (!node) { return undefined; } if (val >= node.value) { return this._nextHelper(node.right, val); } else { const left = this._nextHelper(node.left, val); return left !== undefined ? left : node.value; } } } class FenwickTree { constructor(arraySize) { this.arraySize = arraySize; // Fill tree array with zeros. this.treeArray = Array(this.arraySize + 1).fill(0); } increase(position, value) { if (position < 0 || position > this.arraySize) { throw new Error('Position is out of allowed range'); } for (let i = position; i <= this.arraySize; i += (i & -i)) { this.treeArray[i] += value; } return this; } query(position) { if (position < 0 || position > this.arraySize) { throw new Error('Position is out of allowed range'); } let sum = 0; for (let i = position; i >= 0; i -= (i & -i)) { sum += this.treeArray[i]; } return sum; } queryRange(leftIndex, rightIndex) { if (leftIndex > rightIndex) { throw new Error('Left index can not be greater than right one'); } if (leftIndex === 0) { return this.query(rightIndex); } return this.query(rightIndex) - this.query(leftIndex - 1); } } class FenwickTreeMod { constructor(arraySize) { this.arraySize = arraySize; // Fill tree array with zeros. this.treeArray = Array(this.arraySize + 1).fill(0); } increase(position, value) { if (position < 0 || position > this.arraySize) { throw new Error('Position is out of allowed range'); } for (let i = position; i <= this.arraySize; i += (i & -i)) { this.treeArray[i] = this.treeArray[i].add(value); } return this; } query(position) { if (position < 0 || position > this.arraySize) { throw new Error('Position is out of allowed range'); } let sum = 0; for (let i = position; i >= 0; i -= (i & -i)) { sum = sum.add(this.treeArray[i]); } return sum; } queryRange(leftIndex, rightIndex) { if (leftIndex > rightIndex) { throw new Error('Left index can not be greater than right one'); } if (leftIndex === 0) { return this.query(rightIndex); } return this.query(rightIndex).sub(this.query(leftIndex - 1)); } } // end // デバッグ環境がWindowsであれば条件分岐する if (process.env.OS == "Windows_NT") { const stream = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout, }); stream.on("line", (line) => { inputs += line; inputs += "\n"; }); stream.on("close", () => { inputArray = inputs.split(/\s/); main(); flush(); }); } else { inputs = fs.readFileSync("/dev/stdin", "utf8"); inputArray = inputs.split(/\s/); main(); flush(); } //# sourceMappingURL=main.js.map