The term of this problem is the same as the previous one, the only exception — increased restrictions.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

function main() {
  var input = readline().split(' ').map(Number)
  var n = input[0]
  var k = input[1]

  var need = readline().split(' ').map(Number)
  var have = readline().split(' ').map(Number)

  var l = 0
  var r = Math.pow(10, 9) * 2 + 1

  function canPrepare(c) {
    var total = 0

    for (var i = 0; i < need.length; i++) {
      total += Math.max(need[i] * c - have[i], 0)

      if (total > k) return false
    }

    return true
  }

  while (l + 1 < r) {
    var m = Math.round((l + r) / 2)
    if (canPrepare(m)) {
      l = m
    } else {
      r = m
    }
  }

  print(l)

  return 0
}

main()

var k = readline().split()[1];
var a = readline().split();
var b = readline().split();

function canWeMake(x, a, b, k) {
	for (var i=0; i<a.length; i++) {
		var y = x * a[i];
		var z = y - b[i];
		if (z >= 0) {
			k -= z;
		}
	}
	return k;
}

function f(k, a, b) {
	var max = 0;
	var l = 0;
	var r = 2 * Math.pow(10, 9);
	while (l <= r) {
		var n = Math.floor((r + l) / 2);

		var res = canWeMake(n, a, b, k);

		if (res == 0) {
			return n;
		}

		if (res > 0) {
			max = Math.max(max, n);
			if (l == r) {
				return max;
			}
			l = n + 1;
		}
		else {
			if (l == r) {
				return max;
			}
			r = n;
		}
	}
	return max;
}

var res = f(k, a, b);

print(res);

//f(3, [4,3,5,6], [11,12,14,20]);

var k = readline().split()[1];
var a = readline().split();
var b = readline().split();

function canWeMake(x, a, b, k) {
	for (var i=0; i<a.length; i++) {
		var y = x * a[i];
		var z = y - b[i];
		if (z >= 0) {
			k -= z;
		}
	}
	return k;
}

function f(k, a, b) {
	var max = 0;
	var l = 0;
	var r = 2 * Math.pow(10, 9);
	while (l < r) {
		var n = Math.floor((r + l) / 2);

		var res = canWeMake(n, a, b, k);

		if (res < 0) {
			r = n;
		}
		else if (res > 0) {
			max = Math.max(max, n);
			l = n + 1;
		} else {
			return n;
		}
	}
	return max;
}

var res = f(k, a, b);

print(res);

//f(3, [4,3,5,6], [11,12,14,20]);

function main() {
  var input = readline().split(' ').map(Number)
  var n = input[0]
  var k = input[1]

  var need = readline().split(' ').map(Number)
  var have = readline().split(' ').map(Number)

  var l = 0
  var r = Math.pow(10, 9) * 2 + 1

  function canPrepare(c) {
    var total = 0

    for (var i = 0; i < need.length; i++) {
      total += need[i] * c - have[i]

      if (total > k) return false
    }

    return true
  }

  while (l + 1 < r) {
    var m = Math.round((l + r) / 2)

    if (canPrepare(m)) {
      l = m
    } else {
      r = m
    }
  }

  print(l)

  return 0
}

main()


Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop. The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink. Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.

Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.

NoteOn the first day, Vasiliy won't be able to buy a drink in any of the shops.On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.On the third day, Vasiliy can buy a drink only in the shop number 1.Finally, on the last day Vasiliy can buy a drink in any shop.

'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 shops = readline();
  let prices = readline().split(' ');
  prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  prices = [0].concat(prices).concat([Infinity]);
  let numDays = readline();

  while(numDays > 0){
    let coinsDay1 = readline();
    coinsDay1 = parseInt(coinsDay1)
    console.log(getStoresPerDay(prices, coinsDay1))
    numDays--;
  }
}

function getStoresPerDay(prices, target){
  let ini = 0;
  let fin = prices.length - 1;

  while(ini < fin){
      let mid = Math.floor((fin - ini) / 2) + ini;
      if(prices[mid] <= target){
          ini = mid + 1;
      } else {
          fin = mid;
      }
  }
  return fin - 1;

}

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

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

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);

  let prevCost = 0;
  const positions = []; cnt = 0;
  for (const key in nums) {
    let cost = nums[key];

    for (let i = prevCost; i < cost-1; i += 1) {
      positions[i] = cnt;
    }

    prevCost = cost-1; cnt += 1;
  }

  for (let i = prevCost; i <= prevCost+10; i += 1) {
    positions[i] = cnt;
  }

  const [q] = input[2].split(' ').map(x => parseInt(x));
  for (let i = 3; i < q+3; i += 1) {
    let p = parseInt(input[i]);

    if (positions[p] === undefined) {
      console.log(nums.length);
    } else {
      console.log(positions[p-1]);
    }
  }
});

function rda(){ return readline().split(" ").map(Number); };
function rdn(){ return +readline(); };

var n = rdn(), x = rda().sort(function(x,y){ return x-y; }), q = rdn();

for(var i = 0; i < q; i++){
    var have = rdn();

    var l = 0, r = n-1;
    while(l != r){
        var m = Math.floor((l+r)/2);

        if(x[m] < have){
            l = m+1;
        }else if(x[m] > have){
            r = m;
        }else{
            l = m+1;
        }
    }

    if(x[l] <= have){
        print(l+1);
    }else{
        print(l);
    }
}

var n = readline();
var prices = readline().split(' ').map(Number).sort(function(x,y){ return x-y; });
var days = readline();

for(var i = 0; i < days; i++){
    var money = readline()
    var l = 0, r = n-1;

    while(l != r){
        var m = Math.floor((l+r)/2);

        if(prices[m] < money){
            l = m + 1;
        }else if(prices[m] > money){
            r = m;
        }else{
            l = m + 1;
        }
    }

    if(prices[l] <= money){
        print(l + 1);
    }else{
        print(l);
    }
}

'use strict';

var n = Number(readline());
var count = new Array(100001).fill(0);
var prices = readline().split(' ').map(Number);
for (var i = 0; i < prices.length; i++) {
	count[prices[i]]++;
}
for (var i = 1; i < count.length; i++) {
	count[i] += count[i - 1];
}

var days = Number(readline());

for (var i = 0; i < days; i++) {
	var num = Number(readline());
	if (num >= count.length) {
		print(count[count.length - 1]);
	} else {
		print(count[num]);
	}
}

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, target) {
    var lo = 0,
        hi = a.length,
        mid;
    while (lo != hi) {
        mid = Math.floor( (lo + hi) / 2);
        if (a[mid] <= target) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    return lo;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, item) {
    var l = 0;
    var r = a.length;
    while (l <= r) {
        var i = Math.floor( (r + l) / 2 );
        var curItem = a[i];
        var nextItem = a[i + 1];

        if ( curItem <= item && (typeof nextItem === "undefined" || nextItem > item) ) {
            return i + 1;
        } else if ( curItem <= item ) {
            l = i + 1;
        } else {
            r = i - 1;
        }
    }
    return 0;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+2;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res;
        while (nums[t] === nums[res] && t+1 < nums.length) t += 1;
        console.log(t);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;

    if ( pos >= arr[arr.length-1] ) return arr.length;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) {
      return med+1
    };

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    let num = parseInt(input[i]);
    let res = binarySearch(num, nums);

    if (res < 0) { console.log(0) }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res + 1;
        while (nums[t] === nums[res] && t+1 < nums.length) {
          t += 1;
        }
        console.log(t);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = parseInt((left + right) / 2);

    if (arr[med] === pos) { return med+1; }
    if (med+1 < arr.length) {
      if (arr[med] < pos && arr[med+1] > pos) {
        return med+1;
      }

      if (arr[med+1] === pos) return med+2;
    }

    if (med-1 >= 0) {
      if (arr[med] > pos && arr[med-1] <= pos) return med;
    }

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;

    if ( pos >= arr[arr.length-1] ) return arr.length;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) {
      return med+1
    };

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    let num = parseInt(input[i]);
    let res = binarySearch(num, nums);

    if (res < 0) { console.log(0) }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res + 1;
        while (nums[t] !== nums[res] && t+1 < nums.length) {
          t += 1;
        }
        console.log(t+1);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = parseInt((left + right) / 2);

    if (arr[med] === pos) { return med+1; }
    if (med+1 < arr.length) {
      if (arr[med] < pos && arr[med+1] > pos) {
        return med+1;
      }

      if (arr[med+1] === pos) return med+2;
    }

    if (med-1 >= 0) {
      if (arr[med] > pos && arr[med-1] < pos) return med;
      if (arr[med-1] === pos) return med+1;
    }

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+1;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+2;
}

readLine.on('close', () => {
  const [n] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else console.log(res);
  }
});

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

// function getStoresPerDay(prices, target){
//   let counter = 0;
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

//   for (let i = 0; i < prices.length; i++) {
//      if(prices[i] < target) counter++;
//     if(target < prices[i]){
//       break;
//     }
//   }
//   return counter;
// }
function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target, counter)

  let mid = Math.floor(prices.length / 2);
//   console.log(prices[mid], "mid")
  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();
  let coinsDay1 = readline();
    coinsDay1 = parseInt(coinsDay1)
  let coinsDay2 = readline();
  coinsDay2 = parseInt(coinsDay2)
  let coinsDay3 = readline();
  coinsDay3 = parseInt(coinsDay3)
  let coinsDay4 = readline();
  coinsDay4 = parseInt(coinsDay4)

  console.log(getStoresPerDay(prices, coinsDay1))
  console.log(getStoresPerDay(prices, coinsDay2))
  console.log(getStoresPerDay(prices, coinsDay3))
  console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;

  let mid = Math.floor(prices.length / 2);

  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays >= 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }

'use strict';

function binarySearch(num, prices, left, right) {
	while (left <= right) {
		var mid = parseInt(left + (right - left) / 2);
		if (mid == 0 && prices[mid] > num) {
			return 0;
		} else if (mid == prices.length - 1 && prices[mid] <= num) {
			return prices.length;
		} else if (prices[mid] <= num && prices[mid + 1] > num) {
			return mid + 1;
		} else if (prices[mid] < num) {
			left = mid + 1;
		} else {
			right = mid - 1;
		}
	}
	return -1;
}

var n = Number(readline());
var prices = readline().split(' ').map(Number).sort(function (a, b) {
	return a - b;
});
var days = Number(readline());

for (var i = 0; i < days; i++) {
	var num = Number(readline());
	var index = binarySearch(num, prices, 0, prices.length - 1);
	print(index);
}

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();
var m = [];

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, item) {
    var l = 0;
    var r = a.length;
    while (l <= r) {
        var i = Math.floor((r + l) / 2);
        var curItem = a[i];
        var nextItem = a[i + 1];

        if ( curItem <= item && (typeof nextItem === "undefined" || nextItem > item) ) {
            return i + 1;
        } else if ( curItem < item ) {
            l = i + 1;
        } else {
            r = i - 1;
        }
    }
    return 0;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, target) {
    var lo = 0,
        hi = a.length,
        mid;
    while (lo != hi) {
        mid = Math.floor( (lo + hi) / 2);
        if (a[mid] <= target) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (a[mid] <= target) {
        return mid + 1;
    } else {
        return 0;
    }
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays >= 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

// function getStoresPerDay(prices, target){
//   let counter = 0;
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

//   for (let i = 0; i < prices.length; i++) {
//      if(prices[i] < target) counter++;
//     if(target < prices[i]){
//       break;
//     }
//   }
//   return counter;
// }
function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target, counter)

  let mid = Math.floor(prices.length / 2);
//   console.log(prices[mid], "mid")
  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'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 shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
  console.log(prices, target)

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }


Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most $$$l$$$ centimeters after haircut, where $$$l$$$ is her favorite number. Suppose, that the Alice's head is a straight line on which $$$n$$$ hairlines grow. Let's number them from $$$1$$$ to $$$n$$$. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length $$$l$$$, given that all hairlines on that segment had length strictly greater than $$$l$$$. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:  $$$0$$$ — Alice asks how much time the haircut would take if she would go to the hairdresser now.  $$$1$$$ $$$p$$$ $$$d$$$ — $$$p$$$-th hairline grows by $$$d$$$ centimeters. Note, that in the request $$$0$$$ Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$l$$$ ($$$1 \le n, m \le 100\,000$$$, $$$1 \le l \le 10^9$$$) — the number of hairlines, the number of requests and the favorite number of Alice. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the initial lengths of all hairlines of Alice. Each of the following $$$m$$$ lines contains a request in the format described in the statement. The request description starts with an integer $$$t_i$$$. If $$$t_i = 0$$$, then you need to find the time the haircut would take. Otherwise, $$$t_i = 1$$$ and in this moment one hairline grows. The rest of the line than contains two more integers: $$$p_i$$$ and $$$d_i$$$ ($$$1 \le p_i \le n$$$, $$$1 \le d_i \le 10^9$$$) — the number of the hairline and the length it grows by.

For each query of type $$$0$$$ print the time the haircut would take.

NoteConsider the first example:  Initially lengths of hairlines are equal to $$$1, 2, 3, 4$$$ and only $$$4$$$-th hairline is longer $$$l=3$$$, and hairdresser can cut it in $$$1$$$ second.  Then Alice's second hairline grows, the lengths of hairlines are now equal to $$$1, 5, 3, 4$$$  Now haircut takes two seonds: two swings are required: for the $$$4$$$-th hairline and for the $$$2$$$-nd.  Then Alice's first hairline grows, the lengths of hairlines are now equal to $$$4, 5, 3, 4$$$  The haircut still takes two seconds: with one swing hairdresser can cut $$$4$$$-th hairline and with one more swing cut the segment from $$$1$$$-st to $$$2$$$-nd hairline.  Then Alice's third hairline grows, the lengths of hairlines are now equal to $$$4, 5, 4, 4$$$  Now haircut takes only one second: with one swing it is possible to cut the segment from $$$1$$$-st hairline to the $$$4$$$-th.

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        }
    }
}

var grow = function (hairlinePos, growLength) {
    var oldLength = hairlines[hairlinePos - 1];
    hairlines[hairlinePos - 1] = oldLength + growLength;

    if (oldLength <= favLength && hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");

function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l && arrHair[p] - d <=l){
        if(arrHair.length > 1){
            if(p === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if(p === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                    countChick++;
                else if(arrHair[p-1] > l && arrHair[p+1] > l )
                    countChick--;
            }
        }
        else
            countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength || hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            // if (hairlines[i + 1] > favLength) {
            //     i++;
            // }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var s = [-1];
s.concat(hairlines.push(-1));
hairlines = s;

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        // if (hairlinePos == 1) {
        //     if (noHairlines == 1) {
        //         savedTime++;
        //         return;
        //     }
        //     if (hairlines[1] <= favLength) {
        //         savedTime++;
        //         return;
        //     }
        //     return;
        // }

        // if (hairlinePos == noHairlines) {
        //     if (hairlines[hairlinePos - 2] <= favLength) {
        //         savedTime++;
        //     }
        //     return;
        // }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1] + 1, line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        }
    }
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var printTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
        // printTime();
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            if(requests == 0 && hairlines[1] > favLength){
                savedTime--;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            if (requests == 0 && hairlines[hairlinePos - 2] > favLength) {
                savedTime--;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for(var i = 1; i < noHairlines -1 ; i++){
    if(hairlines[i] > favLength) {
        if(hairlines[i-1]  <= favLength && hairlines[i+1]<= favLength){
            savedTime++;
        }else{
            if(hairlines[i] > favLength && hairlines[i+1] > favLength){
                i++;
            }
        }
    }
}
if(hairlines[noHairlines- 2] <= favLength && hairlines[noHairlines -1] > favLength){
    savedTime++;
}

var grow = function(hairlinePos, growLength){
    hairlines[hairlinePos -1] =  hairlines[hairlinePos -1]  + growLength;

    if(hairlines[hairlinePos -1] > favLength){
        if(hairlinePos == 1 && hairlines[1] <=favLength){
            savedTime++;
            return;
        }

        if(hairlinePos == noHairlines && hairlines[hairlinePos -2] <= favLength){
            savedTime++;
            return;
        }
        if(hairlines[hairlinePos -2]  <= favLength && hairlines[hairlinePos]<= favLength){
            savedTime++;
            return;
        }
        if(hairlines[hairlinePos -2] > favLength && hairlines[hairlinePos] > favLength){
            savedTime --;
            return;
        }
    }
}

while(requests--){
    var line = readline().split(' ').map(Number);
    if(line[0] == 0){
        print(savedTime);
    }else{
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if(noHairlines == 1){
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var printTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests -- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
        // printTime();
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var computeTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        // print(savedTime);
        computeTime();
    } else {
        grow(line[1], line[2]);
    }
}

var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");
function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l){
        if(arrHair.length > 1){
            if((p) === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if((p) === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair.length > 2){
                    if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                        countChick++;
                    else if(arrHair[p-1] > l && arrHair[p+1] > l )
                        countChick--;
                }

            }
        }
        else
            return countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}

var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");
function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l){
        if(arrHair.length > 2){
            if((p) === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if((p) === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                    countChick++;
                else if(arrHair[p-1] > l && arrHair[p+1] > l )
                    countChick--;
            }
        }
        else
            return countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}


Polycarp and his friends want to visit a new restaurant. The restaurant has $$$n$$$ tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from $$$1$$$ to $$$n$$$ in the order from left to right. The state of the restaurant is described by a string of length $$$n$$$ which contains characters "1" (the table is occupied) and "0" (the table is empty).Restaurant rules prohibit people to sit at a distance of $$$k$$$ or less from each other. That is, if a person sits at the table number $$$i$$$, then all tables with numbers from $$$i-k$$$ to $$$i+k$$$ (except for the $$$i$$$-th) should be free. In other words, the absolute difference of the numbers of any two occupied tables must be strictly greater than $$$k$$$.For example, if $$$n=8$$$ and $$$k=2$$$, then:  strings "10010001", "10000010", "00000000", "00100000" satisfy the rules of the restaurant;  strings "10100100", "10011001", "11111111" do not satisfy to the rules of the restaurant, since each of them has a pair of "1" with a distance less than or equal to $$$k=2$$$. In particular, if the state of the restaurant is described by a string without "1" or a string with one "1", then the requirement of the restaurant is satisfied.You are given a binary string $$$s$$$ that describes the current state of the restaurant. It is guaranteed that the rules of the restaurant are satisfied for the string $$$s$$$.Find the maximum number of free tables that you can occupy so as not to violate the rules of the restaurant. Formally, what is the maximum number of "0" that can be replaced by "1" such that the requirement will still be satisfied?For example, if $$$n=6$$$, $$$k=1$$$, $$$s=$$$ "100010", then the answer to the problem will be $$$1$$$, since only the table at position $$$3$$$ can be occupied such that the rules are still satisfied.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case starts with a line containing two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2\cdot 10^5$$$) — the number of tables in the restaurant and the minimum allowed distance between two people. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ consisting of "0" and "1" — a description of the free and occupied tables in the restaurant. The given string satisfy to the rules of the restaurant — the difference between indices of any two "1" is more than $$$k$$$. The sum of $$$n$$$ for all test cases in one test does not exceed $$$2\cdot 10^5$$$.

For each test case output one integer — the number of tables that you can occupy so as not to violate the rules of the restaurant. If additional tables cannot be taken, then, obviously, you need to output $$$0$$$.

NoteThe first test case is explained in the statement.In the second test case, the answer is $$$2$$$, since you can choose the first and the sixth table.In the third test case, you cannot take any free table without violating the rules of the restaurant.

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0];
  var k = input[1];
  var str = readline();
  var dist = k;
  var res = 0;
  for (var i = 0; i < n; i++) {
    if (str[i] == "1") {
      if (dist < k) res--;
      dist = 0;
    } else {
      dist++;
      if (dist == k + 1) {
        res++;
        dist = 0;
      }
    }
  }
  print(res);
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i - k) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < n) {
         ans++;
         last1 += k + 1;
      }
      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');

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 = parseInt(readLine());
    while(t--) {
        let fir = readLine().split(" ");
        let n = parseInt(fir[0]);
        let k = parseInt(fir[1]);
        let arr = readLine().split("").map((x) => {return parseInt(x)});
        let arr1 = [];
        for(let i = 0;i<arr.length;i++) {
            arr1.push(arr[i]);
        }
        for(let i =0; i<arr.length; i++) {
            if(arr[i] === 1) {
                for(let j = 1; (i-j)>=0 && j<=k; j++) {
                    arr1[i-j] += 1;
                }
                for(let j = 1; (i+j)<arr.length && j<=k; j++) {
                    arr1[i+j] += 1;
                }
            }
        }
        let ans = 0;
        let arr2 = [];
        for(let i = 0;i<arr1.length;i++) {
            if(arr1[i]===0) {
                ans++;
            } else {
                if  (ans>0) {
                   arr2.push(ans);
                }
                ans = 0;
            }
        }
        if  (ans>0) {
            arr2.push(ans);
        }
        let realAns = 0;
        for(let i = 0;i<arr2.length;i++) {
            if(arr2[i]-1>0) {
                realAns+= parseInt((arr2[i]-1)/((k)+1))
            }
            realAns++;
        }
        console.log(realAns)
    }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		var list = nextCharArray();
		var count = 0;
		var sum = 0;
		var isOne = false;
		for(var j = 0; j < N; j++){
			if(!isOne){
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 1 + K){
						sum += Math.floor(count / (1 + K));
					}
					count = 0;
					isOne = true;
				}
			}else{
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 2 * K + 1){
						sum++;
						count -= 2 * K + 1;
						sum += Math.floor(count / (K + 1));
					}
					count = 0;
				}
			}
		}

		if(isOne){
			sum += Math.floor(count / (K + 1));
		}else{
			sum += Math.ceil(count / (1 + K));
		}
		output[i] = sum;
	}
	myout(myconv(output,9));
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

// function main(data) {
//     data = data.split('\n');
//     const testCases = data[0] * 2;
//     let i = 1;
//     while (i <= testCases) {
//         const int = data[i].split(' ');
//         const n = int[0] * 1;
//         const k = int[1] * 1;
//         const arr = data[i + 1];
//         let count = 0;
//         for (let j = 0; j < n; j += k + 1)(arr[j] == 0 && arr[j + k] != 1) ? count += 1 : '';
//         console.log(count);
//         i += 2;
//     }
// }
function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
        const int = data[i].split(' ');
        const n = int[0] * 1;
        const k = int[1] * 1;
        const arr = data[i + 1];
        let count = 0;
        let first = arr.indexOf('1');
        let j = 0;
        while (j < n) {
            if (arr[j] == 0 && first === -1) {
                count += 1;
                j += k + 1;
                continue;
            }
            if (arr[j] == 1) {
                j += k + 1;
                continue;
            }
            if (arr[j] == 0) {
                first = arr.indexOf('1', j);
                if (first == -1) {
                    count += 1;
                    j += k + 1;
                    continue;
                } else if (first - j > k) {
                    count += 1;
                    j += k + 1;
                    continue;
                } else j = first;
            }
        }
        console.log(count);
        i += 2;
    }
}

'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() {
  const t = parseInt(readline());
  for (let i=0; i<t; i++) {
    const [n, k] = readline().split(" ").map(x => parseInt(x));
    const s = readline();
    let cooldown = 0,
      vacancy = 0;
    for (let j=0; j<s.length; j++) {
      if (s[j] === "0") {
        if (cooldown == 0) {
          vacancy++;
          cooldown = k;
        } else {
          cooldown--;
        }
      } else {
        // s[j] === "1"
        if (cooldown > 0) {
          vacancy--;
        }
        cooldown = k;
      }
    }
    console.log(vacancy);
  }
}

const process = require('process')
let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n')
    let n = +lines[0]
    for(let i = 0; i < n; i++) {
        let [, k] = lines[1 + i * 2].split(' ')
        let arr = lines[2 + i * 2].trim().split('').map(x => +x)
        console.log(solution(arr, +k))
    }
}

function solution(arr, k) {
    let N = arr.length
    let waiting = 0
    for(let i = N - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            waiting = k
        }
        else if (waiting) {
            arr[i] = 2
            waiting--
        }
    }
    waiting = 0
    let ans = 0
    for(let i = 0; i < N; i++) {
        if (arr[i] === 1) {
            waiting = k
        } else if (arr[i] === 2) {
            // nothing
        } else if (waiting) {
            waiting--
        } else {
            ans++
            waiting = k
        }
    }
    return ans
}

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

    C();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let s = readline().split('');

        let a = new Array(s.length);
        a.fill(false);
        let d = 999999999999;
        for(let i = 0; i < s.length; i++){
            if(s[i] === '1'){
                d = 0;
            }else{
                d += 1;
                if(d > k){
                    a[i] = true;
                }
            }
        }

        d = 999999999999;
        for(let i = s.length-1; i >= 0; i--){
            if(s[i] === '1'){
                d = 0;
            }else{
                d += 1;
                if(d <= k){
                    a[i] = false;
                }
            }
        }

        let p1 = 0;
        let p2 = 0;
        let res = 0;
        while(p1 < s.length && p2 < s.length){
            while(a[p1] && a[p2]){
                p2++;
            }
            let x = p2-p1;
            res += Math.ceil(x/(k+1));
            p2++;
            p1 = p2;
        }

        console.log(res);
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    k = input[1];
  var str = readline();
  var possiple = 1;
  var curr = str[0] == "1" ? 1 : 0;
  var dist = 0;
  for (var i = 1; i < str.length; i++) {
    if (str[i] == "1") curr++;
    if (dist == k) {
      possiple++;
      dist = 0;
      continue;
    }
    dist++;
  }
  print(possiple - curr);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0];
  var k = input[1];
  var str = readline();
  var possiple = Math.floor(n / (k + 1));
  if (n % (k + 1) == k) possiple++;
  var curr = 0;
  for (var i = 0; i < n; i++) {
    if (str[i] == "1") curr++;
  }
  print(possiple - curr);
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i - k - 1) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < n) {
         ans++;
         last1 += k + 1;
      }
      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();
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < s.length) {
         ans++;
         last1 += k + 1;
      }
      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();
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		var list = nextCharArray();
		var count = 0;
		var sum = 0;
		var isOne = false;
		for(var j = 0; j < N; j++){
			if(!isOne){
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 1 + K){
						sum += Math.floor(count / (1 + K));
						count = 0;
					}
					isOne = true;
				}
			}else{
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 2 * K + 1){
						sum++;
						count -= 2 * K + 1;
						sum += Math.floor(count / (K + 1));
						count = 0;
					}
				}
			}
		}
		if(isOne){
			if(count >= 2 * K + 1){
				sum++;
				count -= 2 * K + 1;
				sum += Math.ceil(count / (K + 1));
				count = 0;
			}
		}else{
			sum += Math.ceil(count / (1 + K));
		}
		output[i] = sum;
	}
	myout(myconv(output,9));
}

'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() {
  const t = parseInt(readline());
  for (let i=0; i<t; i++) {
    const [n, k] = readline().split(" ").map(x => parseInt(x));
    const s = readline();
    let cooldown = 0,
        vacancy = 0;
    for (let j=0; j<s.length; j++) {
      if (s[j] === "0") {
        if (cooldown == 0) {
          vacancy++;
          cooldown = k;
        } else {
          cooldown--;
        }
      } else {
        // s[j] === "1"
        if (cooldown > 0) {
          vacancy--;
          cooldown = k;
        }
      }
    }
    console.log(vacancy);
  }
}

const process = require('process')
let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n')
    let n = +lines[0]
    for(let i = 0; i < n; i++) {
        let [, k] = lines[1 + i * 2].split(' ')
        let arr = lines[2 + i * 2].split('').map(x => +x)
        console.log(solution(arr, +k))
    }
}

function solution(arr, k) {
    let N = arr.length
    let waiting = 0
    for(let i = N - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            waiting = k
        }
        else if (waiting) {
            arr[i] = 2
            waiting--
        }
    }
    waiting = 0
    let ans = 0
    for(let i = 0; i < N; i++) {
        if (arr[i] === 1) {
            waiting = k
        } else if (arr[i] === 2) {
            // nothing
        } else if (waiting) {
            waiting--
        } else {
            ans++
            waiting = k
        }
    }
    return ans
}