#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
const int MOD = 1000000007;
struct Mint {
  int val;
  Mint(long long v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = v;
  }
  static int mod_inv(int a, int m = MOD) {
    int g = m, r = a, x = 0, y = 1;
    while (r != 0) {
      int q = g / r;
      g %= r;
      swap(g, r);
      x -= q * y;
      swap(x, y);
    }
    return x < 0 ? x + m : x;
  }
  explicit operator int() const { return val; }
  Mint &operator+=(const Mint &other) {
    val += other.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  Mint &operator-=(const Mint &other) {
    val -= other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return x % m;
    unsigned x_high = x >> 32, x_low = (unsigned)x;
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  Mint &operator*=(const Mint &other) {
    val = fast_mod((uint64_t)val * other.val);
    return *this;
  }
  Mint &operator/=(const Mint &other) { return *this *= other.inv(); }
  friend Mint operator+(const Mint &a, const Mint &b) { return Mint(a) += b; }
  friend Mint operator-(const Mint &a, const Mint &b) { return Mint(a) -= b; }
  friend Mint operator*(const Mint &a, const Mint &b) { return Mint(a) *= b; }
  friend Mint operator/(const Mint &a, const Mint &b) { return Mint(a) /= b; }
  Mint &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  Mint &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  Mint operator++(int32_t) {
    Mint before = *this;
    ++*this;
    return before;
  }
  Mint operator--(int32_t) {
    Mint before = *this;
    --*this;
    return before;
  }
  Mint operator-() const { return val == 0 ? 0 : MOD - val; }
  bool operator==(const Mint &other) const { return val == other.val; }
  bool operator!=(const Mint &other) const { return val != other.val; }
  Mint inv() const { return mod_inv(val); }
  Mint power(long long p) const {
    assert(p >= 0);
    Mint a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      a *= a;
      p >>= 1;
    }
    return result;
  }
  friend ostream &operator<<(ostream &stream, const Mint &m) {
    return stream << m.val;
  }
  friend istream &operator>>(istream &stream, Mint &m) {
    return stream >> m.val;
  }
};
const int N = 200005, up = 3;
struct node {
  Mint sum[up];
  int cnt;
  node() {
    for (int i = 0; i < up; ++i) {
      sum[i] = 0;
    }
    cnt = 0;
  }
} fake;
struct SEGTREE {
  long long a[N];
  SEGTREE() {}
  node tree[4 * N];
  long long lazy[4 * N];
  inline node combine(node a, node b) {
    node ret;
    ret.cnt = a.cnt + b.cnt;
    for (int i = 0; i < up; ++i) {
      ret.sum[i] = a.sum[i] + b.sum[i];
    }
    return ret;
  }
  inline node make_node(long long val, long long x) {
    node ret;
    ret.cnt = x;
    Mint cur = val;
    for (int i = 0; i < up; ++i) {
      ret.sum[i] = val;
      val *= val;
    }
    return ret;
  }
  void buildTree(long long v, long long st, long long en) {
    if (st == en) {
      tree[v] = make_node(a[st], 0);
      return;
    }
    long long mid = (st + en) >> 1;
    buildTree(v << 1, st, mid);
    buildTree(v << 1 | 1, mid + 1, en);
    tree[v] = combine(tree[v << 1], tree[v << 1 | 1]);
  }
  void update(long long v, long long st, long long en, long long in,
              long long val, long long x) {
    long long mid = (st + en) >> 1;
    if (st == en) {
      tree[v] = make_node(val, x);
      a[st] = val;
      return;
    }
    if (in <= mid)
      update(v << 1, st, mid, in, val, x);
    else
      update(v << 1 | 1, mid + 1, en, in, val, x);
    tree[v] = combine(tree[v << 1], tree[v << 1 | 1]);
  }
  node query(long long v, long long st, long long en, long long l,
             long long r) {
    if (en < l || st > r) return fake;
    if (st >= l && en <= r) return tree[v];
    long long mid = (st + en) >> 1;
    return combine(query(v << 1, st, mid, l, r),
                   query(v << 1 | 1, mid + 1, en, l, r));
  }
} seg;
int _runtimeTerror_() {
  int n, Q;
  cin >> n >> Q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<vector<array<int, 3>>> g(n + 1);
  for (int i = 1; i <= Q; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    g[r].push_back({l, d, i});
  }
  vector<string> ans(Q + 1, "No");
  for (int i = 1; i <= n; ++i) {
    seg.a[i] = 0;
  }
  seg.buildTree(1, 1, n);
  map<int, int> last;
  for (int i = 1; i <= n; ++i) {
    if (last.count(a[i])) {
      seg.update(1, 1, n, last[a[i]], 0, 0);
    }
    seg.update(1, 1, n, i, a[i], 1);
    for (auto &[l, d, q] : g[i]) {
      auto val = seg.query(1, 1, n, l, i);
      Mint f = val.sum[0];
      f *= 2;
      f /= val.cnt;
      f -= (val.cnt - 1) * Mint(d);
      f /= 2;
      long long cnt = val.cnt;
      Mint sq = f * f * cnt +
                Mint(cnt) * (cnt - 1) * (2 * cnt - 1) / 6 * d * d +
                2 * f * d * cnt * (cnt - 1) / 2;
      if (sq == val.sum[1]) {
        ans[q] = "Yes";
      }
    }
    last[a[i]] = i;
  }
  for (int i = 1; i <= Q; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

In the year 2420 humans have finally built a colony on Mars thanks to the work of Elon Tusk. There are 10^9+7 cities arranged in a circle in this colony and none of them are connected yet. Elon Tusk wants to connect some of those cities using only roads of the same size in order to lower the production cost of those roads. Because of that he gave a list on N cites where some cites can appear more than once and Q queries that you need to answer. For the query you need to determine if it is possible to connect all the cities from L_{i} to R_{i} on that list using only roads of length D_{i}. 

Input

The first line contains two integers N and Q (1 ≤ N, Q ≤ 2⋅10^5 ) — the length of the array of cities and the number of queries you need to answer. 

The second lines contains N integers representing the array of cites. Next Q lines contain three integers L, R and D (1 ≤ L_{i}, R_{i} ≤ N, 0 ≤ D_{i} ≤ 10^9+6) — the range of cities that needs to be connected and the length of the road that you can use. 

Output

The output contains Q lines. If it is possible to connect all the cities from the i-th query can be connected with roads of length D_{i} the i-th line should contain the word "Yes", otherwise it should contain the word "No". 

Examples

Input


9 8
17 0 12 6 10 8 2 4 5
2 3 12
2 3 6
2 4 6
4 6 2
2 8 2
1 2 17
1 8 2
9 9 14


Output


Yes
No
Yes
Yes
Yes
Yes
No
Yes


Input


4 1
7 21 14 0
1 4 1000000000


Output


Yes

Note

In the 5^{th} query of the first test case we can connect cities in this order 0-2-4-6-8-10-12 this way distance between any two connected cities is 2. In the second test case we can connect cities in this order 21-14-7-0 this way distance between any two connected cities is 10^9 module 10^9+7. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
const int MOD = 1000000007;
struct Mint {
  int val;
  Mint(long long v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = v;
  }
  static int mod_inv(int a, int m = MOD) {
    int g = m, r = a, x = 0, y = 1;
    while (r != 0) {
      int q = g / r;
      g %= r;
      swap(g, r);
      x -= q * y;
      swap(x, y);
    }
    return x < 0 ? x + m : x;
  }
  explicit operator int() const { return val; }
  Mint &operator+=(const Mint &other) {
    val += other.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  Mint &operator-=(const Mint &other) {
    val -= other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return x % m;
    unsigned x_high = x >> 32, x_low = (unsigned)x;
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  Mint &operator*=(const Mint &other) {
    val = fast_mod((uint64_t)val * other.val);
    return *this;
  }
  Mint &operator/=(const Mint &other) { return *this *= other.inv(); }
  friend Mint operator+(const Mint &a, const Mint &b) { return Mint(a) += b; }
  friend Mint operator-(const Mint &a, const Mint &b) { return Mint(a) -= b; }
  friend Mint operator*(const Mint &a, const Mint &b) { return Mint(a) *= b; }
  friend Mint operator/(const Mint &a, const Mint &b) { return Mint(a) /= b; }
  Mint &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  Mint &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  Mint operator++(int32_t) {
    Mint before = *this;
    ++*this;
    return before;
  }
  Mint operator--(int32_t) {
    Mint before = *this;
    --*this;
    return before;
  }
  Mint operator-() const { return val == 0 ? 0 : MOD - val; }
  bool operator==(const Mint &other) const { return val == other.val; }
  bool operator!=(const Mint &other) const { return val != other.val; }
  Mint inv() const { return mod_inv(val); }
  Mint power(long long p) const {
    assert(p >= 0);
    Mint a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      a *= a;
      p >>= 1;
    }
    return result;
  }
  friend ostream &operator<<(ostream &stream, const Mint &m) {
    return stream << m.val;
  }
  friend istream &operator>>(istream &stream, Mint &m) {
    return stream >> m.val;
  }
};
const int N = 200005, up = 3;
struct node {
  Mint sum[up];
  int cnt;
  node() {
    for (int i = 0; i < up; ++i) {
      sum[i] = 0;
    }
    cnt = 0;
  }
} fake;
struct SEGTREE {
  long long a[N];
  SEGTREE() {}
  node tree[4 * N];
  long long lazy[4 * N];
  inline node combine(node a, node b) {
    node ret;
    ret.cnt = a.cnt + b.cnt;
    for (int i = 0; i < up; ++i) {
      ret.sum[i] = a.sum[i] + b.sum[i];
    }
    return ret;
  }
  inline node make_node(long long val, long long x) {
    node ret;
    ret.cnt = x;
    Mint cur = val;
    for (int i = 0; i < up; ++i) {
      ret.sum[i] = val;
      val *= val;
    }
    return ret;
  }
  void buildTree(long long v, long long st, long long en) {
    if (st == en) {
      tree[v] = make_node(a[st], 0);
      return;
    }
    long long mid = (st + en) >> 1;
    buildTree(v << 1, st, mid);
    buildTree(v << 1 | 1, mid + 1, en);
    tree[v] = combine(tree[v << 1], tree[v << 1 | 1]);
  }
  void update(long long v, long long st, long long en, long long in,
              long long val, long long x) {
    long long mid = (st + en) >> 1;
    if (st == en) {
      tree[v] = make_node(val, x);
      a[st] = val;
      return;
    }
    if (in <= mid)
      update(v << 1, st, mid, in, val, x);
    else
      update(v << 1 | 1, mid + 1, en, in, val, x);
    tree[v] = combine(tree[v << 1], tree[v << 1 | 1]);
  }
  node query(long long v, long long st, long long en, long long l,
             long long r) {
    if (en < l || st > r) return fake;
    if (st >= l && en <= r) return tree[v];
    long long mid = (st + en) >> 1;
    return combine(query(v << 1, st, mid, l, r),
                   query(v << 1 | 1, mid + 1, en, l, r));
  }
} seg;
int _runtimeTerror_() {
  int n, Q;
  cin >> n >> Q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<vector<array<int, 3>>> g(n + 1);
  for (int i = 1; i <= Q; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    g[r].push_back({l, d, i});
  }
  vector<string> ans(Q + 1, "No");
  for (int i = 1; i <= n; ++i) {
    seg.a[i] = 0;
  }
  seg.buildTree(1, 1, n);
  map<int, int> last;
  for (int i = 1; i <= n; ++i) {
    if (last.count(a[i])) {
      seg.update(1, 1, n, last[a[i]], 0, 0);
    }
    seg.update(1, 1, n, i, a[i], 1);
    for (auto &[l, d, q] : g[i]) {
      auto val = seg.query(1, 1, n, l, i);
      Mint f = val.sum[0];
      f *= 2;
      f /= val.cnt;
      f -= (val.cnt - 1) * Mint(d);
      f /= 2;
      long long cnt = val.cnt;
      Mint sq = f * f * cnt +
                Mint(cnt) * (cnt - 1) * (2 * cnt - 1) / 6 * d * d +
                2 * f * d * cnt * (cnt - 1) / 2;
      if (sq == val.sum[1]) {
        ans[q] = "Yes";
      }
    }
    last[a[i]] = i;
  }
  for (int i = 1; i <= Q; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}

```