Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.Упрощенно процесс фотографирования можно описать следующим образом. На фотографии каждый из друзей занимает прямоугольник из пикселей: в стоячем положении i-й из них занимает прямоугольник ширины wi пикселей и высоты hi пикселей. Но также, при фотографировании каждый человек может лечь, и тогда он будет занимать прямоугольник ширины hi пикселей и высоты wi пикселей.Общая фотография будет иметь размеры W × H, где W — суммарная ширина всех прямоугольников-людей, а H — максимальная из высот. Друзья хотят определить, какую минимальную площадь может иметь общая фотография. Помогите им в этом.

В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей. В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей.

Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей.

var n = +readline(),
    dims = [],
    dim, i, h, s, pair, min = +Infinity;
for (i = 0; i < n; i++) {
    pair = readline().split(' ');
    dims[i] = [];
    dims[i][0] = +pair[0];
    dims[i][1] = +pair[1];
}
for (h = 1000; h > 0; h--) {
    s = 0;
    for (i = 0; i < n; i++) {
        dim = dims[i].sort(function(a,b) {
            return a - b;
        });
        if (h < dim[0]) {
            h = 0;
            break;
        } else {
            s += h*dim[h < dim[1] ? 1 : 0];
        }
    }
    h == 0 || (min = Math.min(min, s));
}
print(min);

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {
		return Number(v);
	});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].width) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].height) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height <= height && sizes[j].width <= height) {
					if (sizes[j].height <= sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return -1;
			}
		}
	}
	if (width != undefined) {
		return width;
	} else {
		return -1;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width) {
		width = (width + sizes[i].height) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		print(width + sizes[i].height, height)
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width) {
		width = (width + sizes[i].height) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width < height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {
		return Number(v);
	});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].width) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].height) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height <= height && sizes[j].width <= height) {
					if (sizes[j].height <= sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return -1;
			}
		}
	}
	if (width) {
		return width;
	} else {
		return -1;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	width = (width + sizes[i].width) * height;
	if (result) {
		if (result > width) {
			result = width;
		}
	} else {
		result = width;
	}
	height = sizes[i].width;
	width = compare(i, height);
	width = (width + sizes[i].height) * height;
	if (result) {
		if (result > width) {
			result = width;
		}
	} else {
		result = width;
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	} else {
		return 0;
	}
}

print(result)


There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values:   how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?  how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$).

For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them.

NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [a, b, c] = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    let [l, r] = [-1, -1];
    if (a < c) l = 1;

    if (a * b > c) r = b;

    console.log(`${l} ${r}`);
  }
}

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] * 1;
  let i = 1;
  while (i <= testCases) {
    let str = data[i].split(' ');
    let a = +str[0];
    let b = +str[1];
    let c = +str[2];
    if ((a == c && a == b) || a > c) {
      console.log(-1, b);
      i += 1;
      continue;
    }
    if (a == c) {
      console.log(-1, b);
      i += 1;
      continue;
    }
    if (a * b <= c) {
      console.log(1, -1);
      i += 1;
      continue;
    }
    console.log(1, b);
    i += 1;
  }
}

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(/\r?\n/);
    const testCases = data[0] * 1;
    let numAnswered = 0
    let i = 1;
    while (i <= testCases) {
        let split = data[i].split(" ")
        let a = split[0] * 1
        let b = split[1] * 1
        let c = split[2] * 1

        let shop1Cheaper = 0
        let x = 1
        let curDiff = Number.MAX_VALUE
        while (shop1Cheaper === 0) {
            let tempDiff = a * x - Math.ceil(x/b) * c
            let endIfNotAnswer = tempDiff > curDiff
            curDiff = tempDiff
            shop1Cheaper = curDiff < 0 ? x : (endIfNotAnswer ? -1 : 0)
            x++
        }

        let shop2Cheaper = 0
        x = b
        curDiff = Number.NEGATIVE_INFINITY
        while (shop2Cheaper === 0) {
            let tempDiff = a * x - Math.ceil(x/b) * c
            let endIfNotAnswer = tempDiff < curDiff
            curDiff = tempDiff
            shop2Cheaper = curDiff > 0 ? x : (endIfNotAnswer ? -1 : 0)
            x++
        }
        console.log(`${shop1Cheaper} ${shop2Cheaper}`)
        i++
    }
}

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 => string.trim());

    main();
});

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

const s2i = s => parseInt(s, 10);

function main() {
  let T = s2i(readLine());
  let a, b, c, r1, r2;
  while (T--) {
    [a, b, c] = readLine().split(' ').map(s2i);

    if (a < c) {
      r1 = 1;
    } else {
      r1 = -1;
    }

    if (c/b < a) {
      r2 = b;
    } else {
      r2 = -1;
    }

    console.log(r1 + ' ' + r2);
  }
}

function solve() {
   var T = Number(read());
   var ans = [-1, -1];
   for (var t = 0; t < T; t++) {
      var abc = read().split(' ').map(BigInt);
      var a = abc[0];
      var b = abc[1];
      var c = abc[2];
      ans[0] = a < c ? 1 : -1;
      ans[1] = a * b > c ? b : -1;
      write(ans.join(' '));
   }
}

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 n = readline();
var mapping =[];

for (var i = 0; i<n;i++){
    mapping.push(readline().split(" ").map(function (x) {
        return parseInt(x);
    }));
}

for (var i = 0; i<n;i++) {
    if (mapping[i][0]>=mapping[i][2]){
        write(-1 + " ");
    }else{
        var ni = 1;
        while (true){
            if (mapping[i][0] * ni < mapping[i][2] * Math.ceil(parseFloat(ni/mapping[i][1]))){
                break;
            }
            ni++;
        }
        write(ni + " ");
    }

    if (parseFloat(mapping[i][0]) <= parseFloat(mapping[i][2] / mapping[i][1])){
        write(-1 + "\n");
    }else{
        var ni = 1;
        while (true){
            if (parseInt(mapping[i][2] * ni) < parseInt(mapping[i][0] * mapping[i][1] * ni)){
                break;
            }
            ni++;
        }
        write(ni *mapping[i][1]  + "\n");
    }

}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [single, totalItem, totalValue] = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    let [left, right] = [-1, -1];
    if (single - totalValue < 0) {
      left = 1;
      if (+(totalValue / totalItem).toFixed(2) < single) right = 1;
      console.log(`${left} ${right}`);
    } else {
      console.log(`${left} ${1}`);
    }
  }
}

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] * 1;
    let i = 1;
    while (i <= testCases) {
      let str = data[i].split(' ');
      let a = +str[0];
      let b = +str[1];
      let c = +str[2];
      if ((a == c && a == b) || a > c) {
        console.log(-1, b);
        i += 1;
        continue;
      }
      if (a * b <= c) {
        console.log(1, -1);
        i += 1;
        continue;
      }
      console.log(1, b);
      i += 1;
    }
  }


Andi and Budi were given an assignment to tidy up their bookshelf of $$$n$$$ books. Each book is represented by the book title — a string $$$s_i$$$ numbered from $$$1$$$ to $$$n$$$, each with length $$$m$$$. Andi really wants to sort the book lexicographically ascending, while Budi wants to sort it lexicographically descending.Settling their fight, they decided to combine their idea and sort it asc-desc-endingly, where the odd-indexed characters will be compared ascendingly, and the even-indexed characters will be compared descendingly.A string $$$a$$$ occurs before a string $$$b$$$ in asc-desc-ending order if and only if in the first position where $$$a$$$ and $$$b$$$ differ, the following holds:  if it is an odd position, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$;  if it is an even position, the string $$$a$$$ has a letter that appears later in the alphabet than the corresponding letter in $$$b$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \cdot m \leq 10^6$$$). The $$$i$$$-th of the next $$$n$$$ lines contains a string $$$s_i$$$ consisting of $$$m$$$ uppercase Latin letters — the book title. The strings are pairwise distinct.

Output $$$n$$$ integers — the indices of the strings after they are sorted asc-desc-endingly.

NoteThe following illustrates the first example.

"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 [n, m] = readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
  let arr = [];
  for (let i = 0; i < n; i++) arr.push(readline().trim().split(""));
  for (let i = 0; i < n; i++) {
    arr[i].push(i + 1);
  }
  arr.sort((a, b) => {
    let ind = 0;
    for (let j = 0; j < m; j++) {
      if (a[j] !== b[j]) {
        ind = j + 1;
        break;
      }
    }
    if (ind === 0) return 0;
    else if (ind & 1) {
      if (a[ind - 1] < b[ind - 1]) return -1;
      else return 1;
    } else {
      if (a[ind - 1] > b[ind - 1]) return -1;
      else return 1;
    }
  });
  let res = "";
  for (let i = 0; i < n; i++) {
    res += arr[i][m] + " ";
  }
  console.log(res);
};
solve();


Let's call the string beautiful if it does not contain a substring of length at least $$$2$$$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, but the strings ab, abbbaa, cccb are not.Let's define cost of a string as the minimum number of operations so that the string becomes beautiful, if in one operation it is allowed to change any character of the string to one of the first $$$3$$$ letters of the Latin alphabet (in lowercase).You are given a string $$$s$$$ of length $$$n$$$, each character of the string is one of the first $$$3$$$ letters of the Latin alphabet (in lowercase).You have to answer $$$m$$$ queries — calculate the cost of the substring of the string $$$s$$$ from $$$l_i$$$-th to $$$r_i$$$-th position, inclusive.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$ and the number of queries. The second line contains the string $$$s$$$, it consists of $$$n$$$ characters, each character one of the first $$$3$$$ Latin letters. The following $$$m$$$ lines contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) — parameters of the $$$i$$$-th query.

For each query, print a single integer — the cost of the substring of the string $$$s$$$ from $$$l_i$$$-th to $$$r_i$$$-th position, inclusive.

NoteConsider the queries of the example test.  in the first query, the substring is baa, which can be changed to bac in one operation;  in the second query, the substring is baacb, which can be changed to cbacb in two operations;  in the third query, the substring is cb, which can be left unchanged;  in the fourth query, the substring is aa, which can be changed to ba in one operation.

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
const res = []
let pr, cur = 0, m, n;

const pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

/**
 * I have used a split and map together which time complexity is O(n)
 *
 * The sum of characters of every word will
 * always be the length of the sentance.
 * The complexity is O(sum of all words'
 * character lengths), and instead of estimating
 * both character length and amount of words at
 * the worst case, we notice this is simply O(n).
 *
 * As sequential chaining of a constant amount
 * of O(n) operations is still O(n),
 * we get the above mentioned overall complexity
 * of O(n), where n is the amount of characters.
 *
 * used a simple for loop inside of a while loop
 * the complexity of while loop is O(n^2)
 *
 * The total complexity of the program is O(n^2) = O(n) + O(n^2)
*/

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 2) {
    [n, m] = input[0].split(' ').map(e => +e) // O(n)
    let s = input[1]
    pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))
    do { // O(n^2)
      for (let i = 0; i < n; ++i) { // O(n)
        pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);
      }
      ++cur;
    } while(cur < 6)
  }

  if (input.length > 2) {
    const [l, r] = input.pop().split(' ').map(e => +e)
    let ans = n;
    for (let i = 0; i < 6; ++i)
      ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);
    res.push(ans)
  }

});
rl.on("close", () => {
  res.forEach(e => console.log(e))
});

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
const res = []
let pr, cur = 0, m, n
const pers = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
rl.on("line", (line) => {
  input.push(line);
  if (input.length === 2) {
    [n, m] = input[0].split(' ').map(e => +e)
    let s = input[1]
    pr = Array.from({ length: 6 }, () => Array(n + 1).fill(0))
    do {
      for (let i = 0; i < n; ++i) {
        pr[cur][i + 1] = pr[cur][i] + (s[i] !== pers[cur][i % 3]);
      }
      ++cur;
    } while(cur < 6)
  }
  if (input.length > 2) {
    const [l, r] = input.pop().split(' ').map(e => +e)
    let ans = n;
    for (let i = 0; i < 6; ++i) ans = Math.min(ans, pr[i][r] - pr[i][l - 1]);
    res.push(ans)
  }

});
rl.on("close", () => {
  res.forEach(e => console.log(e))
});

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    // var t = parseInt(lines[0]);
    var l = 0;
    var [n, m] = lines[l++].trim().split(' ').map(Number)
    var str = lines[l++]
    var arr = lines.slice(l, l + m).map(str => str.trim().split(' ').map(Number))
    l += m
    console.log(solve(n, m, str, arr))
    // for (var i = 0; i < t; i++) {
    //     var n = +lines[l++]
    //     var a = lines[l++].trim().split(' ').map(Number)
    //     var b = lines[l++].trim().split(' ').map(Number)
    // }
});

function solve(n, m, str, arr) {
    const d = [];
    ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'].forEach((p, i) => {
        d[i] = []
        for (let j = 0; j < n; j++) {
            const ch = p[j % 3]
            d[i][j] = str[j] === ch ? 0 : 1
        }
    })

    const prefix = []
    for (let i = 0; i < d.length; i++) {
        prefix[i] = []
        for (let j = 0; j < d[i].length; j++) {
            prefix[i][j] = j ? d[i][j] + prefix[i][j - 1] : d[i][j]
        }
    }

    return arr.map(([l, r]) => {
        l--
        r--
        const ds = prefix.map(p => p[r] - (l ? p[l - 1] : 0))
        return Math.min(...ds)
    }).join('\n')
}

'use strict';

function solve(n, m, s, a) {
  const sums = [],
        strs = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];
  for (let str of strs) {
    let sum = new Array(n);
    for (let i = 0; i < n; i++) {
      var _sum;
      sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + (s[i] === str[i % 3] ? 0 : 1);
    }
    sums.push(sum);
  }
  let res = new Array(m);
  for (let [i, [l, r]] of a.entries()) {
    let min = Infinity;
    for (let i = 0; i < 6; i++) {
      var _sums$i;
      min = Math.min(min, sums[i][r] - ((_sums$i = sums[i][l - 1]) !== null && _sums$i !== void 0 ? _sums$i : 0));
    }
    res[i] = min;
  }
  return res.join('\n');
}

async function main(read) {
  try {
    let res = [];
    const [n, m] = (await read()).split(' ').map(Number);
    const s = await read();
    const a = [];
    let tmp = m;
    while (tmp--) {
      a.push((await read()).split(' ').map(str => Number(str) - 1));
    }
    res.push(solve(n, m, s, a));
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

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

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

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

function main () {
	let [n, m] = rna();
	const s = rl();

	const cost = Array.from(Array(6), _ => []);
	const perm = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];

	for (let i = 0; i < n; i++) {
		for (let j = 0; j < perm.length; j++) {
			cost[j][i] = cost[j][i-1] || 0;
			if (s[i] != perm[j][i%3]) cost[j][i]++;
		}
	}

	while (m--) {
		let [l, r] = rna(); l--, r--;
		let ans = 1e9;
		for (let i = 0; i < cost.length; i++) {
			ans = Math.min(ans, cost[i][r] - (cost[i][l-1] || 0));
		}
		console.log(ans);
	}
}

'use strict'
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MAX_N = 200010,
  a = new Array(MAX_N),
  b = new Array(MAX_N),
  c = new Array(MAX_N),
  a2 = new Array(MAX_N),
  b2 = new Array(MAX_N),
  c2 = new Array(MAX_N)
__main__(function (e) {
  const [n, t] = e.readIntegersOfLine(),
    i = e.readLine().trim()
  ;(a[0] = b[0] = c[0] = 0), (a2[0] = b2[0] = c2[0] = 0)
  for (let e = 0; e < i.length; ++e) {
    const n = i[e]
    ;(a[e + 1] = c[e] + ('a' === n ? 0 : 1)),
      (b[e + 1] = a[e] + ('b' === n ? 0 : 1)),
      (c[e + 1] = b[e] + ('c' === n ? 0 : 1)),
      (a2[e + 1] = b2[e] + ('a' === n ? 0 : 1)),
      (b2[e + 1] = c2[e] + ('b' === n ? 0 : 1)),
      (c2[e + 1] = a2[e] + ('c' === n ? 0 : 1))
  }
  for (let i = 0; i < t; ++i) {
    let [t, i] = e.readIntegersOfLine()
    t -= 1
    let s = n
    switch ((i - t + 1) % 3) {
      case 0:
        s = Math.min(
          c[i] - a[t],
          a[i] - b[t],
          b[i] - c[t],
          b2[i] - a2[t],
          c2[i] - b2[t],
          a2[i] - c2[t],
        )
        break
      case 1:
        s = Math.min(
          a[i] - a[t],
          b[i] - b[t],
          c[i] - c[t],
          a2[i] - a2[t],
          b2[i] - b2[t],
          c2[i] - c2[t],
        )
        break
      case 2:
        s = Math.min(
          b[i] - a[t],
          c[i] - b[t],
          a[i] - c[t],
          c2[i] - a2[t],
          a2[i] - b2[t],
          b2[i] - c2[t],
        )
    }
    e.print(s + '\n')
  }
})

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/r/g, '').split('\n');
    const [len, total] = input[0].split(' ').map((ele) => +ele);
    const str = input[1];
    const tree = new Tree(str);
    for (let i = 0; i < total; i++) {
        solve(tree, input[2 + i]);
    }

    process.exit();
});

function solve(tree, range) {
    const [L, R] = range.split(' ').map((ele) => ele - 1);
    const result = tree.findEntry(L, R);
    console.log(Math.min(...result));
}

class Tree {

    constructor(str) {
        this.mays = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'];
        this.root = this.build(str, 0, str.length - 1);
    }

    build(str, l, r) {
        if (l === r) {
            const ary = new Array(18);
            for (let i = 0; i < 6; i++) {
                const compare = this.mays[i];
                ary[i * 3] = str[l] === compare[l % 3] ? 0 : 1;
                ary[i * 3 + 1] = str[l] === compare[(l + 1) % 3] ? 0 : 1;
                ary[i * 3 + 2] = str[l] === compare[(l + 2) % 3] ? 0 : 1;
            }
            return {
                l,
                r,
                ary
            };
        } else {
            const mid = (l + r) >> 1;
            const left = this.build(str, l, mid);
            const right = this.build(str, mid + 1, r);
            const ary = new Array(18);
            for (let i = 0; i < 18; i++) {
                ary[i] = left.ary[i] + right.ary[i];
            }
            return {
                l,
                r,
                ary,
                left,
                right
            }
        }
    }

    findEntry(l, r) {
        const result = new Array(18).fill(0);
        this.find(this.root, l, r, result);
        return result;
    }

    find(root, l, r, result) {
        if (root.l === l && root.r === r) {
            for (let i = 0; i < 18; i++) {
                result[i] += root.ary[i];
            }
            return;
        } else {
            root.left.r >= l && this.find(root.left, l, root.left.r, result);
            root.right.l <= r && this.find(root.right, root.right.l, r, result);
        }
    }
}

var readline = require('readline');

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

var g = main();
g.next()
rl.on('line', (input) => {
    g.next(input)
    // console.log('read', input)
    // input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    input = yield 1
    var t = +input
    for (var i = 0; i < t; i++) {
        input = yield 1
        const [n, k] = input.split(' ').map(Number)
        if (i === 400) {
            process.exit(n)
        }
        yield* solve(n, k)
    }
    process.exit(0)
}

function* solve(n, k) {
    let guess = 0
    let sum = 0
    while (guess < n) {
        const next = xor(guess, sum, k)
        console.log(next)

        const ans = yield 1
        if (ans !== '0') break

        sum = xor(sum, next, k)
        guess++
    }
}

function xor(a, b, k) {
    return a ^ b
    if (a > b) return xor(b, a, k)

    a = toBits(a, k)
    b = toBits(b, k)
    const r = a.map((x, i) => (a[i] + b[i]) % k)
    for (let i = a.length; i < b.length; i++) {
        r.push(b[i])
    }

    return toVal(r, k)
}
function toBits(n, k) {
    const r = []
    while (n) {
        r.push(n % k)
        n = Math.floor(n / k)
    }
    return r
}
function toVal(arr, k) {
    let b = 1
    return arr.reduce((s, x) => {
        s = s + x * b
        b *= k
        return s
    }, 0)
}


Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set of n numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.

The first line contains a single integer n — the number of items (1 ≤ n ≤ 105). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.

Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.

NoteIn the first test the numeration is already a permutation, so there is no need to change anything.In the second test there are two pairs of equal numbers, in each pair you need to replace one number.In the third test you need to replace 2 by 1, as the numbering should start from one.

var n = +readline(), a = readline().split(" "), written = [], no = [], unique = {};

for(var i = 0; i < a.length; i++) {
	if(a[i] <= n){
		unique[a[i]] = true;
	}
}

for(i = 1; i <= n; i++){
	if(!unique[i + ""]){
		no.push(i + "");
	}
}

a.forEach(function(item, i){
	if((item <= n) && !written[item]){
		write(item + " ");
		written[item] = true;
	}
	else if(item > n){
		write(no[no.length-1] + " ");
		no.pop();
	}
	else if(written[item]){
		write(no[no.length-1] + " ");
		no.pop();
	}
});

var n = +readline(), a = readline().split(" ");

a.forEach(function(item, i){
	var j;
	var index;
	if(item > n){
		for(j = 1; j <= n; j++){
			if( a.indexOf(j + "") == -1 ){
				a[i] = j + "";
				break;
			}
		}
	}
	else{
		index = a.lastIndexOf(item, i-1)
		if(index + 1){
			for(j = 1; j <= n; j++){
				if( a.indexOf(j + "") == -1 ){
					a[i] = j + "";
					break;
				}
			}
		}
	}
});

write(a.join(" "));


You are given a permutation $$$a$$$ of length $$$n$$$. Recall that permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order.You have a strength of $$$s$$$ and perform $$$n$$$ moves on the permutation $$$a$$$. The $$$i$$$-th move consists of the following:   Pick two integers $$$x$$$ and $$$y$$$ such that $$$i \leq x \leq y \leq \min(i+s,n)$$$, and swap the positions of the integers $$$x$$$ and $$$y$$$ in the permutation $$$a$$$. Note that you can select $$$x=y$$$ in the operation, in which case no swap will occur. You want to turn $$$a$$$ into another permutation $$$b$$$ after $$$n$$$ moves. However, some elements of $$$b$$$ are missing and are replaced with $$$-1$$$ instead. Count the number of ways to replace each $$$-1$$$ in $$$b$$$ with some integer from $$$1$$$ to $$$n$$$ so that $$$b$$$ is a permutation and it is possible to turn $$$a$$$ into $$$b$$$ with a strength of $$$s$$$. Since the answer can be large, output it modulo $$$998\,244\,353$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq s \leq n$$$) — the size of the permutation and your strength, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of $$$a$$$. All elements of $$$a$$$ are distinct. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le n$$$ or $$$b_i = -1$$$) — the elements of $$$b$$$. All elements of $$$b$$$ that are not equal to $$$-1$$$ are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of ways to fill up the permutation $$$b$$$ so that it is possible to turn $$$a$$$ into $$$b$$$ using a strength of $$$s$$$, modulo $$$998\,244\,353$$$.

NoteIn the first test case, $$$a=[2,1,3]$$$. There are two possible ways to fill out the $$$-1$$$s in $$$b$$$ to make it a permutation: $$$[3,1,2]$$$ or $$$[3,2,1]$$$. We can make $$$a$$$ into $$$[3,1,2]$$$ with a strength of $$$1$$$ as follows: $$$$$$[2,1,3] \xrightarrow[x=1,\,y=1]{} [2,1,3] \xrightarrow[x=2,\,y=3]{} [3,1,2] \xrightarrow[x=3,\,y=3]{} [3,1,2].$$$$$$ It can be proven that it is impossible to make $$$[2,1,3]$$$ into $$$[3,2,1]$$$ with a strength of $$$1$$$. Thus only one permutation $$$b$$$ satisfies the constraints, so the answer is $$$1$$$.In the second test case, $$$a$$$ and $$$b$$$ the same as the previous test case, but we now have a strength of $$$2$$$. We can make $$$a$$$ into $$$[3,2,1]$$$ with a strength of $$$2$$$ as follows: $$$$$$[2,1,3] \xrightarrow[x=1,\,y=3]{} [2,3,1] \xrightarrow[x=2,\,y=3]{} [3,2,1] \xrightarrow[x=3,\,y=3]{} [3,2,1].$$$$$$ We can still make $$$a$$$ into $$$[3,1,2]$$$ using a strength of $$$1$$$ as shown in the previous test case, so the answer is $$$2$$$. In the third test case, there is only one permutation $$$b$$$. It can be shown that it is impossible to turn $$$a$$$ into $$$b$$$, so the answer is $$$0$$$.

'use strict';

function solve(n, m, a, b) {
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else {
      if (b[i] + m < a[i]) return 0;
      set.delete(b[i]);
    }
  }
  if (index.length === 0) return 1;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num - m) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = Math.max(l, r);
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else {
      if (b[i] + m < a[i]) return 0;
      set.delete(b[i]);
    }
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num - m) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = Math.max(l, r);
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else {
      if (b[i] > a[i] + m) return 0;
      set.delete(b[i]);
    }
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num - m) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = Math.max(l, r);
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else set.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num - m) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = Math.max(l, r);
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  a.filter(num => num === -1).length;
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else set.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = Math.max(l, r);
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  a.filter(num => num === -1).length;
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else set.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num) l++;
    if (l >= index.length || index[l] > num + m) return 0;
    r = l;
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  a.filter(num => num === -1).length;
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else set.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1;
  const nums = [...set].sort((a, b) => a - b);
  let l = 0,
      r = 0;
  for (let num of nums) {
    while (index[l] < num) l++;
    if (index[l] > num + m) return 0;
    r = l;
    while (r + 1 < index.length && index[r + 1] <= num + m) r++;
    res = mul(res, r - l + 1);
    l++;
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}

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

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

'use strict';

function solve(n, m, a, b) {
  a.filter(num => num === -1).length;
  const index = [];
  const set = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push(a[i]);else set.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a - b);
  let res = 1,
      start = 0;
  const nums = [...set].sort((a, b) => a - b);
  for (let num of nums) {
    let l = binarySearch(index, start, index.length - 1, i => index[i] < num),
        r = binarySearch(index, start, index.length - 1, i => index[i] <= num + m);
    if (index[r] > num + m) r--;
    if (index[l] > num + m) return 0;
    if (l > r) return 0;
    start++;
    res = mul(res, r - l + 1);
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
function binarySearch(arr, l, r, comp) {
  while (l < r) {
    const m = l + r >> 1;
    if (comp(m)) l = m + 1;else r = m;
  }
  return l;
}

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

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

'use strict';

function solve(n, m, a, b) {
  a.filter(num => num === -1).length;
  const index = [];
  const nums = new Set(a);
  for (let i = 0; i < n; i++) {
    if (b[i] === -1) index.push([i, a[i]]);else nums.delete(b[i]);
  }
  if (index.length === 0) return 0;
  index.sort((a, b) => a[1] - b[1]);
  let res = 1;
  for (let num of nums) {
    let l = binarySearch(index, 0, index.length - 1, i => index[i][1] < num),
        r = binarySearch(index, 0, index.length - 1, i => index[i][1] <= num + m);
    if (index[r][1] > num + m) r--;
    if (index[l][1] > num + m) return 0;
    res = mul(res, r - l + 1);
  }
  return res;
}
const MOD = 998244353;
function mul(...args) {
  if (args.length === 0) throw new Error('参数不能为空');
  if (args.length === 1) return args[0];
  const [a, b] = args;
  if (args.length > 2) return mul(mul(a, b), ...args.slice(2));
  return (Math.floor(a / 65536) * b % MOD * 65536 + (a & 65535) * b) % MOD;
}
function binarySearch(arr, l, r, comp) {
  while (l < r) {
    const m = l + r >> 1;
    if (comp(m)) l = m + 1;else r = m;
  }
  return l;
}

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

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


New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.Vasya's verse contains $$$n$$$ parts. It takes $$$a_i$$$ seconds to recite the $$$i$$$-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes $$$a_1$$$ seconds, secondly — the part which takes $$$a_2$$$ seconds, and so on. After reciting the verse, Vasya will get the number of presents equal to the number of parts he fully recited.Vasya can skip at most one part of the verse while reciting it (if he skips more than one part, then Santa will definitely notice it).Santa will listen to Vasya's verse for no more than $$$s$$$ seconds. For example, if $$$s = 10$$$, $$$a = [100, 9, 1, 1]$$$, and Vasya skips the first part of verse, then he gets two presents.Note that it is possible to recite the whole verse (if there is enough time). Determine which part Vasya needs to skip to obtain the maximum possible number of gifts. If Vasya shouldn't skip anything, print 0. If there are multiple answers, print any of them.You have to process $$$t$$$ test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 10^5, 1 \le s \le 10^9$$$) — the number of parts in the verse and the maximum number of seconds Santa will listen to Vasya, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the time it takes to recite each part of the verse. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the number of the part that Vasya needs to skip to obtain the maximum number of gifts. If Vasya shouldn't skip any parts, print 0.

NoteIn the first test case if Vasya skips the second part then he gets three gifts.In the second test case no matter what part of the verse Vasya skips.In the third test case Vasya can recite the whole verse.

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", func);

async function func() {
  const [t, ...queries] = input.split(EOL);
  for (let i = 0; i < t; i++) {
    let res = 0;
    const [n, s] = queries.shift().split(" ").map(a => parseInt(a));
    const verses = queries.shift().split(" ").map(a => parseInt(a));
    const totalTime = verses.reduce((acc, curr) => acc + curr);
    if (totalTime > s) {
      verses.reduce((acc, curr, index) => {
        if (res > 0)
          return;
        if (acc + curr > s) {
          const prevVerses = verses.slice(0, index + 1);
          res = verses.indexOf(Math.max(...prevVerses)) + 1;
        } else {
          return acc + curr;
        }
      })
    }
    console.log(res);
  }
}

module.exports = func;

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        let [n, s] = lines[i].split(' ').map(Number);
        let a = lines[i + 1].split(' ').map(Number);

        let sum = 0;
        let skipIndex = 0;
        let skipValue = a[0];
        let j = 1;
        while (sum <= s && j < a.length) {
            // console.log('--', sum, skipValue);
            if (sum + a[j] <= s || sum + skipValue <= s) {
                if (a[j] > skipValue) {
                    skipIndex = j;
                    sum += skipValue;
                    skipValue = a[j];
                } else {
                    sum += a[j];
                }
            }
            j++;
        }
        // console.log(s, a, sum, skipValue);
        if (sum + skipValue <= s) {
            console.log(0);
        } else {
            console.log(skipIndex + 1);
        }
    }
});

function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum * 2; i += 2) {
    (function (i) {
      testCases[i] = readline();
      testCases[i + 1] = readline();

      checkPoem(testCases[i], testCases[i + 1]);
    })(i)
  }
}

function checkPoem(ns, poem) {
  var nsArr = ns.split(' ').map(Number);
  var n = nsArr[0];
  var s = nsArr[1];
  var poemArr = poem.split(' ').map(Number);

  var poemSum = 0;
  var j = 0;
  var maxJ = 0;

  while (poemSum <= s && j < n) {
    poemSum += poemArr[j];
    if (j == n - 1 && poemSum <= s) {
      print(0);
      return;
    }
    if (poemArr[j] > poemArr[maxJ]) {
      maxJ = j;
    }
    j++;
  }
  print(maxJ + 1)
}

main();

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", func);

async function func() {
  const [t, ...queries] = input.split(EOL);
  for (let i = 0; i < t; i++) {
    let res = 0;
    const [n, s] = queries.shift().split(" ").map(a => parseInt(a));
    const verses = queries.shift().split(" ").map(a => parseInt(a));
    const totalTime = verses.reduce((acc, curr) => acc + curr);
    if (totalTime > s) {
      verses.reduce((acc, curr, index) => {
        if (res > 0)
          return;
        if (acc + curr > s) {
          const prevVerses = verses.slice(0, index);
          res = verses.indexOf(Math.max(...prevVerses)) + 1;
        } else {
          return acc + curr;
        }
      })
    }
    console.log(res);
  }
}

module.exports = func;

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        let [n, s] = lines[i].split(' ').map(Number);
        let a = lines[i + 1].split(' ').map(Number);

        let sum = 0;
        let skipIndex = 0;
        let skipValue = a[0];
        let j = 1;
        while (sum <= s && j < a.length) {
            // console.log('--', sum, skipValue);
            if (sum + a[j] <= s) {
                if (a[j] > skipValue) {
                    skipIndex = j;
                    sum += skipValue;
                    skipValue = a[j];
                } else {
                    sum += a[j];
                }
            }
            j++;
        }
        // console.log(s, a, sum, skipValue);
        if (sum + skipValue <= s) {
            console.log(0);
        } else {
            console.log(skipIndex + 1);
        }
    }
});

function main() {
  var testCasesNum = +readline();
  var testCases = [];
  for (var i = 0; i < testCasesNum * 2; i += 2) {
    (function (i) {
      testCases[i] = readline();
      testCases[i + 1] = readline();

      checkPoem(testCases[i], testCases[i + 1]);
    })(i)
  }
}

function checkPoem(ns, poem) {
  var nsArr = ns.split(' ').map(Number);
  var n = nsArr[0];
  var s = nsArr[1];
  var poemArr = poem.split(' ').map(Number);

  var poemSum = 0;
  var j = 0;
  var maxJ = 0;

  while (poemSum < s && j < n) {
    poemSum += poemArr[j];
    if (j == n - 1 && poemSum <= s) {
      print(0);
      return;
    }
    if (poemArr[j] > poemArr[maxJ]) {
      maxJ = j;
    }
    j++;
  }
  print(maxJ + 1)
}

main();


It is the easy version of the problem. The only difference is that in this version $$$k = 3$$$.You are given a positive integer $$$n$$$. Find $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, such that:  $$$a_1 + a_2 + \ldots + a_k = n$$$  $$$LCM(a_1, a_2, \ldots, a_k) \le \frac{n}{2}$$$ Here $$$LCM$$$ is the least common multiple of numbers $$$a_1, a_2, \ldots, a_k$$$.We can show that for given constraints the answer always exists.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$  — the number of test cases. The only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 10^9$$$, $$$k = 3$$$).

For each test case print $$$k$$$ positive integers $$$a_1, a_2, \ldots, a_k$$$, for which all conditions are satisfied.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let a = Math.floor(n / 2);
    if (a + a < n) {
      console.log(`${a} ${a} ${n - (a + a)}`);
    } else {
      if (a % 2) console.log(`${a - 1} ${a - 1} ${n - (a - 1 + (a - 1))}`);
      else console.log(`${a} ${a / 2} ${a / 2}`);
    }
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var ans = new Array(k).fill(1)
    var x
    if (n % 2 === 1) {
      x = (n - 1) / 2
      return console.log(1, x, x)
    }
    if (n % 4 === 0) {
      x = n / 4
      return console.log(x*2, x, x)
    }

    return console.log(2, (n-2)/2, (n-2)/2)

  });
}

'use strict';

function solve(n, m) {
  let res = [],
      one = 0;
  if (n & 1) {
    if (m === 3) return `1 ${(n - 1) / 2} ${(n - 1) / 2}`;
    m--;
    one++;
    n--;
  }
  for (let i = 30; i >= 0; i--) {
    if (res.length) {
      while (1 << i <= n) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    } else {
      if (1 << i <= n / 2) {
        let cur = 1 << i;
        while (n >= cur) {
          res.push(cur);
          n -= cur;
        }
      }
    }
  }
  if (res.length === m) {
    if (one) res.push(1);
    return res.join(' ');
  } else if (res.length > m) {
    let sum = res.splice(2, res.length - m).reduce((a, b) => a + b, 0) / 2;
    res[0] += sum;
    res[1] += sum;
    if (one) res.push(1);
    return res.join(' ');
  }
  m -= res.length;
  while (m--) {
    let cur = res[res.length - 1];
    if (cur === 2) {
      res.pop();
      one += 2;
    } else {
      res[res.length - 1] /= 2;
      res.push(cur / 2);
    }
  }
  return (res.join(' ') + ' 1'.repeat(one)).trim();
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      res.push(solve(n, m));
    }
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

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

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

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

		let ans;
		if (n % 2 == 0) {
			if (n % 4 == 0){
				ans = [n/2, n/4, n/4];
			} else {
				ans = [n/2-1, n/2-1, 2]
			}
		} else {
			ans = [(n-1)/2, (n-1)/2, 1];
		}

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var K = nextInt();
		if(N % 4 == 0){
			var s = N / 4;
			var d = s * 2;
			myout(d + " " + s + " " + s);
			continue;
		}
		if(N % K == 0){
			var s = N / K;
			myout(s + " " + s + " " + s);
		}else if(N % 2 == 1){
			N--;
			var s = N / 2;
			myout("1 " + s + " " + s);
		}else{
			N -= 2;
			var s = N / 2;
			myout("2 " + s + " " + s);
		}
	}
}

function getInt(num){
    return parseInt(num, 10)
}

var t = parseInt(readline(), 10);

for(var i = 0; i<t; i++){
    var line = readline().split(' ').map(getInt);
    print(solution.apply(undefined, line));
}
function solution(n, k){
    var m;

    if(n%2 === 1){
        m = (n - 1)/ 2;
        return [m, m, 1].join(' ');
    }
    if(n%4 === 0){
        m = n/4;
        return [2*m, m, m].join(' ');
    }else{
        m = (n-2)/4;
        return [2*m, 2*m, 2].join(' ');
    }

}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let a = 1,
      b = Math.floor(n / 2);
    let c = n - (a + b);
    console.log(`${a} ${b} ${c}`);
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });

    var a = getDel(n)
    var b = (n - a[a.length - 1]) /2
    console.log(a[a.length - 1], b, b)
  });
}

function getDel(x) {

  var i = 1
  var ans = []
  while (i * i <= x) {
    if (x % i === 0) {
      ans.push(i)
      // ans.push(x / i)
    }
    i++
  }
  return ans
}

function gcd(a, b) {
  if (!b) {
    return a;
  }

  return gcd(b, a % b);
}


You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $$$k$$$ torches. One torch can be crafted using one stick and one coal.Hopefully, you've met a very handsome wandering trader who has two trade offers:  exchange $$$1$$$ stick for $$$x$$$ sticks (you lose $$$1$$$ stick and gain $$$x$$$ sticks).  exchange $$$y$$$ sticks for $$$1$$$ coal (you lose $$$y$$$ sticks and gain $$$1$$$ coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order.Your task is to find the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$ and $$$k$$$ ($$$2 \le x \le 10^9$$$; $$$1 \le y, k \le 10^9$$$) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively.

For each test case, print the answer: the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints.

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => BigInt(n));
    let ans = "";
    let moves = 1n + k;
    let sticks = y * k + k - x;

    if (sticks < 0) sticks = 0n;

    moves += sticks / (x - 1n);
    if (sticks % (x - 1n) !== 0n) moves++;

    ans += moves;

    console.log(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() {
  const t = parseInt(readline());
  for (var i=0; i<t; i++) {
    const [x, y, k] = readline().split(" ").map(x => BigInt(parseInt(x)));
    const result = (k*y + k - 1n + x - 2n) / (x-1n) + k;
    console.log(result.toString());
  }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var t = +inputs[0];
    for (let i = 0; i < t; i++) {
        var [x, y, k] = inputs[i + 1].split(' ').map(v => BigInt(v));
        var n = (k * y + k - 1n + x - 2n) / (x - 1n);
        console.log(n + k + '');
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => BigInt(n));
    let ans = "";
    let moves = 1n + k;
    let sticks = k * y + k - x;

    moves += sticks / (x - 1n);
    if (sticks % (x - 1n) !== 0n) moves++;

    ans += moves;

    console.log(ans);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  let t = +readLine();

  while (t--) {
    const [x, y, k] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let ans = "";
    let moves = 1n + BigInt(k);
    let sticks = BigInt(k) * BigInt(y) + BigInt(k) - BigInt(x);

    moves += sticks / BigInt(x - 1);
    if (sticks % BigInt(x - 1)) moves++;

    ans += moves;

    console.log(ans);
  }
}


A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture.  For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.

We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).

Print n numbers. The i-th of them should be equal to ai.

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

var progress = input[2];
var left = input[1];
var outputArray = [];
var time = Math.floor((progress * left * input[0]) / 100);

for(var i=1;i<=input[0];i++) {

    if(time < 0) {
        outputArray.push(0);
    } else if(time < left) {
        outputArray.push(time);
    } else {
        outputArray.push(left);
    }

    time = time - left;

}

print(outputArray.join(" "));

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))
  t = t / 100
  let pi = n * t | 0
  let ip = n * t - pi
  let i = ip * k | 0
  let r = []
  for (let j = 0; j < pi; j++) r.push(k)
  if (pi != n) r.push(i)
  for (let j = pi + 1; j < n; j++) r.push(0)
  console.log(r.join(' '))
})

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (let i = 0; (i < q); i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  if (q != n) {
  process.stdout.write(r + ' ');
  }

  //console.log(r + ' ')

// if (n != 1) {
  for (let i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
//}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let [n, k, t] = ipt.split(EOL)[0].split(' ').map(v => parseInt(v))
  t = t / 100
  let pi = n * t | 0
  let ip = n * t - pi
  let i = ip * k | 0
  let r = []
  for (let j = 0; j < pi; j++) r.push(k)
  r.push(i)
  for (let j = pi + 1; j < n; j++) r.push(0)
  console.log(r.join(' '))
})

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }

    process.stdout.write(r + ' ');

  //console.log(r + ' ')

if (n != 1) {
  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  if (n !== 1) {
    process.stdout.write(r + ' ');

  }
  //console.log(r + ' ')

  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {
  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (i = 0; i < q; i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }
  process.stdout.write(r + ' ');
  //console.log(r + ' ')

  for (i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();

const cal = (n, k, t) => {

  let p = (n * k * t) / 100;
  let q = Math.floor(p / k);
  let r = Math.floor(p % k);

  for (let i = 0; (i < q); i++) {
    process.stdout.write(k + ' ');
    //console.log(k + ' ');

  }

  if (q <= (n-q)){
      process.stdout.write(r + ' ');
  }

  //console.log(r + ' ')

if (n != 1) {
  for (let i = q + 1; i < n; i++) {
    process.stdout.write(0 + ' ');
    //console.log(0 + ' ');
  }
}
}

//cal(11, 13, 37);
const runner = () => {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var arr = "";
  process.stdin.on('data', function (chunk) {
    arr += chunk;
  });
  process.stdin.on('end', function () {
    arr = arr.split(" ");
    cal(arr[0], arr[1], arr[2])
    // console.log(arr)
    // var n = parseInt(arr.shift()); // in order ot get no of test cases

  });
}

runner();