malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int two = 0, one = 0;     int x[n + 1000];     for (int i = 0; i < n; ++i) cin >> x[i];     for (int i = 0; i < n; ++i) {       if (x[i] == 2)         ++two;       else         ++one;     }     if (two == 0) {       for (int i = 0; i < one; ++i) cout <<  1  ;     } else if (one == 0) {       for (int i = 0; i < two; ++i) cout <<  2  ;     } else {       --two;       cout <<  2  ;       --one;       cout <<  1  ;       for (int i = 0; i < two; ++i) cout <<  2  ;       for (int i = 0; i < one; ++i) cout <<  1  ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   const int maxn = 3 * (int)1e5 + 5;   int n;   int a[maxn];   int p[maxn];   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       p[a[i]] = i;     }     int q;     cin >> q;     while (q--) {       int tst, x, y;       cin >> tst >> x >> y;       if (tst == 2) {         swap(a[x], a[y]);         p[a[x]] = x;         p[a[y]] = y;       } else {         int ans = 1;         int last = -1;         for (int i = x; i <= y; ++i) {           if (p[i] < last) ++ans;           last = p[i];         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string colors =  ROYGBIV ;     string remainder =  GBIVGB ;     string answer =   ;     for (int i = 0; i < n / 7; ++i) {       answer += colors;     }     for (int i = 0; i < n % 7; ++i) {       answer += remainder[i];     }     cout << answer;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, N = 1e5 + 5;   int n, m, sta[N], tp, tot, siz[N], low[N], dfn[N], be[N], bl, dep[N], f[N][22],       w[N];   vector<int> e[N], vec[N];   int read() {     int x = 0, f = 1;     char s;     while ((s = getchar()) >  9  || s <  0 )       if (s ==  - ) f = -1;     while (s >=  0  && s <=  9 )       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     return x * f;   }   void addEdge(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   void tarjan(int u, int fa) {     sta[++tp] = u;     dfn[u] = low[u] = ++tot;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == fa) continue;       if (!dfn[v])         tarjan(v, u), low[u] = min(low[u], low[v]);       else         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       int v = 0;       ++bl;       do {         v = sta[tp--];         be[v] = bl;         ++siz[bl];       } while (v ^ u);     }   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = 20; i >= 0; --i)       if (dep[f[u][i]] >= dep[v]) u = f[u][i];     if (u == v) return u;     for (int i = 20; i >= 0; --i)       if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   void dfs(int u, int fa) {     dep[u] = dep[fa] + 1;     f[u][0] = fa;     w[u] = w[fa] + (siz[u] > 1);     for (int i = 1; i <= 20; ++i) f[u][i] = f[f[u][i - 1]][i - 1];     for (int i = 0; i < vec[u].size(); ++i)       if (vec[u][i] ^ fa) dfs(vec[u][i], u);   }   int qkpow(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = 1ll * r * x % mod;       x = 1ll * x * x % mod;       y >>= 1;     }     return r;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; ++i) addEdge(read(), read());     tarjan(1, 0);     for (int i = 1; i <= n; ++i)       for (int j = 0; j < e[i].size(); ++j)         if (be[i] ^ be[e[i][j]]) vec[be[i]].push_back(be[e[i][j]]);     dfs(1, 0);     int u, v;     for (int t = read(); t; --t) {       u = be[read()], v = be[read()];       int lca = LCA(u, v);       printf( %d n , qkpow(2, w[u] + w[v] - w[lca] * 2 + (siz[lca] > 1)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const long long INF = 1e18 + 5;   const long long maxn = 5e5 + 5;   long long n = 100000000000, a[1555555], d[555555], mx = -1000000001;   long long u[1511111], b[1100005], sum, cnt, t[555555];   long long bi(long long x, long long y) {     if (y == 0) return 1ll;     if (y == 1) return x;     long long z = bi(x, y / 2);     z = z * z % n;     if (y & 1) z = z * x % n;     return z % n;   }   pair<int, int> p[555555];   vector<pair<int, int> > v, x;   int c[555555], l[555555], y[555555], k[555555];   long long dp[555555][3][3];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     int n, x;     cin >> n >> x;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++)       for (int j = 0; j <= 2; j++)         for (int k = 0; k <= 2; k++) dp[i][j][k] = -1e15;     dp[0][0][0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= 2; j++)         for (int k = 0; k <= 2; k++) {           if (j > 0) dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);           if (k > 0) dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1]);           dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + (j == 1 ? a[i] : 0) *                                                                (k == 1 ? x : 1));         }     cout << dp[n][2][2];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi =       3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862;   void gn(int &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     if (c ==  - )       sg = -1, x = 0;     else       x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   void gn(long long &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     if (c ==  - )       sg = -1, x = 0;     else       x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   int mo = 1000000007;   int inf = 1061109567;   double eps = 1e-6;   int qp(int a, long long b) {     int ans = 1;     do {       if (b & 1) ans = 1ll * ans * a % mo;       a = 1ll * a * a % mo;     } while (b >>= 1);     return ans;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int a[333];   int n;   void out(int i, int t) {     for (int j = 0; j < t; j++) putchar(i - 1 +  a );   }   int ord[333];   int main() {     gn(n);     for (int i = 1; i <= n; i++) gn(a[i]);     int su = 0;     int numodd = 0;     for (int i = 1; i <= n; i++) numodd += a[i] & 1, su += a[i];     if (numodd > 1) {       printf( 0 n );       for (int i = 1; i <= n; i++) out(i, a[i]);       putchar(  n );       return 0;     }     int d = 0;     for (int i = 1; i <= n; i++) d = gcd(d, a[i]);     int no1 = 0;     for (int i = 1; i <= n; i++) no1 += (a[i] / d) & 1;     if (no1 > 1 && d % 2 == 0) d /= 2, no1 = 0;     for (int i = 1; i <= n; i++) a[i] /= d;     for (int i = 1; i <= n; i++) ord[i] = i;     for (int i = 1; i <= n; i++)       if (a[i] & 1) swap(ord[i], ord[n]);     if (no1) {       printf( %d n , d);     } else       printf( %d n , d * 2);     for (int tt = 1; tt <= d; tt++) {       for (int i = 1; i <= n - 1; i++) {         out(ord[i], a[ord[i]] / 2);       }       out(ord[n], a[ord[n]]);       for (int i = n - 1; i >= 1; i--) {         out(ord[i], a[ord[i]] / 2);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   int bt(int x) { return 31 - __builtin_clz(x); }   int bt(long long x) { return 63 - __builtin_clzll(x); }   int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }   long long cdiv(long long a, long long b) {     return a / b + !(a < 0 || a % b == 0);   }   int nxt_C(int x) {     int c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   long long nxt_C(long long x) {     long long c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   vector<int> get_bits(int mask) {     vector<int> bb;     while (mask) {       int b = bt(mask);       bb.push_back(b);       mask ^= (1 << b);     }     reverse(bb.begin(), bb.end());     return bb;   }   int get_mask(vector<int> v) {     int mask = 0;     for (int x : v) {       mask ^= (1 << x);     }     return mask;   }   template <typename T>   void uniq(vector<T> &v) {     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long l, long long r) {     uniform_int_distribution<long long> uid(l, r);     return uid(rng);   }   void sc() {}   template <typename Head, typename... Tail>   void sc(Head &H, Tail &...T) {     cin >> H;     sc(T...);   }   const int mod = 1e9 + 7;   int pwr(int a, long long b) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * 1LL * a) % mod;       a = (a * 1LL * a) % mod;       b >>= 1;     }     return ans;   }   const int N = 1005;   vector<int> s[N];   int in[N];   int query(vector<int> v) {     cout <<  ?   << (int)v.size() <<    ;     for (int x : v) {       cout << x <<    ;     }     cout << endl;     int y;     sc(y);     return y;   }   int go(int l, int r, int maxi) {     if (l == r) return l;     int m = (l + r) >> 1;     vector<int> v;     for (int i = l; i <= m; i++) {       v.push_back(i);     }     int q = query(v);     if (q == maxi) {       return go(l, m, maxi);     } else {       return go(m + 1, r, maxi);     }   }   void solve() {     memset(in, 0, sizeof in);     int n, k;     sc(n, k);     for (int i = 1; i <= k; i++) {       s[i].clear();       int c;       sc(c);       for (int j = 1; j <= c; j++) {         int x;         sc(x);         s[i].push_back(x);         in[x] = i;       }     }     vector<int> v;     for (int i = 1; i <= n; i++) {       v.push_back(i);     }     int maxi = query(v);     int idx = go(1, n, maxi);     int kk = in[idx];     v.clear();     for (int i = 1; i <= n; i++) {       if (in[i] != kk) v.push_back(i);     }     int z = query(v);     cout <<  !  ;     for (int i = 1; i <= k; i++) {       if (i == kk) {         cout << z <<    ;       } else {         cout << maxi <<    ;       }     }     cout << endl;     string s;     sc(s);     if (s ==  Incorrect ) {       exit(0);     }   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     for (int tt = 1; tt <= t; tt++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct number {     long long sum, a, b;     bool operator<(const number& in) const { return sum < in.sum; }     bool operator>(const number& in) const { return sum > in.sum; }   };   vector<number> v;   const long long MN = 2000 + 1;   long long a[MN], b[MN];   long long n, m, suma, sumb;   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       suma += a[i];     }     cin >> m;     for (long long j = 0; j < m; j++) {       cin >> b[j];       sumb += b[j];     }     for (long long i = 0; i < m; i++)       for (long long j = i + 1; j < m; j++) {         number temp;         temp.a = i;         temp.b = j;         temp.sum = 2 * (b[i] + b[j]);         v.push_back(temp);       }     sort(v.begin(), v.end());     long long best = abs(suma - sumb), in1 = -1, in2, in3 = -1;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++)         if (best > abs(suma - sumb - a[i] - a[i] + b[j] + b[j])) {           best = abs(suma - sumb - a[i] - a[i] + b[j] + b[j]);           in1 = i;           in2 = j;         }     if (m > 1 && n > 1) {       for (long long i = 0; i < n; i++)         for (long long j = i + 1; j < n; j++) {           long long want = suma - sumb - a[i] - a[j] - a[i] - a[j];           want *= -1;           vector<number>::iterator low, up;           number temp;           temp.sum = want;           low = std::lower_bound(v.begin(), v.end(), temp);           up = upper_bound(v.begin(), v.end(), temp);           if (low >= v.begin() && low < v.end())             if (best > abs(want - v[low - v.begin()].sum)) {               best = abs(want - v[low - v.begin()].sum);               in1 = i;               in2 = j;               in3 = low - v.begin();             }           while (up >= v.end()) up--;           if (best > abs(want - v[up - v.begin()].sum)) {             best = abs(want - v[up - v.begin()].sum);             in1 = i;             in2 = j;             in3 = up - v.begin();           }         }     }     if (in1 == -1) {       cout << best << endl << 0 << endl;       return 0;     }     if (in3 == -1) {       cout << best << endl << 1 << endl << in1 + 1 <<     << in2 + 1 << endl;       return 0;     }     cout << best << endl;     cout << 2 << endl;     cout << in1 + 1 <<     << v[in3].a + 1 << endl;     cout << in2 + 1 <<     << v[in3].b + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int xx[4] = {1, -1, 0, 0};   const int yy[4] = {0, 0, 1, -1};   int inline nextin() {     int t;     if (scanf( %d , &t) != 1) exit(0);     return t;   }   int inline in() {     int x = 0, c;     for (; (unsigned)((c = getchar()) -  0 ) >= 10;) {       if (c ==  - ) return -in();       if (!~c) throw ~0;     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while ((unsigned)((c = getchar()) -  0 ) < 10);     return x;   }   int n, k;   string s[10005];   map<int, int> m;   int rhyme(int pos) {     string a = s[pos].substr(m[pos], ((int)(s[pos]).size()) - m[pos]);     string b =         s[pos + 1].substr(m[pos + 1], ((int)(s[pos + 1]).size()) - m[pos + 1]);     string c =         s[pos + 2].substr(m[pos + 2], ((int)(s[pos + 2]).size()) - m[pos + 2]);     string d =         s[pos + 3].substr(m[pos + 3], ((int)(s[pos + 3]).size()) - m[pos + 3]);     if (a == b && b == c && c == d) return 0;     if (a == b && c == d) return 1;     if (a == c && b == d) return 2;     if (a == d && b == c) return 3;     return -1;   }   const string ans[4] = { aaaa ,  aabb ,  abab ,  abba };   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < (4 * n); i++) cin >> s[i];     for (int i = 0; i < (4 * n); i++) {       int cnt = 0;       bool ok = false;       for (int j = ((int)(s[i]).size()) - 1; j >= 0; j--) {         if (s[i][j] ==  a  || s[i][j] ==  e  || s[i][j] ==  i  ||             s[i][j] ==  o  || s[i][j] ==  u )           cnt++;         if (cnt == k) {           m[i] = j;           ok = true;           break;         }       }       if (!ok) {         puts( NO );         return 0;       }     }     set<int> Set;     for (int i = 0; i < (n); i++) {       Set.insert(rhyme(i * 4));     }     set<int>::iterator it = Set.begin();     if (*it == -1)       puts( NO );     else if (((int)(Set).size()) >= 3)       puts( NO );     else if (((int)(Set).size()) == 2) {       if (*it == 0) {         it++;         cout << ans[*it] << endl;       } else         puts( NO );     } else       cout << ans[*it] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[500500], b[500500];   int main() {     int n, q;     int p1 = 1;     int p2 = 1;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       if (i % 2)         a[i / 2 + 1] = i;       else         b[i / 2] = i;     }     int tt = 0;     for (int i = 0; i < q; i++) {       int tp;       scanf( %d , &tp);       if (tp == 2) {         tt = 1 - tt;         swap(p1, p2);       }       if (tp == 1) {         int x;         scanf( %d , &x);         if (x % 2 == 0) {           p1 = (p1 - (x / 2) + (n / 2) - 1) % (n / 2) + 1;           p2 = (p2 - (x / 2) + (n / 2) - 1) % (n / 2) + 1;         } else {           x--;           p1 = (p1 - (x / 2) + (n / 2) - 1) % (n / 2) + 1;           p2 = (p2 - (x / 2) + (n / 2) - 1) % (n / 2) + 1;           tt = 1 - tt;           swap(p1, p2);           p1 = (p1 - 1 + (n / 2) - 1) % (n / 2) + 1;         }       }     }     if (tt) swap(a, b);     for (int i = 0; i < n / 2; i++) {       printf( %d %d  , a[p1], b[p2]);       p1++;       p2++;       if (p1 > n / 2) p1 = 1;       if (p2 > n / 2) p2 = 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   namespace number_theory {   long long gcd(long long x, long long y) {     if (x == 0) return y;     if (y == 0) return x;     return gcd(y, x % y);   }   bool isprime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool prime[15000105];   void sieve(long long n) {     for (long long i = 0; i <= n; i++) prime[i] = 1;     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     prime[1] = prime[0] = 0;   }   vector<long long> primelist;   bool __primes_generated__ = 0;   void genprimes(long long n) {     __primes_generated__ = 1;     sieve(n + 1);     for (long long i = 2; i <= n; i++)       if (prime[i]) primelist.push_back(i);   }   vector<long long> factors(long long n) {     if (!__primes_generated__) {       cerr <<  Caint genprimes you dope  << endl;       exit(1);     }     vector<long long> facs;     for (long long i = 0;          primelist[i] * primelist[i] <= n && i < primelist.size(); i++) {       if (n % primelist[i] == 0) {         while (n % primelist[i] == 0) {           n /= primelist[i];           facs.push_back(primelist[i]);         }       }     }     if (n > 1) {       facs.push_back(n);     }     sort(facs.begin(), facs.end());     return facs;   }   vector<long long> getdivs(long long n) {     vector<long long> divs;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         divs.push_back(i);         divs.push_back(n / i);       }     }     {       sort(divs.begin(), divs.end());       divs.erase(unique(divs.begin(), divs.end()), divs.end());     };     return divs;   }   }  // namespace number_theory   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long win = 0, loss = 0, winning_streak_cnt = 0;     vector<long long> lossing_streak;     for (long long i = 0; i < n; i++) {       if (s[i] ==  W ) {         win++;         if (i == 0 or s[i - 1] ==  L ) winning_streak_cnt++;       } else {         loss++;         if (i == 0 or s[i - 1] ==  W ) lossing_streak.push_back(0);         lossing_streak.back()++;       }     }     if (k >= loss) {       cout << 2 * n - 1 <<   n ;       return;     }     if (win == 0) {       if (k == 0)         cout << 0;       else         cout << 2 * k - 1;       cout <<   n ;       return;     }     win += k;     if (s[0] ==  L ) lossing_streak[0] = 1e8;     if (s[n - 1] ==  L ) lossing_streak.back() = 1e8;     sort(lossing_streak.begin(), lossing_streak.end());     for (long long ls : lossing_streak) {       if (ls > k) break;       k -= ls;       winning_streak_cnt--;     }     cout << 2 * win - winning_streak_cnt <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   int main(int argc, char **argv) {     ifstream from;     const int nmin = 2, nmax = 300, kmin = 1, kmax = 300;     int n, rt, rt1, rt2, i, j, j0, j1, k;     int err = 0;     char ch;     cin >> n;     vector<vector<int>> d(n);     for (i = 0; i < n; i++) d[i].resize(n);     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> d[i][j];       }     }     cin >> k;     vector<int> a(k);     vector<int> b(k);     vector<int> c(k);     for (i = 0; i < k; i++) {       cin >> a[i] >> b[i] >> c[i];       a[i]--;       b[i]--;     }     vector<long long> q(k);     for (i = 0; i < k; i++) {       if (d[a[i]][b[i]] > c[i]) {         d[a[i]][b[i]] = c[i];         d[b[i]][a[i]] = c[i];       }       q[i] = 0;       for (j0 = 0; j0 < n - 1; j0++) {         for (j1 = j0 + 1; j1 < n; j1++) {           rt1 = d[j0][a[i]] + d[a[i]][b[i]] + d[b[i]][j1];           rt2 = d[j0][b[i]] + d[a[i]][b[i]] + d[a[i]][j1];           rt = (rt1 < rt2) ? rt1 : rt2;           if (rt < d[j0][j1]) {             d[j0][j1] = rt;             d[j1][j0] = rt;           }           q[i] += d[j0][j1];         }       }     }     for (i = 0; i < k - 1; i++) {       cout << q[i] <<    ;     }     cout << q[k - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j, k, l, sum = 0, flag = 0, t, a[200005], ans = 0;   vector<int> tree[800005];   void build(int node, int low, int high) {     if (low == high) {       tree[node].push_back(a[low]);       return;     }     int mid = (low + high) / 2;     build(2 * node, low, mid);     build(2 * node + 1, mid + 1, high);     merge((tree[2 * node]).begin(), (tree[2 * node]).end(),           (tree[2 * node + 1]).begin(), (tree[2 * node + 1]).end(),           back_inserter(tree[node]));     return;   }   int query(int node, int low, int high, int l, int r, int val) {     if (l > r) return 0;     if (low > r || high < l) return 0;     if (l <= low && high <= r)       return tree[node].end() -              lower_bound((tree[node]).begin(), (tree[node]).end(), val);     int mid = (low + high) / 2;     return query(2 * node, low, mid, l, r, val) +            query(2 * node + 1, mid + 1, high, l, r, val);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     for (i = 1; i <= n; i++) {       ans += query(1, 1, n, i + 1, min(a[i], n), i);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const long long mod = 1e9 + 7;   class matrix {    public:     vector<vector<long long> > v;     matrix() { v = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; }     vector<long long>& operator[](long long loc) { return v[loc]; }   };   matrix mult(matrix a, matrix b) {     matrix c;     for (long long i = 0; i < 3; i++)       for (long long j = 0; j < 3; j++) {         c.v[i][j] = 0;         for (long long k = 0; k < 3; k++)           c.v[i][j] = (c.v[i][j] + a.v[i][k] * b.v[k][j]) % mod;       }     return c;   }   matrix power(matrix base, long long expo) {     matrix ans;     while (expo) {       if (expo & 1) {         ans = mult(base, ans);       }       base = mult(base, base);       expo = expo >> 1;     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> b(4, 0);     vector<pair<pair<long long, long long>, long long> > v(n);     multiset<pair<long long, long long> > s;     for (long long i = 0; i < n; i++) {       cin >> v[i].second >> v[i].first.first >> v[i].first.second;       s.insert({v[i].first.first, v[i].second});       s.insert({v[i].first.second + 1, -v[i].second});     }     long long prev = 1;     matrix ans, c;     c[0] = {1, 1, 0};     c[1] = {1, 1, 1};     c[2] = {0, 1, 1};     for (auto& i : s) {       long long loc = abs(i.second);       long long curr = i.first - 1;       if (curr > prev) {         ans = mult(power(c, curr - prev), ans);         prev = curr;       }       long long val = i.second / loc;       loc--;       b[loc] += val;       if (b[loc] <= 0) {         c[loc] = {loc != 2, 1, loc != 0};       } else {         c[loc] = {0, 0, 0};       }     }     ans = mult(power(c, m - prev), ans);     cout << ans[1][1];     return 0;   }