There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i$$$ cells blocked (the cells in rows $$$1, 2, \dots, a_i$$$), the remaining $$$n - a_i$$$ cells are unblocked.A robot is travelling across this grid. You can send it commands — move up, right, down or left. If a robot attempts to move into a blocked cell or outside the grid, it explodes.However, the robot is broken — it executes each received command $$$k$$$ times. So if you tell it to move up, for example, it will move up $$$k$$$ times ($$$k$$$ cells). You can't send it commands while the robot executes the current one.You are asked $$$q$$$ queries about the robot. Each query has a start cell, a finish cell and a value $$$k$$$. Can you send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $$$k$$$ times?The robot must stop in the finish cell. If it visits the finish cell while still executing commands, it doesn't count.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le m \le 2 \cdot 10^5$$$) — the number of rows and columns of the grid. The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$0 \le a_i \le n$$$) — the number of blocked cells on the bottom of the $$$i$$$-th column. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contain five integers $$$x_s, y_s, x_f, y_f$$$ and $$$k$$$ ($$$a[y_s] < x_s \le n$$$; $$$1 \le y_s \le m$$$; $$$a[y_f] < x_f \le n$$$; $$$1 \le y_f \le m$$$; $$$1 \le k \le 10^9$$$) — the row and the column of the start cell, the row and the column of the finish cell and the number of times each your command is executed. The start and the finish cell of each query are unblocked.

For each query, print "YES" if you can send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $$$k$$$ times. Otherwise, print "NO".

function query(l, r, x, lx, rx) {
  if (lx >= r || rx <= l) return 0;
  if (lx >= l && rx <= r) return tree[x];
  var m = (lx + rx) / 2;
  var left = query(l, r, 2 * x + 1, lx, m),
    right = query(l, r, 2 * x + 2, m, rx);
  return Math.max(left, right);
}

var l = readline().split(" ");
var m = parseInt(l[0]);
var n = parseInt(l[1]);

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

var N = 1;
while (N < arr.length) N *= 2;
tree = new Array(N * 2);
for (var i = 0; i < arr.length; i++) {
  tree[N - 1 + i] = arr[i];
}
for (var i = N - 2; i >= 0; i--) {
  var left = tree[2 * i + 1],
    right = tree[2 * i + 2];
  tree[i] = Math.max(left, right);
}

var q = parseInt(readline(), 10);
while (q--) {
  l = readline().split(" ");
  for (var i = 0; i < l.length; i++) l[i] = parseInt(l[i]);
  var xs = --l[0],
    ys = --l[1],
    xf = --l[2],
    yf = --l[3],
    k = l[4];
  xs = m - xs - 1;
  xf = m - xf - 1;
  if (ys > yf) {
    var temp = ys;
    ys = yf;
    yf = temp;
    temp = xs;
    xs = xf;
    xf = temp;
  }
  if ((xf - xs) % k !== 0 || (yf - ys) % k !== 0) {
    print("NO");
  } else {
    var x = xs % k;
    if (x < m - query(ys, yf, 0, 0, N)) {
      print("YES");
    } else {
      print("NO");
    }
  }
}

function query(l, r, x, lx, rx) {
  if (lx >= r || rx <= l) return 0;
  if (lx >= l && rx <= r) return tree[x];
  var m = (lx + rx) / 2;
  var left = query(l, r, 2 * x + 1, lx, m),
    right = query(l, r, 2 * x + 2, m, rx);
  return Math.max(left, right);
}

var l = readline().split(" ");
var m = parseInt(l[0]);
var n = parseInt(l[1]);

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

var N = 1;
while (N < arr.length) N *= 2;
tree = new Array(N * 2);
for (var i = 0; i < arr.length; i++) {
  tree[N - 1 + i] = arr[i];
}
for (var i = N - 2; i >= 0; i--) {
  var left = tree[2 * i + 1],
    right = tree[2 * i + 2];
  tree[i] = Math.max(left, right);
}

var q = parseInt(readline(), 10);
while (q--) {
  l = readline().split(" ");
  for (var i = 0; i < l.length; i++) l[i] = parseInt(l[i]);
  var xs = --l[0],
    ys = --l[1],
    xf = --l[2],
    yf = --l[3],
    k = l[4];
  xs = m - xs - 1;
  xf = m - xf - 1;
  if (ys > yf) {
    var temp = ys;
    ys = yf;
    yf = temp;
    temp = xs;
    xs = xf;
    xf = temp;
  }
  if ((xf - xs) % k !== 0 || (yf - ys) % k !== 0) {
    print("NO\n");
  } else {
    var x = xs % k;
    if (x < m - query(ys, yf, 0, 0, N)) {
      print("YES\n");
    } else {
      print("NO\n");
    }
  }
}

'use strict';

function solve(n, m, q, a, b) {
  const segTree = new SegTree(m);
  for (let i = 0; i < m; i++) {
    segTree.update(i, a[i]);
  }
  let res = new Array(q);
  for (let i = 0; i < q; i++) {
    let [x1, y1, x2, y2, k] = b[i];
    if (Math.abs(x2 - x1) % k !== 0 || Math.abs(y2 - y1) % k !== 0) {
      res[i] = 'NO';
    } else if (y1 === y2) {
      res[i] = 'YES';
    } else {
      let max = 0;
      if (y1 > y2) {
        max = segTree.query(y2, y1 - 2);
      } else {
        max = segTree.query(y1, y2 - 2);
      }
      const cur = Math.floor((n - x1) / k) * k + x1;
      if (cur > max) {
        res[i] = 'YES';
      } else {
        res[i] = 'NO';
      }
    }
  }
  return res.join('\n');
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, z) => {
      x = Math.max(x, 0);
      x = Math.min(x, n);
      this._update(this.root, 0, n, x, z);
    };
    this.query = (x, y) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._query(this.root, 0, n, x, y);
    };
  }
  _newNode(left = null, right = null) {
    return {
      max: 0,
      left,
      right
    };
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.max = Math.max(left.max, right.max);
  }
  _update(node, l, r, x, z) {
    if (!node) return;
    if (l === r) {
      node.max = z;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (x <= mid) this._update(node.left, l, mid, x, z);else this._update(node.right, mid + 1, r, x, z);
    this._up(node);
  }
  _query(node, l, r, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    if (l === x && r === y) return node.max;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.max(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));
    return res;
  }
}

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

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


The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one.Soon the Hedgehog came up with a brilliant idea: instead of buying ready-made puzzles, one can take his own large piece of paper with some picture and cut it into many small rectangular pieces, then mix them and solve the resulting puzzle, trying to piece together the picture. The resulting task is even more challenging than the classic puzzle: now all the fragments have the same rectangular shape, and one can assemble the puzzle only relying on the picture drawn on the pieces.All puzzle pieces turn out to be of the same size X × Y, because the picture is cut first by horizontal cuts with the pitch of X, then with vertical cuts with the pitch of Y. If we denote the initial size of the picture as A × B, then A must be divisible by X and B must be divisible by Y (X and Y are integer numbers). However, not every such cutting of the picture will result in a good puzzle. The Hedgehog finds a puzzle good if no two pieces in it are the same (It is allowed to rotate the pieces when comparing them, but it is forbidden to turn them over). Your task is to count for a given picture the number of good puzzles that you can make from it, and also to find the puzzle with the minimal piece size.

The first line contains two numbers A and B which are the sizes of the picture. They are positive integers not exceeding 20. Then follow A lines containing B symbols each, describing the actual picture. The lines only contain uppercase English letters.

In the first line print the number of possible good puzzles (in other words, the number of pairs (X, Y) such that the puzzle with the corresponding element sizes will be good). This number should always be positive, because the whole picture is a good puzzle itself.  In the second line print two numbers — the sizes X and Y of the smallest possible element among all good puzzles. The comparison is made firstly by the area XY of one element and secondly — by the length X.

NoteThe picture in the first sample test has the following good puzzles: (2, 1), (2, 2), (2, 4).

'use strict'

let lll
lll = readline().split(' ').map(v => parseInt(v))
let A = lll[1]
let B = lll[0]

let f = []
while (lll = readline()) {
  f.push(lll.split(''))
}

let sa = []
let sb = []
for (let i = 1; i <= 20; i++) {
  if (!(A % i)) sa.push(i)
  if (!(B % i)) sb.push(i)
}

let best = {x: Infinity, y: Infinity}
let all = 0
for (let i = 0; i < sa.length; i++) {
  n: for (let j = 0; j < sb.length; j++) {
    let ps = split(sa[i], sb[j])
    let phs = new Set
    for (let pi = 0; pi < ps.length; pi++) {
      let hs = rotatesHashes(ps[pi])
      if (sa[i] == 6 && sb[j] == 2) {
        for (let hi = 0; hi < 4; hi++) {
          let h = hs[hi]
          if (phs.has(h)) {
            let sss = []
            phs.forEach(v => sss.push(v))
          }
        }
      }
      for (let hi = 0; hi < 4; hi++) {
        let h = hs[hi]
        if (phs.has(h)) continue n
      }
      for (let hi = 0; hi < 4; hi++) {
        phs.add(hs[hi])
      }
    }
    all++
    if (best.x * best.y > sa[i] * sb[j] || best.x * best.y == sa[i] * sb[j] && best.x > sb[j]) {
      best.x = sb[j]
      best.y = sa[i]
    }
  }
}

print(all)
print(best.x + ' ' + best.y)

function split (x, y) {
  let ps = []
  for (let i = 0; i < A; i += x) {
    for (let j = 0; j < B; j += y) {
      let p = []
      for (let r = 0; r < y; r++) {
        p.push(f[j + r].slice(i, i + x))
      }
      ps.push(p)
    }
  }
  return ps
}

function rotatesHashes (p) {
  let hs = [hash(p)]
  for (let i = 0; i < 3; i++) {
    p = rotate(p)
    hs.push(hash(p))
  }
  return hs
}

function rotate (p) {
  let n = []
  for (let i = 0; i < p[0].length; i++) {
    n.push([])
  }
  for (let i = 0; i < p.length; i++) {
    for (let j = 0; j < p[0].length; j++) {
      n[j][p.length - i - 1] = p[i][j]
    }
  }
  return n
}

function hash (p) {
  let h = ''
  for (let i = 0; i < p.length; i++) {
    for (let j = 0; j < p[0].length; j++) {
      h += p[i][j]
    }
    h += '*'
  }
  return h
}

function test (a, b) {
  for (let i = 0; i < a.length; i++) {
    if (a[i] == b[i]) return false
  }
  return true
}

'use strict'

let lll
lll = readline().split(' ').map(v => parseInt(v))
let A = lll[1]
let B = lll[0]

let f = []
while (lll = readline()) {
  f.push(lll.split(''))
}

let sa = []
let sb = []
for (let i = 1; i <= 20; i++) {
  if (!(A % i)) sa.push(i)
  if (!(B % i)) sb.push(i)
}

let best = {x: Infinity, y: Infinity}
let all = 0
for (let i = 0; i < sa.length; i++) {
  n: for (let j = 0; j < sb.length; j++) {
    let ps = split(sa[i], sb[j])
    let phs = new Set
    for (let pi = 0; pi < ps.length; pi++) {
      let hs = rotatesHashes(ps[pi])
      for (let hi = 0; hi < 4; hi++) {
        let h = hs[hi]
        if (phs.has(h)) continue n
      }
      for (let hi = 0; hi < 4; hi++) {
        phs.add(hs[hi])
      }
    }
    all++
    if (best.x * best.y > sa[i] * sb[j] || best.x * best.y == sa[i] * sb[j] && best.x > sb[j]) {
      best.x = sb[j]
      best.y = sa[i]
    }
  }
}

print(all)
print(best.x + ' ' + best.y)

function split (x, y) {
  let ps = []
  for (let i = 0; i < A; i += x) {
    for (let j = 0; j < B; j += y) {
      let p = []
      for (let r = 0; r < y; r++) {
        p.push(f[j + r].slice(i, i + x))
      }
      ps.push(p)
    }
  }
  return ps
}

function rotatesHashes (p) {
  let hs = [hash(p)]
  for (let i = 0; i < 3; i++) {
    p = rotate(p)
    hs.push(hash(p))
  }
  return hs
}

function rotate (p) {
  let n = []
  for (let i = 0; i < p[0].length; i++) {
    n.push([])
  }
  for (let i = 0; i < p.length; i++) {
    for (let j = 0; j < p[0].length; j++) {
      n[j][p.length - i - 1] = p[i][j]
    }
  }
  return n
}

function hash (p) {
  let h = ''
  for (let i = 0; i < p.length; i++) {
    for (let j = 0; j < p[0].length; j++) {
      h += p[i][j]
    }
  }
  return h
}

function test (a, b) {
  for (let i = 0; i < a.length; i++) {
    if (a[i] == b[i]) return false
  }
  return true
}