Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it:   First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them.  Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it.

NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$.

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
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
function main() {
  var num = parseInt(readline())
	while(num--){
  var a = parseInt(readline())
  var line = readline().split(' ').map(Number)
  line.sort((a,b) => (a - b))
  var arr = line[0]
  var pre = 0
  for(let i = 0; i < line.length;i++){
    line[i]-= pre
    arr = (Math.max(arr, line[i]))
    pre += line[i]
  }
  print(arr)

}
}

'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 main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let n=Number(readline());
        let a = readline().split(' ').map(Number)
        a.sort((a, b) => a - b)
        let ans=a[0],pre=0;
        for(let i=0;i<n;i++)
        {
            a[i]-=pre;
            ans=Math.max(ans,a[i]);
            pre+=a[i];
        }
        console.log(ans);
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            var ans = k[0];
            if(n == 1){
                console.log(ans);
                continue;
            }
            for(j = 1; j < n; j++){
                var a = k[j] - k[j - 1];
                if(a > ans){
                    ans = a;
                }
            }
            console.log(ans);
        }
    }
});

const solve = (n,arr)=>{
     if(n===1){
          console.log(arr[0]);
          return;
     }
     arr.sort((a,b)=>a-b);
     let max = arr[0];
     for(let i=1;i<n;i++){
          let t  = arr[i] - arr[i-1];
          if(t>max) max = t;
     }
     console.log(max);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n  = parseInt(readline());
       let arr =  readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(n,arr);
  }
}
main();

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
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
function main() {
  let num = parseInt(readline());
  while (num--) {
    let a = parseInt(readline());
    let line = readline().split(" ").map(Number);
    line.sort((a, b) => a - b);
    let arr = line[0];
    let pre = 0;
    for (let i = 0; i < line.length; i++) {
      line[i] -= pre;
      arr = Math.max(arr, line[i]);
      pre += line[i];
    }
    print(arr);
  }
}

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));

const INF = 1e9;

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

		a.sort((x, y) => x - y);

		let ans = -INF;
		a.unshift(0);
		for (let i = 1; i <= n; i++) {
			ans = Math.max(ans, a[i] - a[i-1]);
		}

		console.log(ans);
	}
}

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--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([n], arr) {
    if (n === 1) {
        console.log(arr[0])
        return
    }
    arr.sort((a, b) => a - b)
    let max = 0
    for (let i = 0; i < n - 1; i++) {
        if (max < arr[i + 1] - arr[i]) {
            max = arr[i + 1] - arr[i]
        }
    }
    console.log((arr[0] < max) ? max : arr[0])
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])
}

'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 gcd(a, b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// let a=readline().split(' ').map(Number)
// a.sort((a,b)=>a-b)

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let n=Number(readline());
        let a = readline().split(' ').map(Number)
        a.sort((a, b) => a - b)
        let ans=a[0],pre=0;
        for(let i=0;i<n;i++)
        {
            a[i]-=pre;
            ans=Math.max(ans,a[i]);
            pre+=a[i];
        }
        console.log(ans);
    }
}

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
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
function main() {
  var num = parseInt(readline())
	while(num--){
  var a = parseInt(readline())
  var line = readline().split(' ').map(Number)
  line.sort((a,b) => (a - b))
  var set = new Set()
  var arr = []
  for(let i = 0;i < line.length;i++){
    set.add(line[i])
  }
  if(set.size == 1){
    print(line[0])
  }
  else{
    var t = line.length
    for(let i = 0; i < t;i++){
      arr.push(line[0])
      line.shift()
      for(let j = 0; j < line.length;j++){
        line[j] -= arr[i]
      }
    }
    print(Math.max(...arr))
  }
}
}

'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 main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let [x,n]=readline().split(' ').map(Number);
        if(n==0)
        {
            console.log(x);
            continue;
        }
        let i = 1;
        let ans=0;
        if(n%4==1)
            ans=-n;
        else if(n%4==2)
            ans=1;
        else if(n%4==3)
            ans=n+1;
        if(Math.abs(x)%2==1)
            ans=-ans;
        console.log(ans+x);
    }
}


In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.

First line of input contains single integer number n (2 ≤ n ≤ 100 000)  — number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≤ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.

Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.

NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.

'use strict';

function create2DArray(rows) {
    let a = [];
    for (let i = 0; i < rows; i++) {
	a[i] = [];
    }
    return a;
}

function bfs(adj) {
    let q = [[1, 0]];
    let counts = new Array(adj.length);
    counts.fill(0);
    counts[0] = 1;

    while (q.length > 0) {
	let u_level= q.shift();
	let u = u_level[0];
	let level = u_level[1];

	for (let i = 0; i < adj[u].length; i++) {
	    let v = adj[u][i];
	    q.push([v, level+1]);
	    counts[level+1] += 1;
	}
    }

    let result = 0;

    for (let i = 0; i < counts.length; i++) {
	if (counts[i] % 2 != 0) result++;
    }

    return result;
}

//let readline = () => input.pop();
//let print = console.log;

// Starting from here we can copy and paste into Codeforces.
let n = parseInt(readline());
let edges = readline().split(' ');
let adj = create2DArray(n+2);

for (let i = 0; i < edges.length; i++) {
    let to = i+2;
    let from = edges[i];
    adj[from].push(to);
}

print(bfs(adj));


You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.More precisely, you want to spam the emote triangle of size $$$k$$$. It consists of $$$2k-1$$$ messages. The first message consists of one emote, the second one — of two emotes, ..., the $$$k$$$-th one — of $$$k$$$ emotes, the $$$k+1$$$-th one — of $$$k-1$$$ emotes, ..., and the last one — of one emote.For example, the emote triangle for $$$k=3$$$ consists of $$$5$$$ messages:  Of course, most of the channels have auto moderation. Auto moderator of the current chat will ban you right after you spam at least $$$x$$$ emotes in succession (you can assume you are the only user in the chat). Now you are interested — how many messages will you write before getting banned? Or maybe you will not get banned at all (i.e. will write all $$$2k-1$$$ messages and complete your emote triangle successfully)? Note that if you get banned as a result of writing a message, this message is also counted.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains integers $$$k$$$ and $$$x$$$ ($$$1 \le k \le 10^9; 1 \le x \le 10^{18}$$$).

For each test case, print the number of messages you will write before getting banned for the corresponding values $$$k$$$ and $$$x$$$.

NoteLet's analyze the test cases of the example.  In the first test case, you write three messages containing $$$1$$$, $$$2$$$ and $$$3$$$ emotes respectively, and since $$$1 + 2 + 3 \ge 6$$$, you get banned after that.  In the second test case, you write four messages containing $$$1$$$, $$$2$$$, $$$3$$$ and $$$4$$$ emotes respectively, and since $$$1 + 2 + 3 + 4 \ge 7$$$, you get banned after that.  In the third test case, you write one message containing exactly $$$1$$$ emote. It doesn't get you banned, since $$$1 < 2$$$, but you have already finished posting your emote triangle. So you wrote one message successfully.  In the fourth test case, you write four messages containing $$$1$$$, $$$2$$$, $$$3$$$ and $$$2$$$ emotes respectively, and since $$$1 + 2 + 3 + 2 \ge 7$$$, you get banned after that.  In the fifth test case, you write three messages containing $$$1$$$, $$$2$$$ and $$$1$$$ emote respectively. It doesn't get you banned, since $$$1 + 2 + 1 < 5$$$, but you have already finished posting your emote triangle. So you wrote three messages successfully.  In the sixth test case, since $$$x = 1$$$, you get banned as soon as you send your first message.  The seventh test case is too large to analyze, so we'll skip it.

'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 foo(x) {

    console.log(x);
}

function find_count(K,y){
 if(y<=K){
  return y*(y+1n)/2n;
 }
 else{
  return find_count(K,K)*2n-K-find_count(K,2n*K-1n-y);
 }
}

function lower_bound(K, x){
  let low=0n;
  let high=2n*K-1n;
  while(low<high){

    let mid = (high+low)/2n
    if(find_count(K,mid)<x){
      low = mid+1n;
    }
    else{
      high=mid;
    }
  }
  return low.toString();
}

function main() {
    const t = parseInt(readline());
    var inp;
    for (var i = 0; i<t; i++){
        inp = readline().split(" ");
        var k = BigInt(inp[0]);
        var x = BigInt(inp[1]);
        var ans = lower_bound(k,x);
        foo(ans);
    }
}

"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());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
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 sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const bs = (n, val) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    let to = (mid * (mid + 1n)) / 2n;
    if (to === val) return mid;
    else if (to < val) low = mid + 1n;
    else {
      ans = mid;
      high = mid - 1n;
    }
  }
  return ans;
};
const bs1 = (n, val) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    let to = (n * (n + 1n)) / 2n - (mid * (mid - 1n)) / 2n;
    if (to === val) return n - mid + 1n;
    else if (to < val) high = mid - 1n;
    else {
      ans = n - mid + 1n;
      low = mid + 1n;
    }
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, x] = BInpArr();
    let total = n * (n + 1n) - n;
    if (x >= total) console.log(2n * n - 1n + "");
    else {
      let to = (n * (n + 1n)) / 2n;
      if (x < to) {
        console.log(bs(n, x) + "");
      } else if (x > to) {
        console.log(n + bs1(n - 1n, x - to) + "");
      } else console.log(n + "");
    }
  }
};
solve();

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 => BigInt(x));

const nsum = n => n*(n+1n)/2n;

function main () {
	let T = rn();
	while (T--) {
		let [k, x] = rna();

		function bs (x, l, r) {
			let mid;
			while (l < r) {
				mid = (l + r) >> 1n;
				if (x > nsum(mid)) {
					l = mid + 1n;
				} else {
					r = mid;
				}
			}
			return l;
		}

		let ans;
		if (x <= nsum(k)) {
			ans = bs(x, 1n, k);
		} else {
			x = x - nsum(k);
			x = nsum(k - 1n) - x + 1n;
			ans = 2n * k - 1n - (bs(x, 1n, k - 1n) - 1n);
		}

		console.log(Number(ans));
	}
}

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 => BigInt(x));

function main () {
	let T = rn();
	while (T--) {
		const [k, x] = rna();

		function bs (x, l, r) {
			let mid;
			while (l < r) {
				mid = (l + r) >> 1n;
				if (x > mid * (mid + 1n)/2n) {
					l = mid + 1n;
				} else {
					r = mid;
				}
			}
			return l;
		}

		let ans;
		if (x <= k*(k+1n)/2n) {
			//console.log('case 1');
			ans = bs(x, 1n, k);
		} else {
			lftx = x - k*(k+1n)/2n;
			lftx = k*(k-1n)/2n - lftx + 1n;
			ans = 2n*k - 1n - (bs(lftx, 1n, k - 1n) - 1n);
		}

		console.log(Number(ans));
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [k, x] = lines[l++].trim().split(' ').map(BigInt)
        output[i] = solve(k, x)
    }
    console.log(output.join('\n'))
// })()
})

function solve(k, limit) {
    const cal = x => {
        if (x <= k) {
            return x * (x + 1n) / 2n
        } else {
            const base = k * (k + 1n) / 2n
            return base + (k - 1n + k - 1n - (x - k - 1n)) * (x - k) / 2n
        }
    }
    const count = binarySearch(0n, 2n * k - 1n, x => cal(x) <= limit)
    return cal(count) === limit ? count : min(2n * k - 1n, count + 1n)
}
function min(a, b) {
    return a < b ? a : b
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = ((l + r) / 2n)
        // const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1n
        } else {
            r = m - 1n
        }
    }
    return r
}

'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();
    });

    something();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function something() {
    const x = parseInt(readline());
    foo(x);
    for (var i=0; i<x; i++){
        var line2 = readline();
        foo(line2);
    }
}
function foo(x) {
    process.stdout.write("hello: ");   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

'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 = parseInt(readline());
    foo(x);
    for (var i=0; i<x; i++){
        var line2 = readline();
        foo(line2);
    }
}
function foo(x) {
    process.stdout.write("hello: ");   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function find_count(K, y) {
  if (y <= K) {
    return (y * (y + 1n)) / 2n;
  } else {
    return find_count(K, K) * 2n - K - find_count(K, 2n * K - 1n - y);
  }
}

function lower_bound(K, x) {
  let low = 0n;
  let high = 2n * K - 1n;
  while (low < high) {
    let mid = (high + low) / 2n;
    if (find_count(K, mid) < x) {
      low = mid + 1n;
    } else {
      high = mid;
    }
  }
  return low.toString();
}
console.log(lower_bound(BigInt("4"), BigInt("6")));

"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());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
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 sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const bs = (n, val) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    let to = (mid * (mid + 1n)) / 2n;
    if (to === val) return mid;
    else if (to < val) low = mid + 1n;
    else {
      ans = mid;
      high = mid - 1n;
    }
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, x] = BInpArr();
    let total = n * (n + 1n) - n;
    if (x >= total) console.log(2n * n - 1n + "");
    else {
      let to = (n * (n + 1n)) / 2n;
      if (x < to) {
        console.log(bs(n, x) + "");
      } else if (x > to) {
        console.log(n + bs(n - 1n, x - to) + "");
      } else console.log(n + "");
    }
  }
};
solve();

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 [k, x] = rna();

		function bs (x, l, r) {
			let mid;
			while (l < r) {
				mid = (l + r) >> 1;
				if (x > mid * (mid + 1)/2) {
					l = mid + 1;
				} else {
					r = mid;
				}
			}
			return l;
		}

		let ans;
		if (x <= k*(k+1)/2) {
			//console.log('case 1');
			ans = bs(x, 1, k);
		} else {
			lftx = x - k*(k+1)/2;
			lftx = k*(k-1)/2 - lftx + 1;
			ans = 2*k - 1 - (bs(lftx, 1, k - 1) - 1);
		}

		console.log(ans);
	}
}


Slavic has an array of length $$$n$$$ consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array. What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to $$$s$$$ after performing all the operations? In case the sum $$$s$$$ can't be obtained after any amount of operations, you should output -1.

The 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 two integers $$$n$$$ and $$$s$$$ ($$$1 \leq n, s \leq 2 \cdot 10^5$$$) — the length of the array and the needed sum of elements. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 1$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to $$$s$$$, or -1 if obtaining an array with sum $$$s$$$ isn't possible.

NoteIn the first test case, the sum of the whole array is $$$1$$$ from the beginning, so we don't have to make any operations.In the second test case, the sum of the array is $$$2$$$ and we want it to be equal to $$$1$$$, so we should remove the first element. The array turns into $$$[1, 0]$$$, which has a sum equal to $$$1$$$.In the third test case, the sum of the array is $$$5$$$ and we need it to be $$$3$$$. We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into $$$[0, 1, 1, 1, 0, 0]$$$, which has a sum equal to $$$3$$$.

//runcommand Get-Content input.txt | node template.js > output.txt or Ctrl+Shift+B
// //libraries
// const heap = require("@datastructures-js/priority-queue");
// const accelerate = require("lodash");
// const linkedlist = require("@datastructures-js/linked-list");
// const { max } = require("lodash");
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 q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let ns = readline().split(" ").map(Number);
    let a = readline().split(" ").map(Number);
    print(Detoperations(a, ns[1]));
  }
}

function Detoperations(arr, sum) {
  let n = arr.length;
  let op = 1e20;
  let s = 0;
  let i = 0;
  let j = 0;
  while (i < n && j < n) {
    s += arr[j];
    if (s > sum) op = Math.min(op, n - (j - i));
    while (s > sum) s -= arr[i++];
    j++;
  }
  if (s == sum) op = Math.min(op, n - (j - i));
  if (op == 1e20) return -1;
  return op;
}

function solve() {
  const [a, b] = cl().split(' ').map((item) => Number(item));
  const arr = cl().split(' ').map((item) => Number(item));

  let len = 0;

  let r = 0, total = 0;
  for (let i = 0; i < a; i++) {
    if (i > 0) {
      total -= arr[i - 1];
    }
    while (r < a && total + arr[r] <= b) {
      total += arr[r++];
    }
    if (total === b) len = Math.max(r - i, len);
  }

  co(len > 0 ? a - len : -1);

}
function Solution() {
  let n = Number(cl());
  while (n--) {
    solve();
  }
}

function cl() {
  return lines.shift();
}

function co(str) {
  console.log(str);
}

const lines = []

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', Solution);

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let sum = 0;
    for (let i = 0; i < n; i++) sum += arr[i];
    if (sum < k) console.log(-1);
    else {
      let sum1 = 0,
        l = 0,
        r = 0,
        res = Infinity;
      while (r < n) {
        sum1 += arr[r];
        if (sum1 > k) {
          while (l <= r && arr[l] !== 1) l++;
          l++;
          sum1 -= 1;
          Math.min(res, n - (r - l + 1));
        } else res = Math.min(res, n - (r - l + 1));
        r++;
      }
      console.log(res);
    }
  }
};
solve();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var [n,s] = readline().split(' ').map((x) => parseInt(x));
  var a = readline().split(' ').map((x) => parseInt(x));
  var pref = []
  pref[0] = 0;
  var inf = 1000000000;
  var ans = -1;
  for(var i=1;i<=n;i++) pref[i] = pref[i-1]+a[i-1]
  var L = 0, R = n;
  while(L <= R) {
    var mid = L + Math.floor((R-L)/2);
    var val = ok(mid);
    if(val <= s) {
      if(val == s) ans = max(ans, mid)
      L = mid+1
    }
    else R = mid-1;
  }
  function ok(x) {
    var mx = -1;
    for(var i=0;i+x<=n;i++) {
      var sum = pref[i+x]-pref[i];
      if(sum == s) return s
      mx = max(mx, sum)
    }
    return mx;
  }
  if(ans != -1) ans = n-ans;
  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

'use strict';

function solve(n, m, a) {
  const sum = new Array(n);
  const map = new Map();
  map.set(m, -1);
  let res = Infinity;
  for (let [i, num] of a.entries()) {
    var _sum;
    sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + num;
  }
  for (let i = 0; i < n; i++) {
    if (map.has(sum[i])) {
      res = Math.min(res, n - (i - map.get(sum[i])));
    }
    const t = sum[i] + m;
    if (!map.has(t)) map.set(t, i);
  }
  return res === Infinity ? -1 : res;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      res[i] = 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);
  process.stdout.write(output);
});

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    const sum = []
    for (let i = 0; i < arr.length; i++) {
        sum[i] = arr[i]
        if (i) sum[i] += sum[i - 1]
    }
    if (sum[n - 1] < k) return -1
    let max = 0
    for (let i = 0; i < arr.length; i++) {
        const j = binarySearch(i, n - 1, x => sum[x] - (sum[i - 1] || 0) <= k)
        max = Math.max(max, j - i + 1)
    }
// console.log(sum)
    return n - max
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

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 q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let ns = readline().split(" ").map(Number);
    let arr = readline().split(" ").map(Number);
    print(Minop(arr, ns[1]));
  }
}

function Minop(arr, sum) {
  let s = 0;
  let op = 0;
  let i = 0;
  let j = arr.length - 1;
  for (let item of arr) s += item;
  if (sum == s) return 0;
  if (sum > s) return -1;
  while (i <= j) {
    if (arr[i] == 1) {
      i++;
      op++;
      s--;
    } else if (arr[j] == 1) {
      j--;
      op++;
      s--;
    } else {
      let temp1 = i;
      let temp2 = j;
      while (i < arr.length && arr[i] !== 1) i++;
      while (j >= 0 && arr[j] !== 1) j--;
      let dis1 = i - temp1;
      let dis2 = temp2 - j;
      if (dis1 < dis2) {
        op += i - temp1;
        j = temp2;
      } else {
        op += temp2 - j;
        i = temp1;
      }
    }
    if (s == sum) return op;
  }
}

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 q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let ns = readline().split(" ").map(Number);
    let arr = readline().split(" ").map(Number);
    print(Minop(arr, ns[1]));
  }
}

function Minop(arr, sum) {
  let s = 0;
  let op = 0;
  let i = 0;
  let j = arr.length - 1;
  let rec1 = 1e9;
  let rec2 = 1e9;
  let pre = [];
  let suff = [];
  for (let k = 0; k < arr.length; k++) {
    if (arr[k] == 1) {
      s++;
      rec1 = k;
    }
    if (arr[arr.length - k - 1] == 1) rec2 = arr.length - k - 1;
    if (arr[k] == 0) pre[k] = rec1 == 1e9 ? rec1 : k - rec1;
    if (arr[arr.length - k - 1] == 0) suff[arr.length - k - 1] = rec2 == 1e9 ? rec2 : rec2 - (arr.length - k - 1);
  }
  if (sum == s) return 0;
  if (sum > s) return -1;
  while (i <= j) {
    if (arr[i] == 1) {
      i++;
      op++;
      s--;
    } else if (arr[j] == 1) {
      j--;
      op++;
      s--;
    } else {
      if (pre[j] < suff[i]) j--;
      else i++;
      op++;
    }
    if (s == sum) return op;
  }
}

function solve() {
  const [a, b] = cl().split(' ').map((item) => Number(item));
  const arr = cl().split(' ').map((item) => Number(item));
  let total = arr.reduce((pre, curr) => pre + curr);

  if (total < b) return co(-1);
  const arr1= new Array(a).fill(0);
  let target = Infinity;
  for (let i = a - 1; i >= 0; i--) {
    if (arr[i] === 1) target = i;
    arr1[i] = target;
  }

  const arr2 = new Array(a).fill(0);
  target = Infinity;
  for (let i = 0; i < a; i++) {
    if (arr[i] === 1) target = a - i - 1;
    arr2[i] = target;
  }

  let l = 0, r = a - 1;
  while (total > b) {
    if (arr[l] === 1) {
      l += 1;
      total -= 1;
    }
    else if (arr[r] === 1) {
      r -= 1;
      total -= 1;
    }
    else {
      if (arr1[l] <= arr2[r]) {
        l += 1;
      } else {
        r -= 1;
      }
    }
  }

  co(l + arr.length - 1 - r);
}
function Solution() {
  let n = Number(cl());
  while (n--) {
    solve();
  }
}

function cl() {
  return lines.shift();
}

function co(str) {
  console.log(str);
}

const lines = []

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', Solution);

function solve() {
  const [_, b] = cl().split(' ').map((item) => Number(item));
  const arr = cl().split(' ').map((item) => Number(item));
  let total = arr.reduce((pre, curr) => pre + curr);

  if (total < b) return co(-1);

  let l = 0, r = arr.length - 1;
  let lastL = 0, lastR = arr.length - 1;
  while (total > b) {
    if (arr[l] === 1) {
      r = lastR;
      l += 1;
      lastL = l;
      total -= 1;
    } else if (arr[r] === 1) {
      l = lastL;
      r -= 1;
      lastR = r;
      total -= 1;
    } else {
      l += 1;
      r -= 1;
    }
  }
  co(l + arr.length - 1 - r);
}
function Solution() {
  let n = Number(cl());
  while (n--) {
    solve();
  }
}

function cl() {
  return lines.shift();
}

function co(str) {
  console.log(str);
}

const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
const lines = []
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', Solution);

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let sum = 0;
    for (let i = 0; i < n; i++) sum += arr[i];
    if (sum < k) console.log(-1);
    else if (sum === k) console.log(0);
    else {
      let i,
        j,
        cnt = 0;
      for (i = 0; i < n; i++) {
        if (sum === k) break;
        if (arr[i] === 0) break;
        sum--;
        cnt++;
      }
      if (sum === k) {
        console.log(cnt);
        continue;
      }
      for (j = n - 1; j >= 0; j--) {
        if (sum === k) break;
        if (arr[j] === 0) break;
        sum--;
        cnt++;
      }
      if (sum === k) {
        console.log(cnt);
        continue;
      }
      let cnt1 = 0,
        cnt2 = 0,
        s1 = sum,
        s2 = sum;
      while (i < n) {
        if (s1 === k) break;
        if (arr[i] === 1) s1--;
        cnt1++;
        i++;
      }
      while (j >= 0) {
        if (s2 === k) break;
        if (arr[j] === 1) s2--;
        j--;
        cnt2++;
      }
      console.log(cnt + Math.min(cnt1, cnt2));
    }
  }
};
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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let sum = 0;
    for (let i = 0; i < n; i++) sum += arr[i];
    if (sum < k) console.log(-1);
    else if (sum === k) console.log(0);
    else {
      let left = [],
        right = [];
      for (let i = 0; i < n; i++) {
        if (arr[i] === 1) left[i] = 0;
        else {
          let cnt = 0;
          for (let j = i; j < n; j++) {
            if (arr[j] === 1) break;
            else cnt++;
          }
          left[i] = cnt;
        }
      }
      for (let i = n - 1; i >= 0; i--) {
        if (arr[i] === 1) right[i] = 0;
        else {
          let cnt = 0;
          for (let j = i; j >= 0; j--) {
            if (arr[j] === 1) break;
            else cnt++;
          }
          right[i] = cnt;
        }
      }
      let i = 0,
        j = n - 1,
        cnt = 0;
      while (cnt < n) {
        if (sum === k) break;
        if (arr[i] === 1) {
          sum--;
          i++;
        } else if (arr[j] === 1) {
          j--;
          sum--;
        } else {
          if (left[i] < right[j]) i++;
          else j--;
        }
        cnt++;
      }
      console.log(cnt);
    }
  }
};
solve();


There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns.   You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.  Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) — the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster.

Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

    'use strict'

    const params = readline().split(' ').map(num => parseInt(num))
    const arr = readline().split(' ').map(num => parseInt(num))

    const a = params[1]
    const b = params[2]
    let k = params[3]

    const all = Array(params[0]).fill(0)
    for (let i in arr) {
      let val = parseInt(arr[i] %  (a + b))

      if (val === 0) {
        val += b
      } else {
        val = Math.max(0, val - a)
      }
      all[i] = parseInt(Math.ceil(val / a))
    }

    all.sort((a, b) => a - b)

    let ans = 0
    for (let i in all) {
      if (k - all[i] < 0) break
      ans ++
      k -= all[i]
    }

    print(ans)

'use strict'

const problem = (n, a, b, k, h) => {
    let d = {};
    let res = 0;
    for (let i = 0; i < n; i++) {
        const hp = (h[i] - 1) % (a+b) + 1 - a;
        if (hp > 0) {
            if (d[hp]) d[hp]++;
            else d[hp] = 1;
        } else {
            res++;
        }
    }

    const monsters = Object.keys(d).sort((x, y) => x-y);
    for (let i = 0; i < monsters.length; i++) {
        const hp = monsters[i];
        const cnt = d[hp];
        const hits = (hp / a | 0) + ((hp % a) ? 1 : 0);
        if (k < cnt * hits) return res + k / hits | 0;
        res += cnt;
        k -= cnt * hits;
    }
    return res;
}

const nabk = readline().split(' ').map(i => +i);
const h = readline().split(' ').map(i => +i);
print(problem(nabk[0], nabk[1], nabk[2], nabk[3], h))

const processData = (lines) => {
  const [n, a, b, k] = lines[0].split(' ').map(x => +x)
  const hps = lines[1].split(' ').map(x => +x)

  const notSoEasyKill = []

  let exp = 0

  const totalDamage = a + b

  for (let i = 0; i<hps.length; i++) {
    const hp = hps[i]
    let leftHp = hp%totalDamage
    if (leftHp === 0) {
      leftHp = totalDamage
    }
    if (leftHp <= a) {
      exp++
    } else {
      notSoEasyKill.push(leftHp - a)
    }
  }

  let leftSkills = k

  const lefts = notSoEasyKill
    .reduce((r, x) => {const key = Math.ceil(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})

  const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)
  let i = 0
  while (leftSkills > 0 && i < keys.length) {
    const key = keys[i]
    const left = lefts[key]
    if (left * key > leftSkills) {
      exp += Math.floor(leftSkills / key)
      leftSkills = 0
    } else {
      leftSkills -= left * key
      exp += left
    }
    i++
  }

  console.log(exp)
}

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)
})

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

const input = [];
readline.on('line', x => input.push(x));

readline.on('close', () => {
    let [n, a, b, k] = input[0].split(' ').map(x => parseInt(x));

    scores = 0;
    let helps = [];
    const monsters = input[1].split(' ').map(
        x => {
            x = parseInt(x);
            let hp = x - a;
            let sum_power = b + a;
            let last_hit_hp = hp - sum_power * Math.trunc(hp / sum_power);

            if (last_hit_hp <= b) helps.push(Math.ceil(last_hit_hp / a));
            else scores++;

            return x;
        }
    );

    helps.sort((a, b) => a - b);
    for (let i = 0; i < helps.length; i++) {
        k -= helps[i];
        if (k >= 0) scores++;
        else break;
    }

    console.log(scores);
});

'use strict'

const params = readline().split(' ').map(num => parseInt(num))
const arr = readline().split(' ').map(num => parseInt(num))

const a = params[1]
const b = params[2]
let k = params[3]

const all = Array(params[0]).fill(0)
for (let i in arr) {
  let val = parseInt(arr[i] %  (a + b))

  if (val === 0) {
    val += b
  } else {
    val = Math.max(0, val - a)
  }
  all[i] = parseInt(Math.ceil(val / a))
}

all.sort()

let ans = 0
for (let i in all) {
  if (k - all[i] < 0) break
  ans ++
  k -= all[i]
}

print(ans)

const processData = (lines) => {
  const [n, a, b, k] = lines[0].split(' ').map(x => +x)
  const hps = lines[1].split(' ').map(x => +x)

  const notSoEasyKill = []

  let exp = 0

  const totalDamage = a + b

  for (let i = 0; i<hps.length; i++) {
    const hp = hps[i]
    let leftHp = hp%totalDamage
    if (leftHp === 0) {
      leftHp = totalDamage
    }
    if (leftHp <= a) {
      exp++
    } else {
      notSoEasyKill.push(leftHp)
    }
  }

  let leftSkills = k

  const lefts = notSoEasyKill
    .reduce((r, x) => {const key = Math.floor(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})

  const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)
  let i = 0
  while (leftSkills > 0 && i < keys.length) {
    const key = keys[i]
    const left = lefts[key]
    if (left * key > leftSkills) {
      exp += Math.ceil(leftSkills / key)
      leftSkills = 0
    } else {
      leftSkills -= left * key
      exp += left
    }
    i++
  }

  console.log(exp)
}

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)
})

const processData = (lines) => {
  const [n, a, b, k] = lines[0].split(' ').map(x => +x)
  const hps = lines[1].split(' ').map(x => +x)

  const notSoEasyKill = []

  let exp = 0

  const totalDamage = a + b

  for (let i = 0; i<hps.length; i++) {
    const hp = hps[i]
    let leftHp = hp%totalDamage
    if (leftHp === 0) {
      leftHp = totalDamage
    }
    if (leftHp <= a) {
      exp++
    } else {
      notSoEasyKill.push(leftHp - a)
    }
  }

  let leftSkills = k

  const lefts = notSoEasyKill
    .reduce((r, x) => {const key = Math.ceil(x/a); r[key] = r[key] ? r[key] + 1 : 1; return r;}, {})

  const keys = Object.keys(lefts).map(x => +x).sort((a, b) => a - b)
  let i = 0
  while (leftSkills > 0 && i < keys.length) {
    const key = keys[i]
    const left = lefts[key]
    if (left * key > leftSkills) {
      exp += Math.ceil(leftSkills / key)
      leftSkills = 0
    } else {
      leftSkills -= left * key
      exp += left
    }
    i++
  }

  console.log(exp)
}

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)
})


Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of $$$n$$$ heroes, the strength of the $$$i$$$-th hero is equal to $$$a_i$$$.According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon's defense is equal to $$$x$$$, then you have to send a hero with a strength of at least $$$x$$$ to kill it. If the dragon's attack power is $$$y$$$, then the total strength of the heroes defending the castle should be at least $$$y$$$.The player can increase the strength of any hero by $$$1$$$ for one gold coin. This operation can be done any number of times.There are $$$m$$$ dragons in the game, the $$$i$$$-th of them has defense equal to $$$x_i$$$ and attack power equal to $$$y_i$$$. Petya was wondering what is the minimum number of coins he needs to spend to defeat the $$$i$$$-th dragon.Note that the task is solved independently for each dragon (improvements are not saved).

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — number of heroes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th hero. The third line contains a single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of dragons. The next $$$m$$$ lines contain two integers each, $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le 10^{12}; 1 \le y_i \le 10^{18}$$$) — defense and attack power of the $$$i$$$-th dragon.

Print $$$m$$$ lines, $$$i$$$-th of which contains a single integer — the minimum number of coins that should be spent to defeat the $$$i$$$-th dragon.

NoteTo defeat the first dragon, you can increase the strength of the third hero by $$$1$$$, then the strength of the heroes will be equal to $$$[3, 6, 3, 3]$$$. To kill the dragon, you can choose the first hero.To defeat the second dragon, you can increase the forces of the second and third heroes by $$$1$$$, then the strength of the heroes will be equal to $$$[3, 7, 3, 3]$$$. To kill the dragon, you can choose a second hero.To defeat the third dragon, you can increase the strength of all the heroes by $$$1$$$, then the strength of the heroes will be equal to $$$[4, 7, 3, 4]$$$. To kill the dragon, you can choose a fourth hero.To defeat the fourth dragon, you don't need to improve the heroes and choose a third hero to kill the dragon.To defeat the fifth dragon, you can increase the strength of the second hero by $$$2$$$, then the strength of the heroes will be equal to $$$[3, 8, 2, 3]$$$. To kill the dragon, you can choose a second hero.

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

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const rbn = () => BigInt(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));
const rbna = () => ra().map(x => BigInt(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const INF = 2e18;

// same as cpp bound functions
// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found
// upperBound(ar, x) - first element > x, return ar.length if no such element is found
function lowerBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] >= x) {
			r = mid;
		} else {
			l = mid;
		}
	}
	return ar[l] >= x ? l : r;
}

function upperBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] <= x) {
			l = mid + 1;
		} else {
			r = mid;
		}
	}
	return a[l] > x ? l : r;
}

const max = (a, b) => a > b ? a : b;
const min = (a, b) => a < b ? a : b;
const B = a => BigInt(a);

function main () {
	const n = rn();
	const a = rna();
	const m = rn();

	let powerSum = 0n;
	for (let i = 0; i < n; i++) powerSum += B(a[i]);
	a.sort((x, y) => x - y);

	for (let i = 0; i < m; i++) {
		let [x, y] = rbna(); x = Number(x);

		let option1 = INF, option2 = INF;
		const j = lowerBound(a, x);
		if (j < n) option1 = max(0n, y - (powerSum - B(a[j])));
		if (j > 0) option2 = B(x) - B(a[j-1]) + max(0n, y - (powerSum - B(a[j-1])));

		console.log(min(option1, option2).toString());
	}
}

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

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const rbn = () => BigInt(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));
const rbna = () => ra().map(x => BigInt(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const INF = 2e18;

// same as cpp bound functions
// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found
// upperBound(ar, x) - first element > x, return ar.length if no such element is found
function lowerBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] >= x) {
			r = mid;
		} else {
			l = mid;
		}
	}
	return ar[l] >= x ? l : r;
}

function upperBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] <= x) {
			l = mid + 1;
		} else {
			r = mid;
		}
	}
	return a[l] > x ? l : r;
}

const max = (a, b) => a > b ? a : b;
const min = (a, b) => a < b ? a : b;
const B = a => BigInt(a);

function main () {
	const n = rn();
	const a = rna();
	const m = rn();
	const x = [], y = [];
	for (let i = 0; i < m; i++) [x[i], y[i]] = rbna();
	for (let i = 0; i < m; i++) x[i] = Number(x[i]);

	let powerSum = 0n;
	for (let i = 0; i < n; i++) powerSum += B(a[i]);
	a.sort((x, y) => x - y);

	for (let i = 0; i < m; i++) {
		const lb = lowerBound(a, x[i]);
		let option1 = INF, option2 = INF;
		if (lb < n) option1 = max(0n, y[i] - (powerSum - B(a[lb])));
		if (lb > 0) option2 = B(x[i]) - B(a[lb-1]) + max(0n, y[i] - (powerSum - B(a[lb-1])));

		console.log(min(option1, option2).toString());
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const INF = 2e18;

// same as cpp bound functions
// lowerBound(ar, x) - first element >= x, return ar.length if no such element is found
// upperBound(ar, x) - first element > x, return ar.length if no such element is found
function lowerBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] >= x) {
			r = mid;
		} else {
			l = mid;
		}
	}
	return ar[l] >= x ? l : r;
}

function upperBound (ar, x) {
	let l = 0, r = ar.length;
	while (r-l > 1) {
		const mid = l+r >> 1;
		if (ar[mid] <= x) {
			l = mid + 1;
		} else {
			r = mid;
		}
	}
	return a[l] > x ? l : r;
}

const max = (a, b) => a > b ? a : b;
const min = (a, b) => a < b ? a : b;

function main () {
	const n = rn();
	const a = rna();
	const m = rn();
	const x = [], y = [];
	for (let i = 0; i < m; i++) [x[i], y[i]] = rna();

	let powerSum = 0n;
	for (let i = 0; i < n; i++) powerSum += a[i];

	for (let i = 0; i < n; i++) a[i] = Number(a[i]);
	a.sort((x, y) => x - y);
	//for (let i = 0; i < n; i++) a[i] = BigInt(a[i]);

	for (let i = 0; i < m; i++) x[i] = Number(x[i]);

	for (let i = 0; i < m; i++) {
		const lb = lowerBound(a, x[i]);
		let option1 = INF, option2 = INF;
		if (lb < n) option1 = max(0n, y[i] - (powerSum - BigInt(a[lb])));
		if (lb > 0) option2 = BigInt(x[i] - a[lb-1]) + max(0n, y[i] - (powerSum - BigInt(a[lb-1])));

		console.log(min(option1, option2).toString());
	}
}

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 lowerBound(arr, x) {
	for (let i = 1; i < arr.length; i++)
		if (x < arr[i]) return i - 1;
	return arr.length - 1;
}

const INF = Number.POSITIVE_INFINITY;

function main () {
	let n = rn();
	let a = rna();
	let m = rn();

	a.sort((x, y) => x - y);

	let sm = 0;
	for (elm of a) sm +=elm;

	while (m--) {
		let [x, y] = rna();

		const l = lowerBound(a, x);
		ansl = Math.max(0, y - (sm - a[l])) + Math.max(0, x - a[l]);
		ansr =  l + 1 < n ? Math.max(0, y - (sm - a[l+1])) : INF;
		const ans = Math.min(ansl, ansr);

		console.log(ans);
	}
}

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 n = rn();
	let a = rna();
	let m = rn();
	let x = [], y = [];
	for (let i = 0; i < m; i++)
		[x[i], y[i]] = rna();

	a.sort((x, y) => x - y);

	let sm = 0;
	for (elm of a) sm +=elm;

	for (let i = 0; i < m; i++) {
		let ans = 0;
		if (x[i] <= a[0]) {
			ans = Math.max(y[i] - (sm - a[0]), 0);
		} else if (x[i] >= a[n-1]) {
			ans = Math.max(y[i] - (sm - a[n-1]), 0) + x[i] - a[n-1];
		} else {
			for (let j = 0; j < n; j++) {
				if (x[i] >= a[j] && x[i] < a[j+1]) {
					ans1 = Math.max(y[i] - (sm - a[j+1]), 0); // select higher powered soldier
					ans2 = Math.max(y[i] - (sm - a[j]), 0) + x[i] - a[j]; // select lower ...
					ans = Math.min(ans1, ans2);
					break;
				}
			}
		}
		console.log(ans);
	}
}


Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 5)$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains 2 integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^4$$$) — the number of elements in the array $$$a$$$ and the number that Ehab hates. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

For each testcase, print the length of the longest subarray whose sum isn't divisible by $$$x$$$. If there's no such subarray, print $$$-1$$$.

NoteIn the first test case, the subarray $$$[2,3]$$$ has sum of elements $$$5$$$, which isn't divisible by $$$3$$$.In the second test case, the sum of elements of the whole array is $$$6$$$, which isn't divisible by $$$4$$$.In the third test case, all subarrays have an even sum, so the answer is $$$-1$$$.

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var lines = input.split('\n');
    var tests = parseInt(lines.shift(), 10);
    var _loop_1 = function () {
        var nx = lineToNumArray(lines.shift());
        var n = nx[0], x = nx[1];
        var arr = lineToNumArray(lines.shift());
        var distFromBegin = arr.findIndex(function (element) { return element % x !== 0; });
        var distFromEnd = arr.reverse().findIndex(function (element) { return element % x !== 0; });
        if (distFromBegin === -1) {
            console.log(-1);
        }
        else {
            var sum = arr.reduce(function (a, b) { return a + b; }, 0);
            console.log(sum % x !== 0 ?
                n :
                n - Math.min(distFromBegin, distFromEnd) - 1);
        }
    };
    while (tests--) {
        _loop_1();
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

var na = readline();
var maxa = [];
var inp = [];
for (var i = 0;i<na;i++){
    maxa.push(parseInt(readline().split(" ")[1]));
    inp.push(readline().split(" ").map(function (a) {
        return parseInt(a);
    }));
}
for (var j = 0;j<na;j++) {
    var n = inp[j].length, x = maxa[j], sum = 0, l = -1, r=0;
    for (var i = 0; i < n; i++) {
        var a = inp[j][i];
        if (a % x) {
            if (l === -1)
                l = i;
            r = i;
        }
        sum += a;
    }
    if (sum % x) {
        write(n + "\n");

    } else if (l === -1) {
        write("-1\n");
    } else {
        write(n - ((l + 1 < n - r) ? l + 1 : n - r) + "\n");
    }
}

// var lineIdx = 0;
// var readline = () => {
//   var input = ["3", "3 3", "1 2 3", "3 4", "1 2 3", "2 2" ,"0 6"]
//   return input[lineIdx++];
// };
// var print = (str) => {
//   console.log(str);
// };

var t = readline().split(" ").map(function (x) { return parseInt(x); })[0];

var step = () => {
  var input = readline().split(" ").map(function (x) { return parseInt(x); });
  var n = input[0];
  var x = input[1];

  var row = readline().split(" ").map(function (x) { return parseInt(x); });

  var max = -2;

  var sum = 0;
  for (var i = 0; i < n; i ++){
    sum += row[i];
    sum = sum % x;
    if(sum != 0){
      max = i;
    }
  }

  sum = 0;
  for (i = n-1; i >= 0; i --){
    sum += row[i];
    sum = sum % x;
    if(sum != 0){
      if(n -1 - i > max){
         max = n -1 - i;
      }
    }
  }

  print(max + 1)

}

for (var i2 = 0; i2 < t; i2++) {
  step();
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nx = read().split(' ').map(Number);
      var n = nx[0];
      var x = nx[1];
      var a = read().split(' ').map(Number);
      var ax = [[-1]];
      var sx = 0;
      for (var i = 0; i < n; ++i) {
         sx = (sx + a[i]) % x;
         if (ax[sx]) {
            ax[sx].push(i);
         } else {
            ax[sx] = [i];
         }
      }
      var ans = -1;
      for (var i = 0; i < x; ++i) {
         if (!ax[i]) {
            continue;
         }
         for (var j = i + 1; j < x; ++j) {
            if (!ax[j]) {
               continue;
            }
            var i1 = ax[i][0];
            var i2 = ax[i][ax[i].length - 1];
            var j1 = ax[j][0];
            var j2 = ax[j][ax[j].length - 1];
            if (i1 < j2 && j2 - i1 > ans) {
               ans = j2 - i1;
            }
            if (j1 < i2 && i2 - j1 > ans) {
               ans = i2 - j1;
            }
         }
      }
      write(ans);
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var lines = input.split('\n');
    var tests = parseInt(lines.shift(), 10);
    var _loop_1 = function () {
        var nx = lineToNumArray(lines.shift());
        var n = nx[0], x = nx[1];
        var arr = lineToNumArray(lines.shift());
        var allDivisible = arr.every(function (element) { return element % x === 0; });
        if (allDivisible) {
            console.log(-1);
        }
        else {
            var sum = arr.reduce(function (a, b) { return a + b; }, 0);
            console.log(sum % x !== 0 ? n : n - 1);
        }
    };
    while (tests--) {
        _loop_1();
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

var n = readline();
var maxa = [];
var inp = [];
for (var i = 0;i<n;i++){
    maxa.push(parseInt(readline().split(" ")[1]));
    inp.push(readline().split(" ").map(function (a) {
        return parseInt(a);
    }));
}
for (var i = 0;i<n;i++) {
    var max = -1;
    for (var j = 0;j<inp[i].length;j++) {
        var tmpSum = 0;
        var llen = 0;
        if (max>inp[i].length - j){
            break;
        }
        for (var k = j; k < inp[i].length; k++) {
            if ((tmpSum + inp[i][k]) === 0  || (tmpSum + inp[i][k]) % maxa[i] === 0){
                break;
            }else{
                tmpSum += inp[i][k];
                llen ++;
            }
        }
        if (llen !== 0 && llen>max){
            max = llen;
        }
    }
    write(max + "\n");
}


You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.If there is no possible sequence then output -1.

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

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

  var tmp = readline().split(' ').map(x => parseInt(x));
  var n = tmp[0];
  var k = tmp[1];
  var sumk = k * (1 + k) / 2;
  var d = [];
  for(var i = Math.sqrt(n) | 0; i >= 1; i -= 1) {
    if(n % i === 0) {
      d.push(n / i);
      d.unshift(i);
    }
  }
  var flag = true;
  for(var i = d.length - 1; i >= 0; i -= 1) {
    var gcd = d[i];
    if(n % gcd !== 0) {
      continue;
    }
    if(n / gcd >= sumk) {
      var sum = 0;
      var b = new Array(k).fill(0).map((x, i) => i + 1);
      b[k - 1] += n / gcd - sumk;
      b = b.map(x => x * gcd);
      print(b.join(' '));
      flag = false;
      break;
    }
  }
  if(flag) {
    print(-1);
  }


William has array of $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. He can perform the following sequence of operations any number of times:   Pick any two items from array $$$a_i$$$ and $$$a_j$$$, where $$$a_i$$$ must be a multiple of $$$2$$$  $$$a_i = \frac{a_i}{2}$$$  $$$a_j = a_j \cdot 2$$$ Help William find the maximal sum of array elements, which he can get by performing the sequence of operations described above.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 15)$$$, the number of elements in William's array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i < 16)$$$, the contents of William's array.

For each test case output the maximal sum of array elements after performing an optimal sequence of operations.

NoteIn the first example test case the optimal sequence would be:   Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_2 = \frac{4}{2} = 2$$$ and $$$a_1 = 6 \cdot 2 = 12$$$, making the array look as: [12, 2, 2].  Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_2 = \frac{2}{2} = 1$$$ and $$$a_1 = 12 \cdot 2 = 24$$$, making the array look as: [24, 1, 2].  Pick $$$i = 3$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_3 = \frac{2}{2} = 1$$$ and $$$a_1 = 24 \cdot 2 = 48$$$, making the array look as: [48, 1, 1]. The final answer $$$48 + 1 + 1 = 50$$$.In the third example test case there is no way to change the sum of elements, so the answer is $$$10$$$.

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            var ans = '';
            var two = 1, max = 0, sum = 0;
            for(j = 0; j < n; j++){
                while(a[j] % 2 === 0){
                    a[j] /= 2;
                    two *= 2;
                }
                max = Math.max(max, a[j]);
                sum += a[j];
            }
            var b = sum - max;
            two *= max;
            console.log(b + two);
        }
    }
});

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--) {
		let n = rn();
		let a = rna();

		let pwr = 1, mxx = 0, sm = 0;
		for (let x of a) {
			while (x % 2 == 0) {
				pwr *= 2;
				x /= 2;
			}
			mxx = Math.max(mxx, x);
			sm += x;
		}

		ans = sm - mxx + mxx*pwr;
		console.log(ans);
	}
}


You are given a grid with $$$n$$$ rows and $$$m$$$ columns. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$. All numbers are equal to $$$1$$$ or to $$$-1$$$. You start from the square $$$(1, 1)$$$ and can move one square down or one square to the right at a time. In the end, you want to end up at the square $$$(n, m)$$$.Is it possible to move in such a way so that the sum of the values written in all the visited cells (including $$$a_{11}$$$ and $$$a_{nm}$$$) is $$$0$$$?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$)  — the size of the grid. Each of the following $$$n$$$ lines contains $$$m$$$ integers. The $$$j$$$-th integer on the $$$i$$$-th line is $$$a_{ij}$$$ ($$$a_{ij} = 1$$$ or $$$-1$$$)  — the element in the cell $$$(i, j)$$$. It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$10^6$$$.

For each test case, print "YES" if there exists a path from the top left to the bottom right that adds up to $$$0$$$, and "NO" otherwise. You can output each letter in any case.

NoteOne possible path for the fourth test case is given in the picture in the statement.

'use strict';

function solve(n, m, a) {
  if ((n & 1) === (m & 1)) return 'NO';
  const dp = Array.from({
    length: n
  }, () => Array.from({
    length: m
  }, () => [0, 0]));
  dp[0][0] = a[0][0] === 1 ? [1, 1] : [0, 0];
  for (let i = 1; i < n; i++) {
    dp[i][0] = [...dp[i - 1][0]];
    if (a[i][0] === 1) {
      dp[i][0][0]++;
      dp[i][0][1]++;
    }
  }
  for (let i = 1; i < m; i++) {
    dp[0][i] = [...dp[0][i - 1]];
    if (a[0][i] === 1) {
      dp[0][i][0]++;
      dp[0][i][1]++;
    }
  }
  for (let i = 1; i < n; i++) {
    for (let j = 1; j < m; j++) {
      dp[i][j][0] = Math.min(dp[i - 1][j][0], dp[i][j - 1][0]);
      dp[i][j][1] = Math.max(dp[i - 1][j][1], dp[i][j - 1][1]);
      if (a[i][j] === 1) {
        dp[i][j][0]++;
        dp[i][j][1]++;
      }
    }
  }
  const last = dp[n - 1][m - 1];
  if (last[0] <= (n + m - 1) / 2 && last[1] >= (n + m - 1) / 2) 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, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = 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);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  if ((n & 1) === (m & 1)) return 'NO';
  const dp = Array.from({
    length: n
  }, () => Array.from({
    length: m
  }, () => [0, 0]));
  dp[0][0] = a[0][0] === 1 ? [1, 1] : [1, 1];
  for (let i = 1; i < n; i++) {
    dp[i][0] = [...dp[i - 1][0]];
    if (a[i][0] === 1) {
      dp[i][0][0]++;
      dp[i][0][1]++;
    }
  }
  for (let i = 1; i < m; i++) {
    dp[0][i] = [...dp[0][i - 1]];
    if (a[0][i] === 1) {
      dp[0][i][0]++;
      dp[0][i][1]++;
    }
  }
  for (let i = 1; i < n; i++) {
    for (let j = 1; j < m; j++) {
      dp[i][j][0] = Math.min(dp[i - 1][j][0], dp[i][j - 1][0]);
      dp[i][j][1] = Math.max(dp[i - 1][j][1], dp[i][j - 1][1]);
      if (a[i][j] === 1) {
        dp[i][j][0]++;
        dp[i][j][1]++;
      }
    }
  }
  const last = dp[n - 1][m - 1];
  if (last[0] <= (n + m - 1) / 2 && last[1] >= (n + m - 1) / 2) 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, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = 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);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  const dp = Array.from({
    length: n
  }, () => Array.from({
    length: m
  }, () => [0, 0]));
  dp[0][0] = a[0][0] === 1 ? [1, 1] : [1, 1];
  for (let i = 1; i < n; i++) {
    dp[i][0] = [...dp[i - 1][0]];
    if (a[i][0] === 1) {
      dp[i][0][0]++;
      dp[i][0][1]++;
    }
  }
  for (let i = 1; i < m; i++) {
    dp[0][i] = [...dp[0][i - 1]];
    if (a[0][i] === 1) {
      dp[0][i][0]++;
      dp[0][i][1]++;
    }
  }
  for (let i = 1; i < n; i++) {
    for (let j = 1; j < m; j++) {
      var _dp$i, _dp$i2;
      dp[i][j][0] = Math.min(dp[i - 1][j][0], (_dp$i = dp[i][j - 1]) === null || _dp$i === void 0 ? void 0 : _dp$i[0]);
      dp[i][j][1] = Math.max(dp[i - 1][j][1], (_dp$i2 = dp[i][j - 1]) === null || _dp$i2 === void 0 ? void 0 : _dp$i2[1]);
      if (a[i][j] === 1) {
        dp[i][j][0]++;
        dp[i][j][1]++;
      }
    }
  }
  const last = dp[n - 1][m - 1];
  if (last[0] <= (n + m - 1) / 2 && last[1] >= (n + m - 1) / 2) 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, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = 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);
  process.stdout.write(output);
});


Constanze is the smartest girl in her village but she has bad eyesight.One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses.However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did.The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper.The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense.But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got.But since this number can be quite large, tell me instead its remainder when divided by $$$10^9+7$$$.If there are no strings that Constanze's machine would've turned into the message I got, then print $$$0$$$.

Input consists of a single line containing a string $$$s$$$ ($$$1 \leq |s| \leq 10^5$$$) — the received message. $$$s$$$ contains only lowercase Latin letters.

Print a single integer — the number of strings that Constanze's machine would've turned into the message $$$s$$$, modulo $$$10^9+7$$$.

NoteFor the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn".For the second example, there is only one: "banana".For the third example, the candidate strings are the following: "nm", "mn" and "nnn".For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.

  var string = String(readline());
  var MOD = 1000000007;

  var restrictedChars = false;

  for (var i = 0; i < string.length; i++) {
    if (string[i] === 'm' || string[i] === 'w') restrictedChars = true;
  }

  if (restrictedChars) {
    print(0);
  } else {
    var dp = Array(string.length + 1);

    dp[0] = 1;
    dp[1] = 1;

    for (var i = 2; i <= string.length; i++) {
      dp[i] = dp[i - 1];
      if (string[i - 1] === string[i - 2] && (string[i - 1] === 'u' || string[i - 1] === 'n'))
        dp[i] = (dp[i] + dp[i - 2]) % MOD;
    }

    print(dp[string.length]);
  }

  var string = String(readline());
  var MOD = 1000000007;
  var result = 1;
  var fibValues = Array(string.length + 2);

  fibValues[0] = 1;
  fibValues[1] = 1;

  for (var i = 2; i <= string.length; i++) {
    fibValues[i] = (fibValues[i - 1] + fibValues[i - 2]) % MOD;
  }

  function fibonacci(num){
    var a = 1, b = 0, temp;

    while (num >= 0){
      temp = a;
      a = (a + b) % MOD;
      b = temp % MOD;
      num--;
    }

    return b;
  }

  var char = '';

  var count = 0;

  // var restrictedChars = false;
  //
  // for (var i = 0; i < string.length; i++) {
  //   if (string[i] === 'm' || string[i] === 'w') restrictedChars = true;
  // }
  //
  // if (restrictedChars) {
  //   print(0);
  // } else {
  //   var dp = Array(string.length + 1);
  //
  //   dp[0] = 1;
  //   dp[1] = 1;
  //
  //   for (var i = 2; i <= string.length; i++) {
  //     dp[i] = dp[i - 1];
  //     if (string[i - 1] === string[i - 2] && (string[i - 1] === 'u' || string[i - 1] === 'n'))
  //       dp[i] = (dp[i] + dp[i - 2]) % MOD;
  //   }
  //
  //   print(dp[string.length]);
  // }
  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * fibValues[count - 1]) % MOD;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }

  if (count) result = (result * fibValues[count - 1]) % MOD;
  print(result);

  var string = String(readline());

  var result = 1;

  var char = "";
  var count = 0;
  var delim = 1e9 + 7;

  function fib(n) {
    var prev = 0,
      next = 1;
    for (var i = 0; i < n; i++) {
      var temp = next;
      next = prev + next;
      prev = temp;
    }
    return prev;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * mult(count)) % delim;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = (result * mult(count)) % delim;

  print(result);

  var string = String(readline());
  var MOD = 1000000007;
  var result = 1;
  var fibValues = Array(string.length + 2);

  fibValues[0] = 1;
  fibValues[1] = 1;

  for (var i = 2; i <= string.length; i++) {
    fibValues[i] = (fibValues[i - 1] + fibValues[i - 2]) % MOD;
  }

  function fibonacci(num){
    var a = 1, b = 0, temp;

    while (num >= 0){
      temp = a;
      a = (a + b) % MOD;
      b = temp % MOD;
      num--;
    }

    return b;
  }

  var char = '';

  var count = 0;

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * fibValues[count]) % MOD;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }

  if (count) result = (result * fibValues[count]) % MOD;
  print(result);

  var string = String(readline());

  var result = 1;

  var char = "";
  var count = 0;
  var delim = 1e9 + 7;

  function fib(n) {
    var prev = 0,
      next = 1;
    for (var i = 0; i < n; i++) {
      var temp = next;
      next = (prev + next) % delim;
      prev = temp;
    }
    return prev;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * mult(count)) % delim;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = (result * mult(count)) % delim;

  print(result);

  var string = String(readline());
  var MOD = 1000000007;

  var dp = Array(string.length + 1);

  dp[0] = 1;
  dp[1] = 1;

  for (var i = 2; i <= string.length; i++) {
    dp[i] = dp[i - 1];
    if (string[i - 1] === string[i - 2] && (string[i - 1] === 'u' || string[i - 1] === 'n'))
      dp[i] = (dp[i] + dp[i - 2]) % MOD;
  }

  print(dp[string.length]);

  var string = String(readline());

  var result = 1;

  var char = "";
  var count = 0;
  var MOD = 1000000007;

  function fib(num){
    var a = 1, b = 0, temp;

    while (num >= 0){
      temp = a;
      a = (a + b) % MOD;
      b = temp % MOD;
      num--;
    }

    return b;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * mult(count)) % MOD;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = (result * mult(count)) % MOD;

  print(result);

  var string = String(readline());

  var result = 1;

  var char = "";
  var count = 0;

  function fib(n) {
    var prev = 0,
      next = 1;
    for (var i = 0; i < n; i++) {
      var temp = next;
      next = prev + next;
      prev = temp;
    }
    return prev;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = result * mult(count);
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = result * mult(count);

  print(result);

  var string = String(readline());

  var result = 1;

  var char = "";
  var count = 0;
  var delim = 1e6 + 7;

  function fib(n) {
    var prev = 0,
      next = 1;
    for (var i = 0; i < n; i++) {
      var temp = next;
      next = prev + next;
      prev = temp;
    }
    return prev;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * mult(count)) % delim;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = (result * mult(count)) % delim;

  print(result);

  var string = String(readline());
  var result = 1;

  var char = "";
  var count = 0;
  var MOD = 1000000007;

  var fibValues = Array(string.length + 1);

  fibValues[0] = 1;
  fibValues[1] = 1;

  for (var i = 2; i <= string.length; i++) {
    fibValues[i] = (fibValues[i - 1] + fibValues[i - 2]) % MOD;
  }

  function fib(num){
    var a = 1, b = 0, temp;

    while (num >= 0){
      temp = a;
      a = (a + b) % MOD;
      b = temp % MOD;
      num--;
    }

    return b;
  }

  function mult(num) {
    return num && num < 4 ? num : fib(num);
  }

  for (var i = 0; i < string.length; i++) {
    if (string[i] !== char && count) {
      result = (result * fibValues[count]) % MOD;
      char = "";
      count = 0;
    }

    if (string[i] === "m" || string[i] === "w") {
      result = 0;
      break;
    } else {
      if (string[i] === "n") {
        count++;
        if (char !== "n") char = "n";
      }
      if (string[i] === "u") {
        count++;
        if (char !== "u") char = "u";
      }
    }
  }
  if (count) result = (result * fibValues[count]) % MOD;

  print(result);