#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int data[26][4 * N], flag[26][4 * N], n, q;
string s;
void shift(int ch, int node, int st, int en) {
  if (flag[ch][node] == -1) return;
  int mid = (st + en) / 2;
  flag[ch][node * 2 + 0] = flag[ch][node];
  flag[ch][node * 2 + 1] = flag[ch][node];
  data[ch][node * 2 + 0] = (mid - st) * flag[ch][node];
  data[ch][node * 2 + 1] = (en - mid) * flag[ch][node];
  flag[ch][node] = -1;
}
void change(int ch, int node, int st, int en, int l, int r, int val) {
  if (en <= l or r <= st) return;
  if (l <= st and en <= r) {
    data[ch][node] = (en - st) * val;
    flag[ch][node] = val;
    return;
  }
  int mid = (st + en) / 2;
  shift(ch, node, st, en);
  change(ch, node * 2 + 0, st, mid, l, r, val);
  change(ch, node * 2 + 1, mid, en, l, r, val);
  data[ch][node] = data[ch][node * 2] + data[ch][node * 2 + 1];
}
int get(int ch, int node, int st, int en, int l, int r) {
  if (en <= l or r <= st) return 0;
  if (l <= st and en <= r) return data[ch][node];
  int mid = (st + en) / 2;
  shift(ch, node, st, en);
  return get(ch, node * 2 + 0, st, mid, l, r) +
         get(ch, node * 2 + 1, mid, en, l, r);
}
int main() {
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 26; ++j) flag[j][i] = -1;
  cin >> n >> q >> s;
  for (int i = 0; i < n; ++i) change((int)(s[i] - 'a'), 1, 0, n, i, i + 1, 1);
  int type, l, r, now, cnt;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%d", &l, &r, &type);
    l--;
    now = l;
    if (type == 0)
      for (int j = 25; j > -1; --j) {
        cnt = get(j, 1, 0, n, l, r);
        change(j, 1, 0, n, l, r, 0);
        change(j, 1, 0, n, now, now + cnt, 1);
        now += cnt;
      }
    if (type == 1)
      for (int j = 0; j < 26; ++j) {
        cnt = get(j, 1, 0, n, l, r);
        change(j, 1, 0, n, l, r, 0);
        change(j, 1, 0, n, now, now + cnt, 1);
        now += cnt;
      }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      if (get(j, 1, 0, n, i, i + 1) > 0) cout << (char)(j + 'a');
}

### Prompt

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

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>
using namespace std;
const int N = 1e5 + 10;
int data[26][4 * N], flag[26][4 * N], n, q;
string s;
void shift(int ch, int node, int st, int en) {
  if (flag[ch][node] == -1) return;
  int mid = (st + en) / 2;
  flag[ch][node * 2 + 0] = flag[ch][node];
  flag[ch][node * 2 + 1] = flag[ch][node];
  data[ch][node * 2 + 0] = (mid - st) * flag[ch][node];
  data[ch][node * 2 + 1] = (en - mid) * flag[ch][node];
  flag[ch][node] = -1;
}
void change(int ch, int node, int st, int en, int l, int r, int val) {
  if (en <= l or r <= st) return;
  if (l <= st and en <= r) {
    data[ch][node] = (en - st) * val;
    flag[ch][node] = val;
    return;
  }
  int mid = (st + en) / 2;
  shift(ch, node, st, en);
  change(ch, node * 2 + 0, st, mid, l, r, val);
  change(ch, node * 2 + 1, mid, en, l, r, val);
  data[ch][node] = data[ch][node * 2] + data[ch][node * 2 + 1];
}
int get(int ch, int node, int st, int en, int l, int r) {
  if (en <= l or r <= st) return 0;
  if (l <= st and en <= r) return data[ch][node];
  int mid = (st + en) / 2;
  shift(ch, node, st, en);
  return get(ch, node * 2 + 0, st, mid, l, r) +
         get(ch, node * 2 + 1, mid, en, l, r);
}
int main() {
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 26; ++j) flag[j][i] = -1;
  cin >> n >> q >> s;
  for (int i = 0; i < n; ++i) change((int)(s[i] - 'a'), 1, 0, n, i, i + 1, 1);
  int type, l, r, now, cnt;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%d", &l, &r, &type);
    l--;
    now = l;
    if (type == 0)
      for (int j = 25; j > -1; --j) {
        cnt = get(j, 1, 0, n, l, r);
        change(j, 1, 0, n, l, r, 0);
        change(j, 1, 0, n, now, now + cnt, 1);
        now += cnt;
      }
    if (type == 1)
      for (int j = 0; j < 26; ++j) {
        cnt = get(j, 1, 0, n, l, r);
        change(j, 1, 0, n, l, r, 0);
        change(j, 1, 0, n, now, now + cnt, 1);
        now += cnt;
      }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      if (get(j, 1, 0, n, i, i + 1) > 0) cout << (char)(j + 'a');
}

```