malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   int n;   int a[200010];   vector<int> B[200010];   void add(int u, int val) {     for (; u <= n; u += u & -u) B[u].push_back(val);   }   int calc(int u, int val) {     int ans = 0;     for (; u; u -= u & -u) {       int id = lower_bound(B[u].begin(), B[u].end(), val) - B[u].begin();       ans += B[u].size() - id;     }     return ans;   }   int calc(int l, int r, int val) {     if (l > r) return 0;     return calc(r, val) - calc(l - 1, val);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) add(i, min(a[i], n));     for (int i = 1; i <= n; i++) sort(B[i].begin(), B[i].end());     INT ans = 0;     for (int i = 1; i < n; i++) {       ans += calc(i + 1, min(n, a[i]), i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   bool a[maxn];   int main() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       int p = (n - k) / 2 + 1;       int t = n / p;       while (t--) {         for (int i = 0; i < p; i++) {           if (i == p - 1)             printf( 0 );           else             printf( 1 );         }       }       for (int i = 0; i < n % p; i++) printf( 1 );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int o = 0;       int z = 0;       for (int i = 0; i < n; i++) {         int y;         cin >> y;         if (y == 1)           o++;         else           z++;       }       if (z == o) {         cout << n / 2 <<   n ;         for (int i = 1; i <= n / 2; i++) cout <<  0  ;       } else if (z > o) {         cout << n / 2 <<   n ;         for (int i = 1; i <= n / 2; i++) cout <<  0  ;       } else {         int y = n / 2;         if (y % 2 == 0) {           cout << y <<   n ;           for (int i = 0; i < y; i++) cout <<  1  ;         } else {           cout << (y + 1) <<   n ;           for (int i = 0; i < y + 1; i++)             cout <<  1                   <<    ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x, i, w[100005], sum;   int main() {     cin >> n >> x;     for (i = 1; i <= n; i++) {       cin >> w[i];       sum = sum + w[i];     }     if (sum + n - 1 == x)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, A, B, a[200006];   long long ask(int l, int r) {     long long ans;     int mid = (l + r) / 2,         num = upper_bound(a + 1, a + k + 1, r) - lower_bound(a + 1, a + k + 1, l);     if (num == 0)       return A;     else       ans = 1LL * B * num * (r - l + 1);     return r - l ? min(ans, ask(l, mid) + ask(mid + 1, r)) : ans;   }   int main() {     scanf( %d%d%d%d , &n, &k, &A, &B);     for (int i = 1; i <= k; i++) scanf( %d , &a[i]);     sort(a + 1, a + k + 1);     printf( %lld n , ask(1, 1 << n));   }
#include <bits/stdc++.h>   const int M = 1e5 + 5;   int len;   long long lsh[M * 3];   int n, m, k, p, t[M], v[M], nxt[M], pre[M];   long long CB[M * 3];   long long now, val[M], ans[M];   struct Query {     int L, R, p, id;     inline bool operator<(const Query& it) const {       return p == it.p ? p & 1 ? R < it.R : R > it.R : L < it.L;     }   } q[M];   inline void Add(const int& id, const int& to) {     now += CB[to];     ++CB[v[id]];   }   inline void Del(const int& id, const int& to) {     --CB[v[id]];     now -= CB[to];   }   signed main() {     register int i, L = 1, R = 0;     scanf( %d%d , &n, &k);     lsh[++len] = 0;     lsh[++len] = k;     lsh[++len] = -k;     for (i = 1; i <= n; ++i) scanf( %d , t + i);     for (i = 1; i <= n; ++i) {       scanf( %lld , val + i);       if (t[i] == 1)         val[i] = val[i - 1] + val[i];       else         val[i] = val[i - 1] - val[i];       lsh[++len] = val[i];       lsh[++len] = val[i] - k;       lsh[++len] = val[i] + k;     }     std::sort(lsh + 1, lsh + len + 1);     len = std::unique(lsh + 1, lsh + len + 1) - lsh - 1;     for (i = 0; i <= n; ++i) {       v[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i]) - lsh;       pre[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i] - k) - lsh;       nxt[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i] + k) - lsh;     }     scanf( %d , &m);     p = ceil(n / sqrt(m * 2.0 / 3));     for (i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].L, &q[i].R);       --q[i].L;       q[i].id = i;       q[i].p = q[i].L / p;     }     std::sort(q + 1, q + m + 1);     for (i = 1; i <= m; ++i) {       const int &QL = q[i].L, &QR = q[i].R;       while (R < QR) ++R, Add(R, pre[R]);       while (L > QL) --L, Add(L, nxt[L]);       while (L < QL) Del(L, nxt[L]), ++L;       while (R > QR) Del(R, pre[R]), --R;       ans[q[i].id] = now;     }     for (i = 1; i <= m; ++i) printf( %lld n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, d[200], g[200][200], dp[200][200], ans[200];   int cnt, st[200], ed[200];   bool flag[200];   void dfs1(int u) {     flag[u] = true;     st[u] = ++cnt;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) dfs1(i);     ed[u] = ++cnt;   }   void dfs2(int u) {     flag[u] = true;     for (int i = 1; i <= n; i++)       if (i ^ u) dp[u][i] = d[g[u][i]];     dp[u][u] = m;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) {         dfs2(i);         for (int j = 1; j <= n; j++)           if (st[i] <= st[j] && ed[j] <= ed[i])             dp[u][j] += dp[i][j];           else             dp[u][j] += min(dp[i][j], dp[i][dp[i][0]]);       }     dp[u][0] = u;     for (int i = 1; i <= n; i++)       if (st[u] <= st[i] && ed[i] <= ed[u] && dp[u][i] < dp[u][dp[u][0]])         dp[u][0] = i;   }   void dfs3(int u) {     flag[u] = true;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) {         if (st[i] <= st[ans[u]] && ed[ans[u]] <= ed[i])           ans[i] = ans[u];         else if (dp[i][ans[u]] < dp[i][dp[i][0]])           ans[i] = ans[u];         else           ans[i] = dp[i][0];         dfs3(i);       }   }   void solve() {     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);     memset(flag, false, sizeof(flag));     cnt = 0;     dfs1(1);     memset(flag, false, sizeof(flag));     dfs2(1);     ans[1] = dp[1][0];     memset(flag, false, sizeof(flag));     dfs3(1);     printf( %d n , dp[1][dp[1][0]]);     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i < n ?     :   n );   }   int main() {     int u, v;     while (scanf( %d%d , &n, &m) == 2) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) g[i][j] = 1000000000;       for (int i = 1; i < n; i++) scanf( %d , d + i);       for (int i = 1; i < n; i++) {         scanf( %d%d , &u, &v);         g[u][v] = g[v][u] = 1;       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, minn = 10000, a[1000], temp = 0;     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= k && a[i] != 0) {         temp = abs(i + 1 - m) * 10;         if (temp < minn) minn = temp;       }     }     cout << minn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gi() {     int a;     scanf( %d , &a);     return a;   }   long long gli() {     long long a;     scanf( %I64d , &a);     return a;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b) return gcd(a % b, b);     return gcd(b % a, a);   }   int pr[1000000];   int main() {     unordered_map<long long, vector<pair<long long, long long> > > m;     unordered_map<long long, vector<pair<long long, long long> > >::iterator it;     int n = gi();     for (int i = 0; i < n; i++) {       long long x = gli();       long long y = gli();       long long c = gli();       m[x].push_back(make_pair(y, c));     }     vector<pair<long long, long long> > main;     int L = 0;     long long gg = 0;     int first = 1;     for (it = m.begin(); it != m.end(); it++) {       vector<pair<long long, long long> > &v = it->second;       sort(v.begin(), v.end());       if (first) {         first = 0;         L = v.size();         long long g = 0;         for (int i = 0; i < L; i++) g = gcd(g, v[i].second);         for (int i = 0; i < L; i++)           main.push_back(make_pair(v[i].first, v[i].second / g));       } else {         if (int(v.size()) != L || v[0].first != main[0].first ||             v[0].second % main[0].second != 0) {           printf( 0 n );           return 0;         }         long long f = v[0].second / main[0].second;         for (int i = 1; i < L; i++)           if (v[i].first != main[i].first || v[i].second % main[i].second != 0 ||               v[i].second / main[i].second != f) {             printf( 0 n );             return 0;           }       }       gg = gcd(gg, v[0].second);     }     m.clear();     long long g = 0;     for (int i = 0; i < L; i++) g = gcd(g, main[i].second);     g *= gg / main[0].second;     memset(pr, -1, sizeof(pr));     long long r = 1;     long long c = 1;     while (g % 2 == 0) {       c++;       g /= 2;     }     r *= c;     for (int i = 3; i < 1000000; i += 2)       if (pr[i]) {         for (int j = i * 3; j < 1000000; j += i * 2) pr[i] = 0;         long long c = 1;         while (g % i == 0) {           c++;           g /= i;         }         r *= c;       }     if (g > 1LL) r *= 2;     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const unsigned long long M = 1000000009LL;   const int K = 3;   const int LIT = 2500;   const int INF = 1 << 30;   const double eps = 1e-6;   const unsigned long long MOD = 1000000007LL;   const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   unsigned long long n, m;   unsigned long long pw2[N] = {0};   void init() {     pw2[0] = 1;     for (int i = 1; i < N; i++) {       pw2[i] = pw2[i - 1] * 2;     }   }   int getCP(int n, int m) {     if (n == 3 && m == 1) return -1;     if (n == 3 && m == 2) return -2;     unsigned long long tot = pw2[n - 2];     unsigned long long mid = pw2[n - 3];     if (m > mid) {       return getCP(n, m - mid) - 1;     } else {       return getCP(n - 1, m);     }   }   vector<unsigned long long> getP(unsigned long long n, unsigned long long m) {     vector<unsigned long long> ans;     if (n == 1) {       ans.push_back(1);       return ans;     }     if (n == 2) {       if (m == 1) {         ans.push_back(1);         ans.push_back(2);       }       if (m == 2) {         ans.push_back(2);         ans.push_back(1);       }       return ans;     }     unsigned long long tot = pw2[n - 1];     unsigned long long mid = pw2[n - 2];     if (m > mid) {       ans = getP(n, tot + 1 - m);       reverse(ans.begin(), ans.end());       return ans;     }     vector<unsigned long long> pre = getP(n - 1, (m + 1) / 2);     int cp = n + getCP(n, m);     for (int i = 0; i < cp; i++) {       ans.push_back(pre[i]);     }     ans.push_back(n);     for (int i = cp; i < n - 1; i++) {       ans.push_back(pre[i]);     }     return ans;   }   void solve() {     vector<unsigned long long> ans = getP(n, m);     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     int T;     while (cin >> n >> m) {       init();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int th[100080], bl[100080];   int main() {     int i, j, n, k, mx = 0, sum, fl, fval;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) {       scanf( %d , &th[i]);     }     for (i = 0; i < n; i++) {       scanf( %d , &bl[i]);     }     j = 0;     i = 0;     sum = 0;     fl = 0;     fval = th[0];     while (j < n) {       while (i < k && j < n) {         if (bl[j] == 0) sum += th[j];         i++;         j++;       }       if (i == k && j <= n) {         if (sum > mx) mx = sum;         fl++;         if (bl[fl - 1] == 0) sum -= fval;         fval = th[fl];         i--;       }     }     for (i = 0; i < n; i++) {       if (bl[i] == 1) mx += th[i];     }     printf( %d , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Solve(long long n, long long k) {     long long low = 1;     long long high = ((long long)1 << n) - 1;     long long mid = low + (high - low) / 2;     if (mid == k)       return n;     else if (mid < k)       return Solve(n - 1, k - mid);     else       return Solve(n - 1, k);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     cout << Solve(n, k) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= 2 * n / 3; i++) printf( %d %d n , i, 1);     for (int i = 1; i <= n - 2 * n / 3; i++) printf( %d %d n , i * 2, 4);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200;   long long n, num[N], tmp;   int main() {     cin >> n;     for (int i = 0, v; i < n; i++) cin >> v, num[v]++;     for (int i = 1; i <= 100; i++) {       for (int j = 1; j < i; j++)         tmp = max(0ll, min(num[0] - num[j], num[i])), num[j] += tmp,         num[i] -= tmp;       tmp = num[i] - num[0];       int k = tmp % (i + 1);       tmp = tmp / (i + 1);       if (tmp > 0 || k > 0)         for (int j = 0; j <= i; j++) {           num[j] += tmp, num[i] -= tmp;           if (j < k) num[j]++, num[i]--;         }     }     cout << num[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     a[0] = 1;     a[1] = 5;     a[2] = 13;     a[3] = 25;     for (int i = 4; i < n; i++) {       a[i] = a[i - 1] + 4 * (i);     }     cout << a[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   class Matrix {    public:     long long m[4][4];     Matrix(){};     Matrix(long long k[4][4]) {       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++) m[i][j] = k[i][j];     }   };   Matrix operator*(const Matrix &a, const Matrix &b) {     Matrix t;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         t.m[i][j] = 0;         for (int c = 0; c < 4; c++) {           t.m[i][j] += (b.m[i][c]) * (a.m[c][j]);           t.m[i][j] %= MOD;         }       }     }     return t;   }   Matrix pow(Matrix m, int p) {     if (p == 1) return m;     Matrix ret = pow(m, p / 2);     if (p & 1) {       return (ret * ret) * m;     } else       return (ret * ret);   }   int main() {     int n;     long long arr[4][4];     scanf( %d , &n);     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++)         if (i == j)           arr[i][j] = 0;         else           arr[i][j] = 1;     Matrix g(arr);     Matrix ret = pow(g, n);     cout << ret.m[3][3] % MOD << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, deg[N], fa[N];   int root = 0;   vector<pair<pair<int, int>, int> > ans;   struct edge {     int to, val;     edge() {}     edge(int to, int val) : to(to), val(val) {}   };   vector<edge> G[N];   vector<int> leaf[N];   void add_edge(int x, int y, int z) { G[x].push_back(edge(y, z)); }   void init() {     scanf( %d , &n);     int x, y, z;     if (n == 2) {       scanf( %d%d%d , &x, &y, &z);       printf( YES n1 n1 2 %d n , z);       exit(0);     }     for (int i = 1; i < n; ++i) {       scanf( %d%d%d , &x, &y, &z);       add_edge(x, y, z);       add_edge(y, x, z);       ++deg[x], ++deg[y];     }   }   void pre(int x, int f) {     fa[x] = f;     for (int i = 0; i < (int)G[x].size(); ++i) {       int to = G[x][i].to, w = G[x][i].val;       if (to == f) continue;       pre(to, x);       leaf[x].push_back(leaf[to][0]);     }     if (G[x].size() == 1) {       leaf[x].push_back(x);     }   }   void add_to_root(int x, int val) {     if (leaf[x].size() >= 2) {       int f1 = leaf[x][0], f2 = leaf[x][1];       ans.push_back(make_pair(make_pair(root, f1), val / 2));       ans.push_back(make_pair(make_pair(root, f2), val / 2));       ans.push_back(make_pair(make_pair(f1, f2), -val / 2));     } else {       ans.push_back(make_pair(make_pair(root, x), val));     }   }   void dfs(int x, int f) {     for (int i = 0; i < (int)G[x].size(); ++i) {       int to = G[x][i].to, w = G[x][i].val;       if (to == f) continue;       dfs(to, x);       add_to_root(to, w);       if (x != root) add_to_root(x, -w);     }   }   void solve() {     int flag = 1;     for (int i = 1; i <= n; ++i) {       if (deg[i] == 2) {         puts( NO );         return;       }     }     puts( YES );     for (int i = 1; i <= n; ++i) {       if (G[i].size() == 1) {         root = i;         break;       }     }     pre(root, 0);     dfs(root, 0);     printf( %d n , ans.size());     for (int i = 0; i < (int)ans.size(); ++i) {       printf( %d %d %d n , ans[i].first.first, ans[i].first.second,              ans[i].second);     }   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int mc = 0, i = 1, j = n;     while (1) {       cout << i <<    ;       mc++;       if (mc == n) break;       cout << j <<    ;       i++;       j--;       mc++;       if (mc == n) break;     }     cout << endl;     return 0;   }
#include <iostream>   #include <sstream>   #include <cstdio>   #include <cmath>   #include <cstring>   #include <cctype>   #include <string>   #include <vector>   #include <set>   #include <unordered_set>   #include <map>   #include <unordered_map>   #include <queue>   #include <stack>   #include <algorithm>   #include <functional>   #include <climits>   #include <iterator>   #include <numeric>   #include <memory>      #define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)      using namespace std;   typedef long long int ll;   typedef pair<int,int> pii;   typedef vector<int> vi;      int main()   {       IOS;       int t, n;       cin>>t;       while(t--) {           cin>>n;           vector<int> p(n), maxP(n);           cin>>p[0];           maxP[0]=p[0];           for(int i=1; i<n; i++) {               cin>>p[i];               maxP[i]=max(maxP[i-1], p[i]);           }           int r=n-1, l=n-1;           while(l>=0) {               while(l>=0 && maxP[r]!=p[l]) {                   l--;               }               for(int i=l; i<=r; i++) {                   cout<<p[i]<<   ;               }               l--;               r=l;           }           cout<<  n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     long long p1 = 0;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       a[i] = x;       p1 = max(p1, x);     }     long long m;     cin >> m;     vector<pair<long long, long long> > b(m);     long long p2 = 0;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       b[i].first = x;       b[i].second = y;       p2 = max(p2, x);     }     if (p2 < p1) {       cout << -1 <<   n ;       return;     }     sort(b.begin(), b.end());     for (long long i = m - 2; i >= 0; i--) {       b[i].second = max(b[i].second, b[i + 1].second);     }     long long mx = 0;     long long cnt = -1;     long long ans = 0;     long long q = -1;     for (long long i = 0; i < n; i++) {       mx = max(mx, a[i]);       long long j = lower_bound(b.begin(), b.end(), make_pair(mx, q)) - b.begin();       if (b[j].second < i - cnt) {         ans++;         mx = 0;         i--;         cnt = i;       }     }     ans++;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long TESTS = 1;     cin >> TESTS;     while (TESTS--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 1e6;   int n;   int p[N];   int division[2][N];   int dln[2];   bool u[N];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;     }     int index1 = -1, index2 = -1;     for (int i = 0; i < n; i++) {       if (p[i] == i) index1 = i;       if (p[p[i]] == i) index2 = i;     }     if (index1 != -1) {       puts( YES );       for (int i = 0; i < n; i++)         if (index1 != i) printf( %d %d n , index1 + 1, i + 1);       return 0;     }     if (index2 != -1) {       bool flag = true;       dln[0] = dln[1] = 0;       fill_n(u, n, 0);       u[index2] = u[p[index2]] = 1;       for (int i = 0; i < n; i++)         if (!u[i]) {           u[i] = 1;           division[0][dln[0]++] = i;           int curI = p[i], step = 1;           while (curI != i) {             u[curI] = 1;             division[step][dln[step]++] = curI;             step ^= 1;             curI = p[curI];           }           if (step == 1) {             flag = false;             break;           }         }       if (!flag) {         puts( NO );         return 0;       }       puts( YES );       printf( %d %d n , index2 + 1, p[index2] + 1);       for (int i = 0; i < dln[0]; i++)         printf( %d %d n , index2 + 1, division[0][i] + 1);       for (int i = 0; i < dln[1]; i++)         printf( %d %d n , p[index2] + 1, division[1][i] + 1);       return 0;     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h;     cin >> n;     int a[n];     cin >> a[0];     h = a[0];     for (int i = 1; i < n; i++) {       cin >> a[i];       h = h + abs(a[i] - a[i - 1]) + 1;     }     cout << h + n;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-8;   const double PI = acos(-1);   template <class T, class S>   inline void add(T& a, S b) {     a += b;     if (a >= mod) a -= mod;   }   template <class T, class S>   inline void sub(T& a, S b) {     a -= b;     if (a < 0) a += mod;   }   template <class T, class S>   inline bool chkmax(T& a, S b) {     return a < b ? a = b, true : false;   }   template <class T, class S>   inline bool chkmin(T& a, S b) {     return a > b ? a = b, true : false;   }   int n, k, v, sum, now1, now2, a[N];   bool dp[N][N];   bool f[N][N];   vector<int> vc[2];   int main() {     scanf( %d%d%d , &n, &k, &v);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (sum < v) return puts( NO ), 0;     dp[0][0] = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         if (!dp[i][j]) continue;         dp[i + 1][(j + a[i + 1]) % k] = true;         f[i + 1][(j + a[i + 1]) % k] = true;         dp[i + 1][j] = true;         f[i + 1][j] = false;       }     }     if (!dp[n][v % k]) return puts( NO ), 0;     int tmp = v % k;     for (int i = n; i >= 1; i--) {       if (f[i][tmp]) {         vc[0].push_back(i);         tmp = ((tmp - a[i]) % k + k) % k;       } else {         vc[1].push_back(i);       }     }     sort((vc[0]).begin(), (vc[0]).end());     sort((vc[1]).begin(), (vc[1]).end());     for (auto& t : vc[0]) now1 += a[t];     now2 = sum - now1;     puts( YES );     for (int i = 1; i < ((int)vc[0].size()); i++)       printf( 100000 %d %d n , vc[0][i], vc[0][0]);     for (int i = 1; i < ((int)vc[1].size()); i++)       printf( 100000 %d %d n , vc[1][i], vc[1][0]);     if (!((int)vc[1].size())) vc[1].push_back(vc[0].back());     if (!((int)vc[0].size())) vc[0].push_back(vc[1].back());     if (now1 < v) printf( %d %d %d n , (v - now1) / k, vc[1][0], vc[0][0]);     if (now1 > v) printf( %d %d %d n , (now1 - v) / k, vc[0][0], vc[1][0]);     return 0;   }