// 1、总数不能整除平分,则无法平分苹果, // 2 、 因为每次只能拿2个苹果,比平均数多或少的个数不是2的整倍数,不能被平分 const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { let n = await readline(); let line2 = await readline(); let apples = line2.split(" ").filter(item => item); let sum = apples.map((item) => parseInt(item)).reduce((c,p) => c + p, 0) if (sum % n !== 0) { console.log(-1); return; } let avg = sum / n; let index = 0; for (let i = 0; i < n; i++) { let t = (apples[i] - avg); if (t % 2 !== 0) { console.log(-1); return; } if (apples[i] >= avg) { index += Math.abs(apples[i] - avg) / 2; } } console.log(index); })();