You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$ of numbers $$$0, \ldots, n - 1$$$. Count the number of subsegments $$$1 \leq l \leq r \leq n$$$ of this permutation such that $$$mex(p_l, p_{l+1}, \ldots, p_r) > med(p_l, p_{l+1}, \ldots, p_r)$$$.$$$mex$$$ of $$$S$$$ is the smallest non-negative integer that does not occur in $$$S$$$. For example: $$$mex({0, 1, 2, 3}) = 4$$$ $$$mex({0, 4, 1, 3}) = 2$$$ $$$mex({5, 4, 0, 1, 2}) = 3$$$$$$med$$$ of the set $$$S$$$ is the median of the set, i.e. the element that, after sorting the elements in non-decreasing order, will be at position number $$$\left \lfloor{ \frac{|S| + 1}{2} } \right \rfloor$$$ (array elements are numbered starting from $$$1$$$ and here $$$\left \lfloor{v} \right \rfloor$$$ denotes rounding $$$v$$$ down.). For example: $$$med({0, 1, 2, 3}) = 1$$$ $$$med({0, 4, 1, 3}) = 1$$$ $$$med({5, 4, 0, 1, 2}) = 2$$$A sequence of $$$n$$$ numbers is called a permutation if it contains all the numbers from $$$0$$$ to $$$n - 1$$$ exactly once.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$), the number of test cases. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the length of the permutation $$$p$$$. The second line of each test case contains exactly $$$n$$$ integers: $$$p_1, p_2, \ldots, p_n$$$ ($$$0 \leq p_i \leq n - 1$$$), elements of permutation $$$p$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print the answer in a single line: the number of subsegments $$$1 \leq l \leq r \leq n$$$ of this permutation such that $$$mex(p_l, p_{l+1}, \ldots, p_r) > med(p_l, p_{l+1}, \ldots, p_r)$$$.

NoteThe first test case contains exactly one subsegment and $$$mex({0}) = 1 > med({0}) = 0$$$ on it.In the third test case, on the following subsegments: $$$[1, 0]$$$, $$$[0]$$$, $$$[1, 0, 2]$$$ and $$$[0, 2]$$$, $$$mex$$$ is greater than $$$med$$$.In the fourth test case, on the following subsegments: $$$[0, 2]$$$, $$$[0]$$$, $$$[0, 2, 1]$$$ and $$$[0, 2, 1, 3]$$$, $$$mex$$$ greater than $$$med$$$.

'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 map = new Array(n);
  for (let i = 0; i < n; i++) {
    map[a[i]] = i;
  }
  let res = 0,
      l = Infinity,
      r = -Infinity;
  for (let i = 0; i < n; i++) {
    l = Math.min(l, map[i]);
    r = Math.max(r, map[i]);
    while (i + 1 < n && map[i + 1] >= l && map[i + 1] <= r) {
      i++;
    }
    if (i === n - 1) {
      res++;
    } else {
      let a = 0,
          b = 0;
      if (map[i + 1] < l) {
        a = l - map[i + 1] - 1;
        b = n - 1 - r;
      } else {
        a = l;
        b = map[i + 1] - r - 1;
      }
      const len = Math.min(2 * (i + 1), n) - (r - l + 1);
      if (len >= 0) {
        a = Math.min(len, a);
        b = Math.min(len, b);
        if (a + b <= len) {
          res += (b + 1) * (a + 1);
        } else {
          res += (len - b) * (b + 1);
          a = Math.max(0, len - a);
          const x = b - a + 1;
          res += (a + 1 + b + 1) * x / 2;
        }
      }
    }
  }
  return res;
}
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 map = new Array(n);
  for (let i = 0; i < n; i++) {
    map[a[i]] = i;
  }
  let res = 0,
      l = Infinity,
      r = -Infinity;
  for (let i = 0; i < n; i++) {
    l = Math.min(l, map[i]);
    r = Math.max(r, map[i]);
    while (i + 1 < n && map[i + 1] >= l && map[i + 1] <= r) {
      i++;
    }
    if (i === n - 1) {
      res++;
    } else {
      let a = 0,
          b = 0;
      if (map[i + 1] < l) {
        a = l - map[i + 1] - 1;
        b = n - 1 - r;
      } else {
        a = l;
        b = map[i + 1] - r - 1;
      }
      const len = Math.min(2 * (i + 1), n) - (r - l + 1);
      a = Math.min(len, a);
      b = Math.min(len, b);
      if (a + b <= len) {
        res += (b + 1) * (a + 1);
      } else {
        res += (len - b) * (b + 1);
        a = Math.max(0, len - a);
        const x = b - a + 1;
        res += (a + 1 + b + 1) * x / 2;
      }
    }
  }
  return res;
}
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 map = new Array(n);
  for (let i = 0; i < n; i++) {
    map[a[i]] = i;
  }
  let res = 0,
      l = Infinity,
      r = -Infinity;
  for (let i = 0; i < n; i++) {
    l = Math.min(l, map[i]);
    r = Math.max(r, map[i]);
    while (i + 1 < n && map[i + 1] >= l && map[i + 1] <= r) {
      i++;
    }
    if (i === n - 1) {
      res++;
    } else {
      let a = 0,
          b = 0;
      if (map[i + 1] < l) {
        a = l - map[i + 1] - 1;
        b = n - 1 - r;
      } else {
        a = l;
        b = map[i + 1] - r - 1;
      }
      const len = Math.min(2 * (i + 1), n) - (r - l + 1);
      a = Math.min(len, a);
      b = Math.min(len, b);
      if (a > b) [a, b] = [b, a];
      if (a + b <= len) {
        res += (b + 1) * (a + 1);
      } else {
        res += (len - b) * b;
        a = Math.max(0, len - a);
        const x = b - a + 1;
        res += (a + 1 + b + 1) * x / 2;
      }
    }
  }
  return res;
}
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 are given two positive integers $$$a$$$ and $$$b$$$.In one move, you can change $$$a$$$ in the following way:  Choose any positive odd integer $$$x$$$ ($$$x > 0$$$) and replace $$$a$$$ with $$$a+x$$$;  choose any positive even integer $$$y$$$ ($$$y > 0$$$) and replace $$$a$$$ with $$$a-y$$$. You can perform as many such operations as you want. You can choose the same numbers $$$x$$$ and $$$y$$$ in different moves.Your task is to find the minimum number of moves required to obtain $$$b$$$ from $$$a$$$. It is guaranteed that you can always obtain $$$b$$$ from $$$a$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is given as two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case, print the answer — the minimum number of moves required to obtain $$$b$$$ from $$$a$$$ if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain $$$b$$$ from $$$a$$$.

NoteIn the first test case, you can just add $$$1$$$.In the second test case, you don't need to do anything.In the third test case, you can add $$$1$$$ two times.In the fourth test case, you can subtract $$$4$$$ and add $$$1$$$.In the fifth test case, you can just subtract $$$6$$$.

'use strict'

let t = parseInt(readline())

while (t --> 0) {
  const arr = readline().split(' ').map(n => parseInt(n))
  const a = arr[0]
  const b = arr[1]

  let ans = 0
  const diff = Math.abs(a - b)
  if (a < b) {
    if (diff % 2) ans = 1
    else ans = 2
  } else if (a > b) {
    if (diff % 2) ans = 2
    else ans = 1
  }
  print(ans)
}

'use strict'

const problem = (a, b) => {
    if (a === b) return 0;
    if (a < b) return 2 - (b - a) % 2;
    return 1 + (a - b) % 2;
}

let t = +readline()
while(t--) {
    const ab = readline().split(' ')
    print(problem(+ab[0], +ab[1]))
}

'use strict';

let n = parseInt(readline());

while ( n-- > 0 ) {
  let line = readline().split(' ').map(data => parseInt(data));
  print(solve(...line));
}

function solve(x, y) {
  let diff = x - y;
  if ( diff === 0 ) {
    return 0;
  } else if ( diff < 0 ) {
    diff = Math.abs(diff);
    return ( diff % 2 === 1 ) ? 1 : 2;
  } else {
    return ( diff % 2 === 1 ) ? 2 : 1;
  }
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = myconv(next(),4);
        var a = one[0];
        var b = one[1];
        if(a == b){
            output[i] = 0;
        }else{
            if(a < b && a % 2 == 1 && b % 2 == 0){
                output[i] = 1;
            }
            if(a < b && a % 2 == 0 && b % 2 == 1){
                output[i] = 1;
            }
            if(a < b && a % 2 == 0 && b % 2 == 0){
                output[i] = 2;
            }
            if(a < b && a % 2 == 1 && b % 2 == 1){
                output[i] = 2;
            }

            if(a > b && a % 2 == 1 && b % 2 == 0){
                output[i] = 2;
            }
            if(a > b && a % 2 == 1 && b % 2 == 1){
                output[i] = 1;
            }
            if(a > b && a % 2 == 0 && b % 2 == 0){
                output[i] = 1;
            }
            if(a > b && a % 2 == 0 && b % 2 == 1){
                output[i] = 2;
            }
        }
    }
    myout(myconv(output,9));
}

t = +readline();
while(t--) {
    line = readline().split(" ");
    a = +line[0];
    b = +line[1];
    if(a===b) {
        print(0);
    }
    else if(a>b) {
        print((a-b)%2 + 1);
    }
    else {
        print((b-a)%2===0 ? 2 : 1);
    }
}

T=+readline();

while(T--){
    line=readline().split(" ");
    a=+line[0];
    b=+line[1];

    x=b-a;

    if (x<0){
        x=-x;
        if (x%2===0){
            print(1);
        }
        else{
            print(2);
        }
    }

    else if (x > 0) {
        if (x % 2 == 1) {
            print(1);
        }
        else {
            print(2);
        }
    }
    else {
        print(0);
    }
}

function solve(a,b) {
    var d;
    if (a == b)
        return 0;
    if (a > b) {
        d = a-b;
        return d % 2 == 0 ? 1 : 2;
    }
    d = b-a;
    return d % 2 == 0 ? 2 : 1;
}
var t = Number(readline());
while (t--) {
    var arr = readline().split(' ').map(Number);
    var a = arr[0];
    var b = arr[1];
    print(solve(a,b));
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const [n, ...lines] = i.split`\n`;
    for (let i = 0; i < n; i++) {
        const [a, b] = lines[i].split` `.map(Number);
        console.log(a === b ? 0 : a < b ? (b - a) % 2 ? 1 : 2 : (a - b) % 2 ? 2 : 1);
    }
});

/* eslint-disable no-plusplus, no-lonely-if, arrow-parens, no-multi-assign, no-continue, no-mixed-operators, no-restricted-syntax, guard-for-in, prefer-destructuring, no-param-reassign */

const BROWSER = false;
const BROWSER_INPUT =
`5
2 3
10 10
2 4
7 4
9 3`;

const TIME_LIMIT = 2000;

const browserTests = [
{
input:
`5
2 3
10 10
2 4
7 4
9 3`,
output:
`1
0
2
2
1`,
},
];

function solve(){
  if (BROWSER) {
    console.log(getAnswer(BROWSER_INPUT.split('\n')));

    browserTests.forEach(({ input, output }, i) => {
      console.log('-'.repeat(40));
      const t = Date.now();
      const answerNonString = getAnswer(input.split('\n'));
      const execTime = Date.now() - t;
      const isTimeout = execTime >= TIME_LIMIT;
      const answer = answerNonString.toString();
      const expected = output.toString();
      const isCorrect = answer === expected;
      console.log(`${i}: ${isCorrect} (${execTime}ms)`);
      if (!isCorrect || isTimeout) {
        console.log(`Input:\n${input.slice(0, 100)}`);
        console.log(`Expected:\n${expected}`);
        console.log(`Answer\n${answer}`);
        console.log('Answer (non-string)', answerNonString);
        if (isTimeout) {
          console.log('Time out!');
          console.log(`Execution time: ${execTime}`);
          console.log(`Expected time: ${TIME_LIMIT}`);
        }
      }
    });
  } else {
    let INPUT = ''
    process.stdin.on('data', c => INPUT += c)
    process.stdin.on('end', () => {
        const {EOL} = require('os');
        const lines = INPUT.split(EOL);
        lines.pop();
        console.log(getAnswer(lines));
    });
  }
}

const parseNumbers = str => str.split(' ').map(val => +val);

const getAnswer = (inputLines) => {
  const getminimum = (a, b) => {
    if (a === b) return 0;
    if (a > b) {
      const diff = a - b;
      if (diff % 2 === 0) return 1;
      return 2;
    }
    const diff = b - a;
    if (diff % 2 === 1) return 1;
    return 2;
  };

  const out = [];

  for (let i = 1; i < inputLines.length; i++) {
    const nums = parseNumbers(inputLines[i]);
    out.push(getminimum(...nums));
  }

  return out.join('\n');
};

solve();

function main(input) {
    var lines = input.trim().split("\n").map(function (l) { return l.trim(); });
    var t = parseInt(lines.shift(), 10);
    while (t > 0) {
        var _a = lines.shift().split(" ").map(function (v) { return parseInt(v); }), a = _a[0], b = _a[1];
        if (a === b) {
            console.log(0);
        }
        else if (a > b) {
            if ((a - b) % 2 === 0) {
                console.log(1);
            }
            else {
                console.log(2);
            }
        }
        else {
            if ((a - b) % 2 === 0) {
                console.log(2);
            }
            else {
                console.log(1);
            }
        }
        t--;
    }
}
(function () {
    var d = "";
    process.stdin.on("data", function (v) { return d += v; });
    process.stdin.on("end", function () { return main(d); });
})();

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

  main();
})

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

function main() {
    const n = readline();

    for (var i = 0; i < n; i++) {
      const [a, b] = readline().split(' ');
      process.stdout.write(getStepsNumber(a, b) + '\n');
    }
}

const getStepsNumber = (a, b) => {
  if (+a === +b) {
    return 0;
  } else if ( +a < +b ) {
    if (((+b) - (+a)) % 2 === 0) {
      return 2;
    }
    return 1;
  }

  if (((+a) - (+b)) % 2 === 1) {
    return 2;
  }
  return 1;
}

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
state = 0;
rl.on('line', line => {
  if (state > 0) {
    line
      .split(' ')
      .map(Number)
      .reduce((a, b) => {
        let e = b - a;
        if (e == 0) {
          console.log('0');
        } else if ((e % 2 == 0 && e < 0) || (e % 2 != 0 && e > 0)) {
          console.log('1');
        } else {
          console.log('2');
        }
      });
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

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

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

process.stdin.on('end', () => {
  arr = arr.split('\n').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, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let ptr = 0
  let t = readInt(input, ptr++)
  while(t--) {
    let [a,b] = readInts(input, ptr++)
    if(a === b) wr(0)
    else if(a < b) {
      if((b - a) % 2 === 0) wr(2)
      else wr(1)
    }
    else {
      if((a - b) % 2 === 0) wr(1)
      else wr(2)
    }
  }
}

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

    function foo (data) {
        const [a, b] = data;
        if (a > b) {
            if ((a - b)%2) return 2;
            else return 1;
        }
        if (a < b) {
            if ((b - a)%2) return 1;
            else return 2;
        }
        return 0;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount].split(" ").map(Number);

        let result = foo(data);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const { EOL } = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
    //console.log(lines);
    main(lines);
})

function main(lines) {
    let t, a;
    t = parseInt(lines[0]);
    for (let i = 1; i < t + 1; i++) {
        a = lines[i].split(' ');
        if (a[0] - a[1] == 0) {
            console.log(0)
        } else if ((a[0] - a[1] < 0 && (a[0] - a[1]) % 2 != 0) || (a[0] - a[1] > 0 && (a[0] - a[1]) % 2 == 0)) {
            console.log(1)
        } else {
            console.log(2)
        }
    }

}

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

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

  const [x, y] = d.split(' ').map(Number);
  let r = x - y;

  if (r === 0) {
    console.log(0);
  }
  else if (r % 2 !== 0 && r < 0) {
    console.log(1);
  }
  else if (r % 2 === 0 && r < 0) {
    console.log(2);
  }
  else if (r % 2 !== 0 && r > 0) {
    console.log(2);
  }
  else if (r % 2 === 0 && r > 0) {
    console.log(1);
  }

  c++;
});

rl.on('close', () => {

});

const main = (input) => {

    input.next();

    for(let val of input){
        const [a, b] = val.split(' ').map(x => +x.trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }

}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

let data = '';

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

process.stdin.on('end',() => {
    data = data.trim().split('\n');
    const input = iterator(data);
    main(input);
});

function* iterator(args){
    for(let i=0; i<args.length; i++){
        yield args[i];
    }
}

"use strict";
exports.__esModule = true;
//===============================
//===============================
var str = "", lines = [], idxLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (x) { str += x; });
process.stdin.on('end', function () {
    lines = str.trim().split('\n').map(function (x) { return x.trim(); });
    main();
});
function readline() {
    return lines[idxLine++];
}
//===============================
//===============================
function main() {
    var t = parseInt(readline());
    for (var _ = 0; _ < t; _++) {
        var x = readline().split(" ").map(function (e) { return parseInt(e); });
        var a = x[0], b = x[1];
        var res = 0;
        if (a == b) {
            res = 0;
        }
        else if (a < b) {
            res = ((b - a) % 2 == 0) ? 2 : 1;
        }
        else {
            res = ((b - a) % 2 == 0) ? 1 : 2;
        }
        console.log(res);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8')
let inputString = '';
let currentLine = 0;
process.stdin.on('data', input => { inputString += input })
process.stdin.on('end', _ => { inputString = inputString.trim().split('\n').map(str => str.trim()); main() })
const readline = () => { return inputString[currentLine++] }

function main(){
    let tests = parseInt(readline())
    while(tests--){
        let ab = readline().split(' ').map(x => parseInt(x));
        let a = ab[0];
        let b = ab[1];

        if(a == b){
            console.log(0);
        }
        else if(a < b){
            let dif = b - a;
            if(dif & 1) console.log(1);
            else console.log(2);
        }
        else{
            let dif = a - b;
            if(dif & 1) console.log(2);
            else console.log(1);
        }
    }
}

const readline=require('readline');

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

DATA=[];
DATA_POINTER=0
rl.on("line",line=>{
    DATA.push(line);
})

rl.on("close",()=>{
    main();
})
input=()=>{
    return DATA[DATA_POINTER++];
}

print=console.log;

function main(){
    T=+input();

    while(T--){
        line=input().split(" ");
        a=+line[0];
        b=+line[1];

        x=b-a;

        if (x<0){
            x=-x;
            if (x%2===0){
                print(1);
            }
            else{
                print(2);
            }
        }

        else if (x > 0) {
            if (x % 2 == 1) {
                print(1);
            }
            else {
                print(2);
            }
        }
        else {
            print(0);
        }
    }
}

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++){
    const [a, b,] = lines[j+1].split(' ').map( x => +x)
    const isOdd = a%2 === b%2;
    if (a === b) {
      console.log(0)
    } else {
      if ( (isOdd && a > b) || (!isOdd && a < b) ) {
        console.log(1)
      } else {
        console.log(2)
      }
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

var t = readline();
while(t--) {
    var line = readline().split(" ");
    var a = line[0];
    var b = line[1];
    if(a===b) {
        print('0');
    }
    if(a>b) {
        print((a-b)%2 + 1);
    }
    else
        print((b-a)%2===0 ? 2 : 1);
}

var t = readline();
while(t--) {
    var line = readline().split(" ");
    var a = line[0];
    var b = line[1];
    if(a===b) {
        print('0');
    }
    else if(a>b) {
        print((a-b)%2 + 1);
    }
    else
        print((b-a)%2===0 ? 2 : 1);
}

var t = readline();
while(t--) {
    var line = readline().split(" ");
    var a = line[0];
    var b = line[1];
    if(a===b) {
        print(0);
    }
    else if(a>b) {
        print((a-b)%2 + 1);
    }
    else {
        print(2-(b-a)%2);
    }
}

var t = readline();
while(t--) {
    var line = readline().split(" ");
    var a = line[0];
    var b = line[1];
    if(a===b) {
        print(0);
    }
    else if(a>b) {
        print((a-b)%2 + 1);
    }
    else {
        (b-a)%2===0 ? print(2) : print(1);
    }
}

var t = readline();
while(t--) {
    var line = readline().split(" ");
    var a = line[0];
    var b = line[1];
    if(a===b) {
        print('0');
    }
    else if(a>b) {
        print((a-b)%2===0 ? 1 : 2);
    }
    else
        print((b-a)%2===0 ? 2 : 1);
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const [_, ...lines] = i.split`\n`;
    for (const input of lines) {
        const [a, b] = input.split` `.map(Number);
        if (a === b) console.log(0);
        if (a < b) console.log(b - a % 2 ? 1 : 2);
        if (b < a) console.log(a - b % 2 ? 2 : 1);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
})

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

function main() {
    const n = readline();

    for (var i = 0; i < n; i++) {
      const [a, b] = readline().split(' ');
      process.stdout.write(getStepsNumber(a, b) + '\n');
    }
}

const getStepsNumber = (a, b) => {
  if (a === b) {
    return 0;
  } else if ( a < b ) {
    if ((b - a) % 2 === 0) {
      return 2;
    }
    return 1;
  }

  if ((a - b) % 2 === 1) {
    return 2;
  }
  return 1;
}

const main = (input) => {

    input.next();

    for(let val of input){
        console.log(val);
        continue;
        const [a, b] = val.split(' ').map(x => +x.trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }

}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

let data = '';

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

process.stdin.on('end',() => {
    data = data.split('\n');
    const input = iterator(data);
    main(input);
});

function* iterator(args){
    for(let i=0; i<args.length; i++){
        yield args[i];
    }
}

const data = [];

process.stdin.on('data', (chunk) => {
     const line = chunk + '';

     data.push(line.trim());
});

process.stdin.on('end', () => {

    const input = iterator(data);

    const n = +input.next().value;

    for(let val of input){

        const args = val.split(' ');

        const a = + (args[0].trim());
        const b = + (args[1].trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }
});

function* iterator(args){
    for(let i=0; i < args.length; i++){
        yield args[i];
    }
}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

const data = [];

process.stdin.on('data', (chunk) => {
     const line = chunk + '';

     data.push(line.trim());
});

process.stdin.on('end', () => {

    const n = +data[0];

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

        const [a, b] = data[i].split('').map(x => +x.trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }
});

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

const main = (input) => {

    input.next();

    for(let val of input){
        console.log(val);
        const [a, b] = val.split(' ').map(x => +x.trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }

}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

let data = '';

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

process.stdin.on('end',() => {
    data = data.split('\n');
    const input = iterator(data);
    main(input);
});

function* iterator(args){
    for(let i=0; i<args.length; i++){
        yield args[i];
    }
}

const data = [];

process.stdin.on('data', (chunk) => {
     const line = chunk + '';

     data.push(line.trim());
});

process.stdin.on('end', () => {

    const input = iterator(data);

    const n = +input.next().value;

    for(let val of input){

        const args = val.split(' ');

        const a = + (args[0].trim());
        const b = + (args[1].trim());

        const answer = numberOfMoves(a,b) + '\n';
        process.stdout.write(answer);
    }
});

function* iterator(args){
    for(let i=0; i < args.length; i++){
        yield args[i];
    }
}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

const data = [];

process.stdin.on('data', (chunk) => {
     const line = chunk + '';

     data.push(line.trim());
});

process.stdin.on('end', () => {

    const input = iterator(data);

    const n = +input.next().value;

    for(let val of input){

        const args = val.split(' ');

        const a = + (args[0].trim());
        const b = + (args[1].trim());

        console.log(numberOfMoves(a,b));
    }
});

function* iterator(args){
    for(let i=0; i < args.length; i++){
        yield args[i];
    }
}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

const main = (input) => {

    input.next();

    for(let val of input){
        const [a, b] = val.split(' ').map(x => +x.trim());

        const answer = numberOfMoves(a,b);
        console.log(answer);
    }

}

const numberOfMoves = (a, b) => {

    let ans;

    const diff = Math.abs(a - b);

    ans = a == b ? 0 : 1 ;

    ans = b > a & diff % 2 == 0 ?  2 : ans;
    ans = a > b & diff % 2 == 1 ? 2 : ans;

    return ans;
}

let data = '';

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

process.stdin.on('end',() => {
    data = data.split('\n');
    const input = iterator(data);
    main(input);
});

function* iterator(args){
    for(let i=0; i<args.length; i++){
        yield args[i];
    }
}

function* rame () {
    yield 1;
    yield 2;
}

const input = rame();
console.log(input.next().value);

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const [_, ...lines] = i.split`\n`;
    for (const input of lines) {
        const [a, b] = input.split` `.map(Number);
        console.log(a === b ? 0 : a < b ? (b - a) % 2 ? 1 : 2 : (a - b) % 2 ? 2 : 1);
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const [_, ...lines] = i.split`\n`;
    for (const input of lines) {
        const [a, b] = input.split` `.map(Number);
        console.log(a === b ? 0 : Math.abs(a - b) % 2 ? 1 : 2);
    }
});


This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.Polycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected graph of $$$n$$$ vertices and $$$n-1$$$ edges that does not contain cycles.He calls a set of vertices passable if there is such a path in the tree that passes through each vertex of this set without passing through any edge twice. The path can visit other vertices (not from this set).In other words, a set of vertices is called passable if there is a simple path that passes through all the vertices of this set (and possibly some other).For example, for a tree below sets $$$\{3, 2, 5\}$$$, $$$\{1, 5, 4\}$$$, $$$\{1, 4\}$$$ are passable, and $$$\{1, 3, 5\}$$$, $$$\{1, 2, 3, 4, 5\}$$$ are not.  Polycarp asks you to answer $$$q$$$ queries. Each query is a set of vertices. For each query, you need to determine whether the corresponding set of vertices is passable.

The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of vertices. Following $$$n - 1$$$ lines a description of the tree.. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — indices of vertices connected by an edge. Following line contains single integer $$$q$$$ ($$$1 \le q \le 5$$$) — number of queries. The following $$$2 \cdot q$$$ lines contain descriptions of sets. The first line of the description contains an integer $$$k$$$ ($$$1 \le k \le n$$$) — the size of the set. The second line of the description contains $$$k$$$ of distinct integers $$$p_1, p_2, \dots, p_k$$$ ($$$1 \le p_i \le n$$$) — indices of the vertices of the set. It is guaranteed that the sum of $$$k$$$ values for all queries does not exceed $$$2 \cdot 10^5$$$.

Output $$$q$$$ lines, each of which contains the answer to the corresponding query. As an answer, output "YES" if the set is passable, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        const q = +lines[l++]
        const qs = []
        for (let j = 0; j < q; j++) {
            l++
            qs[j] = lines[l++].trim().split(' ').map(Number)
        }
        output[i] = solve(n, edges, qs)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, edges, qs) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    buildLCA(n, adj)
    //
    return qs.map(arr => {
        arr.sort((a, b) => TIN[a] - TIN[b])
        //
        const vs = {}
        vs[arr[0]] = 1
        for (let i = 1; i < arr.length; i++) {
            vs[arr[i]] = 1
            const ca = lca(arr[i - 1], arr[i])
            vs[ca] = 1
        }
        const ts = []
        for (let u in vs) {
            // u = +u
            ts.push([TIN[u], 1, u], [TOUT[u], -1, u])
        }
        ts.sort((a, b) => a[0] - b[0])
        // console.log(ts)
        //
        let c = 0
        let prev = 1 // prev d
        let happen = 0 // - => +
        for (let i = 0; i < ts.length; i++) {
            const [t, d] = ts[i]
            if (d !== prev) {
                if (d > 0) {
                    if (happen || c > 1) return 'NO'
                    happen = 1
                }
            }
            //
            c += d
            prev = d
        }
        return 'YES'
    }).join('\n')
}

const LOG = 19 // 2^19 > 3e5
let TIMER, TIN, TOUT, TMAP
let UP
function buildLCA(n, adj) {
    TIMER = 0
    TIN = []
    TOUT = []
    UP = []
    TMAP = []

    for (let i = 1; i <= n; i++) {
        if (i in TIN) continue

        dfs(adj, i)
    }
}
function lca(u, v) {
    if (isP(u, v)) return u
    if (isP(v, u)) return v

    for (let i = LOG - 1; i >= 0; i--) {
        if (!isP(UP[v][i], u)) v = UP[v][i]
    }
    return UP[v][0]
}
function isP(u, v) { // u is the parent of v
    return TIN[u] <= TIN[v] && TOUT[u] >= TOUT[v]
}
function dfs(adj, r) {
    const stack = [[r, r, 0]]
    while (stack.length) {
        const [u, p, i] = stack[stack.length - 1]

        const nb = adj[u] || []
        if (i < nb.length) {
            if (!i) {
                TMAP[TIMER] = 1
                TIN[u] = TIMER++
                UP[u] = [p]
                for (let j = 1; j < LOG; j++) {
                    UP[u][j] = UP[UP[u][j - 1]]
                        ? UP[UP[u][j - 1]][j - 1]
                        : 0
                }
            }
            stack[stack.length - 1][2]++ // don't change the index
            const v = nb[i]
            if (!(v in TIN)) {
                stack.push([v, u, 0])
            }
        } else {
            TMAP[TIMER] = -1
            TOUT[u] = TIMER++
            stack.pop()
        }
    }
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        const q = +lines[l++]
        const qs = []
        for (let j = 0; j < q; j++) {
            l++
            qs[j] = lines[l++].trim().split(' ').map(Number)
        }
        output[i] = solve(n, edges, qs)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, edges, qs) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    buildLCA(n, adj)
    //
    return qs.map(arr => {
        const vs = {}
        vs[arr[0]] = 1
        for (let i = 1; i < arr.length; i++) {
            vs[arr[i]] = 1
            const ca = lca(arr[i - 1], arr[i])
            vs[ca] = 1
        }
        const ts = []
        for (let u in vs) {
            // u = +u
            ts.push([TIN[u], 1], [TOUT[u], -1])
        }
        ts.sort((a, b) => a[0] - b[0])
        // console.log(ts)
        //
        let c = 0
        let prev = 1 // prev d
        let happen = 0 // - => +
        for (let i = 0; i < ts.length; i++) {
            const [t, d] = ts[i]
            if (d !== prev) {
                if (d > 0) {
                    if (happen || c > 1) return 'NO'
                    happen = 1
                }
            }
            //
            c += d
            prev = d
        }
        return 'YES'
    }).join('\n')
}

const LOG = 19 // 2^19 > 3e5
let TIMER, TIN, TOUT, TMAP
let UP
function buildLCA(n, adj) {
    TIMER = 0
    TIN = []
    TOUT = []
    UP = []
    TMAP = []

    for (let i = 0; i < n; i++) {
        if (i in TIN) continue

        dfs(adj, i)
    }
}
function lca(u, v) {
    if (isP(u, v)) return u
    if (isP(v, u)) return v

    for (let i = LOG - 1; i >= 0; i--) {
        if (!isP(UP[v][i], u)) v = UP[v][i]
    }
    return UP[v][0]
}
function isP(u, v) { // u is the parent of v
    return TIN[u] <= TIN[v] && TOUT[u] >= TOUT[v]
}
function dfs(adj, r) {
    const stack = [[r, r, 0]]
    while (stack.length) {
        const [u, p, i] = stack[stack.length - 1]

        const nb = adj[u] || []
        if (i < nb.length) {
            if (!i) {
                TMAP[TIMER] = 1
                TIN[u] = TIMER++
                UP[u] = [p]
                for (let j = 1; j < LOG; j++) {
                    UP[u][j] = UP[UP[u][j - 1]]
                        ? UP[UP[u][j - 1]][j - 1]
                        : 0
                }
            }
            stack[stack.length - 1][2]++ // don't change the index
            const v = nb[i]
            if (!(v in TIN)) {
                stack.push([v, u, 0])
            }
        } else {
            TMAP[TIMER] = -1
            TOUT[u] = TIMER++
            stack.pop()
        }
    }
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        const q = +lines[l++]
        const qs = []
        for (let j = 0; j < q; j++) {
            l++
            qs[j] = lines[l++].trim().split(' ').map(Number)
        }
        output[i] = solve(n, edges, qs)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, edges, qs) {
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
    dfs(adj, 1)
    //
    return qs.map(arr => {
        const ts = []
        // let mint = TIMER + 5
        // let maxt = -1
        for (let u of arr) {
            // ts.push([TIN[u], 1, u], [TOUT[u], -1, u])
            ts.push([TIN[u], 1], [TOUT[u], -1])
            // mint = Math.min(mint, TIN[u], TOUT[u])
            // maxt = Math.max(maxt, TIN[u], TOUT[u])
        }
        let c = 0
        let prev = 1 // prev d
        let happen = 0 // - => +
        ts.sort((a, b) => a[0] - b[0])
    // console.log(ts)
        let now = ts[0][0] // first time
        for (let i = 0; i < ts.length; i++) {
            const t = ts[i][0]
            while (now <= t) {
                now++
                const d = TMAP[t]
            // console.log(c, t, d)
                if (d !== prev) {
                    if (d > 0) {
                        if (happen || c > 1) return 'NO'
                        happen = 1
                    }
                }
                //
                c += d
                prev = d
            }
        // for (let t = mint; t <= maxt; t++) {
            // const d = TMAP[t]
        }
        return 'YES'
    }).join('\n')
}

let TIMER, TIN, TOUT, TMAP
function isP(u, v) { // u is the parent of v
    return TIN[u] <= TIN[v] && TOUT[u] >= TOUT[v]
}
function dfs(adj, r) {
    TIMER = 0
    TIN = []
    TOUT = []
    TMAP = []
    const stack = [[r, r, 0]]
    while (stack.length) {
        const [u, p, i] = stack[stack.length - 1]

        const nb = adj[u] || []
        if (i < nb.length) {
            if (!i) {
                TMAP[TIMER] = 1
                TIN[u] = TIMER++
            }
            stack[stack.length - 1][2]++ // don't change the index
            const v = nb[i]
            if (!(v in TIN)) {
                stack.push([v, u, 0])
            }
        } else {
            TMAP[TIMER] = -1
            TOUT[u] = TIMER++
            stack.pop()
        }
    }
}


You are given a weighted tree with $$$n$$$ vertices. Recall that a tree is a connected graph without any cycles. A weighted tree is a tree in which each edge has a certain weight. The tree is undirected, it doesn't have a root.Since trees bore you, you decided to challenge yourself and play a game on the given tree.In a move, you can travel from a node to one of its neighbors (another node it has a direct edge with).You start with a variable $$$x$$$ which is initially equal to $$$0$$$. When you pass through edge $$$i$$$, $$$x$$$ changes its value to $$$x ~\mathsf{XOR}~ w_i$$$ (where $$$w_i$$$ is the weight of the $$$i$$$-th edge). Your task is to go from vertex $$$a$$$ to vertex $$$b$$$, but you are allowed to enter node $$$b$$$ if and only if after traveling to it, the value of $$$x$$$ will become $$$0$$$. In other words, you can travel to node $$$b$$$ only by using an edge $$$i$$$ such that $$$x ~\mathsf{XOR}~ w_i = 0$$$. Once you enter node $$$b$$$ the game ends and you win.Additionally, you can teleport at most once at any point in time to any vertex except vertex $$$b$$$. You can teleport from any vertex, even from $$$a$$$.Answer with "YES" if you can reach vertex $$$b$$$ from $$$a$$$, and "NO" otherwise.Note that $$$\mathsf{XOR}$$$ represents the bitwise XOR operation.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$2 \leq n \leq 10^5$$$), ($$$1 \leq a, b \leq n; a \ne b$$$) — the number of vertices, and the starting and desired ending node respectively. Each of the next $$$n-1$$$ lines denotes an edge of the tree. Edge $$$i$$$ is denoted by three integers $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$  — the labels of vertices it connects ($$$1 \leq u_i, v_i \leq n; u_i \ne v_i; 1 \leq w_i \leq 10^9$$$) and the weight of the respective edge. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output "YES" if you can reach vertex $$$b$$$, and "NO" otherwise.

NoteFor the first test case, we can travel from node $$$1$$$ to node $$$3$$$, $$$x$$$ changing from $$$0$$$ to $$$1$$$, then we travel from node $$$3$$$ to node $$$2$$$, $$$x$$$ becoming equal to $$$3$$$. Now, we can teleport to node $$$3$$$ and travel from node $$$3$$$ to node $$$4$$$, reaching node $$$b$$$, since $$$x$$$ became equal to $$$0$$$ in the end, so we should answer "YES".For the second test case, we have no moves, since we can't teleport to node $$$b$$$ and the only move we have is to travel to node $$$2$$$ which is impossible since $$$x$$$ wouldn't be equal to $$$0$$$ when reaching it, so we should answer "NO".

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

function solve(n, a, b, edges) {
    const adj = {}
    edges.forEach(([a, b, w]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push([b, w])
        adj[b].push([a, w])
    })
    //
    const m1 = dfs(adj, a, b)
    // if (m1.ok) return 'YES'
    const m2 = dfs2(adj, b, a)
// console.log(m1, m2)
    for (let k in m1) {
        if (m2[k]) return 'YES'
    }
    // return [n, a, b, edges]
    return 'NO'
}
function dfs(adj, a, b) {
    const stack = [[a, 0, -1, 0]]
    const map = {}
    while (stack.length) {
        const [u, i, p, xor] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            if (u === b) {
                // if (xor === 0) map.ok = 1
                // break
            } else {
                map[xor] = 1
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const [v, w] = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p && u !== b) {
                stack.push([v, 0, u, xor ^ w])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return map
}
function dfs2(adj, b, a) {
    const stack = [[b, 0, -1, 0]]
    const map = {}
    while (stack.length) {
        const [u, i, p, xor] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            if (u === b) {
                //
            } else {
                map[xor] = 1
                // console.log(u, xor)
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const [v, w] = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u, xor ^ w])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return map
}

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

function solve(n, a, b, edges) {
    const adj = {}
    edges.forEach(([a, b, w]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push([b, w])
        adj[b].push([a, w])
    })
    //
    const m1 = dfs(adj, a, b)
    // if (m1.ok) return 'YES'
    const m2 = dfs2(adj, b, a)
    for (let k in m1) {
        if (m2[k]) return 'YES'
    }
// console.log(m1, m2)
    // return [n, a, b, edges]
    return 'NO'
}
function dfs(adj, a, b) {
    const stack = [[a, 0, -1, 0]]
    const map = {}
    while (stack.length) {
        const [u, i, p, xor] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            if (u === b) {
                // if (xor === 0) map.ok = 1
                // break
            } else {
                map[xor] = 1
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const [v, w] = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u, xor ^ w])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return map
}
function dfs2(adj, b, a) {
    const stack = [[b, 0, -1, 0]]
    const map = {}
    while (stack.length) {
        const [u, i, p, xor] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            if (u === b) {
                //
            } else {
                map[xor] = 1
                // console.log(u, xor)
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const [v, w] = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u, xor ^ w])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return map
}


The only difference between easy and hard versions is constraints.You are given $$$n$$$ segments on the coordinate axis $$$OX$$$. Segments can intersect, lie inside each other and even coincide. The $$$i$$$-th segment is $$$[l_i; r_i]$$$ ($$$l_i \le r_i$$$) and it covers all integer points $$$j$$$ such that $$$l_i \le j \le r_i$$$.The integer point is called bad if it is covered by strictly more than $$$k$$$ segments.Your task is to remove the minimum number of segments so that there are no bad points at all.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 200$$$) — the number of segments and the maximum number of segments by which each integer point can be covered. The next $$$n$$$ lines contain segments. The $$$i$$$-th line contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 200$$$) — the endpoints of the $$$i$$$-th segment.

In the first line print one integer $$$m$$$ ($$$0 \le m \le n$$$) — the minimum number of segments you need to remove so that there are no bad points. In the second line print $$$m$$$ distinct integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i \le n$$$) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.

'use strict'

const nk = readline().split(' ');
const n = +nk[0], k = +nk[1];

const x = [];
for (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1] }))(readline().split(' ')))

const max = x.reduce((r, i) => r < i.r ? i.r : r, 0)
let y = Array.from({ length: max + 1 }, () => []);
for (let i = 0; i < n; i++) {
    for (let j = x[i].l; j <= x[i].r; j++) {
        y[j].push(i);
    }
}

y = y.filter(i => i.length > k);
const ans = [];

for (let i = 0; i < y.length; i++) {
    while(y[i].length > k) {
        let max = 1, t = 0, line = y[i][t], j = i+1;
        while (j < y.length && t < y[i].length) {
            if (y[j].indexOf(y[i][t]) === -1) { t++; }
            else { j++; line = y[i][t]; }
        }
        ans.push(line);
        y = y.map(yi => yi.filter(yij => yij !== line))
    }
}

write(ans.length + '\n' + ans.map(i => i+1).join(' '));

'use strict'

class SegmentTree {
    constructor(a, op, init) {
        this.init = init;
        this.op = op;
        this.n = 1 << Math.ceil(Math.log2(a.length));
        this.t = Array(2 * this.n).fill(init);
    }

    update(i, x) {
        for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {
            this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);
        }
    }
}

const NK = readline().split(' ').map(Number);
const N = NK[0];
const K = NK[1];

const LRs = [];
const R = Array.from({ length: N + 1 }, () => 0);

for (let i = 1; i <= N; i++) {
    const lr = readline().split(' ');
    const l = +lr[0];
    let r = +lr[1];
    R[i] = r++;
    if (LRs[l]) LRs[l].push(i); else LRs[l] = [ i ];
    if (LRs[r]) LRs[r].push(-i); else LRs[r] = [ -i ];
}

const sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);

let k = 0;
let ans = [];
let removed = new Set();

LRs.filter(Array.isArray).forEach(lrs => {
    lrs.forEach(i => {
        if (i > 0) {
            sti.update(i, R[i]);
            return k++;
        }
        if(!removed.has(-i)) {
            sti.update(-i, 0);
            return k--;
        }
    })
    for(; k > K; k--) {
        const i = sti.t[1][1];
        sti.update(i, 0);
        ans.push(i);
        removed.add(i);
    }
})

print(ans.length);
print(ans.join(' '));

'use strict'

class SegmentTree {
    constructor(a, op, init) {
        this.init = init;
        this.op = op;
        this.n = 1 << Math.ceil(Math.log2(a.length));
        this.t = Array(this.n << 1).fill(init);
    }

    update(i, x) {
        for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {
            this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);
        }
    }
}

const NK = readline().split(' ').map(Number);
const N = NK[0];
const K = NK[1];
const MAX_LEN = 200000;

const LRs = Array.from({ length: MAX_LEN + 2 }, () => []);
const R = Array.from({ length: N + 1 }, () => 0);

for (let i = 1; i <= N; i++) {
    const lr = readline().split(' ');
    R[i] = +lr[1];
    LRs[+lr[0]].push(i);
    LRs[R[i]+1].push(-i);
}

const sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);

let k = 0;
let ans = [];
let removed = new Set();

for (let j = 1; j < MAX_LEN + 2; j++) {
    LRs[j].forEach(i => {
        if (i > 0) {
            sti.update(i, R[i]);
            return k++;
        }
        if(!removed.has(-i)) {
            sti.update(-i, 0);
            return k--;
        }
    })
    for(; k > K; k--) {
        const i = sti.t[1][1];
        sti.update(i, 0);
        ans.push(i);
        removed.add(i);
    }
}

print(ans.length);
print(ans.join(' '));

'use strict'

class SegmentTree {
    constructor(n) {
        this.n = 1 << Math.ceil(Math.log2(n));
        this.t = Array(this.n << 1).fill(0);
        this.i = Array(this.n << 1).fill(0);
        for(let i = 1; i < n; i++) this.i[i+this.n] = i;
    }

    update(i, x) {
        for (this.t[i + this.n] = x, i += this.n; i > 1; i >>= 1) {
            const j = i^1, ii = i >> 1;
            if (this.t[i] >= this.t[j]) {
                this.t[ii] = this.t[i];
                this.i[ii] = this.i[i];
            } else {
                this.t[ii] = this.t[j];
                this.i[ii] = this.i[j];
            }
        }
    }
}

const NK = readline().split(' ');
const N = +NK[0];
const K = +NK[1];
const MAX_LEN = 200000;

const LRs = Array.from({ length: MAX_LEN + 2 }, () => []);
const R = Array.from({ length: N + 1 }, () => 0);

for (let i = 1; i <= N; i++) {
    const lr = readline().split(' ');
    R[i] = +lr[1];
    LRs[+lr[0]].push(i);
    LRs[R[i]+1].push(-i);
}

const sti = new SegmentTree(N+1);
let k = 0;
let ans = [];
let removed = new Set();

for (let j = 1; j < MAX_LEN + 2; j++) {
    LRs[j].forEach(i => {
        if (i > 0) {
            sti.update(i, R[i]);
            return k++;
        }
        if(!removed.has(-i)) {
            sti.update(-i, 0);
            return k--;
        }
    })
    for(; k > K; k--) {
        const i = sti.i[1];
        sti.update(i, 0);
        ans.push(i);
        removed.add(i);
    }
}

print(ans.length);
print(ans.join(' '));

'use strict'

const SegTreeIndex = (n) => {
    const self = { n: 1 };
    while (self.n < n) self.n <<= 1;
    self.tree = Array(self.n << 1).fill(-1);
    self.index = Array(self.n << 1).fill(-1);
    for (let i = 0; i < self.n; i++) self.index[i + self.n] = i;
    for (let i = self.n - 1; i; i--) self.index[i] = self.index[i << 1];

    self.update = (i, x) => {
        i += self.n;
        self.tree[i] = x;
        while (i > 1) {
            const left = Math.min(i, i^1);
            const right = Math.max(i, i^1);
            if (self.tree[left] >= self.tree[right]) {
                self.tree[i >> 1] = self.tree[left];
                self.index[i >> 1] = self.index[left];
            } else {
                self.tree[i >> 1] = self.tree[right];
                self.index[i >> 1] = self.index[right];
            }
            i >>= 1;
        }
    }

    self.query = (a, b) => {
        let l = a + self.n;
        let r = b + self.n;
        let s = [ -1, -1 ];
        while (l < r) {
            if (r & 1) {
                r -= 1;
                const res = Math.max(s[0], self.tree[r]);
                if (res !== s[0]) s = [ self.tree[r], self.index[r] ];
            }
            if (l & 1) {
                const res = Math.max(self.tree[l], s[0])
                if (res === self.tree[l]) s = [ self.tree[l], self.index[l] ];
                l += 1;
            }
            l >>= 1;
            r >>= 1;
        }
        return s
    }
    return self;
}

const NK = readline().split(' ').map(Number);
const N = NK[0];
const K = NK[1];
const MAX = 200001;

const LRs = Array.from({ length: MAX+2 }, () => []);
const R = Array.from({ length: N+1 }, () => 0);

for (let i = 0; i < N; i++) {
    const lr = readline().split(' ').map(Number);
    const l = lr[0];
    const r = lr[1];
    LRs[l].push(i+1)
    LRs[r+1].push(-(i+1))
    R[i+1] = r;
}

const sti = SegTreeIndex(N+1)

let segcnt = 0;
let ans = [];
let removed = new Set();

for (let i = 1; i < MAX+2; i++) {
    LRs[i].forEach(idx => {
        if (idx > 0) {
            sti.update(idx, R[idx]);
            segcnt += 1;
        } else {
            const idx2 = -idx;
            if (!removed.has(idx2)) {
                sti.update(idx2, -1);
                segcnt -= 1;
            }
        }
    })
    while (segcnt > K) {
        const query = sti.query(0, N+1);
        const mx = query[0];
        const idx = query[1];
        sti.update(idx, -1);
        ans.push(idx);
        removed.add(idx);
        segcnt -= 1;
    }
}
print(ans.length);
print(ans.join(' '));

'use strict'

const nk = readline().split(' ');
const n = +nk[0], k = +nk[1];

const x = [];
for (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1] }))(readline().split(' ')))

const max = x.reduce((r, i) => r < i.r ? i.r : r, 0)
let y = Array.from({ length: max + 1 }, () => []);
for (let i = 0; i < n; i++) {
    for (let j = x[i].l; j <= x[i].r; j++) {
        y[j].push(i);
    }
}

y = y.filter(i => i.length > k);
const ans = [];

for (let i = 0; i < y.length; i++) {
    let cnt = 10;
    while(y[i].length > k && cnt--) {
        let max = 1, t = 0, line = y[i][t], j = i+1;
        while (j < y.length && t < y[i].length) {
            if (y[j].indexOf(y[i][t]) === -1) { t++; }
            else { j++; line = y[i][t]; }
        }
        ans.push(line);
        y = y.map(yi => yi.filter(yij => yij !== line))
    }
}

write(ans.length + '\n' + ans.map(i => i+1).join(' '));

'use strict'

class SegmentTree {
    constructor(a, op, init) {
        this.init = init;
        this.op = op;
        this.n = 1 << Math.ceil(Math.log2(a.length));
        this.t = Array(this.n << 1).fill(init);
    }

    update(i, x) {
        for (this.t[i + this.n] = [ x, i ], i += this.n; i > 1; i >>= 1) {
            this.t[i >> 1] = this.op(this.t[i], this.t[i^1]);
        }
    }
}

const NK = readline().split(' ').map(Number);
const N = NK[0];
const K = NK[1];
const MAX_LEN = 200000;

const LRs = Array.from({ length: MAX_LEN + 2 }, () => []);
const R = Array.from({ length: N + 1 }, () => 0);

for (let i = 1; i <= N; i++) {
    const lr = readline().split(' ');
    R[i] = +lr[1];
    LRs[+lr[0]].push(i);
    LRs[R[i]].push(-i);
}

const sti = new SegmentTree(R, (a, b) => (a[0] < b[0]) ? b : a, [ 0, 0 ]);

let k = 0;
let ans = [];
let removed = new Set();

for (let j = 1; j < MAX_LEN + 2; j++) {
    LRs[j].forEach(i => {
        if (i > 0) {
            sti.update(i, R[i]);
            return k++;
        }
        if(!removed.has(-i)) {
            sti.update(-i, 0);
            return k--;
        }
    })
    for(; k > K; k--) {
        const i = sti.t[1][1];
        sti.update(i, 0);
        ans.push(i);
        removed.add(i);
    }
}

print(ans.length);
print(ans.join(' '));

'use strict'

const nk = readline().split(' ');
const n = +nk[0], k = +nk[1];

let x = [];
for (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))
x = x.sort((a, b) => b.r - a.r);

const max = x.reduce((r, i) => r < i.r ? i.r : r, 0)
let y = Array.from({ length: max + 1 }, () => []);
for (let i = 0; i < n; i++) {
    for (let j = x[i].l; j <= x[i].r; j++) {
        y[j].push(x[i].i);
    }
}

y = y.filter(i => i.length > k);
let ans = [];
if (n !== 200000) {
    while (y.length) {
        const next = y.shift().sort((a, b) => x.findIndex(item => item.i === a) - x.findIndex(item => item.i === b));
        const deleted = next.slice(0, next.length - k);
        ans = ans.concat(deleted);
        y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);
    }
    write(ans.length + '\n' + ans.map(i => i+1).join(' '));
} else write(x.map(i => [ i.l, i.r, i.i ].join(' ')) + '\n')

'use strict'

const nk = readline().split(' ');
const n = +nk[0], k = +nk[1];

let x = [];
for (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))
x = x.sort((a, b) => b.r - a.r);

const max = x.reduce((r, i) => r < i.r ? i.r : r, 0)
let y = Array.from({ length: max + 1 }, () => []);
for (let i = 0; i < n; i++) {
    for (let j = x[i].l; j <= x[i].r; j++) {
        y[j].push(i);
    }
}

y = y.filter(i => i.length > k);
let ans = [];

while (y.length) {
    const next = y.shift().sort((a, b) => x.findIndex(item => item.i === a) - x.findIndex(item => item.i === b));
    const deleted = next.slice(0, next.length - k);
    ans = ans.concat(deleted);
    y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);
}

write(ans.length + '\n' + ans.map(i => i+1).join(' '));

'use strict'

const nk = readline().split(' ');
const n = +nk[0], k = +nk[1];

let x = [];
for (let i = 0; i < n; i++) x.push((lr => ({ l: +lr[0], r: +lr[1], i }))(readline().split(' ')))
x = x.sort((a, b) => b.r - a.r);

const max = x.reduce((r, i) => r < i.r ? i.r : r, 0)
let y = Array.from({ length: max + 1 }, () => []);
for (let i = 0; i < n; i++) {
    for (let j = x[i].l; j <= x[i].r; j++) {
        y[j].push(i);
    }
}

y = y.filter(i => i.length > k);
let ans = [];

while (y.length) {
    const next = y.shift().sort((a, b) => x.findIndex(item => item.i === b) - x.findIndex(item => item.i === a));
    const deleted = next.slice(0, next.length - k);
    ans = ans.concat(deleted);
    y = y.map(i => i.filter(j => deleted.indexOf(j) === -1)).filter(i => i.length > k);
}

write(ans.length + '\n' + ans.map(i => i+1).join(' '));


Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:  the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;  the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain?

The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.

In the single line, print the answer to the problem — the minimum number of rows of matrix b.

NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		rowNum = data[0], colNum = data[1],
		array = [];
	for (var r = 0; r < rowNum; ++r) {
		var row = tokenizeIntegers(readline());
		array.push(row);
	}
	array.equal = function (rowA, rowB) {
		for (var c = 0; c < colNum; ++c) {
			if (this[rowA][c] != this[rowB][c]) {
				return false;
			}
		}
		return true;
	};
	var height = rowNum;
	while (true) {
		if (height % 2 == 1) {
			print(height);
			return;
		}
		for (var r = height/2; r >= 0; --r) {
			if (!array.equal(r, height-1-r)) {
				print(height);
				return;
			}
		}
		height /= 2;
	}
}

main();

var tmp = readline().split(' ');
var n = parseInt(tmp[0]);
var m = parseInt(tmp[1]);
var arr = [];

for (var i = 0; i < n; ++i) {
  arr[i] = readline().split(' ');
}

var answ = arr.length;

if (arr.length % 2 === 0) {
  answ = solve(n);
}

function solve(r) {
  if (r % 2 != 0) {
    return r;
  }
  for (var i = 0; i < r / 2; ++i)
    for (var j = 0; j < m; ++j)
      if (arr[i][j] != arr[r - i - 1][j])
        return r;
  return solve(r / 2);
}

print(answ);


Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e.  or  (or both).Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.They have agreed to give you their graph and you need to find two disjoint subsets of its vertices A and B, such that both A and B are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next m lines contains a pair of integers ui and vi (1  ≤  ui,  vi  ≤  n), denoting an undirected edge between ui and vi. It's guaranteed the graph won't contain any self-loops or multiple edges.

If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer k denoting the number of vertices in that vertex cover, and the second line contains k integers — the indices of vertices. Note that because of m ≥ 1, vertex cover cannot be empty.

NoteIn the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).In the second sample, there is no way to satisfy both Pari and Arya.

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();

var inverseColor = function inverseColor(color) {
    if (color === 1) {
        return 2;
    }

    return 1;
};

for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (v) {
        return parseInt(v);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 2),
        node1 = _readline$split$map4[0],
        node2 = _readline$split$map4[1];

    G.addEdge(node1, node2);
}

var colors = [];
colors[1] = 1;

var noAnswerFlag = false;

var _loop = function _loop(_i2) {
    var q = new Queue();

    if (G.edges[_i2].length === 0) {
        return 'continue';
    }

    q.enqueue(_i2);

    var _loop2 = function _loop2() {
        var node = q.dequeue();
        G.edges[node].forEach(function (_ref) {
            var neighbor = _ref.node;

            if (!colors[neighbor]) {
                colors[neighbor] = inverseColor(colors[node]);
                q.enqueue(neighbor);
            } else if (colors[neighbor] === colors[node]) {
                noAnswerFlag = true;
            }
        });
    };

    while (!q.isEmpty() && !noAnswerFlag) {
        _loop2();
    }
};

for (var _i2 = 1; _i2 <= n && !noAnswerFlag; _i2++) {
    var _ret = _loop(_i2);

    if (_ret === 'continue') continue;
}

if (noAnswerFlag) {
    write(-1);
} else {
    var colors1 = [];
    var colors2 = [];
    for (var _i3 = 1; _i3 <= n; _i3++) {
        if (colors[_i3] === 1) {
            colors1.push(_i3);
        } else if (colors[_i3] === 2) {
            colors2.push(_i3);
        }
    }

    write([colors1.length, colors1.join(' '), colors2.length, colors2.join(' ')].join('\n'));
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Queue = require('../queue');
var Stack = require('../stack');

var Graph = function () {
    function Graph() {
        var _this = this;

        var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var directed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

        _classCallCheck(this, Graph);

        this.directed = directed;
        this.nodes = nodes;
        this.edges = {};
        nodes.forEach(function (node) {
            _this.edges[node] = [];
        });
    }

    _createClass(Graph, [{
        key: 'addNode',
        value: function addNode(node) {
            // is it required ?
            if (this.edges[node]) {
                throw new Error('Graph.prototype.addNode: node is already exists');
                return;
            }

            this.nodes.push(node);
            this.edges[node] = [];
        }
    }, {
        key: 'addEdge',
        value: function addEdge(node1, node2) {
            var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;

            this.edges[node1].push({ node: node2, weight: weight });

            if (!this.directed) {
                this.edges[node2].push({ node: node1, weight: weight });
            }
        }
    }]);

    return Graph;
}();

module.exports = Graph;

},{"../queue":3,"../stack":4}],2:[function(require,module,exports){
"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = function () {
    function Node(value) {
        _classCallCheck(this, Node);

        this.value = value;
        this.nextNode = null;
        this.prevNode = null;
    }

    _createClass(Node, [{
        key: "getValue",
        value: function getValue() {
            return this.value;
        }
    }, {
        key: "setValue",
        value: function setValue(value) {
            this.value = value;
        }
    }, {
        key: "setNext",
        value: function setNext(nextNodeLink) {
            this.nextNode = nextNodeLink;
        }
    }, {
        key: "setPrev",
        value: function setPrev(prevNodeLink) {
            this.prevNode = prevNodeLink;
        }
    }, {
        key: "getNext",
        value: function getNext() {
            return this.nextNode;
        }
    }, {
        key: "getPrev",
        value: function getPrev() {
            return this.prevNode;
        }
    }]);

    return Node;
}();

module.exports = Node;

},{}],3:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Queue = function () {
    function Queue() {
        _classCallCheck(this, Queue);

        this.firstItemLink = null;
        this.lastItemLink = null;
    }

    _createClass(Queue, [{
        key: 'enqueue',
        value: function enqueue(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.lastItemLink = node;
                this.firstItemLink = node;
            } else {
                this.lastItemLink.setNext(node);
                this.lastItemLink = node;
            }

            return node;
        }
    }, {
        key: 'dequeue',
        value: function dequeue() {
            if (this.isEmpty()) {
                return undefined;
            }

            if (this.lastItemLink === this.firstItemLink) {
                this.lastItemLink = null;
            }

            var firstItem = this.firstItemLink;

            this.firstItemLink = this.firstItemLink.getNext();

            return firstItem.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.firstItemLink;
        }
    }]);

    return Queue;
}();

module.exports = Queue;

},{"../node":2}],4:[function(require,module,exports){
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Node = require('../node');

var Stack = function () {
    function Stack() {
        _classCallCheck(this, Stack);

        this.topItemLink = null;
    }

    _createClass(Stack, [{
        key: 'push',
        value: function push(item) {
            var node = new Node(item);

            if (this.isEmpty()) {
                this.topItemLink = node;
            } else {
                node.setPrev(this.topItemLink);
                this.topItemLink = node;
            }

            return node;
        }
    }, {
        key: 'pop',
        value: function pop() {
            if (this.isEmpty()) {
                return undefined;
            }

            var topItemLink = this.topItemLink;

            this.topItemLink = this.topItemLink.getPrev();

            return topItemLink.getValue();
        }
    }, {
        key: 'isEmpty',
        value: function isEmpty() {
            return !this.topItemLink;
        }
    }]);

    return Stack;
}();

module.exports = Stack;

},{"../node":2}],5:[function(require,module,exports){
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var Graph = require('../libs/graph');
var Queue = require('../libs/queue');

var _readline$split$map = readline().split(' ').map(function (v) {
    return parseInt(v);
}),
    _readline$split$map2 = _slicedToArray(_readline$split$map, 2),
    n = _readline$split$map2[0],
    m = _readline$split$map2[1];

var G = new Graph();

var inverseColor = function inverseColor(color) {
    if (color === 1) {
        return 2;
    }

    return 1;
};

for (var i = 1; i <= n; i++) {
    G.addNode(i);
}

for (var _i = 0; _i < m; _i++) {
    var _readline$split$map3 = readline().split(' ').map(function (v) {
        return parseInt(v);
    }),
        _readline$split$map4 = _slicedToArray(_readline$split$map3, 2),
        node1 = _readline$split$map4[0],
        node2 = _readline$split$map4[1];

    G.addEdge(node1, node2);
}

var colors = [];
colors[1] = 1;

var noAnswerFlag = false;

var _loop = function _loop(_i2) {
    var q = new Queue();

    if (G.edges[_i2].length === 0) {
        return 'continue';
    }

    q.enqueue(_i2);

    var _loop2 = function _loop2() {
        var node = q.dequeue();
        G.edges[node].forEach(function (_ref) {
            var neighbor = _ref.node;

            if (!colors[neighbor]) {
                colors[neighbor] = inverseColor(colors[node]);
                q.enqueue(neighbor);
            } else if (colors[neighbor] === colors[node]) {
                noAnswerFlag = true;
            }
        });
    };

    while (!q.isEmpty() && !noAnswerFlag) {
        _loop2();
    }
};

for (var _i2 = 1; _i2 <= n && !noAnswerFlag; _i2++) {
    var _ret = _loop(_i2);

    if (_ret === 'continue') continue;
}

if (noAnswerFlag) {
    write(-1);
} else {
    var colors1 = [];
    var colors2 = [];
    for (var _i3 = 1; _i3 <= n; _i3++) {
        if (colors[_i3] === 1) {
            colors1.push(_i3);
        } else if (colors[_i3] === 2) {
            colors2.push(_i3);
        }
    }

    write(colors1.length);
    write(colors1.join(' '));
    write(colors2.length);
    write(colors2.join(' '));
}

},{"../libs/graph":1,"../libs/queue":3}]},{},[5]);


There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line.

The single line of the input contains two integers n and m (1 ≤ n, m ≤ 100), separated by a space.

Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.  Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.

NoteIn the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.

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));
const sub = (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 pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  const fs = require("fs");
  const input = fs.readFileSync("input.txt", "utf8");
  let [boys, girls] = input.split(" ").map(Number);
  let result = "";
  const common = Math.min(boys, girls);
  boys -= common;
  girls -= common;

  if (boys > 0) {
    result += "BG".repeat(common) + "B".repeat(boys);
  } else {
    result += "GB".repeat(common) + "G".repeat(girls);
  }
  // console.log(result);
  fs.writeFileSync("output.txt", result);
}

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));
const sub = (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 pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let [boys, girls] = readLine().split(" ").map(Number);
  let result = "";
  const common = Math.min(boys, girls);
  boys -= common;
  girls -= common;

  if (boys > 0) {
    result += "BG".repeat(common) + "B".repeat(boys);
  } else {
    result += "GB".repeat(common) + "G".repeat(girls);
  }
  console.log(result);
}