You are given an array $$$a$$$ of length $$$n$$$. The array is called 3SUM-closed if for all distinct indices $$$i$$$, $$$j$$$, $$$k$$$, the sum $$$a_i + a_j + a_k$$$ is an element of the array. More formally, $$$a$$$ is 3SUM-closed if for all integers $$$1 \leq i < j < k \leq n$$$, there exists some integer $$$1 \leq l \leq n$$$ such that $$$a_i + a_j + a_k = a_l$$$.Determine if $$$a$$$ is 3SUM-closed.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output "YES" (without quotes) if $$$a$$$ is 3SUM-closed and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

NoteIn the first test case, there is only one triple where $$$i=1$$$, $$$j=2$$$, $$$k=3$$$. In this case, $$$a_1 + a_2 + a_3 = 0$$$, which is an element of the array ($$$a_2 = 0$$$), so the array is 3SUM-closed.In the second test case, $$$a_1 + a_4 + a_5 = -1$$$, which is not an element of the array. Therefore, the array is not 3SUM-closed.In the third test case, $$$a_i + a_j + a_k = 0$$$ for all distinct $$$i$$$, $$$j$$$, $$$k$$$, and $$$0$$$ is an element of the array, so the array is 3SUM-closed.

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m) {
                        if (!lookup[(test[l] + test[m] + test[n]).toString()]) {
                            result = 'NO';
                        }
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

function solve(n, a) {
  const nums = [],
        map = new Map();
  for (let num of a) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
    if (num !== 0 && map.get(num) > 2) return 'NO';
    if (map.get(num) <= 2) nums.push(num);
  }
  const N = nums.length;
  for (let i = 0; i < N; i++) {
    for (let j = i + 1; j < N; j++) {
      for (let k = j + 1; k < N; k++) {
        if (!map.has(nums[i] + nums[j] + nums[k])) return 'NO';
      }
    }
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

"use strict";
const fs = require("fs");
// let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let obj = {};
    let res = [],
      flag = 0;
    for (let i = 0; i < n; i++) {
      if (arr[i] === 0 && flag === 0) {
        flag = 1;
        res.push(0);
      } else if (arr[i] === 0 && flag === 1) continue;
      else res.push(arr[i]);
    }
    if (res.length === 1) console.log("YES");
    else if (res.length > 5) console.log("NO");
    else {
      for (let i = 0; i < res.length; i++) {
        if (obj[res[i]] === undefined) obj[res[i]] = 1;
      }
      flag = 0;
      for (let i = 0; i < res.length; i++) {
        for (let j = i + 1; j < res.length; j++) {
          for (let k = j + 1; k < res.length; k++) {
            let sum = res[i] + res[j] + res[k];
            if (obj[sum] !== 1) {
              flag = 1;
            }
          }
        }
      }
      if (flag === 1) console.log("NO");
      else console.log("YES");
    }
  }
};
solve();

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        if (i === 750) {
            output(arr.filter(num => num !== 0));
            return;
        }
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        if (i === 750) {
            output(arr.filter(num => num !== 0).length);
            return;
        }
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        if (i === 750) {
            output(arr.join(','));
            return;
        }
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        if (i === 750) {
            output(n);
            return;
        }
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        if (i === 750) {
            output(n + ' ' + arr.join(','));
            return;
        }
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[(arr[l] + arr[m] + arr[n]).toString()]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        const zero = arr.filter(num => num === 0).slice(0, 2);
        const test = nonZero.concat(zero);
        if (nonZero.length > 4) {
            output('NO');
            continue;
        }
        let result = 'YES';
        for (let l = 0; l < test.length; l++) {
            for (let m = 1; m < test.length; m++) {
                for (let n = 2; n < test.length; n++) {
                    if (l !== m && l !== n && n !== m && !lookup[arr[l] + arr[m] + arr[n]]) {
                        result = 'NO';
                    }
                }
            }
        }
        output(result);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let i = 0; i < N; i++) {
        const n = Number(readline());
        let arr = readline().split(' ').map(Number);
        const lookup = {};
        for (let num of arr) lookup[num] = true;
        if (n === 3) {
            output(lookup[arr[0] + arr[1] + arr[2]] ? 'YES': 'NO');
            continue;
        }
        const nonZero = arr.filter(num => num !== 0);
        if (nonZero.length < 2) {
            output('YES');
        } else if (nonZero.length === 2) {
            const areInverse = nonZero[0] === -1 * nonZero[1];
            output(areInverse ? 'YES' : 'NO');
        } else {
            output('NO');
        }
    }
}

'use strict';

function solve(n, a) {
  if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';
  let nums = [],
    map = new Map(),
    zero = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) {
      var _map$get;
      nums.push(a[i]);
      map.set(a[i], ((_map$get = map.get(a[i])) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
    } else zero++;
  }
  if (zero) {
    if (nums.length < 2) return 'YES';
    if (nums.length === 2) {
      return nums[0] + nums[1] === 0 ? 'YES' : 'NO';
    } else {
      return 'NO';
    }
  } else {
    if (map.size !== 2) return 'NO';
    const [x, y] = [...map];
    if (x[0] + y[0] !== 0) return 'NO';
    if (x[1] > 2 || y[1] > 2) return 'NO';
    return 'YES';
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
  str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';
  let nums = [],
      set = new Set(),
      zero = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) {
      nums.push(a[i]);
      set.add(a[i]);
    } else zero++;
  }
  if (zero) {
    if (nums.length < 2) return 'YES';
    if (nums.length === 2) {
      return nums[0] + nums[1] === 0 ? 'YES' : 'NO';
    } else {
      return 'NO';
    }
  } else {
    if (set.size > 2) return 'NO';
    const [x, y] = [...set];
    if (x + y === 0) return 'YES';
    return 'NO';
  }
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';
  let nums = [],
      set = new Set(),
      zero = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) {
      nums.push(a[i]);
      set.add(a[i]);
    } else zero++;
  }
  if (zero) {
    if (nums.length === 2) {
      return nums[0] + nums[1] === 0 ? 'YES' : 'NO';
    } else if (nums.length > 2) {
      return 'NO';
    }
  } else {
    if (set.size > 2) return 'NO';
    const [x, y] = [...set];
    if (x + y !== 0) return 'NO';
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  if (n === 3) return new Set(a).has(a.reduce((a, b) => a + b, 0)) ? 'YES' : 'NO';
  let nums = [];
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) nums.push(a[i]);
  }
  if (nums.length === 2) {
    return nums[0] + nums[1] === 0 ? 'YES' : 'NO';
  } else if (nums.length > 2) {
    return 'NO';
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  if (n === 3) return a.reduce((a, b) => a + b, 0) === 0 ? 'YES' : 'NO';
  let nums = [];
  for (let i = 0; i < n; i++) {
    if (a[i] !== 0) nums.push(a[i]);
  }
  if (nums.length === 2) {
    return nums[0] + nums[1] === 0 ? 'YES' : 'NO';
  } else if (nums.length > 2) {
    return 'NO';
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  let nums = [];
  for (let i = 0; i < n; i++) {
    if (a[i] === 0) ;else nums.push(a[i]);
  }
  if (nums.length > 2) return 'NO';
  if (nums.length <= 1) return 'YES';
  if (nums[0] + nums[1] === 0) return 'YES';
  return 'NO';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, a) {
  const set = new Set(a);
  a.sort((a, b) => a - b);
  for (let i = 2; i < n; i++) {
    const sum = a[i] + a[i - 1] + a[i - 2];
    if (!set.has(sum)) return 'NO';
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let obj = {};
    let res = [],
      flag = 0;
    for (let i = 0; i < n; i++) {
      if (arr[i] === 0 && flag === 0) {
        flag = 1;
        res.push(0);
      }
      res.push(arr[i]);
    }
    if (res.length > 5) console.log("NO");
    else {
      for (let i = 0; i < res.length; i++) {
        if (obj[res[i]] === undefined) obj[res[i]] = 1;
      }
      flag = 0;
      for (let i = 0; i < res.length; i++) {
        for (let j = i + 1; j < res.length; j++) {
          for (let k = j + 1; k < res.length; k++) {
            let sum = res[i] + res[j] + res[k];
            if (obj[sum] !== 1) {
              flag = 1;
            }
          }
        }
      }
      if (flag === 1) console.log("NO");
      else console.log("YES");
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let obj = {};
    let res = [];
    if (arr.length === 3) {
      let k = arr[0] + arr[1] + arr[2];
      if (k === arr[0] || k === arr[1] || k === arr[2]) console.log("YES");
      else console.log("NO");
      continue;
    }
    for (let i = 0; i < n; i++) if (arr[i] !== 0) res.push(arr[i]);
    if (res.length === 0) console.log("YES");
    else {
      if (res.length > 2) console.log("NO");
      else {
        if (Math.abs(res[0]) === Math.abs(res[1])) console.log("YES");
        else console.log("NO");
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let obj = {};
    for (let i = 0; i < n; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
    }
    let k = arr[0] + arr[1] + arr[2];
    if (obj[k] !== 1) {
      console.log("NO");
      continue;
    }
    let flag = 1;
    for (let i = 3; i < n; i++) {
      if (arr[i] !== 0) {
        flag = 0;
        break;
      }
    }
    if (flag === 1) console.log("YES");
    else console.log("NO");
  }
};
solve();


Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0). Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph. The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

In the first line print number m, the number of edges of the graph. Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b). Edges can be printed in any order; vertices of the edge can also be printed in any order.

NoteThe XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".

function main() {
  var n = +nxt();
  var d = [], s = [];
  var qu = [];
  for (var i = -1; ++ i < n; ) {
    d[i] = +nxt();
    s[i] = +nxt();
    if (d[i] === 1) {
      qu.push(i);
    }
  }
  var l = 0;
  var ans = [];
  while (l < qu.length) {
    var u = qu[l ++];
    if (d[u] === 0) continue;
    --d[u];
    ans.push([u, s[u]]);
    s[s[u]] ^= u;
    --d[s[u]];
    if (d[s[u]] === 1) qu.push(s[u]);
  }
  print(ans.length);
  for (var i = -1; ++ i < ans.length; ) {
    print(ans[i][0] + ' ' + ans[i][1]);
  }
}

var line = null, linepos = 0;
function nxt() {
  if (!line || linepos === line.length) {
    line = readline().split(' ');
    linepos = 0;
  }
  return line[linepos++];
}

if (typeof readline == 'undefined') {
  process.stdin.resume();
  process.stdin.setEncoding('ascii');

  var input_stdin = "";
  process.stdin.on('data', function (data) { input_stdin += data; });
  process.stdin.on('end', function () {
    // input_stdin = input_stdin.split(/\s/);
    input_stdin = input_stdin.split('\n');
    var curline = 0;
    readline = () => input_stdin[curline++];
    if (typeof print === 'undefined') print = console.log;
    main();
  });
} else main();


Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
a.sort(function(a, b){
	return a-b;
});

var ans=0;
for(var i=0; i<m; i++){
	if(a[i]<0){
		ans+=- a[i] ;
	}
}
print(ans);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort(function(a, b){return a - b;});
var res = 0, carried = 0;

for(var i = 0; i < n[0]; ++i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

;(function () {
	print(function (n, m) {
		var s = readline().split(' ').map(Number).filter(function (e) { return e < 0; }).sort(function (a, b) { return a - b; }),
			l = 0, k = 0;

		for (var i = 0, _i = Math.min(m, s.length); i < _i; i++) {
			l += -s[i];
		}

		return l;
	}.apply(null, readline().split(' ').map(Number)));
}.call(this));

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var itemNum = integers[0], capacity = integers[1];

	var weights = tokenizeIntegers(readline());
	weights.sort(function(a, b) {
		return a-b;
	});

	var total = 0;
	for (var i = 0; i < capacity; ++i) {
		if (weights[i] >= 0) {
			break;
		}
		total -= weights[i];
	}
	print(total);
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let N = lll[0]
let M = lll[1]
let res = readline().split(' ').map(v => parseInt(v))
  .filter(v => v < 0)
  .sort((a, b) => a - b)
  .slice(0, M)
  .reduce((r, v) => r + v, 0)

print(-res)

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ')
			 .map(e=>Number(e))
			 .filter(x=> x < 0)
			 .sort(function(a,b){return a - b});
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

var a = readline().split(' ').map(e=>Number(e));
var b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);

if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var t = readline().split(' ').map(cur => Number(cur));
var inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {
return a-b;
});
var sum = 0;
for (var i = 0; i < t[1]; i++){
    if(inp[i] <= 0)
    sum-= inp[i];
}
print(sum);

	//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);
var llsort = [];
for(var i=0;i<ll.length;i++){if((+ll[i])<=0){llsort.push(ll[i])}}

if(llsort.length==0){print(0)}else{

var ashraf =0
if(llsort.length<n[1]) {n[1] =llsort.length}

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(llsort[x]) ;

}
ashraf = ashraf *-1
print(ashraf)
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const [len, t] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  arr.sort((a, b) => a - b);
  let result = 0;
  for (let i = 0; i < t; i++) {
    if (arr[i] < 0) result += Math.abs(arr[i]);
  }

  console.log(result);
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let sum = 0;

  for (let i = 0; i < m; i++) {
    if (arr[i] < 0) {
      sum += Math.abs(arr[i]);
    }
  }

  console.log(sum);

  c++;
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr.push(Number(temp[i]));
    }
    arr.sort(function(a, b){return a - b});
    var ans = 0;
    for(i = 0; i < m && arr[i] < 0; i++){
      ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) if (p[i] < 0) s += p[i];

	s = s < 0 ? s * -1 : s;
	console.log(s);
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let [n, m] = readLine().split(' ').map(Number);
    let prices = readLine().split(' ').map(Number);
    prices.sort((a, b) => {
        return a - b;
    });
    let final = 0;
    for (let i = 0; i < m; i++) {
        if (Math.sign(prices[i]) === -1) {
            final += Math.abs(prices[i]);
        }
    }
    console.log(final);
}

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
a.sort(function(a, b){
	return a-b;
});

var ans=0;
for(var i=0; i<m; i++){
	ans+=0-a[i];
}
print(ans);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort(function(a, b){return a - b;});
var res = 0, carried = 0;

for(var i = n[0] - 1; i >= 0; --i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort();
var res = 0, carried = 0;

for(var i = n[0] - 1; i >= 0; --i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);});
a.sort();
var res = 0,
	carried = 0;
for(var i = 0; i < n[0]; ++i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

;(function () {
	print(function (n, m) {
		var s = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
			l = 0, k = 0;

		for (var i = 0; i < n && k < m; i++) {
			if (s[i] <= l) {
				l -= s[i];
				k++
			} else {
				break;
			}
		}

		return l;
	}.apply(null, readline().split(' ').map(Number)));
}.call(this));

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var itemNum = integers[0], capacity = integers[1];

	var weights = tokenizeIntegers(readline());
	weights.sort(function(a, b) {
		return a-b;
	});

	var total = 0;
	for (var i = 0; i < capacity; ++i) {
		total -= weights[i];
	}
	print(total);
}

main();

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ')
			 .filter(x=> x < 0)
			 .sort(function(a,b){return a - b});
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ').map(e=>Number(e)).sort();
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }
    if (i==max){
        break;
    }
  }
  print(-1*sum);

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ').map(e=>Number(e)).sort();
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

var a = readline().split(' ').map(e=>Number(e));
var b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);

if (b.length === 0){
	print(0);
} else {
	print(b.reduce((prev,next)=>prev+next));
}

'use strict';

var a = readline().split(' ');
var b = readline().split(' ').map(function (e) {
	return Number(e);
}).filter(function (e) {
	return e < 0;
});

if (b.length === 0) {
	print(0);
} else {
	var p = new Promise(function (resolve, reject) {
		var what = 0;
		for (var i = 0; i < a[1]; i++) {
			var max = b.reduce(function (prev, next) {
				return Math.max(prev, next);
			});
			b.pop(b.indexOf(max));
			what += max;
		}
		resolve(what);
	});p.then(function (data) {
		print(what);
	});
}

var a = readline().split(' ');
var b = readline().split(' ').filter(e=>Number(e)<0).map(e=>Number(e)).sort().slice(0,a[0]).reduce((prev,next)=>prev+next);
print(b);

'use strict';

var a = readline().split(' ');
var b = readline().split(' ').map(function (e) {
	return Number(e);
}).filter(function (e) {
	return e < 0;
});

if (b.length === 0) {
	print(0);
} else {
	var p = new Promise(function (resolve, reject) {
		var what = 0;
		for (var i = 0; i < a[1]; i++) {
			var max = b.reduce(function (prev, next) {
				return Math.max(prev, next);
			});
			b.pop(b.indexOf(max));
			what += max;
		}
		resolve(what);
	});p.then(function (data) {
		print(data);
	});
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).filter(e=>e<0);

if (b.length === 0){
	print(0);
} else {
	var p = new Promise((resolve,reject)=>{
		var what = 0;
		for(var i = 0; i < a[1]; i++){
			var max = b.reduce((prev,next)=>Math.max(prev,next));
			b.pop(b.indexOf(max));
			what+=max;
		}
		resolve(what);
	}); p.then(data=>{
		print(what);
	})
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[1]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().reverse().filter(e=>Number(e)<0).slice(0,a[1]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);
if (b === []){
	print(0);
} else {
	print(b.reduce((prev,next)=>prev+next));
}

var t = readline().split(' ').map(cur => Number(cur));
var inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {
return a-b;
});
var sum = 0;
for (var i = 0; i < t[1]; i++){
    sum-= inp[i];
}
print(sum);
//

//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);
var llsort = [];
for(var i=0;i<ll.length;i++){if((+ll[i])<=0){llsort.push(ll[i])}}

if(llsort.length==0){print(0)};

var ashraf =0
if(llsort.length<n[1]) {n[1] =llsort.length}
for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(llsort[x]) ;

}
ashraf = ashraf *-1
print(ashraf)

//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);

var ashraf =0

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(ll[x]) ;

}
if(ashraf<0){ashraf=ashraf*-1}else{print("0")}
print(ashraf)

//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);

var ashraf =0

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(ll[x]) ;

}
ashraf = ashraf*-1 ;

print(ashraf)

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => {
            if (x) {
                return +x
            }
        })
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        console.log(prices)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => +x);
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => +x);
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += -price
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let sum = 0;

  for (let i = 0; i < m; i++) {
    sum += Math.abs(arr[i]);
  }

  console.log(sum);

  c++;
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr[i] = Number(temp[i]);
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0 && i < m) ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

// input module
const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
       readline.question('', (data) => {
           resolve(data);
       });
    });
}

async function main(){

    const n = Number(await input());
    const m = Number(await input());
    var arr = []
    for(i = 0; i < n; i++) arr[i] = Number(await input());
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0) ans += arr[i] * -1;
    }
    console.log(ans);

    // to end the terminal
    readline.close();
}
main();

// input module
const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
       readline.question('', (data) => {
           resolve(data);
       });
    });
}

async function main(){

    var temp = (await input()).split(" ");
    var n = Number(temp[0]);
    var m = Number(temp[1]);
    temp = (await input()).split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr[i] = Number(temp[i]);
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0) ans += arr[i] * -1;
    }
    console.log(ans);

    // to end the terminal
    readline.close();
}
main();

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr.push(Number(temp[i]));
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0 && i < m) ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) {
		s += p[i];
	}
	s = s < 0 ? s * -1 : s;
	console.log(s);
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) {
		s += p[i];
	}
	console.log(s);
}


You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.

For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.

let i = ''
var segments = {
    1: 2,
    7: 3,
}
var segmentHistory = new Map();
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    for (var index = 1; index < lines.length; index++) {
        segmentHistory = new Map();
        console.log(largestNum(lines[index]))
    }
})

function largestNum(n) {
    var arr = []
    if (n % 2 === 1) {
        arr.length = (n-3)/2
        arr.fill('1')
        return '7' + arr.join('')
    }
    else {
        arr.length = n/2
        arr.fill('1')
        return arr.join('')
    }
}

const calc = (d, x) => Math.ceil( d / (x + 1) + x)

const processData = (lines) => {
  const num = +lines[0]

  for (let j=1; j<=num; j++){
    let n = +lines[j]
    let result = ''
    if (n%2 === 1) {
      result = '7'
      n -= 2
    }
    for (let r = n; r > 1; r -= 2) {
      result += '1'
    }
    console.log(result)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

'use strict'

const problem = (n) => (n%2 ? '7' : '1') + '1'.repeat((n>>1) - 1);

let t = +readline()
while(t--) print(problem(+readline()))

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = [];
    for(var i = 0; i < t; i++){
        var n = myconv(next(),1);
        if(n == 2){
            output.push("1");
        }else if(n == 3){
            output.push("7");
        }else{
            if(n % 2 == 0){
                output.push(new Array(n/2).fill("1").join(""));
            }else{
                output.push("7" + new Array((n-3)/2).fill("1").join(""));
            }
        }
    }
    myout(myconv(output,9));
}

var t = parseInt(readline());

while(t--){
  var n = parseInt(readline());
  var ones = Math.floor(n/2);

  var result = "";
  if (n % 2 == 1)
  {
    result += "7";
    ones--;
  }

  while(ones--)
  {
    result += "1";
  }

  print(result);
}

'use strict';

function a(n) {
  if (n % 2 === 1) {
    return '7' + '1'.repeat((n-3)/2);
  }
  return '1'.repeat(n/2);
}

function main() {
  const t = Number(readline());
  for(let i = 0; i < t; i++) {
    const n = Number(readline());
    print(a(n));
  }
}

main();

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;
let ans = "";
const obj = {
  0: 6,
  1: 2,
  2: 5,
  3: 5,
  4: 4,
  5: 5,
  6: 6,
  7: 3,
  8: 7,
  9: 6,
};

rl.on("line", (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let n = +d;
  let val = "";

  if (n % 2 === 0) {
    val += "1".repeat(n / 2);
  } else {
    val += "7";
    n -= 3;
    val += "1".repeat(n / 2);
  }

  ans += `${val}\n`;

  c++;
});

rl.on("close", () => {
  console.log(ans);
});

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;
let ans = "";

rl.on("line", (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let n = +d;
  let val = "";

  if (n % 2) {
    val += "7";
    n -= 3;
  }

  val += "1".repeat(n / 2);
  ans += `${val}\n`;

  c++;
});

rl.on("close", () => {
  console.log(ans);
});

const calc = (d, x) => Math.ceil( d / (x + 1) + x)

const processData = (lines) => {
  const num = +lines[0]

  for (let j=1; j<=num; j++){
    const n = +lines[j]
    let result = ''
    for (let r = n; r > 1; r -= 2) {
      if (n == 3) {
        result += '7'
      } else {
        result += '1'
      }
    }
    console.log(result)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join())
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join(''))
    }
}

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join())
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join())
    }
}

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join(''))
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join(''))
    }
}

'use strict'

const problem = (n) => '1'.repeat((n>>1) - 1) + (n%2 ? '7' : '1')

let t = +readline()
while(t--) print(problem(+readline()))

let i = ''
var segments = {
    1: 2,
    7: 3,
}
var segmentHistory = new Map();
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    for (var index = 1; index < lines.length; index++) {
        segmentHistory = new Map();
        console.log(largestNum(lines[index]))
        console.log(segmentHistory)
    }
})

function largestNum(n) {
    if (segmentHistory.has(n)) return segmentHistory.get(n)
    if (n <= 1) return ''
    var largest = -1
    for (const num in segments) {
        var cur = ''
        if (segments[num] <= n) {
            cur = num + largestNum(n-segments[num])
        }
        largest = Math.max(largest, +cur)
    }
    segmentHistory.set(n, largest)
    return largest
}