Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order. That is, he took a certain segment [l, r] and reversed it. At that the segment's endpoints did not coincide. For example, if n = 8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2, 6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... n using exactly one segment reversal. If it is possible, find the segment itself.

The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.

If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.

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 length = parseInt(readline(), 10),
		items = tokenizeIntegers(readline()),
		left = 0, right = length-1;

	while (items[left] == left+1) {
		++left;
		if (left == length) {
			print("0 0");
			return;
		}
	}

	while (items[right] == right+1) {
		--right;
	}

	for (var delta = 0; right-delta >= left; ++delta) {
		if (items[right-delta] != left+1+delta) {
			print("0 0");
			return;
		}
	}
	print([left+1, right+1].join(" "));
}

main();

'use strict'

let lll
let N = +readline()
lll = readline().split(' ').map(v => parseInt(v))
let ss = []
for (let i = 1; i < lll.length; i++) {
  ss.push(Math.sign(lll[i] - lll[i - 1]))
}

let ifm = ss.indexOf(-1)
let ilm = ss.lastIndexOf(-1)

if (~ifm && ~ilm) {
  let bad
  for (let i = ifm; i < ilm; i++) {
    if (ss[i] == 1) {
      bad = true
      break
    }
  }
  if (bad) {
    print('0 0')
  } else {
    let ns = lll.slice(0, ifm).concat(lll.slice(ifm, ilm + 2).reverse(), lll.slice(ilm + 2))
    for (let i = 1; i < ns.length; i++) {
      if (ns[i] < ns[i - 1]) {bad = true; break}
    }
    print(bad ? '0 0' : (ifm + 1) + ' ' + (ilm + 2))
  }
} else {
  print('0 0')
}

'use strict';

/*let input = `2
2 1`.split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}*/

//code

var n = Number(readline());
var num = readline().split(' ').map(Number);
num.unshift(0);
var j = 1,
    lIndex = void 0,
    rIndex = void 0,
    sum = void 0;
while (j < num.length && num[j] === j) {
	j++;
}
//first break
lIndex = j;
if (lIndex === num.length || num[lIndex] <= lIndex || num[lIndex] > n) {
	print("0 0");
} else {
	sum = lIndex + num[lIndex];
	rIndex = num[lIndex];
	while (j <= rIndex && num[j] + j === sum) {
		j++;
	}
	//second break
	if (j !== rIndex + 1) {
		print("0 0");
	} else {
		while (j < num.length && num[j] === j) {
			j++;
		}
		//last break
		if (j === num.length) {
			print(lIndex + " " + rIndex);
		} else {
			print("0 0");
		}
	}
}

'use strict'

let lll
let N = +readline()
lll = readline().split(' ').map(v => parseInt(v))
let ss = []
for (let i = 1; i < lll.length; i++) {
  ss.push(Math.sign(lll[i] - lll[i - 1]))
}

let ifm = ss.indexOf(-1)
let ilm = ss.lastIndexOf(-1)

if (~ifm && ~ilm && ifm != ilm) {
  let bad
  for (let i = ifm; i < ilm; i++) {
    if (ss[i] == 1) {
      bad = true
      break
    }
  }
  print(bad ? '0 0' : (ifm + 1) + ' ' + (ilm + 2))
} else {
  print('0 0')
}

'use strict';

/*let input = `4
1 2 3 4`.split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}
*/
//code

var n = Number(readline());
var num = readline().split(' ').map(Number);
num.unshift(0);
var j = 0,
    lIndex = void 0,
    rIndex = void 0;
while (j < num.length && num[j] === j) {
	j++;
}
//first break
lIndex = j;
if (lIndex === num.length || num[lIndex] <= lIndex || lIndex + num[lIndex] !== n) {
	print("0 0");
} else {
	rIndex = num[lIndex];
	while (j <= rIndex && num[j] + j === n) {
		j++;
	}
	//second break
	if (j !== rIndex + 1) {
		print("0 0");
	} else {
		while (j < num.length && num[j] === j) {
			j++;
		}
		//last break
		if (j === num.length) {
			print(lIndex + ' ' + rIndex);
		} else {
			print("0 0");
		}
	}
}


Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam.They love equilateral triangles and want to create $$$n$$$ equilateral triangles on the grid by adding some straight lines. The triangles must all be empty from the inside (in other words, no straight line or hexagon edge should pass through any of the triangles).You are allowed to add straight lines parallel to the edges of the hexagons. Given $$$n$$$, what is the minimum number of lines you need to add to create at least $$$n$$$ equilateral triangles as described?  Adding two red lines results in two new yellow equilateral triangles.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$) — the required number of equilateral triangles.

For each test case, print the minimum number of lines needed to have $$$n$$$ or more equilateral triangles.

NoteIn the first and second test cases only 2 lines are needed. After adding the first line, no equilateral triangles will be created no matter where it is added. But after adding the second line, two more triangles will be created at once.   In the third test case, the minimum needed is 3 lines as shown below.

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const N = 10 ** 9;
const dp = [];
let cur = 0;
for (let i = 0;; i++) {
  var _dp;
  if (i % 3 !== 2) cur += 2;
  dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + cur;
  if (dp[i] > N) break;
}
function solve(n) {
  let l = 0,
      r = dp.length - 1;
  while (l < r) {
    const mid = l + r >> 1;
    if (dp[mid] < n) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return l + 2;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();


Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y".There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon".Sergey is very busy and asks you to help him and write the required program.

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of letters in the word written by Stepan. The second line contains the string s which has length that equals to n and contains only lowercase English letters — the word written by Stepan.

Print the single string — the word written by Stepan converted according to the rules described in the statement.

pobeda implemeentatioon aeiouyaeeioouy aoiuyeggghhh

var n = parseInt(readline());
var s = "#" + readline() + "#";

var ans = "";
// var prev = s[0];

function isVowel(c) {
    return c == 'a' || c == 'e' || c == 'i' || c =='o' || c == 'u' || c == 'y';
}
var i = 1;
var count = 0;
while(i <= n) {
    //print(s[i])
    if(!isVowel(s[i])) {
        ans += s[i];
    } else {
        count = 1;
        while(s[i] == s[i + 1]) {
            count++;
            i++;
        }
        if((s[i] == 'e' || s[i] == 'o') && count == 2) {
            ans += s[i] + s[i];
        } else {
            ans += s[i];
        }

    }
    i++;
}

print(ans);

readline();
str = readline();

res = [];
word = "";
function addWord() {
    var ch = word.charAt(0);
    if ((ch == 'e' || ch == 'o') && word.length <= 2) {
        res.push(word);
    } else if (['e', 'a', 'i', 'o', 'u', 'y'].indexOf(ch) !== -1) {
        res.push(ch);
    } else {
        res.push(word);
    }
    word = '';
}
for (var i = 0; i < str.length; i++) {
    if (word == '' || word[0] === str[i]) {
        word += str[i];
    } else {
        addWord();
        word = str[i];
    }
}
addWord();

write(res.join(''));

var n = parseInt(readline());
s = readline().split('');
var i;
for (i = 1; i < n; i++) {
    var lowel = 0;
    if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y'){
        lowel = 1;
    }
    var start = i-1;
    while (i<n && s[i] == s[i-1] && lowel){
        i++;
    }
    if (s[start] == 'e' || s[start] == 'o'){
        if (i - start > 2){
            for(var j=start+1; j<i; j++){
                s[j] = '#';
            }
        }
    }
    else {
        if (i - start > 1){
            for(var j=start+1; j<i; j++){
                s[j] = '#';
            }
        }
    }
    // print(s);
    if (i - start > 1)
        i--;
}
output = ""
for (i = 0; i < n; i++) {
    if (s[i] != '#'){
        output += s[i];
    }
}
print(output);

var n = readline();
var s = readline()

var letters = ['a', 'i', 'u', 'y']
var lettters = ['o', 'e']

var ss = ""
var k = 1;

for (var i = 1; i < s.length; ++i) {
  if (s[i] == s[i - 1]) ++k;
  else {
    if (k > 1) {
      if (letters.indexOf(s[i - 1]) != -1) {
        ss += s[i - 1];
      }
      else if (lettters.indexOf(s[i - 1]) != -1) {
        if (k > 2) ss += s[i - 1];
        else ss += s[i - 1] + s[i - 1];
      }
      else {
        for (var q = 0; q < k; ++q) ss += s[i - 1];
      }
    }
    else ss += s[i - 1];
    k = 1;
  }
}

var i = s.length
if (k > 1) {
  if (letters.indexOf(s[i - 1]) != -1) {
    ss += s[i - 1];
  }
  else if (lettters.indexOf(s[i - 1]) != -1) {
    if (k > 2) ss += s[i - 1];
    else ss += s[i - 1] + s[i - 1];
  }
  else {
    for (var q = 0; q < k; ++q) ss += s[i - 1];
  }
}
else ss += s[i - 1];

print(ss);

maybelength = +readline();
s = readline();
s = s.replace(/e{3,}/g,'e');
s = s.replace(/o{3,}/g,'o');
s = s.replace(/a{2,}/g,'a');
s = s.replace(/u{2,}/g,'u');
s = s.replace(/y{2,}/g,'y');
s = s.replace(/i{2,}/g,'i');
print(s);

x=+readline()
s=readline()
var curs="";
var result = "";
var count = 0;
for(i=0; i<x; i++) {
    if(isVowel(s[i])) {
        if(s[i] == curs) {
            count++;
            curs = "";
            curs += s[i];
        } else {
            result+=curs;
            if(count==2 && (curs=='e' || curs=='o')) result+=curs;
            curs=s[i];
            count = 1;
        }
    } else {
        result+=curs;
        if(count==2 && (curs=='e' || curs=='o')) result+=curs;
        curs="";
        count=0;
        result+=s[i];
    }
}
result+=curs;
if(count==2 && (curs=='e' || curs=='o')) result+=curs;

print(result);

function isVowel(a) {
    if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='y') return true;
    return false;
}

var n = readline();
var s = readline();
var currO = false;
var currE = false;
for(var i = 0 ; i < s.length; i++){
    if(s[i] != 'o') currO = false;
    if(s[i] != 'e') currE = false;
    if(s[i] == 'a' && i +1 < s.length &&  s[i+1] == 'a') {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        continue;
    }
    if(s[i] == 'o' && ((i + 2 < s.length &&  s[i+1] == 'o' && s[i+2] == 'o') || (currO && i+1 < s.length && s[i+1] == 'o') )) {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        currO = true;
        continue;

    }
    if(s[i] == 'e' && ((i + 2 < s.length &&  s[i+1] == 'e' && s[i+2] == 'e') || (currE && i +1 < s.length && s[i+1] == 'e' ))) {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        currE = true;
        continue;
    }
    if(s[i] == 'i' && i+1 < s.length && s[i+1] == 'i') {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        continue;
    }
    if(s[i] == 'u' && i+1 < s.length && s[i+1] == 'u') {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        continue;
    }
    if(s[i] == 'y' && i+1 < s.length && s[i+1] == 'y') {
        s = s.slice(0,i) + s.slice(i+1,s.length);
        i--;
        continue;
    }
}
print(s);

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

function is_vowel(c) {
  return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}

var ans = "";
for (var i = 0; i < n ; ) {
  if (is_vowel(s[i])) {
    var cnt = 0;
    var cur = s[i];
    var j;
    for (j = i; j < n; ++j) {
      if (s[j] != s[i]) break;
      cnt ++;
    }

    if (s[i] == 'e' || s[i] == 'o') {
      if (cnt == 2) {
        ans += cur + cur;
      }
      else {
        ans += cur;
      }
    }
    else {
      ans += cur;
    }
    i = j;
  }
  else {
     ans += s[i];
     i ++;
  }
}

print(ans)

function main() {
	    var n = readline(), str = readline();
var res = "";
for (var i=0; i<str.length; i++) {
	var c = str[i];
	if (c == "e" || c == "o") {
		var cnt = 0;

		while(i < str.length && str[i] == c) {cnt++; i++;}
		res += c;
		if (cnt == 2)
			res += c;
		i--;

    } else if (c == "a" || c == "i" || c == "u" || c == "y") {
		while(i < str.length && str[i] == c) { i++;}
		res += c;
		i--;

    } else {
		res += str[i];
    }
}

	    print(res);

}
main();

n=+readline()
s=readline()

var l = 0
var pr = s[0]
var ans = ""
for(var i=0; i<=n; i++){
    if(i<n && s[i]==pr){
        l++;
    }else{
        if(l==2 && (pr=='e' || pr=='o')) l = 2
        else
        if(l>1 && (pr=='a' || pr=='e'|| pr=='i'|| pr=='o'|| pr=='u'|| pr=='y')) l = 1
        ans+=Array(l+1).join(pr)
        l = 1
    }
    if(i==n) break;
    pr = s[i]
}

print(ans)

var n = +readline() + 1;
var s = readline() + '1';
var prev = s.charAt(0);
var cnt = 1;
var answer = "";
for (i = 1; i < n; i++) {
    var c = s.charAt(i);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' || c == '1') {
        if (c == prev) {
            cnt++;
        } else {
            if (cnt == 2 && (prev == 'e' || prev == 'o')) {
                answer += prev;
                answer += prev;
            } else {
                answer += prev;
            }
            prev = c;
            cnt = 1;
        }
    } else {
        if (cnt == 2 && (prev == 'e' || prev == 'o')) {
            answer += prev;
            answer += prev;
        } else {
            answer += prev;
        }
        prev = '';
        cnt = 0;
        answer += c;
    }
}
print(answer);

readline();
str = readline();

res = "";
word = "";
function addWord() {
    if (word.length <= 2) {
        res += word;
    } else {
        res += word.charAt(0);
    }
    word = '';
}
for (var i = 0; i < str.length; i++) {
    if (word == '' || word[0] === str[i]) {
        word += str[i];
    } else {
        addWord();
        word = str[i];
    }
}
addWord();

write(res);

var n = readline();
var s = readline()

ss = s[0];

for (var i = 1; i < s.length; ++i) {
  if (s[i] != s[i - 1]) ss += s[i];
}

print(ss);


People worry that computers will get too smart and take over the world, but the real problem is that they're too stupid and they've already taken over the world.— Pedro DomingosYou work for a well-known department store that uses leading technologies and employs mechanistic work — that is, robots!The department you work in sells $$$n \cdot k$$$ items. The first item costs $$$1$$$ dollar, the second item costs $$$2$$$ dollars, and so on: $$$i$$$-th item costs $$$i$$$ dollars. The items are situated on shelves. The items form a rectangular grid: there are $$$n$$$ shelves in total, and each shelf contains exactly $$$k$$$ items. We will denote by $$$a_{i,j}$$$ the price of $$$j$$$-th item (counting from the left) on the $$$i$$$-th shelf, $$$1 \le i \le n, 1 \le j \le k$$$.Occasionally robots get curious and ponder on the following question: what is the mean price (arithmetic average) of items $$$a_{i,l}, a_{i,l+1}, \ldots, a_{i,r}$$$ for some shelf $$$i$$$ and indices $$$l \le r$$$? Unfortunately, the old robots can only work with whole numbers. If the mean price turns out not to be an integer, they break down.You care about robots' welfare. You want to arrange the items in such a way that the robots cannot theoretically break. Formally, you want to choose such a two-dimensional array $$$a$$$ that:  Every number from $$$1$$$ to $$$n \cdot k$$$ (inclusively) occurs exactly once.  For each $$$i, l, r$$$, the mean price of items from $$$l$$$ to $$$r$$$ on $$$i$$$-th shelf is an integer. Find out if such an arrangement is possible, and if it is, give any example of such arrangement.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 500$$$) — the number of shelves and length of each shelf, respectively. It is guaranteed that the sum $$$n$$$ over all test cases does not exceed $$$500$$$ and the sum $$$k$$$ over all test cases does not exceed $$$500$$$.

Print the answer for each test case. If such an arrangement exists, print "YES" on a single line. After that, print any example on $$$n$$$ lines of $$$k$$$ numbers each, one line per shelf. Each number from $$$1$$$ to $$$n \cdot k$$$ must occur exactly once in the output. If no good arrangement exists, print a single word "NO" on its own line.

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

		if (k == 1 || (n&1) == 0) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				const ar = [];
				for (let j = 0; j < k; j++) {
					ar.push(i + 1 + j*n);
				}
				console.log(ar.join(' '));
			}
		} else {
			console.log('NO');
		}
	}
}

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

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

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

		if (k == 1) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				console.log(i+1);
			}
		} else if ((n&1) == 0) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				const ar = [];
				for (let j = 0; j < k; j++) {
					ar.push(i + 1 + j*n);
				}
				console.log(ar.join(' '));
			}
		} else {
			console.log('NO');
		}
	}
}

const yes = (n,k)=>{
     console.log("YES");
          for(let i=0;i<n;i++){
               let str="";
               let t = i+1;
               for(let j=0;j<k;j++){
                    str+=t+" ";
                    t+=n;
               }
               console.log(str);
          }
}
const solve = (n,k)=>{
     if((n===1)&&(k!==1)) console.log("NO");
     else if((k===1)) yes(n,k);
     else if(n%2===0) yes(n,k);
     else console.log("NO");
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr[0],arr[1]);
  }
}
main();

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];
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        var n = a[0], k = a[1];
        if(k == 1 || n % 2 === 0){
            console.log('YES');
            var ans = '';
            for(j = 0; j < n; j++){
                for(l = 0; l < k; l++){
                    ans += j + 1 + l * n + ' ';
                }
                console.log(ans);
                ans = '';
            }
        }else{
            console.log('NO');
        }
    }
});

//  Author:   old_school
//  Created:  08.02.2022 09:33:53

var t = readline();
function solve(flag) {
    var arr = [];
    for(var i = 1; i <= n*m; i++) {
        if (i % 2 == flag) {
            arr.push(i);
        }
        if(arr.length == m) {
            print(arr.join(' '));
            arr = [];
        }
    }
}
while(t--) {
    var c = readline().split(" ");
    var n = c[0], m = c[1];
    var even = Math.floor((n*m)/2);
    if (even % m) {
        print("NO");
        continue;
    }
    print("YES");
    solve(1);
    solve(0);
}

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

		if (k == 1) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				console.log(i+1);
			}
		} else if ((n&1) == 0) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				const ar = [];
				for (let j = 0; j < k; j++) {
					ar.push(i + 1 + j*k);
				}
				console.log(ar.join(' '));
			}
		} else {
			console.log('NO');
		}
	}
}

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

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

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

		if (k == 1) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				console.log(i+1);
			}
		} else if ((n&1) == 0) {
			console.log('YES');
			for (let i = 0; i < n; i++) {
				const ar = [];
				for (let j = 0; j < k; j++) {
					ar.push((i>>1)*k + j + 1);
				}
				console.log(ar.join(' '));
			}
		} else {
			console.log('NO');
		}
	}
}

const yes = (n,k)=>{
     console.log("YES");
          for(let i=0;i<n;i++){
               let str="";
               let t = i+1;
               for(let j=0;j<k;j++){
                    str+=t+" ";
                    t+=n;
               }
               console.log(str);
          }
}
const solve = (n,k)=>{
     if((n===1)&&(k!==1)) console.log("NO");
     else if((k===1)) yes(n,k);
     else if(n%2===0) yes(n,k);
     console.log("NO");
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr[0],arr[1]);
  }
}
main();

const solve = (n,k)=>{
     if(k===1){
          console.log("YES");
          for(let i=0;i<n;i++) console.log(i+1);
     }
     else if((n===1)||(n%2===0)){
          console.log("YES");
          let cnt=2,start=0;
          for(let i=0;i<n;i++){
               let str="";
               if(cnt===0){
                    cnt = 2;
                    start = start + ((k-1)*2) + 1;
               }
               else start++;
               for(let j=0;j<k;j++) str+=start+(j*2)+" ";
               console.log(str);
               cnt--;
          }
     }
     else console.log("NO");
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr[0],arr[1]);
  }
}
main();

//  Author:   old_school
//  Created:  08.02.2022 09:33:53

var t = readline().split("");
function solve(flag) {
    var arr = [];
    for(var i = 1; i <= n*m; i++) {
        if (i % 2 == flag) {
            arr.push(i);
        }
        if(arr.length == m) {
            print(arr.join(' '));
            arr = [];
        }
    }
}
while(t--) {
    var c = readline().split(" ");
    var n = c[0], m = c[1];
    var even = Math.floor((n*m)/2);
    if (even % m) {
        print("NO");
        continue;
    }
    print("YES");
    solve(1);
    solve(0);
}


The next lecture in a high school requires two topics to be discussed. The $$$i$$$-th topic is interesting by $$$a_i$$$ units for the teacher and by $$$b_i$$$ units for the students.The pair of topics $$$i$$$ and $$$j$$$ ($$$i < j$$$) is called good if $$$a_i + a_j > b_i + b_j$$$ (i.e. it is more interesting for the teacher).Your task is to find the number of good pairs of topics.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of topics. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the interestingness of the $$$i$$$-th topic for the teacher. The third line of the input contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the interestingness of the $$$i$$$-th topic for the students.

Print one integer — the number of good pairs of topic.

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const ai = getInts()
  const bi = getInts()

  const arr = []
  for (let i = 0; i < n; ++i) {
    arr.push(ai[i] - bi[i])
  }

  arr.sort((a, b) => a - b)
  let ans = 0
  let l = 0
  let r = n - 1
  while (l < r) {
    while (l < r && arr[l] + arr[r] > 0) {
      r --
    }

    if (l == r) break
    ans += n - r - 1
    l ++
  }

  ans += sum(n - r)
  print(ans)
}

function sum (k) {
  return (k * (k - 1)) / 2
}

var t = Number(readline());
var a = readline().split(' ').map(x=>Number(x));
var b = readline().split(' ').map(x=>Number(x));
var c = [];
for(var i=t-1;i>=0;i--)
 c[i] = a[i]-b[i];
c.sort(function(a,b){return b-a;});
var r=0;
var z=0;
for(;z<t;z++)
 if(c[z]<=0)
  break;

var i=z-1;
var j=z;
for(;i>=0;i--){
 for(;j<t;j++){
  if(c[j]+c[i]<=0)
   break;
 }
 r += j-i-1;
}
print(r);

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a) {
  return parseInt(a[ptr++])
}

function readString(a) {
  return a[ptr++]
}

function readStrings(a) {
  return a[ptr++].split(' ')
}

function readInts(a) {
  return a[ptr++].split(' ').map(a => parseInt(a))
}

function main(input) {
  const n = readInt(input)
  const a = readInts(input)
  const b = readInts(input)

  let diff = new Array(n)
  for(let i = 0; i < n; i++){
    diff[i] = a[i] - b[i]
  }
  sort(diff)
  // console.log(diff)
  let map = {}
  let ne = 0
  let ze = 0
  let po = 0
  for(let i = 0; i < n; i++){
    if(diff[i] === 0) ze++
    else if(diff[i] > 0) po++
    else ne++
  }
  let count = Math.abs(po * (po - 1) / 2)
  if(ze > 0) count += po * ze
  // console.log(count)
  let i
  for(i = 0; i < n && diff[i] < 0; i++){
    if(!map[diff[i]]) map[diff[i]] = 1
    else map[diff[i]]++
  }
  let k = i
  while(diff[k] === 0) k++
  i--
  // console.log(i, k)

  while(i >= 0 && k < n) {
    if(diff[i] > -diff[k]) {
      count += n - k
      i--
    }
    else k++
  }
  wr(count)
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const ai = getInts()
  const bi = getInts()

  const arr = []
  for (let i = 0; i < n; ++i) {
    arr.push(ai[i] - bi[i])
  }

  arr.sort((a, b) => a - b)
  let r = n - 1
  let ans = 0

  for (let l = 0; l < r; ++l) {
    while (r >= 0) {
      if (arr[r] + arr[l] <= 0) break
      r --
    }
    ans += n - r - 1
  }
  ans += sum(n - r)
  print(ans)
}

function sum (k) {
  return (k * (k - 1)) / 2
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const ai = getInts()
  const bi = getInts()

  const arr = []
  for (let i = 0; i < n; ++i) {
    arr.push(ai[i] - bi[i])
  }

  arr.sort((a, b) => a - b)
  let r = n - 1
  let ans = 0

  for (let l = 0; l < r; ++l) {
    while (r > 0) {
      if (arr[r] + arr[l] <= 0) break
      r --
    }
    if (arr[r] + arr[l] > 0) break
    ans += n - r - 1
  }

  ans += sum(n - r)
  print(ans)
}

function sum (k) {
  return (k * (k - 1)) / 2
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const ai = getInts()
  const bi = getInts()

  const arr = []
  for (let i = 0; i < n; ++i) {
    arr.push(ai[i] - bi[i])
  }

  arr.sort((a, b) => a - b)
  let l = n - 1
  while (l > 0 && arr[l] + arr[0] > 0) l --
  if (arr[l] + arr[0] <= 0) l ++

  const k = (n - l)
  let ans = l * k + ((k * (k - 1)) / 2)
  print(ans)
}

var t = Number(readline());
var a = readline().split(' ').map(x=>Number(x));
var b = readline().split(' ').map(x=>Number(x));
var c = [];
for(var i=t-1;i>=0;i--)
 c[i] = a[i]-b[i];
c.sort(function(a,b){return b-a;});
var r=0;
var z=0;
for(;z<t;z++)
 if(c[z]<=0)
  break;

var i=z-1;
var j=z;
for(;i>=0;i--){
 for(;j<t;j++){
  if(c[j]+c[i]<0)
   break;
 }
 r += j-i-1;
}
print(r);

var t = Number(readline());
var a = readline().split(' ').map(x=>Number(x));
var b = readline().split(' ').map(x=>Number(x));
var c = [];
for(var i=t-1;i>=0;i--)
 c[i] = a[i]-b[i];
c.sort(function(a,b){return b-a;});
print(c);
var r=0;
var z=0;
for(;z<t;z++)
 if(c[z]<=0)
  break;

var i=z-1;
var j=z;
for(;i>=0;i--){
 for(;j<t;j++){
  if(c[j]+c[i]<=0)
   break;
 }
 print(i,j);
 r += j-i-1;
}
print(r);

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a) {
  return parseInt(a[ptr++])
}

function readString(a) {
  return a[ptr++]
}

function readStrings(a) {
  return a[ptr++].split(' ')
}

function readInts(a) {
  return a[ptr++].split(' ').map(a => parseInt(a))
}

function main(input) {
  const n = readInt(input)
  const a = readInts(input)
  const b = readInts(input)

  let diff = new Array(n)
  for(let i = 0; i < n; i++){
    diff[i] = a[i] - b[i]
  }
  sort(diff)
  // console.log(diff)
  let map = {}
  let ne = 0
  let ze = 0
  let po = 0
  for(let i = 0; i < n; i++){
    if(diff[i] === 0) ze++
    else if(diff[i] > 0) po++
    else ne++
  }
  let count = po * (po - 1) / 2
  if(ze > 0) count += po
  // console.log(count)
  let i
  for(i = 0; i < n && diff[i] < 0; i++){
    if(!map[diff[i]]) map[diff[i]] = 1
    else map[diff[i]]++
  }
  let k = i
  while(diff[k] === 0) k++
  i--
  // console.log(i, k)

  while(i >= 0 && k < n) {
    if(diff[i] > -diff[k]) {
      count += n - k
      i--
    }
    else k++
  }
  wr(count)
}

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a) {
  return parseInt(a[ptr++])
}

function readString(a) {
  return a[ptr++]
}

function readStrings(a) {
  return a[ptr++].split(' ')
}

function readInts(a) {
  return a[ptr++].split(' ').map(a => parseInt(a))
}

function main(input) {
  const n = readInt(input)
  const a = readInts(input)
  const b = readInts(input)

  let diff = new Array(n)
  for(let i = 0; i < n; i++){
    diff[i] = a[i] - b[i]
  }
  sort(diff)
  // console.log(diff)
  let map = {}
  let ne = 0
  let ze = 0
  let po = 0
  for(let i = 0; i < n; i++){
    if(diff[i] === 0) ze++
    else if(diff[i] > 0) po++
    else ne++
  }
  let count = po * (po - 1) / 2
  if(ze > 0) count += po * ze
  // console.log(count)
  let i
  for(i = 0; i < n && diff[i] < 0; i++){
    if(!map[diff[i]]) map[diff[i]] = 1
    else map[diff[i]]++
  }
  let k = i
  while(diff[k] === 0) k++
  i--
  // console.log(i, k)

  while(i >= 0 && k < n) {
    if(diff[i] > -diff[k]) {
      count += n - k
      i--
    }
    else k++
  }
  wr(count)
}


Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples:  for the array $$$[0, 0, 1, 0, 2]$$$ MEX equals to $$$3$$$ because numbers $$$0, 1$$$ and $$$2$$$ are presented in the array and $$$3$$$ is the minimum non-negative integer not presented in the array;  for the array $$$[1, 2, 3, 4]$$$ MEX equals to $$$0$$$ because $$$0$$$ is the minimum non-negative integer not presented in the array;  for the array $$$[0, 1, 4, 3]$$$ MEX equals to $$$2$$$ because $$$2$$$ is the minimum non-negative integer not presented in the array. You are given an empty array $$$a=[]$$$ (in other words, a zero-length array). You are also given a positive integer $$$x$$$.You are also given $$$q$$$ queries. The $$$j$$$-th query consists of one integer $$$y_j$$$ and means that you have to append one element $$$y_j$$$ to the array. The array length increases by $$$1$$$ after a query.In one move, you can choose any index $$$i$$$ and set $$$a_i := a_i + x$$$ or $$$a_i := a_i - x$$$ (i.e. increase or decrease any element of the array by $$$x$$$). The only restriction is that $$$a_i$$$ cannot become negative. Since initially the array is empty, you can perform moves only after the first query.You have to maximize the MEX (minimum excluded) of the array if you can perform any number of such operations (you can even perform the operation multiple times with one element).You have to find the answer after each of $$$q$$$ queries (i.e. the $$$j$$$-th answer corresponds to the array of length $$$j$$$).Operations are discarded before each query. I.e. the array $$$a$$$ after the $$$j$$$-th query equals to $$$[y_1, y_2, \dots, y_j]$$$.

The first line of the input contains two integers $$$q, x$$$ ($$$1 \le q, x \le 4 \cdot 10^5$$$) — the number of queries and the value of $$$x$$$. The next $$$q$$$ lines describe queries. The $$$j$$$-th query consists of one integer $$$y_j$$$ ($$$0 \le y_j \le 10^9$$$) and means that you have to append one element $$$y_j$$$ to the array.

Print the answer to the initial problem after each query — for the query $$$j$$$ print the maximum value of MEX after first $$$j$$$ queries. Note that queries are dependent (the array changes after each query) but operations are independent between queries.

NoteIn the first example:  After the first query, the array is $$$a=[0]$$$: you don't need to perform any operations, maximum possible MEX is $$$1$$$.  After the second query, the array is $$$a=[0, 1]$$$: you don't need to perform any operations, maximum possible MEX is $$$2$$$.  After the third query, the array is $$$a=[0, 1, 2]$$$: you don't need to perform any operations, maximum possible MEX is $$$3$$$.  After the fourth query, the array is $$$a=[0, 1, 2, 2]$$$: you don't need to perform any operations, maximum possible MEX is $$$3$$$ (you can't make it greater with operations).  After the fifth query, the array is $$$a=[0, 1, 2, 2, 0]$$$: you can perform $$$a[4] := a[4] + 3 = 3$$$. The array changes to be $$$a=[0, 1, 2, 2, 3]$$$. Now MEX is maximum possible and equals to $$$4$$$.  After the sixth query, the array is $$$a=[0, 1, 2, 2, 0, 0]$$$: you can perform $$$a[4] := a[4] + 3 = 0 + 3 = 3$$$. The array changes to be $$$a=[0, 1, 2, 2, 3, 0]$$$. Now MEX is maximum possible and equals to $$$4$$$.  After the seventh query, the array is $$$a=[0, 1, 2, 2, 0, 0, 10]$$$. You can perform the following operations:   $$$a[3] := a[3] + 3 = 2 + 3 = 5$$$,  $$$a[4] := a[4] + 3 = 0 + 3 = 3$$$,  $$$a[5] := a[5] + 3 = 0 + 3 = 3$$$,  $$$a[5] := a[5] + 3 = 3 + 3 = 6$$$,  $$$a[6] := a[6] - 3 = 10 - 3 = 7$$$,  $$$a[6] := a[6] - 3 = 7 - 3 = 4$$$.  The resulting array will be $$$a=[0, 1, 2, 5, 3, 6, 4]$$$. Now MEX is maximum possible and equals to $$$7$$$.

'use strict'

const qx = readline().split(' ');
let q = +qx[0];
const x = +qx[1];

const problem = (n) => {
    for (let i = 2; i < Math.cbrt(n); i++) {
        if (n % i === 0) {
            n /= i;
            for (let j = i + 1; j < Math.sqrt(n); j++) {
                if (n % j === 0) return `YES\n${i} ${j} ${n/j}`;
            }
        }
    }
    return 'NO';
}
const r = Array(x).fill(0);
let j = 0;

while(q--) {
    r[+readline() % x]++;
    while(r[j % x]) { r[j % x]--; j++; }
    print(j);
}


Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

readline()
var s=readline().split(' ').map(function(v){return v%2}).join('')
print(s.indexOf(s.match(/0/g).length<=1?0:1)+1)

var i1=0;
var i2=0;
var c1=0;
var c2=0;
readline();
readline().split(' ').map(Number).forEach(function(v, i){
	if(v%2){
		c1++;
		i1=i;
	}else{
		c2++;
		i2=i;
	}
});
print(c1>c2 ? i2+1 : i1+1);

readline();
var a=readline().split(' ').map(function(v){return v%2});
var s=0;
for(var i=0;i<3;i++){
	s+=a[i]%2;
}
print( a.indexOf( s>=2?0:1 ) + 1 );

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

if(+numbers[0] % 2 == 0){
	if(+numbers[1] % 2 == 0){
		for(i = 2; i < n; i++){
			if(+numbers[i] % 2 == 1){
				write(i+1);
				break;
			}
		}
	}
	else{
		if(+numbers[2] % 2 == 0){
			write(2);
		}
		else{
			write(1);
		}
	}
}
else{
	if(+numbers[1] % 2 == 1){
		for(i = 2; i < n; i++){
			if(+numbers[i] % 2 == 0){
				write(i+1);
				break;
			}
		}
	}
	else{
		if(+numbers[2] % 2 == 1){
			write(2);
		}
		else{
			write(1);
		}
	}
}

var n = +readline();
var a = readline().split(' ').map(function(x) {return (+x) % 2;});
var sum = a.reduce(function(a, b) {return a + b});
var lookFor = sum == 1 ? 1 : 0;
for (var i = 0; i < n; i ++) if (a[i] == lookFor) print(i + 1);

var n = readline();
var s = readline().split(' ');

var i = 0;

var odd_n = 0;
var odd_x = 0;
var evenn = 0;
var evenx = 0;

for(i=0; i<n; i++)
{
  if(s[i]%2==0)
  {
    odd_n++;
    odd_x = i;
  }
  else
  {
    evenn++;
    evenx = i;
  }
}

if(odd_n == 1) print(odd_x+1);
else print(evenx+1);

var n = readline();
var s = readline().split(' ');

var i = 999;

var odd_n = 0;
var odd_x = 0;
var evenn = 0;
var evenx = 0;

for(i=0; i<n; i++)
{
  if(s[i]%2==0)
  {
    odd_n++;
    odd_x = i;
  }
  else
  {
    evenn++;
    evenx = i;
  }
}

if(odd_n == 1) print(odd_x+1);
else print(evenx+1);

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]);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline());
	var integers = tokenizeIntegers(readline());
	var counts = [0, 0], last = new Array(2);
	for (var i = 0; i < n; i += 1) {
		counts[integers[i]%2] += 1;
		last[integers[i]%2] = i+1;
	}
	print(counts[0] == 1 ? last[0] : last[1]);
}

main();

//Read the input
const N = readline();
if (N <= 100 && N >= 3)
	input = readline();

//turn the string to array of intgers
input = input.split(' ').map((str) => {
	return parseInt(str);
});

index = 0; //index counter

//return as soon as the condition is true
input.some((num) => {
	index++;
	//Check weather the first number is the different one
	if ((input[1] % 2 === input[2] % 2) &&
		(input[1] % 2 !== input[0] % 2)) {
		return true;
	}
	//return when a number differs than the first number
	else {
		if (input[0] % 2 === 0)
			return num % 2 !== 0;
		else
			return num % 2 === 0;
	}
});

print(index);

'use strict'

let lll = readline()

let ns = readline().split(' ').map(v => parseInt(v))

let fe = ns[0] % 2
let se = ns[1] % 2
let te = ns[2] % 2

let ae = +(fe + se + te >= 2)

;(function () {
  for (let i = 0; i < ns.length; i++) {
    if (ns[i] % 2 != ae) return print(i + 1)
  }
})()

    var n=readline()
    var a=readline()
    var e=0,o=0,pose=0,poso=0;
    var arr=new Array();
    var st="";
    for(var i=0;i<a.length;++i){
        if (a[i]!=' ')st+=a[i]
        else{
            arr.push(st)
            if (st&1){o++;poso=arr.length}
            else {e++;pose=arr.length}
            st=""
        }
    }
    arr.push(st)
    if (st&1){o++;poso=arr.length}
    else{e++;pose=arr.length}
    print(o<=1?poso:pose)

process.stdin.setEncoding("ascii");
let input = "";
process.stdin.on("data", data => input += data);
process.stdin.on("end", () => {
    const parities = input.split("\n")[1].split(" ").map(Number).map(x => x % 2);
    if (parities.reduce((a, b) => a + b) > 1)
    {
        console.log(parities.indexOf(0) + 1);
    } else {
        console.log(parities.indexOf(1) + 1);
    }
});

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const n = parseInt(inputs[0]);
    const numbers = inputs[1].split(' ').map(number => parseInt(number));
    let chages = 0;

    for (let i = 1; i < numbers.length; i++) {

        if (numbers[i] % 2 != numbers[0] % 2)
            chages++;

        // if the change occurred early
        if (i == 1 && chages == 1) {
            if (numbers[i] % 2 == numbers[i + 1] % 2)
                return console.log(1)
            else
                return console.log(2)
        }

        //
        if (i > 1 && chages == 1) {
            return console.log(i + 1)
        }

    }

});

const input = [];

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

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

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

    nums.forEach((x, i) => {
      if (x % 2 === 0) cnt[0] += 1;
      else cnt[1] += 1;
      if (i === 2) return;
    });

    nums.forEach( (x, i) => {
      if (cnt[0] > cnt[1] && x % 2 !== 0) {
        console.log(i+1); return;
      } else if (cnt[1] > cnt[0] && x % 2 === 0) {
        console.log(i+1); return;
      }
    });
});

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

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

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  const nums = splitAndParseInt(input[1]);
  let cntOdd = (nums[0] % 2 !== 0) + (nums[1] % 2 !== 0) + (nums[2] % 2 !== 0);

  for (let i = 0; i < nums.length; i += 1) {
    let n = nums[i];
    if (cntOdd <= 1 && n % 2 !== 0) {
      console.log(i + 1);
      return;
    } else if (cntOdd > 1 && n % 2 === 0) {
      console.log(i + 1);
      return;
    }
  }
});

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

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

readline.on('close', () => {
    const [n] = input[0].split(' ').map(Number);
    const arr = input[1].split(' ').map(Number);
    const evens = [], odds = [];
    arr.forEach((v, i) => v % 2 === 0 ? evens.push(i + 1) : odds.push(i + 1));
    if (evens.length === 1) console.log(evens[0]);
    else console.log(odds[0]);
});

let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split("\n").filter(data => data.length > 0);
for (let i = 0; i < txt.length; i += 2) {
    doit(txt[i + 1].split(" ").filter(data => data.length > 0).map(data => data * 1));
}

function doit(tab) {
    let t = tab.filter(data => data % 2 === 0);
    if (t.length == 1) {
        console.log(tab.indexOf(t[0]) + 1);
    } else {
        console.log(tab.indexOf(tab.filter(data => data % 2 == 1)[0]) + 1);
    }

}

print((d => 1 + d.findIndex(x => x % 2 == d.reduce((d, x) => d.splice(x%2, 1, d[x%2]+1) && d, [0, 0]).indexOf(1)))((readline() && readline()).toString().split(/\s+/).map(Number)))

var n = parseInt(readline());
var arr = readline().split(' ').map(el => parseInt(el)),
    even=0, odd=0, index=0;
for (var i = 0; i < arr.length; i++) {
    if (arr[i] % 2 == 0) {
        even++;
    } else {
        odd++;
    }
}
if (even < odd) {
    for (var j = 0; j < arr.length; j++) {
        if(arr[j] % 2 == 0){
            index = j;
        }
    }
} else {
    for (var a = 0; a < arr.length; a++) {
        if(arr[a] % 2 != 0){
            index = a;
        }
    }
}
print(index+1);

var n=readline(); n=parseInt(n);
var arr=readline().split(' ').map(function(x){return parseInt(x)});
for(i = 0 ; i<n;i++)
{
    var num=0;
    for(var j=0;j<n;j++)
    if(arr[i]%2!=arr[j]%2)num++;
    if(num==n-1){print(i+1);}
}

var n=readline(); n=parseInt(n);
var arr=readline().split(' ').map(function(x){return parseInt(x)});
var even=0,odd=0; var Evenans=0 , Oddans=0;
for(var i=0;i<n;i++)
{
    if(arr[i]%2==0){even++; Evenans=i+1;}
    else {odd++; Oddans=i+1;}
}
if(even==1)print(Evenans);
else print(Oddans);

'use strict';

const getArray = (array_1, array_2) => {
    if (array_1.length === 1) {
        return array_1;
    }

    return array_2;
}

const filterOddNumbers = number => number % 2;
const filterEvenNumbers = number => number % 2 === 0;

const n = readline(),
      array = readline().split(' ').map(value => parseInt(value));

write(array.indexOf(getArray(
    array.filter(filterOddNumbers),
    array.filter(filterEvenNumbers)
)[0]) + 1);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var even = 0;
for(var i = 0; i < 3; ++i)
{
    if(parseInt(mas[i]) % 2 == 0){even ++;}
}
var i;
for(i = 0; i < n; ++i)
{
         if(even > 1 && parseInt(mas[i]) % 2 != 0){break;}
    else if(even < 2 && parseInt(mas[i]) % 2 == 0){break;}
}
print(i+1);

var n = Number(readline());
var s = readline().split(" ");
var k = 0, k1 = 0, res = 0, res1 = 0;
for (var i = 0; i<n; i++) {
    if (s[i] % 2 === 0) {
        k++;
        res = i;
    }
    else {
        k1++;
        res1 = i;
    }
}

if (k === 1) {
    print(res+1);
}
else {
    print(res1+1);
}

var n = readline();
var arr = readline().split(" ");
var chet = arr.filter(x=>x%2==0);

		for (var i=0; i<+n; i++){
			if(chet.length>1&&arr[i]%2!=0){
				print(i+1);
				break;
			}
			else if (chet.length==1&&arr[i]%2==0){
				print(i+1);
				break;
			}
		}

var x=parseInt(readline());
var arr=readline().split(' ');
var e=0,ev,od;
for(var i=0;i<x;i++)
{
   if(parseInt(arr[i])%2==0)
   {
       e+=1;
       ev=i;
   }
   else
{
    e-=1;
    od=i;
}
}
if(e>0)
{print(parseInt(od+1));
}else{
    print(parseInt(ev+1));
}

var temporary = readline();
var inputedNumbers = readline().split(' ');
var evenNumbers = [];
var notEvenNumbers = [];
var printed = false;
for (var index  = 0; index < inputedNumbers.length; index++)
    {
        if (isEven(+inputedNumbers[index]))
            {
               if (notEvenNumbers.length > 1)
               {
                   print(index+1);
                   printed = true;
                   break;
                }
               else
                   {
                       evenNumbers.push(index);
                   }
            }
         else
             {
                 if (evenNumbers.length > 1)
                     {
                         print(index+1);
                         printed = true;
                         break;
                         }
                  else
                      {
                          notEvenNumbers.push(index);
                          }

                 }
    }
if (evenNumbers.length > 1 && !printed)
    {
        print(notEvenNumbers[0]+1);
    }
else if(!printed)
    {
        print(evenNumbers[0]+1);
        }

function isEven(number)
{
    for(var counter = 2; ;)
        {
            if (number === 1)
                {
                    return false;
                    }
            else if ( !(number -= counter) )
                {
                    return true;
                }

       }
    return false;
}

var n = readline();
var data = readline().split(" ");

var count_o=0;
var last_e,last_o;
for(var i = 0; i < n; i++){
	if(data[i]&1){
		count_o++;
		last_o = i+1;
	}
	else
		last_e = i+1;

}
if(count_o == 1)
	print(last_o);
else
	print(last_e);

var n = readline();
var numbers = readline().split(' ');
findUniqueNumber();

function findUniqueNumber() {
    var isRemArr = [];
    var sumOfRes = 0;
    for (var i = 1; i < 2; i++) {
        var div = i + 1;
        for (var j = 0; j < numbers.length; j++) {
            if (numbers[j] % div !== 0) {
                isRemArr.push(1);
                sumOfRes++;
            } else {
                isRemArr.push(0);
            }
        }
        // print(isRemArr);
        var answer;
        if (sumOfRes === n - 1) {
            answer = isRemArr.indexOf(0);
        } else if (sumOfRes === 1) {
            answer = isRemArr.indexOf(1);
        }
        if (answer !== -1) {
            print(answer + 1);
            return;
        }
    }
}

var line = readline();
var n = parseInt(line);

var newnum = readline().split(' ').map(Number);

var oddcount=0;
var evencount=0;

for(i=0;i<n;i++){
    if(newnum[i]%2===0){
	evencount+=1;
    } else{
	oddcount+=1;
    }
}

if(oddcount===1){
    for(i=0;i<n;i++){
	if(newnum[i]%2===1){
	    print(i+1);
	}
    }
}else{
    for(i=0;i<n;i++){
	if(newnum[i]%2===0){
	    print(i+1);
	}
    }
}

n=parseInt(readline())
var odd, even;
X=readline().split(' ').map(i => parseInt(i)).reduce((a,c,i) => {
	if (c%2) odd=i; else even=i;
	return a + c%2
}, 0)
print((X===1?odd:even)+1)

var n = parseInt(readline());
var array = readline().split(' ').map(Number);
var even = [];
var odd = [];

for (var i = 0; i < n; i++) {
	if (array[i] % 2 == 0) {
		even.push(i);
	}
	else {
		odd.push(i);
	}
}

print (odd.length == 1 ? odd[0] + 1 : even[0] + 1);

var chetnie = [];
var nechetniye = [];
var num = parseInt(readline());
var numbers = readline().split(' ').map(function (num) {return parseInt(num)});

for (var i = 0; i < num; i++) {
	if (numbers[i] % 2 == 0) {
		chetnie.push(numbers[i]);
		lastChetnoye = i + 1;
	} else {
		nechetniye.push(numbers[i]);
		lastNechetnoye = i + 1;
	}
	if (chetnie.length > 1 && nechetniye.length == 1) {
		print(lastNechetnoye);
		break;
	}
	if (nechetniye.length > 1 && chetnie.length == 1) {
		print(lastChetnoye);
		break;
	}
}

	readline();var prm = readline().split(" ").map(function(m){if((+m)%2==0){return "z"}else{return "f"}});
		var r = 0;

	for(var i=0;i<prm.length;i++){
		if(prm[i]=="z"){r++}
        if(r==2){print((prm.indexOf("f")+1));break}
}
if(r!=2){print((prm.indexOf("z")+1))}

var n = Number(readline());

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

var parity = arr.map(a => a % 2);
parity.sort();

var kontr = parity[1];
for(var i = 0; i < n; i++){
    if(kontr != arr[i] % 2){
        print(i + 1);
    }
}

var n = readline();
var s = readline().split(' ');

var i = 0;

var odd_n = 0;
var odd_x = 0;
var evenn = 0;
var evenx = 0;

for(i=0; i<n; i++)
{
  if(s[i]%2==0)
  {
    odd_n++;
    odd_x = i;
  }
  else
  {
    evenn++;
    evenx = i;
  }
}

if(odd_n == 1) print(odd_x);
else print(evenx);

const N = readline();
if (N <= 100 && N >= 3)
	input = readline();

//turn the string to array of intgers
input = input.split(' ').map((str) => {
	return parseInt(str);
});

var index = 0; //index counter
var firstNum = input[0]; //first num of the array

//return as soon as the condition is true
input.some((num) => {
	index++;
	if (firstNum % 2 === 0)
		return num % 2 !== 0;
	else
		return num % 2 === 0;
});

print(index);

var n=readline()
var arr=readline()
var ev=0,od=0,pose=-1,poso=-1
for(var i=0;i<n;++i){
    if (arr[i]&1){od++;poso=i;}
    else {ev++;pose=i}
}
print(ev==1?pose:poso)

var n=readline()
var arr=readline()
print(arr[0])

var n=readline()
var arr=readline()
var ev=0,od=0,pose=-1,poso=-1
for(var i=0;i<n;++i){
    if (arr[i]&1){od++;poso=i;}
    else {ev++;pose=i}
}
print(ev==1?arr[pose]:arr[poso])

var n=readline()
var arr=readline().split(' ').join('')
var e=0,o=0,pe=0,po=0;
for(var i=0;i<n;++i){
    if ((arr[i]&1)){o++;po=i}
    else {e++;pe++;}
}
print(e==1?pe+1:po+1)

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const n = parseInt(inputs[0]);
    const numbers = inputs[1].split(' ').map(number => parseInt(number));
    let numberIdx = 1;
    let base = Math.ceil(numbers[0] % 2);

    for (let i = 0; i < numbers.length; i++) {

        if (Math.ceil(numbers[i] % 2) != base)
            return console.log(numberIdx);

        numberIdx++;
    }

});

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

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

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  const nums = splitAndParseInt(input[1]);
  let cntOdd = (nums[0] % 2 !== 0) + (nums[1] % 2 !== 0) + (nums[2] % 2 !== 0);

  for (let i = 0; i < nums.length; i += 1) {
    let n = nums[i];
    if (cntOdd === 1 && n % 2 !== 0) {
      console.log(i + 1);
      return;
    } else if (cntOdd > 1 && n % 2 === 0) {
      console.log(i + 1);
      return;
    }
  }
});

    var n=readline()
    var a=readline()
    var e=0,o=0,pose=0,poso=0;
    var arr=new Array();
    var st="";
    for(var i=0;i<a.length;++i){
        if (a[i]!=' ')st+=a[i]
        else{
            arr.push(st)
            if (st&1){o++;poso=arr.length}
            else {e++;pose=arr.length}
            st=""
        }
    }
    arr.push(st)
    print(o<=1?poso:pose)

var n=readline()
var arr=readline().split(' ').join('')
var e=0,o=0,pe=0,po=0;
for(var i=0;i<n;++i){
    if ((arr[i]&1)){o++;po=i;}
    else {e++;pe=i;}
}
print((e==1?pe+1:po+1))

var n=readline()
var arr=readline().split(' ').join('')
var e=0,o=0,pe=0,po=0;
for(var i=0;i<n;++i){
    if ((arr[i]&1)){o++;po=i;}
    else {e++;pe=i;}
    print(arr[i])
}
print((e==1?pe+1:po+1))

print((d => 1 + d.findIndex(x => x % 2 == d.reduce((d, x) => d.splice(x%2, 1, d[x%2]+1) && d, [0, 0]).indexOf(1)))((readline() && readline()).toString().split(/\s+/).slice(1).map(Number)))

'use strict';

const getArray = (array_1, array_2) => {
    if (array_1.length === 1) {
        return array_1;
    }

    return array_2;
}

const filterOddNumbers = number => number % 2;
const filterEvenNumbers = number => number % 2 === 0;

const n = readline(),
      array = readline().split(' ').map(value => parseInt(value));

write(array.indexOf(getArray(
    array.map(filterOddNumbers),
    array.map(filterEvenNumbers)
)[0]) + 1);

var n = readline();
var str = readline().split(" ");
var nc =0; c=0;
	for (var i=0; i<n; i++){
		if (str[i]%2==0)
			c++;
		else nc++;
	}
c>nc? print(nc):print(c);

var n = readline();
var str = readline().split(" ");
var chet = 0;
if ((Number(str[0])+Number(str[1]))%2==0||(Number(str[1])+Number(str[2]))%2==0)
	chet=1;
	for (var i=0; i<n; i++){
			if(chet!=0&&str[i]%2!=0){
		print(i+1);
			break;}
			else if (chet==0&&str[i]%2==0){
			print(i+1);
			break;
		}
	}

var x=parseInt(readline());
var arr=readline().split(' ');
var e=0,ev,od,o=0;
for(var i=0;i<x;i++)
{
   if(parseInt(arr[i])%2==0)
   {
       e+=1;
       ev=i;
   }
   else
{
    o+=1;
    od=i;
}
}
if(e>0)
{print(parseInt(ev+1));
}else{
    print(parseInt(od+1));
}

var x=parseInt(readline());
var arr=readline().split(' ');
var e=0,ev,od;
for(var i=0;i<x;i++)
{
   if(parseInt(arr[i])%2==0)
   {
       e+=1;
       ev=i;
   }
   else
{
    e-=1;
    od=i;
}
}
if(e>0)
{print(parseInt(ev+1));
}else{
    print(parseInt(od+1));
}

var n = Number(readline());
var s = readline().split(" ");

var k = 0, k1 = 0, res = 0, res1 = 0;
for (var i = 1; i<n; i++) {
    if (s[i] % 2 === 0) {
        k++;
        res = i;
    }
    else {
        k1++;
        res1 = i;
    }
}

if (k === 1) {
    print(res+1);
}
else {
    print(res1+1);
}

var n = readline();
var numbers = readline().split(' ');

findUniqueNumber();

function findUniqueNumber() {

    var redundantStack = [];

for (var i = 1; i < 3; i++) { // find divider

  var div = i+1;
  var redundantCount = 0; // with remainder count

    for (var j = 0; j < numbers.length; j++) {

        // print('test %: ', numbers[j], div, numbers[j] % div);
        // print('test /: ', numbers[j], div, numbers[j] / div);
        // || numbers[j] / div > 1

        if (numbers[j] % div !== 0 ) {

            redundantCount++;
            redundantStack.push(j);
        } else {
            var specialInd = j;
        }
    }
    // print('redundantCount : ', redundantCount);
    if (redundantCount === 1) {
        var lastInd = redundantStack.length - 1;
        print(redundantStack[lastInd] + 1); // answer
        return;
    } else if (redundantCount === numbers.length - 1) {
        print(redundantStack[specialInd]); // answer
        return;
    }
}

}

var n = parseInt(readline());
var array = readline().split(' ').map(Number);
var even = [];
var odd = [];

for (var i = 0; i < 3; i++) {
	if (array[i] % 2 == 0) {
		even.push(array[i]);
	}
	else {
		odd.push(array[i]);
	}
}

print (odd.length == 1 ? odd[0] : even[0]);

var n = parseInt(readline());
var array = readline().split(' ').map(Number);
var even = [];
var odd = [];

for (var i = 0; i < 3; i++) {
	if (array[i] % 2 == 0) {
		even.push(i);
	}
	else {
		odd.push(i);
	}
}

print (odd.length == 1 ? odd[0] + 1 : even[0] + 1);


This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers $$$-1$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ with the following property:  Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$.  The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition.The set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, \ldots k-1$$$. In other words, each element of the array must belong to exactly one segment.You have to build a partition of the given array with properties described above or determine that such partition does not exist.Note that it is not required to minimize the number of segments in the partition.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$-1$$$ or $$$1$$$) — the elements of the given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case, if required partition does not exist, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of segments in the partition.  Then in the $$$i$$$-th of the following $$$k$$$ lines print two integers $$$l_i$$$ and $$$r_i$$$ — description of the $$$i$$$-th segment. The following conditions should be satisfied:   $$$l_i \le r_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k$$$.  $$$l_{i + 1} = r_i + 1$$$ for each $$$i$$$ from $$$1$$$ to $$$(k - 1)$$$.  $$$l_1 = 1, r_k = n$$$.  If there are multiple correct partitions of the array, print any of them.

NoteIn the first test case we can build a partition of one segment of length $$$4$$$. The sum of this segment will be equal to $$$1 - 1 + 1 - 1 = 0$$$.In the second test case we can build a partition of two segments of length $$$3$$$. The sum of the first segment will be equal to $$$-1 -1 + 1 = -1$$$, and the sum of the second segment: $$$1 - 1 + 1 = 1$$$. So, the total sum will be equal to $$$-1 + 1 = 0$$$.In the third and in the fourth test cases it can be proved that there are no required partition.

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) {
    const sum = arr.reduce((s, x) => s + x, 0)
    // if (!sum) {
    //     return `1\n1 ${n}`
    // }
    const t = sum > 0 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push([i, i + 1])
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push([i + 1, i + 1])
        }
    }
    ans.sort((a, b) => a[0] - b[0])
    return ans.length + '\n' + ans.map(x => x.join(' ')).join('\n')
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  const l = [a[0]];
  for (let i = 1; i < n; i++) {
    if (i & 1) {
      l[i] = l[i - 1] - a[i];
    } else {
      l[i] = l[i - 1] + a[i];
    }
  }
  const r = [];
  r[n - 1] = a[n - 1];
  const odd = new Map(),
        even = new Map();
  for (let i = n - 1; i >= 0; i--) {
    if (i < n - 1) {
      if (n - i - 1 & 1) {
        r[i] = a[i] - r[i + 1];
      } else {
        r[i] = a[i] - r[i + 1];
      }
    }
    if (i & 1) {
      if (!odd.has(r[i])) odd.set(r[i], []);
      odd.get(r[i]).push(i);
    } else {
      if (!even.has(r[i])) even.set(r[i], []);
      even.get(r[i]).push(i);
    }
  }
  for (let [key, arr] of odd) arr.reverse();
  for (let [key, arr] of even) arr.reverse();
  const find = arr => {
    while (arr.length && arr[arr.length - 1] > right) arr.pop();
    if (arr.length && arr[arr.length - 1] > left) {
      const ans = arr[arr.length - 1];
      pre = r[ans];
      sum = d = 0;
      res.push([pl, left], [ans, right]);
      right = ans - 1;
      pl = left + 1;
      return true;
    }
    return false;
  };
  let sum = 0,
      pre = 0,
      res = [];
  let left = 0,
      right = n - 1,
      d = 0,
      pl = 0;
  for (; left <= right; left++) {
    if (d & 1) {
      sum -= a[left];
    } else {
      sum += a[left];
    }
    if (sum === 0) {
      res.push([pl, left]);
      pl = left + 1;
      sum = d = 0;
      continue;
    }
    d++;
    if (right & 1) {
      let t = -sum - pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
    } else {
      let t = -sum - pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
    }
  }
  res.sort((a, b) => a[0] - b[0]);
  const check = arr => {
    var _arr$, _arr;
    if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;
    for (let i = 1; i < arr.length; i++) {
      if (arr[i][0] !== arr[i - 1][1] + 1) return false;
    }
    return true;
  };
  if (!check(res)) return -1;
  return `${res.length}\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\n')}`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

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

function solve(n, arr) {
    const sum = arr.reduce((s, x) => s + x, 0)
    // if (!sum) {
    //     return `1\n1 ${n}`
    // }
    const t = sum > 0 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push(`${i} ${i + 1}`)
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push(`${i + 1} ${i + 1}`)
        }
    }
    ans.unshift(ans.length)
    return ans.join('\n')
}

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) {
    const sum = arr.reduce((s, x) => s + x, 0)
    // if (!sum) {
    //     return `1\n1 ${n}`
    // }
    const t = sum > 1 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push(`${i} ${i + 1}`)
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push(`${i + 1} ${i + 1}`)
        }
    }
    ans.unshift(ans.length)
    return ans.join('\n')
}

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) {
    const sum = arr.reduce((s, x) => s + x, 0)
    if (!sum) {
        return `1\n1 ${n}`
    }
    const t = sum > 1 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push(`${i} ${i + 1}`)
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push(`${i + 1} ${i + 1}`)
        }
    }
    ans.unshift(ans.length)
    return ans.join('\n')
}

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) {
    const sum = arr.reduce((s, x) => s + x, 0)
    if (!sum) {
        return '1\n1 n'
    }
    const t = sum > 1 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push(`${i} ${i + 1}`)
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push(`${i + 1} ${i + 1}`)
        }
    }
    ans.unshift(ans.length)
    return ans.join('\n')
}

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) {
    const sum = arr.reduce((s, x) => s + x, 0)
    if (!sum) {
        return '1\n1 n'
    }
    const t = sum > 1 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push(`${i} ${i + 1}`)
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push(`${i + 1} ${i + 1}`)
        }
    }
    ans.unshift(ans.length)
    return ans.join('\n')
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  const l = [a[0]];
  for (let i = 1; i < n; i++) {
    if (i & 1) {
      l[i] = l[i - 1] - a[i];
    } else {
      l[i] = l[i - 1] + a[i];
    }
  }
  const r = [];
  r[n - 1] = a[n - 1];
  const odd = new Map(),
        even = new Map();
  for (let i = n - 1; i >= 0; i--) {
    if (i < n - 1) {
      if (n - i - 1 & 1) {
        r[i] = a[i] - r[i + 1];
      } else {
        r[i] = a[i] - r[i + 1];
      }
    }
    if (i & 1) {
      if (!odd.has(r[i])) odd.set(r[i], []);
      odd.get(r[i]).push(i);
    } else {
      if (!even.has(r[i])) even.set(r[i], []);
      even.get(r[i]).push(i);
    }
  }
  for (let [key, arr] of odd) arr.reverse();
  for (let [key, arr] of even) arr.reverse();
  const find = arr => {
    while (arr.length && arr[arr.length - 1] > right) arr.pop();
    if (arr.length && arr[arr.length - 1] > left) {
      const ans = arr[arr.length - 1];
      pre = r[ans];
      sum = d = 0;
      res.push([pl, left], [ans, right]);
      right = ans - 1;
      pl = left + 1;
      return true;
    }
    return false;
  };
  let sum = 0,
      pre = 0,
      res = [];
  let left = 0,
      right = n - 1,
      d = 0,
      pl = 0;
  for (; left < right; left++) {
    if (d & 1) {
      sum -= a[left];
    } else {
      sum += a[left];
    }
    d++;
    if (right & 1) {
      let t = -sum - pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
    } else {
      let t = -sum - pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
    }
  }
  res.sort((a, b) => a[0] - b[0]);
  const check = arr => {
    var _arr$, _arr;
    if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;
    for (let i = 1; i < arr.length; i++) {
      if (arr[i][0] !== arr[i - 1][1] + 1) return false;
    }
    return true;
  };
  if (!check(res)) return -1;
  return `${res.length}\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\n')}`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  const l = [a[0]];
  for (let i = 1; i < n; i++) {
    if (i & 1) {
      l[i] = l[i - 1] - a[i];
    } else {
      l[i] = l[i - 1] + a[i];
    }
  }
  const r = [];
  r[n - 1] = a[n - 1];
  const odd = new Map(),
        even = new Map();
  for (let i = n - 1; i >= 0; i--) {
    if (i < n - 1) {
      if (n - i - 1 & 1) {
        r[i] = a[i] - r[i + 1];
      } else {
        r[i] = a[i] - r[i + 1];
      }
    }
    if (i & 1) {
      if (!odd.has(r[i])) odd.set(r[i], []);
      odd.get(r[i]).push(i);
    } else {
      if (!even.has(r[i])) even.set(r[i], []);
      even.get(r[i]).push(i);
    }
  }
  for (let [key, arr] of odd) arr.reverse();
  for (let [key, arr] of even) arr.reverse();
  const find = arr => {
    while (arr.length && arr[arr.length - 1] > right) arr.pop();
    if (arr.length && arr[arr.length - 1] > left) {
      const ans = arr[arr.length - 1];
      pre = r[ans];
      sum = d = 0;
      res.push([pl, left], [ans, right]);
      right = ans - 1;
      pl = left + 1;
      return true;
    }
    return false;
  };
  let sum = 0,
      pre = 0,
      res = [];
  let left = 0,
      right = n - 1,
      d = 0,
      pl = 0;
  for (; left < right; left++) {
    if (d & 1) {
      sum -= a[left];
    } else {
      sum += a[left];
    }
    d++;
    if (right & 1) {
      let t = -sum - pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
    } else {
      let t = -sum - pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
    }
  }
  res.sort((a, b) => a[0] - b[0]);
  const check = arr => {
    var _arr$, _arr;
    if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;
    for (let i = 1; i < arr.length; i++) {
      if (arr[i][0] !== arr[i - 1][1] + 1) return false;
    }
    return true;
  };
  if (!check(res)) return -1;
  return `${res.length}\n${res.map(arr => arr.join(' ')).join('\n')}`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


You came to a local shop and want to buy some chocolate bars. There are $$$n$$$ bars in the shop, $$$i$$$-th of them costs $$$a_i$$$ coins (and you want to buy all of them).You have $$$m$$$ different coupons that allow you to buy chocolate bars. $$$i$$$-th coupon allows you to buy $$$q_i$$$ chocolate bars while you have to pay only for the $$$q_i - 1$$$ most expensive ones (so, the cheapest bar of those $$$q_i$$$ bars is for free).You can use only one coupon; if you use coupon $$$i$$$, you have to choose $$$q_i$$$ bars and buy them using the coupon, and buy all the remaining $$$n - q_i$$$ bars without any discounts.To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of chocolate bars in the shop. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the cost of $$$i$$$-th chocolate bar. The third line contains one integer $$$m$$$ ($$$1 \le m \le n - 1$$$) — the number of coupons you have. The fourth line contains $$$m$$$ integers $$$q_1$$$, $$$q_2$$$, ..., $$$q_m$$$ ($$$2 \le q_i \le n$$$), where $$$q_i$$$ is the number of chocolate bars you have to buy using $$$i$$$-th coupon so that the least expensive of them will be for free. All values of $$$q_i$$$ are pairwise distinct.

Print $$$m$$$ integers, $$$i$$$-th of them should be the minimum amount of money you have to pay if you buy $$$q_i$$$ bars with $$$i$$$-th coupon, and all the remaining bars one by one for their full price.

NoteConsider the first example.If we use the first coupon, we may choose chocolate bars having indices $$$1$$$, $$$6$$$ and $$$7$$$, and we pay $$$18$$$ coins for them and $$$9$$$ coins for all other bars.If we use the second coupon, we may choose chocolate bars having indices $$$1$$$, $$$5$$$, $$$6$$$ and $$$7$$$, and we pay $$$25$$$ coins for them and $$$5$$$ coins for all other bars.

let data = '';
process.stdin.on('data',c => data += c);

const solution = () => {
	let line = data.split('\n');
	let n = Number(line.shift());
	let a = line.shift().split(' ').map(i => Number(i));
	let m = Number(line.shift());
	let q = line.shift().split(' ').map(i => Number(i));
	let r = [];
	let s = a.reduce((w, c) => w + c);
	a.sort((a, b) => b - a);
	for(let i of q){
		r.push(s - a[i-1]);
	}
	console.log(r.join('\n'));
};

process.stdin.on('end',solution);

let data = '';
process.stdin.on('data',c => data += c);

const solution = () => {
	let line = data.split('\n');
	let n = parseInt(line.shift(),10);
	let a = line.shift().split(' ').map(i => parseInt(i,10));
	let m = parseInt(line.shift(),10);
	let q = line.shift().split(' ').map(i => parseInt(i,10));
	let r = [];
	let s = a.reduce((w, c) => w + c);
	a.sort((a, b) => b - a);
	for(let i of q){
		r.push(s - a[i-1]);
	}
	console.log(r.join('\n'));
};

process.stdin.on('end',solution);

let data = '';
process.stdin.on('data',c => data += c);

const solution = () => {
	let line = data.split('\n');
	let n = parseInt(line[0],10);
	let a = line[1].split(' ').map(i => parseInt(i,10));
	let m = parseInt(line[2],10);
	let q = line[3].split(' ').map(i => parseInt(i,10));
	let r = [];
	let s = a.reduce((w, c) => w + c);
	a.sort((a, b) => b - a);
	for(let i of q){
		r.push(s - a[i-1]);
	}
	console.log(r.join('\n'));
};

process.stdin.on('end',solution);


You are given an array a of size n, and q queries to it. There are queries of two types:   1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari;  2 li ri — reverse the segment [li, ri].  There are m important indices in the array b1, b2, ..., bm. For each i such that 1 ≤ i ≤ m you have to output the number that will have index bi in the array after all queries are performed.

The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100).  The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).  Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this query is performed (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).  The last line contains m integer numbers b1, b2, ..., bm (1 ≤ bi ≤ n) — important indices of the array.

Print m numbers, i-th of which is equal to the number at index bi after all queries are done.

 function reverse(x, start, end) {
        if (x < start || x > end) {
            return x;
        }

        var mid = (start + end) / 2;
        if (x === mid) {
            return x;
        }

        var dist = mid - x;
        return mid + dist;
    }

    function unshift(x, start, end) {
        if (x < start || x > end) {
            return x;
        }

        if (x === start) {
            return end;
        }

        return x - 1;
    }

    // read input
    var params = readline().split(' ');
    var queriesCount = parseInt(params[1]);

    var elements = readline().split(' ');
    elements.unshift('0');

    var queries = [];
    for (var i = 0; i < queriesCount; i++) {
        var queryParams = readline().split(' ');
        queries.push({
            type: parseInt(queryParams[0]),
            start: parseInt(queryParams[1]),
            end: parseInt(queryParams[2])
        });
    }

    var special = readline().split(' ');
    // end read input

    var output = [];
    for (var i = 0; i < special.length; i++) {
        var index = parseInt(special[i]);

        for (var q = queries.length - 1; q >= 0; q--) {
            var query = queries[q];
            index = query.type === 1 ? unshift(index, query.start, query.end) : reverse(index, query.start, query.end);
        }

        output.push(elements[index]);
    }

    print(output.join(' '));