#include <bits/stdc++.h>
using namespace std;
#include "gift.h"
int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) {
vector<int> p;
for (int i = 0; i < r; i++) if (x[i] == 1) p.push_back(i);
ranges::sort(p, [&](int i, int j) { return a[i] < a[j]; });
vector<pair<int, int> > q;
for (int i: p)
if (q.empty() || q.back().second < a[i]) q.emplace_back(a[i], b[i]);
else q.back().second = max(q.back().second, b[i]);
vector<int> t(n);
for (int i = 0; i < q.size(); i++) {
t[q[i].first] = i % 2 ? 1 : 2;
if (q[i].second != n - 1) t[q[i].second + 1] = -1;
}
for (int i = 1; i < n; i++) if (t[i] == 0) t[i] = t[i - 1];
vector<int> cnt1(n), cnt2(n);
for (int i = 0; i < n; i++) {
if (t[i] == 1) cnt1[i] = 1;
if (t[i] == 2) cnt2[i] = 1;
}
for (int i = 1; i < n; i++) cnt1[i] += cnt1[i - 1], cnt2[i] += cnt2[i - 1];
for (int i = 0; i < r; i++)
if (x[i] == 2 && (cnt1[b[i]] == (a[i] ? cnt1[a[i] - 1] : 0) ||
cnt2[b[i]] == (a[i] ? cnt2[a[i] - 1] : 0)))
return 0;
string ans(n, 'R');
for (int i = 0; i < n; i++) if (t[i] == 2) ans[i] = 'B';
craft(ans);
return 1;
}