Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.Du will chat in the group for $$$n$$$ days. On the $$$i$$$-th day:  If Du can speak, he'll make fun of Boboniu with fun factor $$$a_i$$$. But after that, he may be muzzled depending on Boboniu's mood.  Otherwise, Du won't do anything. Boboniu's mood is a constant $$$m$$$. On the $$$i$$$-th day:  If Du can speak and $$$a_i>m$$$, then Boboniu will be angry and muzzle him for $$$d$$$ days, which means that Du won't be able to speak on the $$$i+1, i+2, \cdots, \min(i+d,n)$$$-th days.  Otherwise, Boboniu won't do anything. The total fun factor is the sum of the fun factors on the days when Du can speak.Du asked you to find the maximum total fun factor among all possible permutations of $$$a$$$.

The first line contains three integers $$$n$$$, $$$d$$$ and $$$m$$$ ($$$1\le d\le n\le 10^5,0\le m\le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$).

Print one integer: the maximum total fun factor among all permutations of $$$a$$$.

NoteIn the first example, you can set $$$a'=[15, 5, 8, 10, 23]$$$. Then Du's chatting record will be:  Make fun of Boboniu with fun factor $$$15$$$.  Be muzzled.  Be muzzled.  Make fun of Boboniu with fun factor $$$10$$$.  Make fun of Boboniu with fun factor $$$23$$$. Thus the total fun factor is $$$48$$$.

'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++]
}

String.prototype.count = function (c) {
    let result = 0
    for (let i = 0; i < this.length; i++)
        if (this[i] == c)
            result++
    return result
}

function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        } else {
            lo = mi;
        }
    }
    return hi;
}

function lowerBound(array, item) {
    return binarySearch(array, j => item <= j);
}

function upperBound(array, item) {
    return binarySearch(array, j => item < j);
}

function nextChar(c) {
    return String.fromCharCode(c.charCodeAt(0) + 1)
}

function main() {
    const params = readLine().split(' ')
    const N = Number(params[0].trim())
    const D = Number(params[1].trim())
    const M = Number(params[2].trim())

    let A = []
    for(let a of readLine().split(' '))
        A.push(Number(a.trim()))

    A.sort((a, b) => a - b)
    let pref = [0]
    for (let i = 0; i < N; ++i)
        pref.push(pref[i] + A[i])

    const K = upperBound(A, M)

    let ans = 0
    for (let numLo = 0; numLo <= K; ++numLo) {
        const numHi = Math.floor((N - numLo + D) / (D + 1))
        if(numHi <= N-K) {
            ans = Math.max(ans, (pref[N] - pref[N-numHi]) + (pref[K] - pref[K-numLo]))
        }
    }

    process.stdout.write(ans + '\n')
}

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    // if (n === 5) {
    //     return 48
    // } else if (n === 20) {
    //     return 195
    // }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    // return 10000

    let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
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*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    return 10000

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
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*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    } else {
        return 1000
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
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*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')
const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

// Split this out to make it easier to test
chats = chats.map((value, index) => {
    return {
        value,
        index,
        bad: m < value,
        average: m < value ? value / (d + 1) : value,
    }
})

chats.sort((a, b) => b.average - a.average)

const good = chats.filter((chat) => !chat.bad)
let bad = chats.filter((chat) => chat.bad)

const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
// console.log('maxBadChatCount', maxBadChatCount)
bad = bad.slice(0, maxBadChatCount)

let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
let totalFun = bestTotalFun

// Add each good and remove bad as necessary
let goodAdded = 0
for (const chat of good) {
    // console.log('bad', bad)
    // console.log('good', good)
    // Add a good
    totalFun += chat.value
    goodAdded += 1
    const daysNeededToChatAllChats =
        // All the bads but the last one
        (bad.length - 1) * (d + 1) +
        // The last bad
        1 +
        // The goods
        goodAdded
    if (n < daysNeededToChatAllChats) {
        const chat = bad.pop()
        totalFun -= chat.value
    }

    // console.log(totalFun)
    bestTotalFun = Math.max(bestTotalFun, totalFun)
}

console.log(bestTotalFun)

/*

Old solution:

let daysLeft = n
let totalFun = 0
let i = 0

while (d + 1 < daysLeft) {
    const chat = chats[i]
    totalFun += chat.value
    daysLeft -= chat.bad ? d + 1 : 1
    i += 1
}

// console.log(chats)
// console.log('daysLeft', daysLeft)
// console.log('totalFun', totalFun)
// console.log('i', i)

// Now, you roughly want to take the top chats. However, you can insert non-bad
// chats just before the last bad chat and "go out with a bang".

// Get the best remaining non-bad chats equal in number to "daysLeft"
// Get the best remaining non-bad chat

let bestRemainingBadChat = undefined
let bestRemainingGoodChats = []

while (
    i < n &&
    (bestRemainingBadChat === undefined ||
     bestRemainingGoodChats.length < daysLeft)
) {
    const chat = chats[i]
    // Order these conditions for branch prediction optimization
    if (bestRemainingBadChat === undefined && chat.bad) {
        bestRemainingBadChat = chat
    } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
        bestRemainingGoodChats.push(chat)
    }

    i += 1
}

// console.log('bestRemainingBadChat', bestRemainingBadChat)
// console.log('bestRemainingGoodChats', bestRemainingGoodChats)

// Option 1: use only good chats
const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

// Option 2: use best bad chat and remaining good chats
const option2 =
    bestRemainingBadChat === undefined ?
    option1 :
    bestRemainingBadChat.value +
    bestRemainingGoodChats
        .slice(0, daysLeft - 1)
        .map((chat) => chat.value)
        .reduce((a, b) => a + b)

// console.log('option1', option1)
// console.log('option2', option2)

totalFun += Math.max(option1, option2)

// console.log(totalFun)

*/

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    // return 10000

    let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
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*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})


You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.If there exists no such matrix then output -1.

The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).

If the answer exists then output resulting matrix. Otherwise output -1.

  var tmp = readline().split(' ').map(x => parseInt(x));
  var n = tmp[0];
  var k = tmp[1];
  if(n * n < k) {
    print('-1');
  } else {
    var m = new Array(n).fill(0).map(function(x) { return new Array(n).fill(0);});
    var d = 0;
    var i = 0;
    var j = 1;
    while(k > 0) {
      if(d <= i) {
        m[d][d] = 1;
        k -= 1;
        d += 1;
        continue;
      }
      if(j === n) {
        i += 1;
        j = i + 1;
        continue;
      }
      if(k === 1) {
        m[d][d] = 1;
        k -= 1;
        continue;
      }
      m[i][j] = 1;
      m[j][i] = 1;
      k -= 2;
      j += 1;
    }
    print(m.map(x => x.join(' ')).join('\n'));
  }


Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:  he chooses two elements of the array ai, aj (i ≠ j);  he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

print(function(n, a) {

	var sum = a.reduce(function(a, b) {
		return a + b;
	});

	return sum % n === 0 ? n : n - 1;

}(+readline(), readline().split(' ').map(Number)));

;(function () {

    print(function (n, a) {
        var k = a.reduce(function (p, e) {
            return p + e;
        }, 0) / n;
        if ((k%1) === 0) return n;
        return n - 1;
    }.apply(null, [+readline(), (readline().split(' ').map(Number))]));

}.call(this));

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStd => inputString += inputStd);
process.stdin.on('end', () => {
    inputString = inputString.trim().split('\n').map(str => str.trim());
    solve();
});
let readLine = () => inputString[currentLine++];

function solve(){
    const n = +(readLine());
    let arr = readLine().split(' ').map(Number);
    let sum = 0;
    for(let i of arr) sum += i;
    console.log(sum%n ? n-1 : n);
}

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++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let len = +readLine();
  const arr = readLine().split(" ").map(Number);
  const sum = arr.reduce((s, n) => s + n, 0);

  if (sum % len === 0) console.log(len);
  else console.log(len - 1);
}


You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.

First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.

For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    let sum = arr[0];
    let min = 0;
    for(let i = 1 ; i < n ; i++){
        if(sum + arr[i] > min){
            sum += arr[i];
            min++;
            sum -= min;
        } else {
            return 'NO'
        }
    }
    return 'YES'
}

module.exports = a;

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        arr[i + 1] += arr[i] - i
        if (arr[i] < i) {
          return false
        }
        arr[i] = i
    }
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= arr[i + 1]) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

'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++];
}

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var a = readline().split(' ').map((x, i) => {
            return parseInt(x)
        })

        var answer = true
        var sum = 0
        for (let j = 0; j < n; j++) {
            sum += a[j]

            if (sum < j) answer = false
            sum = sum - j
        }
        // console.log(a)
        console.log(answer ? 'YES' : 'NO')
    })

}

function find(a, m) {
    var sum = 0
    for (var i = 0; i <= m; i++) {
        sum += a[i]
    }
    i = m + 1
    while (sum >= a[i]) {
        sum += a[i]
        i++
    }
    if (i === a.length) return true
    return false
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            if(e == 1){
                console.log('YES');
                continue;
            }
            var k = lines[j].split(' ').map(Number);
            var have = k[0];
            k[0] = 0;
            for(var l = 1; l < e; l++){
                if(k[l] > k[l - 1]){
                    have += k[l] - (k[l - 1] + 1);
                    k[l] = k[l - 1] + 1;
                }else if(k[l - 1] == k[l]){
                    if(have > 0){
                        k[l]++;
                        have--;
                    }
                }else{
                    var gap = k[l - 1] - k[l] + 1;
                    if(gap <= have){
                        k[l] += gap;
                        have -= gap;
                    }
                }
            }
            var ok = false;
            for(var b = 1; b < e; b++){
                if(k[b] > k[b - 1]){
                    ok = true;
                    continue;
                }
                ok = false;
                break;
            }
            if(ok){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const h = rna();

		let cur = 0, ok = true;
		for (let i = 0; i < n; i++) {
			cur += h[i];
			ok = ok && cur >= i;
			cur -= i;
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    preRun(lines);
});

// preRun([
// 	"6",
// 	"2",
// 	"1 2",
// 	"2",
// 	"1 0",
// 	"3",
// 	"4 4 4",
// 	"2",
// 	"0 0",
// 	"3",
// 	"0 1 0",
// 	"4",
// 	"1000000000 1000000000 1000000000 1000000000"
// ]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[1+(i*2)]);
		let stacks = lines[1+(i*2)+1].split(" ").map((e) => parseInt(e));
		console.log(verdict(stacks));
	}
}

function verdict(stacks)
{
	let c = 0;
	for(let i=0;i<stacks.length;i++)
	{
		if (stacks[i]<i) return "NO";
		if ((stacks[i]>i) && (i<stacks.length-1)) stacks[i+1]+= (stacks[i]-i);
	}
	return "YES";
}

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

let standardInputString = "";
let currentLine = 0;

const readline = () => standardInputString[currentLine++];

process.stdin.on("data", (rawdata) => {
  standardInputString += rawdata;
});

process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => line.trim());
  main();
});

const main = () => {
  let t = parseInt(readline());
  while (t--) {
     let n = parseInt(readline());
     let arr = readline();
     let remain = 0,fl=1;
     arr = arr.split(' ').map(a=>parseInt(a));
     for(let i=0;i<n;i++){
        if(remain+arr[i]>=i){
            remain += arr[i] - i;
        }else{
            fl=0;
            console.log("NO");
            break;
        }
     }
     if(fl) console.log("YES");
  }
};

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var min = 0;
		var sum = list[0];
		list[0] = 0;
		var isOK = true;
		for(var j = 1; j < N; j++){
			if(sum + list[j] > min){
				sum += list[j];
				min++;
				sum -= min;
			}else{
				isOK = false;
				break;
			}
		}
		myout((isOK) ? "YES" : "NO");
	}
}

'use strict'

//let numbers = readline().split(" ").map(function(x) { return parseInt(x); });
//print(numbers); write(numbers);
//let n = readline();

let n = readline();

NEXT: while(n--) {

    let a = readline().split(' ');
    a = readline().split(' ');
    for(var i=0; i<a.length;i++) a[i] = +a[i];

    let flag = true;

    for(let i = 0; i < a.length - 1; ++i) {
        let diff = a[i] - i;
        if(diff < 0) {
            flag = false;
            break;
        }
        else {
            a[i + 1] += diff;
            a[i] = i;
        }
    }

    for(let i = 1; i < a.length; ++i) {
        if (a[i] <= a[i - 1]){
            flag = false;
            break;
        }
    }

    if(flag) print("YES");
    else print("NO");
}

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    // console.log(`arr = ${arr}`)

    for(let i = 0; i< n - 1; i++){
        if(arr[i] >= arr[i+1] && arr[i] !== 0){

                arr[i] = arr[i] - (n - i + 1)
                arr[i+1] = arr[i + 1] + (n + i + 1);

        }

    }
    for(let i = 0 ; i < n - 1; i++){
        if(arr[i] >= arr[i+1]){
            return 'NO';
        }
    }
    return 'YES';

}

module.exports = a;

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    // console.log(`arr = ${arr}`)

    for(let i = 0; i< n - 1; i++){
        if(arr[i] >= arr[i+1] && arr[i] !== 0){
                arr[i] = arr[i] - (n - i)
                arr[i+1] = arr[i + 1] + (n + i);
        }
        // console.log(`arr = ${arr}`)
    }
    for(let i = 0 ; i < n - 1; i++){
        if(arr[i] >= arr[i+1]){
            return 'NO';
        }
    }
    return 'YES';

}

module.exports = a;

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            arr[i + 1] += arr[i] - i
            if(arr[i] < i) return false
            arr[i] = i
        }
    }
    for (let i = 0; i < arr.length ; i++) {
        if (arr[i] < i) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < arr[i + 1]) {
            let temp = arr[i + 1]
            arr[i + 1] = arr[i]
            arr[i] = temp
        }
    }
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] <= arr[i + 1]) {
            if (arr[i] === 0 && arr[i + 1] === 0) {
                return false
            }
        }
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            arr[i + 1] += arr[i] - i
            arr[i] = i
        }
    }
    for (let i = 0; i < arr.length ; i++) {
        if (arr[i] < i) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

'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++];
}

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var a = readline().split(' ').map((x, i) => {
            return parseInt(x)
        })

        var answer = true
        var sum = 0
        for (let j = 0; j < n; j++) {
            sum+=a[j]

            if(sum<j) answer = false
        }
        // console.log(a)
        console.log(answer ? 'YES' :'NO')
    })

}

function find(a, m) {
    var sum = 0
    for (var i = 0; i <= m; i++) {
        sum += a[i]
    }
    i = m + 1
    while (sum >= a[i]) {
        sum += a[i]
        i++
    }
    if (i === a.length) return true
    return false
}


You are walking through a parkway near your house. The parkway has $$$n+1$$$ benches in a row numbered from $$$1$$$ to $$$n+1$$$ from left to right. The distance between the bench $$$i$$$ and $$$i+1$$$ is $$$a_i$$$ meters.Initially, you have $$$m$$$ units of energy. To walk $$$1$$$ meter of distance, you spend $$$1$$$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed $$$m$$$.Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$; $$$1 \le m \le 10^4$$$). The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the distance between benches $$$i$$$ and $$$i+1$$$.

For each test case, print one integer — the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk) in the corresponding test case.

NoteIn the first test case of the example, you can walk to the bench $$$2$$$, spending $$$1$$$ unit of energy, then restore $$$2$$$ units of energy on the second bench, walk to the bench $$$3$$$, spending $$$2$$$ units of energy, restore $$$1$$$ unit of energy and go to the bench $$$4$$$.In the third test case of the example, you have enough energy to just go to the bench $$$6$$$ without sitting at all.

var testcases=readline();
for(var i=0;i<testcases;i++){
  var n=readline().split(" ")[1];
  var v=readline().split(" ");
  var sum=0;
  for(var j=0;j<v.length;j++)
    sum+=parseInt(v[j]);

  n<sum?print(sum-n):print(0);
}

t = parseInt(readline(), 10)

while (t > 0) {
    var inp = readline().split(' ')
    var n = parseInt(inp[0], 10)
    var x = parseInt(inp[1], 10)

    t -= 1

    var arr = readline().split(' ').map((item) => parseInt(item, 10))
    var sum = arr.reduce((sum, item) => sum + item, 0)
    print(Math.max(0, sum - x))
}

var N=readline();
for(var i=0;i<N;i++){
  var n=readline().split(" ")[1];
  var benches=readline().split(" ");
  var sum=0;
  for(var i2=0;i2<benches.length;i2++){
    sum+=parseInt(benches[i2]);
  }
  n<sum?print(sum-n):print(0);
}

'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 test = 0; test < N; test++) {
        let [n, m] = readline().split(' ').map(Number);
        let arr = readline().split(' ').map(Number);

        let res = 0;
        for (let i = 0; i < arr.length; i++) {
            let diff = m - arr[i];
            if (diff < 0) {
                m -= diff;
                res -= diff;
            }
            m -= arr[i];
        }
        output(res);
    }
}

const readline = require("readline");

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

class Input {
	constructor(line) {
		this.pointer = -1;
		this.content = [line];
	}
	add(line) {
		this.content.push(line);
	}
	get(line) {
		if (!(this.pointer < this.content.length - 1)) {
			return -1
		}
		return this.content[++this.pointer];
	}
}

const intify = (arr) => {
	if (typeof arr == "string") {
		let temp = "";
		for (let i = 0; i < arr.length; i++) {
			if (arr[i] != ' ') {
				temp += arr[i];
			}
		}
		return parseInt(temp)
	} else {
		return arr.map(ele => parseInt(ele))
	}
}

rl.once("line", line => {
	let inp = new Input(line);
	rl.on("line", line => {
		inp.add(line)
	}).on("close", () => {

		let t = intify(inp.get());
		while (t--) {
			let [n, m] = intify(inp.get().split(' '))
			let arr = intify(inp.get().split(' '))
			let total = 0;
			for (let ele of arr) {
				total += ele;
			}
			console.log(Math.max(0, total - m));
		}

    });
});

/**
 * https://codeforces.com/problemset/problem/1697/A
 */

function nodeJSReader() {
    const readLine = require('readline').createInterface({
        input: process.stdin,
        output: process.stdout,
    });

    const input = [];
    return new Promise((resolve) => {
        readLine.on('close', () => resolve(input));
        readLine.on('line', (line) => input.push(line));
    });
}

/**
 *
 * @param {number} energy
 * @param {Array<number>} distances
 * @returns {number}
 */
function run(energy, distances) {
    const requiredEnergy = distances.reduce((sum, el) => sum + Number.parseInt(el), 0);
    const requiredRest = requiredEnergy - energy;
    return requiredRest < 0 ? 0 : requiredRest;
}

nodeJSReader().then(([
    testCount,
    ...data
]) => {
    for (let i = 0, ii = 0; i < testCount; i++, ii = i * 2) {
        const energy = data[ii].split(' ')[1];
        const distances = data[ii + 1].split(' ');

        console.log(run(energy, distances));
    }
});

'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++];
}

/**
 *
 * @param {number} m
 * @param {number[]} a
 */
function doOne(m, a) {
    let sum = a.reduce((t, c) => t + c);
    return Math.max(0, sum - m)
}

function main() {
  const n = Number(readline());
  for (let i = 0; i < n; i++) {
    const [n, m] = readline().split(' ').map(Number)
    const a = readline().split(' ').map(Number)
    console.log(doOne(m, a))
  }
}

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    const numberOfTestCases = parseInt(x);
    for(let i=0; i<numberOfTestCases; i++){
        const bench_energy = readline();
        const costBetweenBench = readline();
        var totalEnergyNeeded = 0;
        var [, energy] = bench_energy.split(' ').map(r=>parseInt(r));
        costBetweenBench.split(' ').forEach(r=>{
            const a = parseInt(r);
            totalEnergyNeeded +=a;
        });
        const result = totalEnergyNeeded-energy;
        foo(result > 0 ? String(result) : '0');
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}

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++];
}

/***
Educational Codeforces Round 125 (Div. 2)
2022-03-22

A. Integer Moves
***/

function main() {
  // INPUT: Number of test cases
  let t = readline();
  t = parseInt(t);
  for (let i = 0; i < t; i++) {
    // INPUT: n "spaces" between benches, m starting energy
    let s = readline();
    s = s.split(" ");
    s = s.map((k) => parseInt(k));

    const n = s[0];
    const m = s[1];

    // INPUT: space between benches
    let a = readline();
    a = a.split(" ");
    a = a.map((k) => parseInt(k));

    let sum = 0;
    a.forEach((k) => {
      sum += k;
    });

    console.log(Math.max(sum - m, 0));
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let nm = readline().split(" ").map(Number);
    let arr = readline().split(" ").map(Number);
    print(Runner(arr, nm[1]));
  }
}

function Runner(arr, m) {
  let energy = 0;
  for (let elem of arr) {
    if (elem > m) {
      // we neeed to store energy
      let diff = elem - m;
      energy += diff;
      m = 0;
    } else {
      m -= elem;
    }
  }
  return energy;
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var a = readline().split(' ');
        let sum = 0;
        for (let j = 0; j < n; j++) {
            a[j] = parseInt(a[j]);
            sum += a[j];
        }

        if (m >= sum) console.log(0);
        else console.log(sum-m);

    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    const [n, m] = readLine().split(" ").map(i => parseInt(i));
    let sum = readLine().split(" ").map(i=>parseInt(i)).reduce((a, c) => a + c, 0);
    return m >= sum ? 0 : sum - m;
}

'use strict';

async function solve(n, m, a) {
  const sum = a.reduce((a, b) => a + b, 0);
  return Math.max(0, sum - m);
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      res.push(await solve(n, m, 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);
  console.log(output);
});