The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).

The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are:    1 ≤ n ≤ 300  The input limitations for getting 50 points are:    1 ≤ n ≤ 2000  The input limitations for getting 100 points are:    1 ≤ n ≤ 105

Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.

var n = readline();
n--;
var a =  readline().split(' '); // a0..a(n-1)
var k = 0;
var t = 0
var turns = 0;

for(k=0; k<n; k++)
{
  while(k+Math.pow(2,t) <= n)
  {
    t++;
  }
  t--;

  turns= turns + Number(a[k]);

  a[k+Math.pow(2,t)] = Number(a[k+Math.pow(2,t)]) + Number(a[k]);

  print(turns);
}

const Fs = require('fs')

const content = Fs.readFileSync(0).toString()

const parse = (a) => {
  return a.split('\n')[1].split(' ')
}

const computeMaxIndex = (i, m) => {
  const rec = (p) => {
    const j = i + Math.pow(2, p)
    if (m < j) {
      return i + Math.pow(2, p - 1)
    } else {
      return rec(p + 1)
    }
  }
  return rec(0)
}

const minMove = (array) => {
  let ans = []

  for (let i = 0; i < array.length - 1; i++) {
    const max_index = computeMaxIndex(i, array.length - 1)
    let prev = 0
    if (ans.length !== 0) {
      prev = ans[ans.length - 1]
    }
    ans.push(prev + array[i])
    array[max_index] += array[i]
    array[i] = 0
  }

  return ans
}

const array = parse(content).map(a=>Number(a))
minMove(array).forEach((a)=>console.log(a))

var n = readline();
var a =  Number(readline().split(' ')); // a0..a(n-1)
var k = 0;
var t = 0
var turns = 0;

for(k=0; k<n; k++)
{
  while(k+Math.pow(2,t) <= n)
  {
    t++;
  }
  t--;

  turns= turns + a[k];

  a[k+Math.pow(2,t)] = a[k+Math.pow(2,t)] + a[k];

  print(turns);
}

var n = readline();
var a =  readline().split(' '); // a0..a(n-1)
var k = 0;
var t = 0
var turns = 0;

for(k=0; k<n; k++)
{
  while(k+Math.pow(2,t) <= n)
  {
    t++;
  }
  t--;

  turns= turns + Number(a[k]);

  a[k+Math.pow(2,t)] = Number(a[k+Math.pow(2,t)]) + Number(a[k]);

  print(turns);
}

var n = readline();
var a = readline().split(' '); // a0..a(n-1)
var k = 0;
var t = 0
var turns = 0;

for(k=0; k<n; k++)
{
  while(k+Math.pow(2,t) <= n)
  {
    t++;
  }
  t--;

  turns= turns + a[k];

  a[k+Math.pow(2,t)] = a[k+Math.pow(2,t)] + a[k];

  print(turns);
}


Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

Output one integer  — the maximum number of breaks.

NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.

const readline = require('readline')

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

let lineIndex = 0
let inputs

let customerNum, totalTimeLen, breakLen
let time, length
let breakNum = 0, lastFinish = 0
interface.on('line', line => {
  inputs = line.split(' ').map(v => parseInt(v))
  if (lineIndex === 0) {
    customerNum = inputs[0]
    totalTimeLen = inputs[1]
    breakLen = inputs[2]
  } else {
    time = inputs[0]
    length = inputs[1]
    breakNum += Math.floor((time - lastFinish) / breakLen)
    lastFinish = time + length
  }

  if (lineIndex == customerNum) {
    breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)
    console.log(breakNum)
    process.exit()
  }
  lineIndex ++
})

var input = readline().split(' ');
var breaks = 0;

var n = Number(input[0]);
var l = Number(input[1]);
var a = Number(input[2]);
var prevEnd = 0;

for(var i=0; i<n; i++) {
  var interval = readline().split(' ').map(function(x) {return parseInt(x)});
  var start = interval[0];
  var len = interval[1];

  breaks += Math.floor((start-prevEnd)/a);
  prevEnd = start+len;
}

breaks += Math.floor((l-prevEnd)/a);
print(breaks);

var input = readline().split(' ');
var breaks = 0;

var n = Number(input[0]);
var l = Number(input[1]);
var a = Number(input[2]);
var prevEnd = 0;

for(var i=0; i<n; i++) {
  var interval = readline().split(' ');
  var start = Number(interval[0]);
  var len = Number(interval[1]);

  breaks += Math.floor((start-prevEnd)/a);
  prevEnd = start+len;
}

breaks += Math.floor((l-prevEnd)/a);
print(breaks);

var input = readline().split(' ').map(function(x) {return parseInt(x)});
var breaks = 0;

var n = input[0];
var l = input[1];
var a = input[2];
var prevEnd = 0;

for(var i=0; i<n; i++) {
  var interval = readline().split(' ').map(function(x) {return parseInt(x)});
  var start = interval[0];
  var len = interval[1];

  breaks += Math.floor((start-prevEnd)/a);
  prevEnd = start+len;
}

breaks += Math.floor((l-prevEnd)/a);
print(breaks + "");

function main(){
	var s = readline();
	var arr = s.split(" ").map(elm=>{
		return parseInt(elm);
	})
	var n = arr[0], L = arr[1], a = arr[2];
	var result = 0;
	var arr1 = [];
	arr1[0] = [];
	arr1[0][0] = arr1[0][1] = 0;
	for(var i = 1; i <= n; i++){
		var ss = readline().split(" ").map(x=>+x);
		// var t = arr1[i][0], l = arr1[i][1];
		arr1[i] = [];
		arr1[i][0] = ss[0], arr1[i][1] = ss[1];
		var cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);
		if(cnt >= a){
			result += Math.floor(cnt/a);
		}
	}
	if(L - (arr1[n][0]+arr1[n][1]) >= a){
		result += Math.floor((L - arr1[n][0]-arr1[n][1])/a);
	}
	// console.log(result);
	print(result)
}
main();

var input = readline().split(" ").map(function(el) {return parseFloat(el)});
var n = input[0];
var L = input[1];
var a = input[2];
var lastClientTime = 0;
var breaks = 0;
for (var i = 0; i < n; i++) {
    var client = readline().split(" ").map(function(el) {return parseFloat(el)});
    breaks += parseInt((client[0] - lastClientTime)/a);
    lastClientTime = client[0]+client[1];
    if (i == n - 1)
        breaks += parseInt((L - client[0]-client[1])/a);
}
if (n == 0)
    breaks = parseInt(L/a);
print(breaks);

var g = readline().split(" ");

var n = Number(g[0]);
var L = Number(g[1]);
var a = Number(g[2]);

var time = 0;
var count = 0;

for(i=0;i<n;i++){

    var y = readline().split(" ");

    var t = Number(y[0]);
    var l = Number(y[1]);

    count += Math.floor((t-time)/a);

    time = t + l;
}

count += Math.floor((L-time)/a);

print(count);

var line = readline().split(' ');
var numClients = line[0];
var totalTime = line[1];
var rest = line[2];

var occupiedArray = [];

var tTotal = [];
var lTotal = [];

for(var i=0; i < numClients; i++) {
    var newLine = readline().split(' ');
    var tinicial = parseInt(newLine[0]);
    var lfinal = parseInt(newLine[1]);

    tTotal[i] = tinicial;
    lTotal[i] = lfinal;
}

var ans = 0;
var start = 0;

for(var j=0; j < numClients; j++) {
    ans += Math.floor((tTotal[j] - start)/rest);
    start = tTotal[j] + lTotal[j];
}

ans += (totalTime-start)/rest;

print(Math.floor(ans));

const readline = require('readline')

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

let lineIndex = 0
let inputs

let customerNum, totalTimeLen, breakLen
let time, length
let breakNum = 0, lastFinish = 0
interface.on('line', line => {
  inputs = line.split(' ')

  if (lineIndex === 0) {
    customerNum = inputs[0]
    totalTimeLen = inputs[1]
    breakLen = inputs[2]
  } else {
    time = inputs[0]
    length = inputs[1]
    breakNum += Math.floor((time - lastFinish) / breakLen)
    lastFinish = time + length
  }
})
interface.on('close', () => {
  breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)
  console.log(breakNum)
  process.exit()
})

const readline = require('readline')

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

let lineIndex = 0
let inputs

let customerNum, totalTimeLen, breakLen
let time, length
let breakNum = 0, lastFinish = 0
interface.on('line', line => {
  inputs = line.split(' ')

  if (lineIndex === 0) {
    customerNum = inputs[0]
    totalTimeLen = inputs[1]
    breakLen = inputs[2]
  } else {
    time = inputs[0]
    length = inputs[1]
    breakNum += Math.floor((time - lastFinish) / breakLen)
    lastFinish = time + length
  }
  lineIndex ++
})
interface.on('close', () => {
  breakNum += Math.floor((totalTimeLen - lastFinish) / breakLen)
  console.log(breakNum)
  process.exit()
})

function main(){
	var s = readline();
	var arr = s.split(" ").map(elm=>{
		return parseInt(elm);
	})
	var n = arr[0], L = arr[1], a = arr[2];
	var result = 0;
	var arr1 = [];
	arr1[0] = [];
	arr1[0][0] = arr1[0][1] = 0;
	for(var i = 1; i <= n; i++){
		var ss = readline().split(" ").map(x=>+x);
		// var t = arr1[i][0], l = arr1[i][1];
		arr1[i] = [];
		arr1[i][0] = ss[0], arr[i][1] = ss[1];
		var cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);
		if(cnt >= a){
			result += cnt/a;
		}
	}
	if(L - (arr1[n][0]+arr1[n][1]) >= a){
		result += (L - arr1[n][0]-arr1[n][1])/a;
	}
	// console.log(result);
	print(result)
}
main();

function main(){
	var s = readline();
	var arr = s.split(" ").map(elm=>{
		return parseInt(elm);
	})
	var n = arr[0], L = arr[1], a = arr[2];
	var result = 0;
	var arr1 = [];
	arr1[0] = [];
	arr1[0][0] = arr1[0][1] = 0;
	for(var i = 1; i <= n; i++){
		var ss = readline().split(" ").map(x=>+x);
		// var t = arr1[i][0], l = arr1[i][1];
		arr1[i] = [];
		arr1[i][0] = ss[0], arr1[i][1] = ss[1];
		var cnt = arr1[i][0] - (arr1[i-1][0]+arr1[i-1][1]);
		if(cnt >= a){
			result += cnt/a;
		}
	}
	if(L - (arr1[n][0]+arr1[n][1]) >= a){
		result += (L - arr1[n][0]-arr1[n][1])/a;
	}
	// console.log(result);
	print(result)
}
main();

var input = readline().split(" ").map(function(el) {return parseFloat(el)});
var n = input[0];
var L = input[1];
var a = input[2];
var lastClientTime = 0;
var breaks = 0;
for (var i = 0; i < n; i++) {
    var client = readline().split(" ").map(function(el) {return parseFloat(el)});
    breaks += parseInt((client[0] - lastClientTime)/a);
    lastClientTime = client[1];
    if (i == n - 1)
        breaks += parseInt((L - client[1])/a);
}
if (n == 0)
    breaks = parseInt(L/a);
print(breaks);

var input = readline().split(" ").map(function(el) {return parseFloat(el)});
var n = input[0];
var L = input[1];
var a = input[2];
var lastClientTime = 0;
var breakMin = 0;
for (var i = 0; i < n; i++) {
    var client = readline().split(" ").map(function(el) {return parseFloat(el)});
    breakMin += (client[0] - lastClientTime);
    lastClientTime = client[1];
    if (i == n - 1)
        breakMin += L - client[0] - client[1];
}
if (n == 0)
    breakMin = L;
print(parseInt(breakMin/a));

var input = readline().split(" ").map(function(el) {return parseFloat(el)});
var n = input[0];
var L = input[1];
var a = input[2];
var lastClientTime = 0;
var breaks = 0;
for (var i = 0; i < n; i++) {
    var client = readline().split(" ").map(function(el) {return parseFloat(el)});
    breaks += parseInt((client[0] - lastClientTime)/a);
    lastClientTime = client[1];
    if (i == n - 1)
        breaks += parseInt((L - client[0] - client[1])/a);
}
if (n == 0)
    breaks = parseInt(L/a);
print(breaks);

var line = readline().split(' ');
var numClients = line[0];
var totalTime = line[1];
var rest = line[2];

var occupiedArray = [];

var tTotal = [];
var lTotal = [];

for(var i=0; i < numClients; i++) {
    var newLine = readline().split(' ');
    var tinicial = parseInt(newLine[0]);
    var lfinal = parseInt(newLine[1]);

    tTotal[i] = tinicial;
    lTotal[i] = lfinal;
}

var ans = 0;
var start = 0;

for(var j=0; j < numClients; j++) {
    ans += (tTotal[j] - start)/rest;
    start = tTotal[j] + lTotal[j];
}

ans += (totalTime-start)/rest;

print(Math.floor(ans));

var currentLine = 0;

function readline() {
    var ret = getline().split('\n')[currentLine];

    currentLine++;

    return ret;
}

function getline() {
    return '2 11 3\n0 1\n1 1'
}

var line = readline().split(' ');
var numClients = line[0];
var totalTime = line[1];
var rest = line[2];

var timeArray = [];
var occupiedArray = [];

for(var x=0; x <= totalTime; x++){ timeArray.push(x) }

for(var i=0; i < numClients; i++) {
    var newLine = readline().split(' ');

    timeArray[parseInt(newLine[0])] = 'x';
    timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';
}

var iterable = 0;
var numIntervals = 0;
var freeTime = 0;

while(iterable <= totalTime ) {

    if(timeArray[iterable] !== 'x') {
        freeTime++;
    } else {
        freeTime = 0;
    }

    if(freeTime == rest) {
        numIntervals++
        freeTime = 0;
    }

    iterable++
}

print(numClients > 0 ? numIntervals : Math.floor(totalTime/rest));

var line = readline().split(' ');
var numClients = line[0];
var totalTime = line[1];
var rest = line[2];

var timeArray = [];
var occupiedArray = [];

for(var x=0; x <= totalTime; x++){ timeArray.push(x) }

for(var i=0; i < numClients; i++) {
    var newLine = readline().split(' ');

    timeArray[parseInt(newLine[0])] = 'x';
    timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';
}

var iterable = 0;
var numIntervals = 0;
var freeTime = 1;

while(iterable <= totalTime ) {
    if(freeTime == Math.floor(totalTime / rest)) {
        numIntervals++
        freeTime = 1;
    }

    if(timeArray[iterable] !== 'x') {
        freeTime++;
    } else {
        freeTime = 0;
    }

    iterable++
}

print(numClients > 0 ? numIntervals : Math.floor(totalTime/rest));

var line = readline().split(' ');
var numClients = line[0];
var totalTime = line[1];
var rest = line[2];

var timeArray = [];
var occupiedArray = [];

for(var x=0; x <= totalTime; x++){ timeArray.push(x) }

for(var i=0; i < numClients; i++) {
    var newLine = readline().split(' ');

    timeArray[parseInt(newLine[0])] = 'x';
    timeArray[parseInt(newLine[0]) + parseInt(newLine[1])] = 'x';
}

var iterable = 0;
var numIntervals = 0;
var freeTime = 1;

while(iterable <= totalTime ) {
    if(freeTime == Math.floor(totalTime / rest)) {
        numIntervals++
        freeTime = 1;
    }

    if(timeArray[iterable] !== 'x') {
        freeTime++;
    } else {
        freeTime = 0;
    }

    iterable++
}

print(numIntervals);


Shohag has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He can perform the following operation any number of times (possibly, zero):  Select any positive integer $$$k$$$ (it can be different in different operations).  Choose any position in the sequence (possibly the beginning or end of the sequence, or in between any two elements) and insert $$$k$$$ into the sequence at this position.  This way, the sequence $$$a$$$ changes, and the next operation is performed on this changed sequence. For example, if $$$a=[3,3,4]$$$ and he selects $$$k = 2$$$, then after the operation he can obtain one of the sequences $$$[\underline{2},3,3,4]$$$, $$$[3,\underline{2},3,4]$$$, $$$[3,3,\underline{2},4]$$$, or $$$[3,3,4,\underline{2}]$$$.Shohag wants this sequence to satisfy the following condition: for each $$$1 \le i \le |a|$$$, $$$a_i \le i$$$. Here, $$$|a|$$$ denotes the size of $$$a$$$.Help him to find the minimum number of operations that he has to perform to achieve this goal. We can show that under the constraints of the problem it's always possible to achieve this goal in a finite number of operations.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the initial length of the sequence. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the sequence.

For each test case, print a single integer  — the minimum number of operations needed to perform to achieve the goal mentioned in the statement.

NoteIn the first test case, we have to perform at least one operation, as $$$a_2=3>2$$$. We can perform the operation $$$[1, 3, 4] \rightarrow [1, \underline{2}, 3, 4]$$$ (the newly inserted element is underlined), now the condition is satisfied.In the second test case, Shohag can perform the following operations:$$$[1, 2, 5, 7, 4] \rightarrow [1, 2, \underline{3}, 5, 7, 4] \rightarrow [1, 2, 3, \underline{4}, 5, 7, 4] \rightarrow [1, 2, 3, 4, 5, \underline{3}, 7, 4]$$$.In the third test case, the sequence already satisfies the condition.

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);
            var x = 0;
	        var ans = 0;
	        for(j = 0; j < n; j++){
	            if(a[j] > j + 1){
	                x = Math.abs((j + 1) - a[j]);
	                ans = Math.max(ans, x);
	            }
	        }
	        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);
	        var x = 0;
	        var ans = 0;
	        for(j = 0; j < n; j++){
	            if(k[j] > j + 1){
	                x = Math.abs((j + 1) - k[j]);
	                ans = Math.max(ans, x);
	            }
	        }
	        console.log(ans);
	    }
	}
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var output = 0;
		for(var i = 0; i < N; i++){
			output = Math.max(output, list[i] - (i + 1));
		}
		myout(output);
	}
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

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

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

  main();
});

// Codeforces Round #752 (Div. 2)

const main = () => {
  const t = +readLine();

  for (let testCaseNum = 0; testCaseNum < t; testCaseNum += 1) {
    const n = +readLine();

    const sequence = readLine()
      .split(' ')
      .map(str => +str);

    let shift = 0;

    for (let numIx = 0; numIx < n; numIx += 1) {
      const num = sequence[numIx];

      const diff = num - numIx - shift - 1;

      shift += diff > 0 ? diff : 0;
    }

    console.log(shift);
  }
};

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) {
    let ans = 0, summ = 0
    for (let i = 0; i < n; ++i) {
        if (arr[i] > (i + 1 + summ)) {
            summ += (arr[i] - i - 1 - summ)
        }
    }
    console.log(summ)
}

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

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 = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let cur = 0
    let ans = 0
    arr.forEach((x, i) => {
        cur++
        if (x > cur) {
            ans += x - cur
            cur += x - cur
        }
    })
    return ans
}

const numTestCases = parseInt(readline());
for (var i = 0; i < numTestCases; i++) {
    var initialLength = parseInt(readline());
    var sequence = readline().split(' ');
    var changes = 0;
    var an = 1;
    for (var j = 0; j < sequence.length; j++) {
        sequence[j] = parseInt(sequence[j]);
    }

    for (var t = 0; t < sequence.length; t++) {
        if (an < sequence[t]) {
            var changesNeeded = sequence[t] - an;
            an += changesNeeded;
            changes += changesNeeded;
        }
        an++;
    }

    print(changes);
}

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);
            var x = 0;
	        var ans = 0;
	        for(j = 0; j < n; j++){
	            if(a[j] > j + 1){
	                x = Math.abs((j + 1) - a[j]);
	                ans = Math.max(ans, x);
	            }
	        }
	        console.log(ans);
        }
    }
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var index = 0;
		var max = 0;
		for(var i = 0; i < N; i++){
			if(max < list[i] && i + 1 < list[i]){
				max = list[i];
				index = i + 1;
			}
		}
		myout(Math.max(0, max - index));
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var index = -1;
		var max = 0;
		for(var i = 0; i < N; i++){
			if(max < list[i]){
				max = list[i];
				index = i + 1;
			}
		}
		myout(Math.max(0, max - index));
	}
}


Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.

The first line of the input data contains an integer n (1 ≤ n ≤ 105). The second line contains an array of original integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).

Print on the single line the answer to the problem: the amount of subarrays, which are magical. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).

NoteNotes to sample tests:Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const A = ipt.split(EOL).slice(1, -1)[0].split(' ').map(v => parseInt(v))
  let B = []
  for (let i = 0; i < A.length;) {
    let k = 1
    while (A[i] == A[++i]) k++
    B.push(k)
  }

  let s = 0
  for (let i = 0; i < B.length; i++) {
    let b = B[i];
    s += b * (b + 1) / 2
  }
  console.log(s)
})


Long time ago there was a symmetric array $$$a_1,a_2,\ldots,a_{2n}$$$ consisting of $$$2n$$$ distinct integers. Array $$$a_1,a_2,\ldots,a_{2n}$$$ is called symmetric if for each integer $$$1 \le i \le 2n$$$, there exists an integer $$$1 \le j \le 2n$$$ such that $$$a_i = -a_j$$$.For each integer $$$1 \le i \le 2n$$$, Nezzar wrote down an integer $$$d_i$$$ equal to the sum of absolute differences from $$$a_i$$$ to all integers in $$$a$$$, i. e. $$$d_i = \sum_{j = 1}^{2n} {|a_i - a_j|}$$$.Now a million years has passed and Nezzar can barely remember the array $$$d$$$ and totally forget $$$a$$$. Nezzar wonders if there exists any symmetric array $$$a$$$ consisting of $$$2n$$$ distinct integers that generates the array $$$d$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.  The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$2n$$$ integers $$$d_1, d_2, \ldots, d_{2n}$$$ ($$$0 \le d_i \le 10^{12}$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print "YES" in a single line if there exists a possible array $$$a$$$. Otherwise, print "NO". You can print letters in any case (upper or lower).

NoteIn the first test case, $$$a=[1,-3,-1,3]$$$ is one possible symmetric array that generates the array $$$d=[8,12,8,12]$$$.In the second test case, it can be shown that there is no symmetric array consisting of distinct integers that can generate array $$$d$$$.

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

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

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

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

		//console.log({d})
		let ans = true, ssum = 0;
		for (let i = 0; i < 2*n; i += 2) {
			cur = (d[i]- 2*ssum) / (2*n-i);
			if (d[i] != d[i-1] && d[i] == d[i+1]  && cur > 0 && cur%1 == 0) ;
			else ans = false;
			//console.log({ssum, cur})
			ssum += cur;
		}

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

function solve(a){
    a.sort((x, y) => x-y);
    var d = [], sum = 0;
    for(var i = 0; i < a.length; i++){
        if(a[i] != a[i+1]) return 'NO';
        if(a[i] == a[i+2]) return 'NO';
        d.push(a[i]);
        i++;
    }
    for(var i = 2; i < d.length+1; i++){
        var dii1 = d[i-1]-d[i-2];
        var xi =  dii1 / (2*i-2);
        if(xi%1 != 0) return 'NO';
        else{
            sum += (d.length-i+1)*xi;
        }
    }
    if(d[0]-2*sum <= 0 || ((d[0]-2*sum)%(2*d.length))) return 'NO';
    return 'YES';
}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    var n = Number(readline());
    a = readline().split(' ').map((x) => Number(x));
    write(solve(a)+'\n');
}

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

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

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

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

		//console.log({d})
		let ans = true, ssum = 0;
		for (let i = 0; i < 2*n; i += 2) {
			cur = (d[i]- 2*ssum) / (2*n-i);
			if (d[i] != d[i+1] || cur == 0 || cur%1) ans = false;
			//console.log({ssum, cur})
			ssum += cur;
		}

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

function solve(a){
    a.sort((x, y) => x-y);
    var d = [], sum = 0;
    for(var i = 0; i < a.length; i++){
        if(a[i] != a[i+1]) return 'NO';
        d.push(a[i]);
        i++;
    }
    for(var i = 2; i < d.length+1; i++){
        var dii1 = d[i-1]-d[i-2];
        var xi =  dii1 / (2*i-2);
        if(xi%1 != 0) return 'NO';
        else{
            sum += (d.length-i+1)*xi;
        }
    }
    if(d[0]-2*sum <= 0 || ((d[0]-2*sum)%(2*d.length))) return 'NO';
    return 'YES';
}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    var n = Number(readline());
    a = readline().split(' ').map((x) => Number(x));
    write(solve(a)+'\n');
}


AquaMoon had $$$n$$$ strings of length $$$m$$$ each. $$$n$$$ is an odd number.When AquaMoon was gone, Cirno tried to pair these $$$n$$$ strings together. After making $$$\frac{n-1}{2}$$$ pairs, she found out that there was exactly one string without the pair!In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least $$$1$$$ and at most $$$m$$$) and swapped the letters in the two strings of this pair at the selected positions.For example, if $$$m = 6$$$ and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions $$$2$$$, $$$3$$$ and $$$6$$$ she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf".Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order.AquaMoon found the remaining $$$n-1$$$ strings in complete disarray. Also, she remembers the initial $$$n$$$ strings. She wants to know which string was stolen, but she is not good at programming. Can you help her?

This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the interactive problems guide for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq m \leq 10^5$$$) — the number of strings and the length of each string, respectively. The next $$$n$$$ lines each contain a string with length $$$m$$$, describing the original $$$n$$$ strings. All string consists of lowercase Latin letters. The next $$$n-1$$$ lines each contain a string with length $$$m$$$, describing the strings after Cirno exchanged and reordered them. It is guaranteed that $$$n$$$ is odd and that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. Hack format: The first line should contain a single integer $$$t$$$. After that $$$t$$$ test cases should follow in the following format: The first line should contain two integers $$$n$$$ and $$$m$$$. The following $$$n$$$ lines should contain $$$n$$$ strings of length $$$m$$$, describing the original strings. The following $$$\frac{n-1}{2}$$$ lines should describe the pairs. They should contain, in the following order: the index of the first string $$$i$$$ ($$$1 \leq i \leq n$$$), the index of the second string $$$j$$$ ($$$1 \leq j \leq n$$$, $$$i \neq j$$$), the number of exchanged positions $$$k$$$ ($$$1 \leq k \leq m$$$), and the list of $$$k$$$ positions that are exchanged ($$$k$$$ distinct indices from $$$1$$$ to $$$m$$$ in any order). The final line should contain a permutation of integers from $$$1$$$ to $$$n$$$, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored.

For each test case print a single line with the stolen string.

3
3 5
aaaaa
bbbbb
ccccc
aaaaa
bbbbb
3 4
aaaa
bbbb
cccc
aabb
bbaa
5 6
abcdef
uuuuuu
kekeke
ekekek
xyzklm
xbcklf
eueueu
ayzdem
ukukuk

NoteIn the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string.In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string.This is the first test in the hack format: 33 5aaaaabbbbbccccc1 2 5 1 2 3 4 52 1 33 4aaaabbbbcccc1 2 2 1 22 1 35 6abcdefuuuuuukekekeekekekxyzklm1 5 3 2 3 62 4 3 2 4 65 4 1 2 3

"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 flush() {
  process.stdout.clearLine();
  process.stdout.cursorTo(0);
}
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    n = (n << 1) - 1;
    let arr = [],
      ans = new Array(m).fill(0);
    for (let i = 0; i < n; i++) arr.push(readline().trim());
    for (let i = 0; i < m; i++) {
      for (let j = 0; j < n; j++) ans[i] ^= arr[j].charCodeAt(i);
    }
    let res = "";
    for (let i = 0; i < m; i++) res += String.fromCharCode(ans[i]);
    console.log(res);
  }
};
solve();

const aCharCode = 'a'.charCodeAt(0);
const zCharCode = 'z'.charCodeAt(0);

function solve() {
   const [n, m] = readArray(Number);
   const xxx = 'x'.repeat(zCharCode - aCharCode + 1).split('').map((x) => 0);
   const counter = 'x'.repeat(m).split('').map(() => xxx.slice(0));
   let str;
   for (let i = 0; i < n; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         counter[j][str.charCodeAt(j) - aCharCode]++;
      }
   }
   for (let i = 0; i < n - 1; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         counter[j][str.charCodeAt(j) - aCharCode]++;
      }
   }
   ans = '';
   for (let i = 0; i < m; i++) {
      for (let j = 0; j <= zCharCode - aCharCode; j++) {
         if (counter[i][j] & 1) {
            ans += String.fromCharCode(aCharCode + j);
            break;
         }
      }
   }
   write(ans);
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e + e.stack.split('\n').join(' '));
   }
}

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

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;

   var needWriteFile = false;

   var writeResult = '';
   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');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

"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, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr1 = [];
    for (let i = 0; i < n; i++) arr1.push(readline().trim().split(""));
    let arr2 = [];
    for (let i = 0; i < n - 1; i++) arr2.push(readline().trim().split(""));
    for (let i = 0; i < m; i++) {
      let obj = {};
      for (let j = 0; j < n - 1; j++) obj[arr2[j][i]] = 1;
      let flag = false,
        ind = -1;
      for (let j = 0; j < n; j++) {
        if (!obj[arr1[j][i]]) {
          flag = true;
          ind = j;
          break;
        }
      }
      if (flag) {
        console.log(arr1[ind].join(""));
        break;
      }
    }
  }
};
solve();

const aCharCode = 'a'.charCodeAt(0);
const zCharCode = 'z'.charCodeAt(0);

function solve() {
   const [n, m] = readArray(Number);
   const xxx = 'x'.repeat(zCharCode - aCharCode + 1).split('').map((x) => 0);
   const counter = 'x'.repeat(m).split('').map(() => xxx.slice(0));
   let str;
   for (let i = 0; i < n; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         counter[j][str.charCodeAt(j) - aCharCode]++;
      }
   }
   for (let i = 0; i < n - 1; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         counter[j][str.charCodeAt(j) - aCharCode]++;
      }
   }
   ans = '';
   for (let i = 0; i < m; i++) {
      for (let j = 0; j <= zCharCode - aCharCode; j++) {
         if (counter[i][j] & 1) {
            ans += String.fromCharCode(aCharCode + j);
            break;
         }
      }
   }
   write(ans);
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e + e.stack);
   }
}

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

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;

   var needWriteFile = false;

   var writeResult = '';
   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');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

const letters = [];
const aCharCode = 'a'.charCodeAt(0);
const zCharCode = 'z'.charCodeAt(0);
for (let i = aCharCode; i <= zCharCode; i++) {
   letters.push(String.fromCharCode(i));
}

function solve() {
   const [n, m] = readArray(Number);
   const counter = 'x'.repeat(m).split('').map(() => new Map());
   let str;
   for (let i = 0; i < n; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         const currentCounter = counter[j];
         if (currentCounter.has(str[j])) {
            currentCounter.set(str[j], currentCounter.get(str[j]) + 1);
         } else {
            currentCounter.set(str[j], 1);
         }
      }
   }
   for (let i = 0; i < n - 1; i++) {
      str = read();
      for (let j = 0; j < m; j++) {
         const currentCounter = counter[j];
         if (currentCounter.has(str[j])) {
            currentCounter.set(str[j], currentCounter.get(str[j]) + 1);
         } else {
            currentCounter.set(str[j], 1);
         }
      }
   }
   ans = '';
   for (let i = 0; i < m; i++) {
      const currentCounter = counter[i];
      for (let j = 0; j < letters.length; j++) {
         if (!currentCounter.has(letters[j])) {
            continue;
         }
         const num = currentCounter.get(letters[j]);
         if (num & 1) {
            ans += letters[j];
            break;
         }
      }
   }
   write(ans);
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e + e.stack);
   }
}

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

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;

   var needWriteFile = false;

   var writeResult = '';
   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');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}


Valera loves his garden, where n fruit trees grow.This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.  Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.

Print a single integer — the maximum number of fruit that Valera can collect.

NoteIn the first sample, in order to obtain the optimal answer, you should act as follows.   On the first day collect 3 fruits from the 1-st tree.  On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.  On the third day collect the remaining fruits from the 2-nd tree.  In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.

var nextToken = new function() {
    var line = [];
    var lineIndex = 0;

    return function() {
        while (lineIndex >= line.length) {
            line = readline().split(/\s+/);
            lineIndex = 0;
        }

        return line[lineIndex++];
    }
}();

var nextInt = function() {
    return parseInt(nextToken(), 10);
};

var main = function () {
    var n = nextInt();
    var v = nextInt();
    var ans = 0;
    var i, a, b, cur;

    var cnt = [];
    for (i = 0; i < n; ++i) {
            var a, b;
            a = nextInt();
            b = nextInt();

            while (cnt.length <= a) {
                cnt.push(0);
            }

            cnt[a] += b;
    }
    cnt.push(0);

    var left = 0;

    for (i = 0; i < cnt.length; ++i) {
            var cur = v;
            if (left <= cur) {
                ans += left;
                cur -= left;
                left = 0;
            } else {
                ans += cur;
                left -= cur;
                cur = 0;
            }

            ans += Math.min(cur, cnt[i]);
            left = Math.max(0, cnt[i] - cur);
    }

    print(ans);
};

main();

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		numTrees = data[0], fruitPerDay = data[1],
		days = new Array(3003);
	for (var i = 0; i <= 3002; ++i) {
		days[i] = [0, 0];
	}
	for (var i = 0; i < numTrees; ++i) {
		data = tokenizeIntegers(readline());
		var day = data[0], fruit = data[1];
		days[day][0] += fruit;
		days[day+1][1] += fruit;
	}
	var result = 0;
	for (var i = 1; i <= 3001; ++i) {
		var yesterday = Math.min(fruitPerDay, days[i][1]),
			total = Math.min(fruitPerDay, yesterday + days[i][0]),
			today = total - yesterday;
		days[i+1][1] = Math.max(0, days[i+1][1] - today);
		result += total;
	}
	print(result);
}

main();

var nextToken = new function() {
    var line = [];
    var lineIndex = 0;

    return function() {
        while (lineIndex >= line.length) {
            line = readline().split(/\s+/);
            lineIndex = 0;
        }

        return line[lineIndex++];
    }
}();

var nextInt = function() {
    return parseInt(nextToken(), 10);
};

var main = function () {
    var n = nextInt();
    var v = nextInt();
    var ans = 0;
    var i, a, b, cur;

    var cnt = [];
    for (i = 0; i < n; ++i) {
            var a, b;
            a = nextInt();
            b = nextInt();

            while (cnt.length <= a) {
                cnt.push(0);
            }

            cnt[a] += b;
    }
    cnt.push(0);

    var left = 0;

    for (i = 0; i < cnt.length; ++i) {
            var cur = v;
            if (left <= cur) {
                ans += left;
                cur -= left;
                left = 0;
            } else {
                ans += cur;
                left -= cur;
                cur = 0;
            }

            ans += Math.min(cur, cnt[i]);
            left += Math.max(0, cnt[i] - cur);
    }

    print(ans);
};

main();


Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.The prefix of string $$$s$$$ of length $$$l$$$ ($$$1 \le l \le n$$$) is a string $$$s[1..l]$$$.For example, for the string $$$s=$$$"abba" there are two prefixes of the even length. The first is $$$s[1\dots2]=$$$"ab" and the second $$$s[1\dots4]=$$$"abba". Both of them have the same number of 'a' and 'b'.Your task is to calculate the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.

The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.

In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.

NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.

//Don't have to see. start------------------------------------------
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);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var s = nextCharArray();
  var count = 0;
  for(var i = 0; i < N; i += 2){
    if(s[i] == s[i + 1]){
      if(s[i] == "a"){
        s[i] = "b";
      }else{
        s[i] = "a";
      }
      count++;
    }
  }
  myout(count);
  myout(myconv(s, 0));
}

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

    function foo (oldStr, length) {
        let count = 0;
        let data = oldStr.split('');
        let index = 0;
        while (index <  (length)) {
            let pair = data.slice(index, index + 2);
            if (pair[0] === pair[1]) {
                count++;
                data[index] = data[index] === 'a' ? 'b' : 'a';
            }
            index = index + 2;
        }

        return {count, newStr: data.join('')};
    }

    let length = +lines[0];
    let oldStr = lines[1];

    let result = foo(oldStr, length);

    let answer = '';
    answer += result.count + "\n";
    answer += result.newStr;

    console.log(answer);
})

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

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

  let ans = 0;
  let obj = {
    'a': 'b',
    'b': 'a',
  };
  const arr = str.split('');

  for (let i = 0; i < arr.length; i += 2) {
    if (arr[i] === arr[i + 1]) {
      ans++;
      arr[i] = obj[arr[i]];
    }
  }

  console.log(ans);
  console.log(arr.join(''));

  c++;
});

// const readline = require('readline');
//
// const rl = readline.createInterface({ input: process.stdin , output: process.stdout });
//
// const getLine = (function () {
//     const getLineGen = (async function* () {
//         for await (const line of rl) {
//             yield line;
//         }
//     })();
//     return async () => ((await getLineGen.next()).value);
// })();
//
// async function main() {
//     let n = Number(await getLine());
//     let s = await getLine();
//     let c = 0;
//     let result = "";
//
//     for (let i = 0; i < n; i += 2){
//         if (s[i] == s[i + 1]) {
//             c++;
//             result += s[i] == 'a' ? 'b' : 'a';
//             result += s[i + 1];
//         }
//         else{
//             result += s[i] + s[i + 1];
//         }
//     }
//
//     console.log(c);
//     console.log(result);
//     process.exit(0);
// }
//
// main();

var n = parseInt(readline());
var s = readline();
var c = 0;
var result = "";

for (var i = 0; i < n; i += 2) {
    if (s[i] == s[i + 1]) {
        c++;
        result += s[i] == 'a' ? 'b' : 'a';
        result += s[i + 1];
    } else {
        result += s[i] + s[i + 1];
    }
}

print(c);
print(result);

'use strict'

const n = parseInt(readline());
const s = readline();

let r = 0;
let S = '';
for (let i = 0; i < n; i+=2) {
    const x = s[i] + s[i+1];
    if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}
    else { S += x };
}
write(r + '\n' + S);

n = +readline()
s = readline()
op = 0
ans = ''
for (i = 1; i < s.length; i += 2) {
  x = s.charAt(i - 1), y = s.charAt(i)
  if (x == y) {
    op++
    ans += 'ab'
  }
  else
    ans += x + y
}
print(op + '\n' + ans)

n = +readline()
s = readline()
op = 0
ans = ''
for (i = 1; i < s.length; i += 2) {
  if (s[i - 1] == s[i]) {
    op++
    ans += 'ab'
  }
  else
    ans += s[i - 1] + s[i]
}
print(op + '\n' + ans)

'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() {
    var q = 0;
    var n = readline();
    var s = readline();
    s = s.split('');
    for (var i = 1; i < s.length; i+=2) {
      if(s[i]==s[i-1]){
          q++;
          if(s[i]=='a')
              s[i]='b';
          else
              s[i]='a';
      }
    }
    console.log(q);
    console.log(s.join(''));
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')

  const l = parseInt(arr.shift())
  let str = arr.shift()
  let str2 = ''
  let no = 0

  for(let i = 0; i < l; i += 2) {
    if(str[i] == str[i + 1]) {
      no ++
      str2 += 'ab'
    }

    else {
      str2 = str2 + str[i] + str[i + 1]
    }

  }

  console.log(no)
  console.log(str2)

})

function replace(a, index, char) {
  return a.substr(0, index) + char + a.substr(index + 1)
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')

  const l = parseInt(arr.shift())
  let str = arr.shift()
  let str2 = ''
  let no = 0

  for(let i = 0; i < l; i += 2) {
    str2 += 'ab'
    if(str[i] == str[i + 1]) {
      no ++
    }
  }

  console.log(no)
  console.log(str)

})

function replace(a, index, char) {
  return a.substr(0, index) + char + a.substr(index + 1)
}

'use strict'

const n = parseInt(readline());
const s = readline();

let r = 0;
let S = '';
for (let i = 0; i < n / 2; i++) {
    const x = s.slice(i, i+2);
    if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}
    else { S += x };
}
write(r + '\n' + S + (n % 2) ? s[n-1] : '');

'use strict'

const n = parseInt(readline());
const s = readline();

let r = 0;
let S = '';
for (let i = 0; i < n / 2; i++) {
    const x = s[i] + s[i+1];
    if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}
    else { S += x };
}
write(r + '\n' + S + (n % 2 ? s[n-1] : ''));

'use strict'

const n = parseInt(readline());
const s = readline();

let r = 0;
let S = '';
for (let i = 0; i < n / 2; i+=2) {
    const x = s[i] + s[i+1];
    if (x !== 'ab' && x !== 'ba') { r++; S += 'ab';}
    else { S += x };
}
write(r + '\n' + S);

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')

  const l = parseInt(arr.shift())
  let str = arr.shift()
  let str2 = ''
  let no = 0

  for(let i = 0; i < l; i += 2) {
    str2 += 'ab'
    if(str[i] == str[i + 1]) {
      no ++
    }
  }

  console.log(no)
  console.log(str2)

})

function replace(a, index, char) {
  return a.substr(0, index) + char + a.substr(index + 1)
}