Moamen has an array of $$$n$$$ distinct integers. He wants to sort that array in non-decreasing order by doing the following operations in order exactly once:  Split the array into exactly $$$k$$$ non-empty subarrays such that each element belongs to exactly one subarray.  Reorder these subarrays arbitrary.  Merge the subarrays in their new order. A sequence $$$a$$$ is a subarray of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Can you tell Moamen if there is a way to sort the array in non-decreasing order using the operations written above?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le |a_i| \le 10^9$$$). It is guaranteed that all numbers are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^5$$$.

For each test case, you should output a single string. If Moamen can sort the array in non-decreasing order, output "YES" (without quotes). Otherwise, output "NO" (without quotes). You can print each letter of "YES" and "NO" in any case (upper or lower).

NoteIn the first test case, $$$a = [6, 3, 4, 2, 1]$$$, and $$$k = 4$$$, so we can do the operations as follows:   Split $$$a$$$ into $$$\{ [6], [3, 4], [2], [1] \}$$$.  Reorder them: $$$\{ [1], [2], [3,4], [6] \}$$$.  Merge them: $$$[1, 2, 3, 4, 6]$$$, so now the array is sorted. In the second test case, there is no way to sort the array by splitting it into only $$$2$$$ subarrays.As an example, if we split it into $$$\{ [1, -4], [0, -2] \}$$$, we can reorder them into $$$\{ [1, -4], [0, -2] \}$$$ or $$$\{ [0, -2], [1, -4] \}$$$. However, after merging the subarrays, it is impossible to get a sorted array.

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const idx = []
function calcNumRanks(e) {
  const n = e.length
  if (n <= 0) return [0, []]
  if (1 === n) return [1, [1]]
  idx.length = n
  for (let e = 0; e < n; ++e) idx[e] = e
  idx.sort((n, t) => e[n] - e[t])
  let t = 1
  const i = new Array(n)
  i[idx[0]] = 1
  for (let s = 1, r = e[idx[0]]; s < n; ++s) {
    const n = e[idx[s]]
    n > r && ((t += 1), (r = n)), (i[idx[s]] = t)
  }
  return [t, i]
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const [, i] = calcNumRanks(t)
  let s = 1
  for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] !== i[n] + 1 && (s += 1)
  return s <= n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      i = solve(n, t, e.readIntegersOfLine())
    e.print((i ? 'YES' : 'NO') + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const idx = []
function calcNumRanks(e) {
  const n = e.length
  if (n <= 0) return [0, []]
  if (1 === n) return [1, [1]]
  idx.length = n
  for (let e = 0; e < n; ++e) idx[e] = e
  idx.sort((n, t) => e[n] - e[t])
  let t = 1
  const i = new Array(n)
  i[idx[0]] = 1
  for (let s = 1, r = e[idx[0]]; s < n; ++s) {
    const n = e[idx[s]]
    n > r && ((t += 1), (r = n)), (i[idx[s]] = t)
  }
  return [t, i]
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const [, i] = calcNumRanks(t)
  let s = e
  for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] === i[n] + 1 && (s -= 1)
  return s <= n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      i = solve(n, t, e.readIntegersOfLine())
    e.print((i ? 'YES' : 'NO') + '\n')
  }
})

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 08/09/21 evening
const solve = (n, k, a) => {
    // pr(n, k, a)
    let m = 1;
    a = a.map((x, i) => [x, i]);
    a.sort((x, y) => {
        if (x[0] == y[0]) return x[1] - y[1];
        return x[0] - y[0];
    })
    // pr(a)
    for (let i = 0; i < n - 1; i++) {
        if (a[i][1] + 1 != a[i + 1][1]) m++;
    }
    // pr(m, k);
    pr(m <= k ? 'Yes' : 'No');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

"use strict";

const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (n === k) {
      console.log("YES");
      continue;
    }
    for (let i = 0; i < n; i++) {
      let k = { val: arr[i], ind: i };
      arr[i] = k;
    }
    arr.sort((a, b) => a.val - b.val);
    let cnt = 1;
    for (let i = 1; i < n; i++) {
      if (arr[i - 1].ind + 1 !== arr[i].ind) cnt++;
    }
    if (cnt <= k) console.log("YES");
    else console.log("NO");
  }
};
solve();

let examplesStrings = [
`3
5 4
6 3 4 2 1
4 2
1 -4 0 -2
5 1
1 2 3 4 5`,
// `3
// 1 2 3`,
// `9
// 1 2 1 3 2 2 2 2 3`
];

let examples = [
    [
        [
            {k: 4, arr: [6,3,4,2,1]}
        ],
        [
            {k: 2, arr: [1, -4, 0, -2]}
        ],
        [
            {k: 14, arr: [1,2,3,4,5]}
        ]
    ],
    // [1,2,3],
    // [1,2,1,3,2,2,2,2,3]
];

let answers = [
`YES
NO
YES`
// `2`,
// `4`,
// '10'
];

//

const parser = (string) => {
    const lines = string.match(/[^\r\n]+/g);

    // return lines[1].split(' ').map(x => parseInt(x, 10))

    const finalResult = [];
    for(let i = 1; i < lines.length; i+=2) {
        finalResult.push({
            k: lines[i].split(' ').map(x => parseInt(x, 10))[1],
            arr: lines[i+1].split(' ').map(x => parseInt(x, 10))
        })
    }
    return finalResult;
}

const solver = (arr2d) => {

    function binarySearch(arr, val) {
        let start = 0;
        let end = arr.length - 1;

        while (start <= end) {
          let mid = Math.floor((start + end) / 2);

          if (arr[mid] === val) {
            return mid;
          }

          if (val < arr[mid]) {
            end = mid - 1;
          } else {
            start = mid + 1;
          }
        }
        return -1;
      }

    return arr2d.map(({k, arr}) => {
        const sorted = arr.slice(0);
        sorted.sort((a,b) => a-b);

        let subArrCount = 0;

        let originalIndex = null;
        for(let i = 0; i < arr.length; i++) {
            // if (originalIndex === null) {
            //     subArrCount++;
            //     originalIndex = i;
            // }

            if ( (originalIndex === null) || (arr[i] !== sorted[++originalIndex])) {
                // console.log('new', i, originalIndex)
                subArrCount++;

                originalIndex = binarySearch(sorted, arr[i]);
                // originalIndex2 = arr.indexOf(sorted[i]);

                // console.log({originalIndex, originalIndex2, arr, el: sorted[i]})
            }

            // if ()
        }

        // console.log({k, arr, sorted, subArrCount})

        return (k >= subArrCount) ? 'YES' : 'NO';
    }).join("\r\n")

};

const multiSolver = (_inputs) => {
    const isMulti = false;

    const inputs = isMulti ? _inputs : [_inputs];

    let results = [];
    for(let input of inputs) {
        results.push(solver(input));
        // logResult(solver(input))
    }
    console.log({results})
    const strResults = results.join("\r\n");
    logResult(strResults);
    return strResults;

}

// FINISH HERE !!!
// STOP
// STOP

const isDevMode = process.env.LOCAL === 'knotri';
const logResult = console.log;

const deepEq = (obj1, obj2) => JSON.stringify(obj1) === JSON.stringify(obj2)
const validate = ({examplesStrings, examples, answers, parser, multiSolver}) => {
    examplesStrings.forEach((string, index) => {
        const actualParse = parser(string);
        const desiredParse = examples[index];

        if (!deepEq(actualParse, desiredParse)) {
            console.error('PARSE WRONG!');
            console.log({actualParse, desiredParse})
        }

        const actualAnswer = multiSolver(actualParse);
        const desiredAnswer = answers[index];

        if (!deepEq(actualAnswer, desiredAnswer)) {
            console.error('SOLVE WRONG!');
            console.log({actualParse, actualAnswer, desiredAnswer})
        }

    });

}

if (!isDevMode) {
    console.log = () => {};
    const fs = require("fs");
    const stdinBuffer = fs.readFileSync(0);
    const string = stdinBuffer.toString();

    multiSolver(parser(string));
} else {
    validate({examplesStrings, examples, answers, parser, multiSolver})
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main()
});

function readline() {
  return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // console.time('Execution Time')
  let testCases = readline()
  while(testCases--)
    solve()
  // console.timeEnd('Execution Time');
}

// function to solve problems
function solve (){
  let [n, k] = readline().split(' ')
  let arr = readline().split(' ').map(x => +x),
    ansArr = []

  // copy arr
  arr.forEach(num => {
    ansArr.push(num)
  })
  ansArr.sort(sortAscending)
  let ansMap = new Map()
  for (let i=0; i < ansArr.length; i++) {
    ansMap.set(ansArr[i], i)
  }
  for (let i=0; i < arr.length - 1 && k > 0; i++) {
    // check it's agad no is same as ans arr
    // find index
    let index = ansMap.get(arr[i])
    if ((index - ansMap.get(arr[i+1])) != -1) {
      // not consecutive - make bracket
      k--
    }
  }
  (k > 0) ? console.log('YES') : console.log('NO')
}

function sortAscending(a, b) {
  return a - b
}
// String.prototype.replaceAt = function (index, replacement) {
//   return this.substring(0, index) + replacement + this.substring(index + replacement.length)
// }

//Copy arr
// Map vs array

function solve() {
   const [n, k] = readArray(Number);
   const arr = readArray((x, i) => [Number(x), i]);
   arr.sort((a, b) => a[0] - b[0]);
   let goodCounter = 0;
   for (let i = 1; i < n; i++) {
      if (arr[i - 1][1] + 1 === arr[i][1]) {
         goodCounter++;
      }
   }
   write(goodCounter + k >= n ? 'YES' : 'NO');
}

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

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

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

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

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

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

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

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

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

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

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

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

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const idx = []
function calcNumRanks(e) {
  const n = e.length
  if (n <= 0) return [0, []]
  if (1 === n) return [1, [1]]
  idx.length = n
  for (let e = 0; e < n; ++e) idx[e] = e
  idx.sort((n, t) => e[n] - e[t])
  let t = 1
  const i = new Array(n)
  i[idx[0]] = 1
  for (let s = 1, r = e[idx[0]]; s < n; ++s) {
    const n = e[idx[s]]
    n > r && ((t += 1), (r = n)), (i[idx[s]] = t)
  }
  return [t, i]
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const [, i] = calcNumRanks(t)
  let s = 0
  for (let n = 0, t = e - 1; n < t; ++n)
    i[n + 1] !== i[n] && i[n + 1] !== i[n] + 1 && (s += 1)
  return s <= n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      i = solve(n, t, e.readIntegersOfLine())
    e.print((i ? 'YES' : 'NO') + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const idx = []
function calcNumRanks(e) {
  const n = e.length
  if (n <= 0) return [0, []]
  if (1 === n) return [1, [1]]
  idx.length = n
  for (let e = 0; e < n; ++e) idx[e] = e
  idx.sort((n, t) => e[n] - e[t])
  let t = 1
  const i = new Array(n)
  i[idx[0]] = 1
  for (let s = 1, r = e[idx[0]]; s < n; ++s) {
    const n = e[idx[s]]
    n > r && ((t += 1), (r = n)), (i[idx[s]] = t)
  }
  return [t, i]
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const [, i] = calcNumRanks(t)
  let s = 0
  for (let n = 0, t = e - 1; n < t; ++n) i[n + 1] !== i[n] + 1 && (s += 1)
  return s <= n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      i = solve(n, t, e.readIntegersOfLine())
    e.print((i ? 'YES' : 'NO') + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const idx = []
function calcNumRanks(e) {
  const n = e.length
  if (n <= 0) return [0, []]
  if (1 === n) return [1, [1]]
  idx.length = n
  for (let e = 0; e < n; ++e) idx[e] = e
  idx.sort((n, t) => e[n] - e[t])
  let t = 1
  const i = new Array(n)
  i[idx[0]] = 1
  for (let s = 1, r = e[idx[0]]; s < n; ++s) {
    const n = e[idx[s]]
    n > r && ((t += 1), (r = n)), (i[idx[s]] = t)
  }
  return [t, i]
}
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const [, i] = calcNumRanks(t)
  let s = 0
  for (let n = 1; n < e; ++n) i[n] !== i[n - 1] + 1 && (s += 1)
  return s <= n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const [n, t] = e.readIntegersOfLine(),
      i = solve(n, t, e.readIntegersOfLine())
    e.print((i ? 'YES' : 'NO') + '\n')
  }
})

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/09/21 morning
 * https://codeforces.com/contest/1557/problem/B
 */
const solve = (n, k, a) => {
    // pr(n, k, a)
    if (k == n) return pr('Yes')
    let tmp = LISA(a);
    let [m, d] = tmp;
    // pr(m, n - m + 1, k, d)
    if (n - m + 1 <= k) return pr('Yes');
    let sum = sm(d);
    if (n - sum + d.length <= k) return pr('Yes');
    pr('No')
};

const LISA = (a) => {
    let max = 1, len = 1, n = a.length, d = [];
    for (let i = 1; i < n; i++) {
        if (a[i] >= a[i - 1]) {
            len++;
        } else {
            d.push(len)
            if (len > max) max = len;
            len = 1;
        }
    }
    if (len > max) max = len;
    return [max, d];
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/09/21 morning
 * https://codeforces.com/contest/1557/problem/B
 */
const solve = (n, k, a) => {
    // pr(n, k, a)
    if (k == n) return pr('Yes')
    let tmp = LISA(a);
    let [m, cnt] = tmp;
    // pr(m, n - m + 1, k, 'cnt', cnt)
    if (n - m + 1 <= k) return pr('Yes');
    pr('No')
};

const LISA = (a) => {
    let max = 1, len = 1, n = a.length, cnt = 0;
    for (let i = 1; i < n; i++) {
        if (a[i] >= a[i - 1]) {
            len++;
        } else {
            cnt++;
            if (len > max) max = len;
            len = 1;
        }
    }
    if (len > max) max = len;
    return [max, cnt];
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/09/21 morning
 * https://codeforces.com/contest/1557/problem/B
 */
const solve = (n, k, a) => {
    // pr(n, k, a)
    if (k == n) return pr('Yes')
    let m = LISA(a);
    // pr(m, n - m + 1, k)
    if (n - m + 1 > k) return pr('No');
    pr('Yes')
};

const LISA = (a) => {
    let max = 1, len = 1, n = a.length;
    for (let i = 1; i < n; i++) {
        if (a[i] > a[i - 1]) {
            len++;
        } else {
            if (max < len) max = len;
            len = 1;
        }
    }
    if (len > max) max = len;
    return max;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/09/21 morning
 * https://codeforces.com/contest/1557/problem/B
 */
const solve = (n, k, a) => {
    // pr(n, k, a)
    let m = LISA(a);
    // pr(m, n - m + 1, k)
    if (n - m + 1 <= k) return pr('Yes');
    pr('No')
};

const LISA = (a) => {
    let max = 1, len = 1, n = a.length;
    for (let i = 1; i < n; i++) {
        if (a[i] > a[i - 1]) {
            len++;
        } else {
            if (max < len) max = len;
            len = 1;
        }
    }
    if (len > max) max = len;
    return max;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

"use strict";

const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (n === k) {
      console.log("YES");
      continue;
    }
    for (let i = 0; i < n; i++) {
      let k = { val: arr[i], ind: i };
      arr[i] = k;
    }
    arr.sort((a, b) => a.val - b.val);
    let cnt = 0;
    for (let i = 1; i < n; i++) {
      if (arr[i - 1].ind + 1 !== arr[i].ind) cnt++;
    }
    if (cnt <= k) console.log("YES");
    else console.log("NO");
  }
};
solve();


Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.

The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj).

In a single line print a single integer — the answer to the problem.

print(function(n, k) {
	var f = new Int8Array(1e5 + 5);
	var cnt = 0;
	for (var i = 0; i < n; i++)
		readline().split(' ').map(Number).reduce(function(l, r) {
			cnt += r - l + 1;
		});

	return k * Math.ceil(cnt / k) - cnt;

} .apply(0, readline().split(' ').map(Number)));

print(function(n, k) {
	var cnt = 0;
	for (var i = 0; i < n; i++)
		readline().split(' ').map(Number).reduce(function(l, r) {
			cnt += r - l + 1;
		});

	return k * Math.ceil(cnt / k) - cnt;

} .apply(0, readline().split(' ').map(Number)));

ip = readline().split(" ");
n = parseInt(ip[0]);
k = parseInt(ip[1]);
sum = 0;
ats = 0;

for (var i = 0; i < n; i++){
	ip = readline().split(" ");
	l = parseInt(ip[0]);
	r = parseInt(ip[1]);
	sum += (Math.abs(r-l)+1);
}
if (sum % k != 0){
	ats = k - (sum % k);
}
write(ats);

;(function () {

	print(function () {

		var p = readline().split(' ').map(Number),
			n = p[0], k = p[1]; p = 0;

		while (n--) {
			p += readline().split(' ').map(Number).reduce(function (a, b) { return b - a + 1; });
		}

		if ((p % k) === 0) return 0;

		return (parseInt(p/k) + 1) * k - p;

	}());

}.call(this));

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var spanNum = integers[0], factor = integers[1];

	var total = 0;

	for (var i = 0; i < spanNum; i += 1) {
		var span = tokenizeIntegers(readline());
		total += span[1] - span[0] + 1;
	}

	print((factor-total%factor)%factor);
}

main();

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var spanNum = integers[0], factor = integers[1];

	var total = 0;

	for (var i = 0; i < spanNum; i += 1) {
		var span = tokenizeIntegers(readline());
		total += span[1] - span[0] + 1;
	}

	print(Math.min(total%factor, factor-total%factor));
}

main();


After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.Could you find out who is going to be the winner if they all play optimally?

The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.

Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".

7
treasurehunt
threefriends
hiCodeforces

NoteIn the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.

var N = parseInt(readline());

var cats = [];
cats[0] = readline().split("");
cats[1] = readline().split("");
cats[2] = readline().split("");
var len = cats[0].length;

var res = cats.map(function(str, i) {
  var dict = {};
  var max = 0;
  str.map(function(l) {
    if (dict[l]) {
      dict[l]++;
      if (dict[l] > max) {
        max = dict[l];
      }
    } else {
      dict[l] = 1;
      if (max < 1) max = 1;
    }
  })
  return max;
})

if (len === 1 || N >= len) {
  print('Draw');
} else if (N === 1) {
  for(var i = 0; i< 3; i++) {
    if (res[i] === len) {
      res[i]--;
    } else {
      res[i]++;
    }
  }
  calc(res, len);
} else {
  for(var i = 0; i< 3; i++) {
    res[i] += N;
  }
  calc(res, len);
}

function calc(res, len) {
  if (res[0] >= len && res[1] >= len || res[0] >= len && res[2] >= len || res[1] >= len && res[2] >= len) {
    print('Draw');
  } else {
    res[0] = {result: res[0], cat: 'Kuro'};
    res[1] = {result: res[1], cat: 'Shiro'};
    res[2] = {result: res[2], cat: 'Katie'};
    res.sort(function(a, b) {return b.result - a.result});
    if (res[0].result === res[1].result) {
      print('Draw');
    } else {
      print(res[0].cat);
    }
  }
}

var N = parseInt(readline());

var cats = [];
cats[0] = readline().split("");
cats[1] = readline().split("");
cats[2] = readline().split("");
var len = cats[0].length;

var res = cats.map(function(str, i) {
  var dict = {};
  var max = 0;
  str.map(function(l) {
    if (dict[l]) {
      dict[l]++;
      if (dict[l] > max) {
        max = dict[l];
      }
    } else {
      dict[l] = 1;
      if (max < 1) max = 1;
    }
  })
  return max;
})

if (len === 1 || N >= len) {
  print('Draw');
} else if (N === 1) {
  for(var i = 0; i< 3; i++) {
    if (res[i] === len) {
      res[i]--;
    } else {
      res[i]++;
    }
    if (res[0] >= len && res[1] >= len || res[0] >= len && res[2] >= len || res[1] >= len && res[2] >= len) {
    print('Draw');
  } else {
    res[0] = {result: res[0], cat: 'Kuro'};
    res[1] = {result: res[1], cat: 'Shiro'};
    res[2] = {result: res[2], cat: 'Katie'};
    res.sort(function(a, b) {return b.result - a.result});
    if (res[0].result === res[1].result) {
      print('Draw');
    } else {
      print(res[0].cat);
    }
  }
  }
} else {
  for(var i = 0; i< 3; i++) {
    res[i] += N;
  }

  if (res[0] >= len && res[1] >= len || res[0] >= len && res[2] >= len || res[1] >= len && res[2] >= len) {
    print('Draw');
  } else {
    res[0] = {result: res[0], cat: 'Kuro'};
    res[1] = {result: res[1], cat: 'Shiro'};
    res[2] = {result: res[2], cat: 'Katie'};
    res.sort(function(a, b) {return b.result - a.result});
    if (res[0].result === res[1].result) {
      print('Draw');
    } else {
      print(res[0].cat);
    }
  }
}

var N = parseInt(readline());

var cats = [];
cats[0] = readline().split("");
cats[1] = readline().split("");
cats[2] = readline().split("");
var len = cats[0].length;

var res = cats.map(function(str, i) {
  var dict = {};
  var max = 0;
  str.map(function(l) {
    if (dict[l]) {
      dict[l]++;
      if (dict[l] > max) {
        max = dict[l];
      }
    } else {
      dict[l] = 1;
      if (max < 1) max = 1;
    }
  })
  return max;
})

if (len === 1 || N >= len) {
  print('Draw');
} else if (N === 1) {
  for(var i = 0; i< 3; i++) {
    if (res[i] === len) {
      res[i]--;
    } else {
      res[i]++
    }
  }
} else {
  for(var i = 0; i< 3; i++) {
    res[i] += N;
  }

  if (res[0] >= len && res[1] >= len || res[0] >= len && res[2] >= len || res[1] >= len && res[2] >= len) {
  print('Draw');
} else {
  res[0] = {result: res[0], cat: 'Kuro'};
  res[1] = {result: res[1], cat: 'Shiro'};
  res[2] = {result: res[2], cat: 'Katie'};
  res.sort(function(a, b) {return b.result - a.result});
  if (res[0].result === res[1].result) {
    print('Draw')
  } else {
    print(res[0].cat);
  }
}
}


n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.You have to write a program which prints the number of the child to be eliminated on every step.

The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

NoteLet's consider first example:   In the first step child 4 is eliminated, child 5 becomes the leader.  In the second step child 2 is eliminated, child 3 becomes the leader.  In the third step child 5 is eliminated, child 6 becomes the leader.  In the fourth step child 6 is eliminated, child 7 becomes the leader.  In the final step child 1 is eliminated, child 3 becomes the leader.

/*
    The idea to solve this problem is by using index of child number in array instead of
    using the child number itself.

    If we are using index, we could get consistent behavior with mod formula. For example
    if we want to move 7 times on circular array which have 7 elements starting from index
    after 0 (index 1), then we will arrive again at index 0 ((0 + 7) % 7 = 0).
*/

var params = readline().split(' ').map(Number),
    n = params[0],
    k = params[1];

var counts = readline().split(' ').map(Number),
    children = [],
    eliminated_children = [];

var leaderIdx = 0;

for(var i = 1; i <= n; i++)
    children.push(i);

for(var i = 0; i < k; i++) {

    var eliminatedIdx = (leaderIdx + counts[i]) % children.length;

    eliminated_children.push(children.splice(eliminatedIdx, 1));
    leaderIdx = eliminatedIdx % children.length;
}

print(eliminated_children.join(' '));

var params = readline().split(" ").map(function convert(value) {return +value; });
var n = params[0];
var k = params[1];
var input = readline().split(" ").map(function convert(value) {return +value;});
var children = [];
var answer = [];
var prevChildIndex = 0;

for (var i = 1; i <= n; i++)
	children.push(i);

for (var i = 0; i < k; i++ ) {
	var curChildIndex = (prevChildIndex + input[i]) % children.length;
	answer.push(children.splice(curChildIndex, 1));
	prevChildIndex = curChildIndex % children.length;
}

print(answer.join(" "));

if (typeof print === 'undefined') print = console.log;
if (typeof readline === 'undefined') readline = (function() {
    var lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var id = 0;
    return function() {return lines[id++];}
})();

var t = readline().split(' ');
var n = +t[0], q = +t[1];
var a = readline().split(' ' ).map(function(x) { return (+x); });

var qu = [], ans = [];
for (var i = -1; ++i < n; ) qu.push(i + 1);

for (var i = -1; ++i < q; ) {
    var k = (a[i]) % qu.length;
    //console.warn(k);
    for (var f = k; f--; ) {
        qu.push(qu[0]);
        qu.shift();
    }
    ans.push(qu.shift());
}
print(ans.join(' '));

  var tmp = readline().split(' ').map(function(x) {
    return parseInt(x);
  });
  var n = tmp[0];
  var k = tmp[1];
  var d = readline().split(' ').map(function(x) {
    return parseInt(x);
  });
  var children = new Array(n).fill(0).map(function(x, i) {
    return i + 1;
  });
  var curr = 0;
  var res = [];
  for(var i = 0; i < k; i += 1) {
    curr = (curr + d[i] % children.length) % children.length;
    res.push(children[curr]);
    children.splice(curr, 1);
  }
  print(res.join(' '));

var params = readline().split(" ").map(function convert(value) {return +value; });
var n = params[0];
var k = params[1];
var input = readline().split(" ").map(function convert(value) {return +value;});
var children = [];
var answer = [];
var prevChildIndex = 0;

for (var i = 1; i <= n; i++)
	children.push(i);

for (var i = 0; i < k; i++ ) {
	var curChildIndex = (prevChildIndex + input[i]) % children.length;
	answer.push(children.splice(curChildIndex, 1));
	prevChildIndex = curChildIndex % children.length;
}

print(answer);


One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?There is an Agent in Valorant, and he has $$$n$$$ weapons. The $$$i$$$-th weapon has a damage value $$$a_i$$$, and the Agent will face an enemy whose health value is $$$H$$$.The Agent will perform one or more moves until the enemy dies.In one move, he will choose a weapon and decrease the enemy's health by its damage value. The enemy will die when his health will become less than or equal to $$$0$$$. However, not everything is so easy: the Agent can't choose the same weapon for $$$2$$$ times in a row.What is the minimum number of times that the Agent will need to use the weapons to kill the enemy?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$H$$$ $$$(2 \leq n \leq 10^3, 1 \leq H \leq 10^9)$$$ — the number of available weapons and the initial health value of the enemy. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$ — the damage values of the weapons. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the minimum number of times that the Agent will have to use the weapons to kill the enemy.

NoteIn the first test case, the Agent can use the second weapon, making health value of the enemy equal to $$$4-7=-3$$$. $$$-3 \le 0$$$, so the enemy is dead, and using weapon $$$1$$$ time was enough.In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to $$$6-4-2 = 0$$$, meaning he would be killed after using weapons $$$2$$$ times.In the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to $$$11 - 7 - 2 - 7 = -5$$$ after using the weapons $$$3$$$ times. Note that we can't kill the enemy by using the third weapon twice, as even though $$$11-7-7<0$$$, it's not allowed to use the same weapon twice in a row.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var n = 0;
	var h = 0;
	for(i = 1; i <= t * 2; i++) {
		var a = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = a[0]; h = a[1];
        }else{
            a = a.sort(function(a, b){return b - a});
    		var x = a[0]; var y = a[1];
    		var b = 2 * Math.floor(h / (x + y)); var c = h % (x + y);
            if(c === 0){

            }else if(c <= x){
    			b++;
    		}else {
    			b+=2;
    		}
    		console.log(b);
        }
	}
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var max = list[0];
		var max2 = list[1];
		var output = Math.floor(X / (max + max2));
		X -= output * (max + max2);
		output *= 2;
		if(X > 0){
			X -= max;
			output++;
		}
		if(X > 0){
			X -= max2;
			output++;
		}
		myout(output);
	}
}

const readline = require('readline')

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

function solve(n, h, arr) {
    const [x, y] = arr.sort((a, b) => b - a)
    const k = Math.floor(h / (x + y))
    const r = h - k * (x + y)
    if (!r) {
        return k * 2
    } else if (r <= x) {
        return k * 2 + 1
    } else {
        return k * 2 + 2
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var n = 0;
	var h = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0];
            h = k[1];
        }else{
            k = k.sort(function(a, b){return b - a});
            var x = k[0];
            var y = k[1];
            var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);
            if(b === 0){

            }else if(b % 1 === 0){
                a++;
            }else{
                a+=2;
            }
            console.log(a);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var n = 0;
	var h = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0];
            h = k[1];
        }else{
            k = k.sort(function(a, b){return b - a});
            var x = k[0];
            var y = k[1];
            var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);
            if(b === 0){

            }else if(b % 2 == 1){
                a+=2;
            }else{
                a++;
            }
            console.log(a);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var n = 0;
	var h = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0];
            h = k[1];
        }else{
            k = k.sort(function(a, b){return b - a});
            var x = k[0];
            var y = k[1];
            var a = 2 * Math.floor(h / (x + y)); var b = h % (x + y);
            if(b === 0){

            }else if(b % 2 === 0){
                a++;
            }else{
                a+=2;
            }
            console.log(a);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    var hp = 0;
    var a = 0;
    var b = 0;
    for(var j = 1; j <= n * 2; j++){
        var k = lines[j].split(' ').map(Number);
        if(j % 2 == 1){
            e = k[0];
            hp = k[1];
        }else{
            k = k.sort(function(a, b){return b - a});
            a = k[0];
            b = k[1];
            if(hp % (a + b) === 0){
                console.log((hp / (a + b)) * 2);
            }else if(hp % (a + b) <= a){
                console.log(Math.floor(((hp / (a + b)) * 2) + 1));
            }else{
                console.log(Math.floor(((hp / (a + b)) * 2) + 2));
            }
        }
    }
});

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

    for(j = 1; j <= n;j ++){
        var a = lines[j].split(' ').map(Number)
        console.log((a[1] - a[0]) - 1)
    }
});


Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string $$$s$$$ of length $$$n$$$.Grandma Capa wants to knit a beautiful scarf, and in her opinion, a beautiful scarf can only be knit from a string that is a palindrome. She wants to change the pattern written by Grandpa Sher, but to avoid offending him, she will choose one lowercase English letter and erase some (at her choice, possibly none or all) occurrences of that letter in string $$$s$$$.She also wants to minimize the number of erased symbols from the pattern. Please help her and find the minimum number of symbols she can erase to make string $$$s$$$ a palindrome, or tell her that it's impossible. Notice that she can only erase symbols equal to the one letter she chose.A string is a palindrome if it is the same from the left to the right and from the right to the left. For example, the strings 'kek', 'abacaba', 'r' and 'papicipap' are palindromes, while the strings 'abb' and 'iq' are not.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain the description of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string. The second line of each test case contains the string $$$s$$$ consisting of $$$n$$$ lowercase English letters. 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 minimum number of erased symbols required to make the string a palindrome, if it is possible, and $$$-1$$$, if it is impossible.

5
8
abcaacab
6
xyzxyz
4
abba
8
rprarlap
10
khyyhhyhky

NoteIn the first test case, you can choose a letter 'a' and erase its first and last occurrences, you will get a string 'bcaacb', which is a palindrome. You can also choose a letter 'b' and erase all its occurrences, you will get a string 'acaaca', which is a palindrome as well.In the second test case, it can be shown that it is impossible to choose a letter and erase some of its occurrences to get a palindrome.In the third test case, you don't have to erase any symbols because the string is already a palindrome.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    if (n === 1) {
      console.log(0);
      continue;
    }
    else if(n===2){
      if(str[0]===str[1]) console.log(0);
      else console.log(1);
      continue;
    }
    let fr = new Set();
    for (let i = 0; i < n; i++) fr.add(str[i]);
    if (fr.size === n) {
      console.log(-1);
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - i - 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      console.log(0);
      continue;
    }
    let res = [];
    for (let i of fr) {
      let l = 0,
        r = n - 1,
        cnt = 0,
        flag = true;
      while (l <= r) {
        if (str[l] === str[r]) {
          l++;
          r--;
        } else if (str[l] === i) {
          l++;
          cnt++;
        } else if (str[r] === i) {
          r--;
          cnt++;
        } else {
          flag = false;
          break;
        }
      }
      if (flag) res.push(cnt);
    }
    if (res.length) {
      let min = Infinity;
      for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);
      console.log(min);
    } else console.log(-1);
  }
};
solve();

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

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

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let s = rl();

		let i = 0, j = n - 1;
		while (i < j && s[i] == s[j]) {
			i++; j--;
		}

		if (i >= j) { console.log(0); continue; }

		function check(i, j, k) {
			let cnt = 0;
			while (i < j) {
				if (s[i] == s[j]) {
					i++; j--;
				}
				else {
					if (s[i] == s[k]) {
						cnt++;  i++;
					}
					else if (s[j] == s[k]) {
						cnt++; j--;
					}
					else return -1;
				}
			}
			return cnt;
		}

		let ans;
		x = check(i, j, i);
		y = check(i, j, j);
		if (x == -1 || y == -1) ans = Math.max(x ,y);
		else ans = Math.min(x, y);

		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(n, str) {
    let ans = Infinity
    for (let i = 0; i < 26; i++) {
        const cur = isp(str, String.fromCharCode('a'.charCodeAt(0) + i))
        if (cur >= 0) {
            ans = Math.min(ans, cur)
        }
    }
    return ans === Infinity ? -1 : ans

//     let count = Array(26).fill(0)
//     for (let i = 0; i < str.length; i++) {
//         const k = str.charCodeAt(i) - 'a'.charCodeAt(0)
//         count[k]++
//     }
//     const final = count
// // console.log(final)
//     count = Array(26).fill(0)
//     for (let i = 0; i < str.length; i++) {
//         const k = str.charCodeAt(i) - 'a'.charCodeAt(0)
//         count[k]++

//         let same = 0
//         let diff
//         for (let j = 0; j < final.length; j++) {
//             if (count[j] * 2 === final[j]) {
//                 same++
//             } else {
//                 diff = Math.abs(final[j] - count[j] * 2)
//             }
//         }
//         if (same === 25) {
//             ans = Math.min(ans, diff)
//         }
//     }
}
function isp(str, ch) {
    let i = 0
    let j = str.length - 1
    let left = 0
    let right = 0
    while (i < j) {
        if (str[i] === ch && str[j] === ch) {
            i++
            j--
            left++
            right++
        } else if (str[i] === ch) {
            i++
            left++
        } else if (str[j] === ch) {
            j--
            right++
        } else {
            if (str[i] !== str[j]) return -1
            i++
            j--
        }
    }

    i = 0
    j = str.length - 1
    let ans = 0
    while (i < j) {
        if (str[i] !== str[j]) {
            if (str[i] === ch) {
                i++
                left--
            } else if (str[j] === ch) {
                j--
                right++
            } else if (left > right) {
                i++
                left--
            } else {
                j--
                right--
            }
            ans++
        } else {
            i++
            j--
        }
    }
    return ans
}

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   const str = read();
   let ans = Infinity;
   for (let i = acode; i <= zcode; i++) {
      const letter = String.fromCharCode(i);
      let currentAns = 0;
      let left = 0;
      let right = n - 1;
      while(true) {
         if (left > right) {
            break;
         }
         if (str[left] === str[right]) {
            left++;
            right--;
            continue;
         }
         if (str[left] === letter) {
            currentAns++;
            left++;
            continue;
         }
         if (str[right] === letter) {
            currentAns++;
            right--;
            continue;
         }
         currentAns = Infinity;
         break;
      }
      if (currentAns < ans) {
         ans = currentAns;
      }
   }
   write(ans === Infinity ? -1 : ans);
}

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

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

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    if (n === 1) {
      console.log(0);
      continue;
    }
    let fr = new Set();
    for (let i = 0; i < n; i++) fr.add(str[i]);
    if (fr.size === n) {
      console.log(-1);
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - i - 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      console.log(0);
      continue;
    }
    let res = [];
    for (let i of fr) {
      let l = 0,
        r = n - 1,
        cnt = 0,
        flag = true;
      while (l <= r) {
        if (str[l] === str[r]) {
          l++;
          r--;
        } else if (str[l] === i) {
          l++;
          cnt++;
        } else if (str[r] === i) {
          r--;
          cnt++;
        } else {
          flag = false;
          break;
        }
      }
      if (flag) res.push(cnt);
    }
    if (res.length) {
      let min = Infinity;
      for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);
      console.log(min);
    } else console.log(-1);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    let fr = new Set();
    for (let i = 0; i < n; i++) fr.add(str[i]);
    if (fr.size === n) {
      console.log(-1);
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - i - 1]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      console.log(0);
      continue;
    }
    let res = [];
    for (let i of fr) {
      let l = 0,
        r = n - 1,
        cnt = 0,
        flag = true;
      while (l <= r) {
        if (str[l] === str[r]) {
          l++;
          r--;
        } else if (str[l] === i) {
          l++;
          cnt++;
        } else if (str[r] === i) {
          r--;
          cnt++;
        } else {
          flag = false;
          break;
        }
      }
      if (flag) res.push(cnt);
    }
    if (res.length) {
      let min = Infinity;
      for (let i = 0; i < res.length; i++) min = Math.min(res[i], min);
      console.log(min);
    } else console.log(-1);
  }
};
solve();

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

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

function main () {
	let t = rn();
	while (t--) {
		let n = rn();
		let s = rl();

		let i = 0, j = n - 1;
		while (i < j && s[i] == s[j]) {
			i++; j--;
		}

		if (i >= j) { console.log(0); continue; }

		function check(i, j, k) {
			let cnt = 0;
			while (i < j) {
				if (s[i] == s[j]) {
					i++; j--;
				}
				else {
					if (s[i] == s[k]) {
						cnt++;  i++;
					}
					else if (s[j] == s[k]) {
						cnt++; j--;
					}
					else return -1;
				}
			}
			return cnt;
		}

		ans = check(i, j, i);
		if (ans == -1) ans = check(i, j, j);

		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(n, str) {
    let ans = Infinity
    for (let i = 0; i < 26; i++) {
        const cur = isp(str, String.fromCharCode('a'.charCodeAt(0) + i))
        if (cur >= 0) {
            ans = Math.min(ans, cur)
        }
    }
    return ans === Infinity ? -1 : ans

//     let count = Array(26).fill(0)
//     for (let i = 0; i < str.length; i++) {
//         const k = str.charCodeAt(i) - 'a'.charCodeAt(0)
//         count[k]++
//     }
//     const final = count
// // console.log(final)
//     count = Array(26).fill(0)
//     for (let i = 0; i < str.length; i++) {
//         const k = str.charCodeAt(i) - 'a'.charCodeAt(0)
//         count[k]++

//         let same = 0
//         let diff
//         for (let j = 0; j < final.length; j++) {
//             if (count[j] * 2 === final[j]) {
//                 same++
//             } else {
//                 diff = Math.abs(final[j] - count[j] * 2)
//             }
//         }
//         if (same === 25) {
//             ans = Math.min(ans, diff)
//         }
//     }
}
function isp(str, ch) {
    let i = 0
    let j = str.length - 1
    let left = 0
    let right = 0
    while (i < j) {
        if (str[i] === ch && str[j] === ch) {
            i++
            j--
            left++
            right++
        } else if (str[i] === ch) {
            i++
            left++
        } else if (str[j] === ch) {
            j--
            right++
        } else {
            if (str[i] !== str[j]) return -1
            i++
            j--
        }
    }

    i = 0
    j = str.length - 1
    let ans = 0
    while (i < j) {
        if (str[i] !== str[j]) {
            if (left > right) {
                i++
                left--
            } else {
                j--
                right--
            }
            ans++
        } else{
            i++
            j--
        }
    }
    return ans
}


Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans.Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses one of the four directions (up, down, left or right) and runs from 1 to k meters in this direction. Of course, she can only run through empty cells.Now Olya needs to get from cell (x1, y1) to cell (x2, y2). How many seconds will it take her if she moves optimally?It's guaranteed that cells (x1, y1) and (x2, y2) are empty. These cells can coincide.

The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 1000) — the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i, j) is littered with cans, and "." otherwise. The last line contains four integers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — the coordinates of the first and the last cells.

Print a single integer — the minimum time it will take Olya to get from (x1, y1) to (x2, y2). If it's impossible to get from (x1, y1) to (x2, y2), print -1.

NoteIn the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second.In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds.Olya does not recommend drinking energy drinks and generally believes that this is bad.

s=readline().split(' ')
n=+s[0]
m=+s[1]
k=+s[2]
room=[]
for (i=0;i<n;i++)
{
    room.push(readline())
}
nm=n*m
d=new Array(nm)
for (i=0;i<nm;i++)
    d[i]=-1;
a=readline().split(' ').map(function(x){return +x})
--a[0]
--a[1]
--a[2]
--a[3]
d[a[0]*m+a[1]]=0
q=[[a[0],a[1]]]
ql=0
qr=0
while(ql<=qr)
{
    y=q[ql][0]
    x=q[ql][1]
    tek=d[y*m+x]
    ++ql
    st=0
    for (i=y-1;;i--)
    {
        if (i<0)
            break
        if (room[i][x]=='#')
            break
        if (d[i*m+x]!=-1)
            break
        ++st
        if (st>k)
            break
        ++qr
        q.push([i,x])
        d[i*m+x]=1+tek
    }
    st=0
    for (i=y+1;;i++)
    {
        if (i>=n)
            break
        if (room[i][x]=='#')
            break
        if (d[i*m+x]!=-1)
            break
        ++st
        if (st>k)
            break
        ++qr
        d[i*m+x]=tek+1
        q.push([i,x])
    }
    st=0
    for (i=x-1;;i--)
    {
        if (i<0)
            break
        if (room[y][i]=='#')
            break
        if (d[y*m+i]!=-1)
            break
        ++st
        if (st>k)
            break
        ++qr
        d[y*m+i]=1+tek
        q.push([y,i])
    }
    st=0
    for (i=x+1;;i++)
    {
        if (i>=m)
            break
        if (room[y][i]=='#')
            break
        if (d[y*m+i]!=-1)
            break
        ++st
        if (st>k)
            break
        ++qr
        d[y*m+i]=1+tek
        q.push([y,i])
    }
}
//print(d)
print(d[a[2]*m+a[3]])