#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
string s1;
int st[26][300000];
int lazy[26][300000];
int ar[100001];
void build(int l, int r, int ind, int s) {
  if (l == r) {
    st[ind][s] = (s1[l] == ('a' + ind)) ? 1 : 0;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, ind, 2 * s + 1);
  build(mid + 1, r, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
void update(int l, int r, int x, int y, int val, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (l > y or r < x) return;
  if (x <= l and y >= r) {
    st[ind][s] = (r - l + 1) * val;
    if (l != r) {
      lazy[ind][2 * s + 1] = val;
      lazy[ind][2 * s + 2] = val;
    }
    return;
  }
  int mid = (l + r) / 2;
  update(l, mid, x, y, val, ind, 2 * s + 1);
  update(mid + 1, r, x, y, val, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
int find(int l, int r, int x, int y, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (l > y or r < x) return 0;
  if (x <= l and y >= r) {
    return st[ind][s];
  }
  int mid = (l + r) / 2;
  int p = find(l, mid, x, y, ind, 2 * s + 1);
  int q = find(mid + 1, r, x, y, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
  return p + q;
}
void calc(int l, int r, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (st[ind][s] == 0) return;
  if (l == r) {
    ar[l] = ind;
    return;
  }
  int mid = (l + r) / 2;
  calc(l, mid, ind, 2 * s + 1);
  calc(mid + 1, r, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
void solve() {
  memset(lazy, -1, sizeof(lazy));
  int n, q, i, x, y, k;
  cin >> n >> q;
  cin >> s1;
  for (i = 0; i < 26; i++) {
    build(0ll, n - 1, i, 0ll);
  }
  while (q--) {
    cin >> x >> y >> k;
    x--;
    y--;
    int ind;
    if (k == 1)
      ind = x;
    else
      ind = y;
    for (i = 0; i < 26; i++) {
      if (k == 1) {
        int val = find(0, n - 1, x, y, i, 0);
        update(0, n - 1, x, y, 0, i, 0);
        update(0, n - 1, ind, ind + val - 1, 1, i, 0);
        ind = ind + val;
      } else {
        int val = find(0, n - 1, x, y, i, 0);
        update(0, n - 1, x, y, 0, i, 0);
        update(0, n - 1, ind - val + 1, ind, 1, i, 0);
        ind = ind - val;
      }
    }
  }
  for (i = 0; i < 26; i++) calc(0, n - 1, i, 0);
  for (i = 0; i < n; i++) cout << (char)(ar[i] + 'a');
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.

Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively. 

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n, <image>).

Output

Output one line, the string S after applying the queries.

Examples

Input

10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1


Output

cbcaaaabdd

Input

10 1
agjucbvdfk
1 10 1


Output

abcdfgjkuv

Note

First sample test explanation:

<image>

<image>

<image>

<image>

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
string s1;
int st[26][300000];
int lazy[26][300000];
int ar[100001];
void build(int l, int r, int ind, int s) {
  if (l == r) {
    st[ind][s] = (s1[l] == ('a' + ind)) ? 1 : 0;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, ind, 2 * s + 1);
  build(mid + 1, r, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
void update(int l, int r, int x, int y, int val, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (l > y or r < x) return;
  if (x <= l and y >= r) {
    st[ind][s] = (r - l + 1) * val;
    if (l != r) {
      lazy[ind][2 * s + 1] = val;
      lazy[ind][2 * s + 2] = val;
    }
    return;
  }
  int mid = (l + r) / 2;
  update(l, mid, x, y, val, ind, 2 * s + 1);
  update(mid + 1, r, x, y, val, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
int find(int l, int r, int x, int y, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (l > y or r < x) return 0;
  if (x <= l and y >= r) {
    return st[ind][s];
  }
  int mid = (l + r) / 2;
  int p = find(l, mid, x, y, ind, 2 * s + 1);
  int q = find(mid + 1, r, x, y, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
  return p + q;
}
void calc(int l, int r, int ind, int s) {
  if (lazy[ind][s] != -1) {
    st[ind][s] = (lazy[ind][s]) * (r - l + 1);
    if (l != r) {
      lazy[ind][2 * s + 1] = lazy[ind][s];
      lazy[ind][2 * s + 2] = lazy[ind][s];
    }
    lazy[ind][s] = -1;
  }
  if (st[ind][s] == 0) return;
  if (l == r) {
    ar[l] = ind;
    return;
  }
  int mid = (l + r) / 2;
  calc(l, mid, ind, 2 * s + 1);
  calc(mid + 1, r, ind, 2 * s + 2);
  st[ind][s] = st[ind][2 * s + 1] + st[ind][2 * s + 2];
}
void solve() {
  memset(lazy, -1, sizeof(lazy));
  int n, q, i, x, y, k;
  cin >> n >> q;
  cin >> s1;
  for (i = 0; i < 26; i++) {
    build(0ll, n - 1, i, 0ll);
  }
  while (q--) {
    cin >> x >> y >> k;
    x--;
    y--;
    int ind;
    if (k == 1)
      ind = x;
    else
      ind = y;
    for (i = 0; i < 26; i++) {
      if (k == 1) {
        int val = find(0, n - 1, x, y, i, 0);
        update(0, n - 1, x, y, 0, i, 0);
        update(0, n - 1, ind, ind + val - 1, 1, i, 0);
        ind = ind + val;
      } else {
        int val = find(0, n - 1, x, y, i, 0);
        update(0, n - 1, x, y, 0, i, 0);
        update(0, n - 1, ind - val + 1, ind, 1, i, 0);
        ind = ind - val;
      }
    }
  }
  for (i = 0; i < 26; i++) calc(0, n - 1, i, 0);
  for (i = 0; i < n; i++) cout << (char)(ar[i] + 'a');
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```