malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, c[N][N];   struct node {     int v, pos;   } a[N];   inline bool cmp(node x, node y) { return x.v > y.v; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].v), a[i].pos = i;     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i)       for (int j = 1, k = i; j <= a[i].v; ++j, k = k % (n + 1) + 1)         c[k][a[i].pos] = 1;     printf( %d n , n + 1);     for (int i = 1; i <= n + 1; puts(  ), ++i)       for (int j = 1; j <= n; ++j) printf( %d , c[i][j]);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:33554432 )   using namespace std;   int P[1 << 18];   int B[1 << 18];   int C[1 << 18];   int S[1 << 18];   long long R[1 << 18];   vector<pair<int, int> > E[1 << 18];   int gMark, gS;   int Parent(int a) {     if (P[a] == a) return a;     return P[a] = Parent(P[a]);   }   void dfs(int a, int p) {     B[a] = gMark;     int i;     for (i = 0; i < int((E[a]).size()); i++) {       int b = E[a][i].first;       if (b == p) continue;       dfs(b, a);       S[a] += S[b];     }     S[a] += C[a];   }   void dfs2(int a, int p) {     B[a] = gMark;     int i;     for (i = 0; i < int((E[a]).size()); i++) {       int b = E[a][i].first;       if (b == p) continue;       dfs2(b, a);       long long s = S[b];       R[E[a][i].second] = s * (gS - s);     }   }   int main() {     int n;     scanf( %d , &n);     int i, j;     vector<pair<pair<int, int>, pair<int, int> > > v;     for (i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       v.push_back(make_pair(pair<int, int>(c, i), pair<int, int>(a - 1, b - 1)));     }     sort((v).begin(), (v).end());     for (i = 0; i < n + n; i++) {       P[i] = i;       C[i] = 1;       S[i] = 0;     }     memset(B, 0, sizeof(B));     gMark = 0;     int prev = 0;     int cnt = n;     for (i = 1; i < n; i++)       if (i == n - 1 || v[i].first.first != v[i - 1].first.first) {         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           int b = Parent(v[j].second.second);           E[a].push_back(pair<int, int>(b, v[j].first.second));           E[b].push_back(pair<int, int>(a, v[j].first.second));         }         ++gMark;         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           if (B[a] != gMark) dfs(a, -1);         }         ++gMark;         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           if (B[a] != gMark) {             gS = S[a];             dfs2(a, -1);           }         }         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           int b = Parent(v[j].second.second);           P[a] = P[b] = cnt;           C[cnt] = C[a] + C[b];           ++cnt;         }         prev = i;       }     long long res = 0;     for (i = 0; i < n - 1; i++) res = max(res, R[i]);     vector<int> ret;     for (i = 0; i < n - 1; i++)       if (R[i] == res) ret.push_back(i + 1);     printf( %lld %d n , res + res, int((ret).size()));     for (i = 0; i < int((ret).size()); i++)       printf( %d%c , ret[i], i == int((ret).size()) - 1 ?   n  :    );     return 0;   };
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   vector<long long> v;   void lucky(long long x) {     queue<long long> q;     q.push(x);     while (x < 1e9) {       x = q.front();       q.pop();       x *= 10;       q.push(x + 4);       q.push(x + 7);       v.push_back(x + 4);       v.push_back(x + 7);     }   }   int next(long long x) {     int str = 0, ed = v.size() - 1, ans;     while (str <= ed) {       int mid = str + ((ed - str) / 2);       if (v[mid] >= x) {         ans = mid;         ed = mid - 1;       } else         str = mid + 1;     }     return ans;   }   int main() {     long long x, y;     cin >> x >> y;     lucky(0);     unsigned long long sum = 0;     sort(v.begin(), v.end());     int z = next(x);     if (y <= v[z])       return cout << (y - x + 1) * v[z], 0;     else {       sum += (v[z] - x + 1) * v[z];       int i;       for (i = z + 1; v[i] <= y; i++) {         sum += (v[i] - v[i - 1]) * v[i];       }       sum += (y - v[i - 1]) * v[i];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   int32_t main() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long f = 0;     long long c = 0;     for (long long i = 0; i < n - 1; i++) {       c += a[i] / k;       a[i] = a[i] % k;       if (a[i] != 0) {         if (k - a[i] < a[i + 1])           a[i + 1] -= (k - a[i]);         else           a[i + 1] = 0;         c += 1;       }       a[i] = 0;     }     c += a[n - 1] / k;     if (a[n - 1] % k != 0) c += 1;     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000LL * 1000 * 1000 + 7;   const int INF = 1000 * 1000 * 1000;   const long long base = 1e18;   const int MAXN = 600000;   const double EPS = 1e-9;   const double PI = acos(-1.);   long long binPow(long long a, long long x) {     long long res = 1;     while (x) {       if (x & 1) {         res *= a;         res %= MOD;       }       a *= a;       a %= MOD;       x /= 2;     }     return res;   }   long long dpT[200000][2];   long long n, m;   long long a[200000];   long long b[200000];   long long dp(int pos, int more) {     if (pos == n) {       return more;     }     if (dpT[pos][more] != -1) return dpT[pos][more];     if (more == 1) {       long long ans = dp(pos + 1, more);       if (a[pos] == 0) {         ans *= m;         ans %= MOD;       }       if (b[pos] == 0) {         ans *= m;         ans %= MOD;       }       return dpT[pos][more] = ans;     }     if (a[pos] && b[pos] && a[pos] < b[pos]) return dpT[pos][more] = 0;     if (a[pos] && b[pos] && a[pos] > b[pos])       return dpT[pos][more] = dp(pos + 1, 1);     if (a[pos] && b[pos] && a[pos] == b[pos]) {       return dpT[pos][more] = dp(pos + 1, 0);     }     if (a[pos] == 0 && b[pos]) {       long long res = 0;       res += (dp(pos + 1, 1) * (m - b[pos])) % MOD;       res %= MOD;       res += dp(pos + 1, 0);       res %= MOD;       return dpT[pos][more] = res;     }     if (a[pos] && b[pos] == 0) {       long long res = 0;       res += (dp(pos + 1, 1) * (a[pos] - 1)) % MOD;       res %= MOD;       res += dp(pos + 1, 0);       res %= MOD;       return dpT[pos][more] = res;     }     long long res = 0;     long long cur = (m * (m - 1) / 2) % MOD;     res += (dp(pos + 1, 1) * (cur)) % MOD;     res %= MOD;     res += (dp(pos + 1, 0) * m) % MOD;     res %= MOD;     return dpT[pos][more] = res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int cnt = 0;     for (int i = (0); i < (n); ++i) {       cin >> a[i];       if (!a[i]) cnt++;     }     for (int i = (0); i < (n); ++i) {       cin >> b[i];       if (!b[i]) cnt++;     }     memset(dpT, -1, sizeof dpT);     long long div = binPow(m, cnt);     long long y = binPow(div, MOD - 2);     cout << (dp(0, 0) * y) % MOD;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, s, p;   int main() {     scanf( %d %d %d , &t, &s, &p);     int l = t;     int x1 = 0, x2 = s;     int co = 1;     while (x1 < l) {       x1 = x1 + p;       x2 = x2 + p - 1;       if (x1 >= l && x2 >= l)         break;       else if (x1 >= x2) {         x1 = 0;         co++;       }     }     cout << co << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(0);       int t;       cin >> t;       while (t--) {           int u, v; cin >> u >> v;           if (u > v)               printf( NO n );           else if (u == v)               printf( YES n );           else {               int U = 0, V = 0, fail = 0;               // (u) 1 0111 0111 -> 1 1010 0110 (v)               // bit0: {0, 1, 2, 4, 5, 6, 8} -> bit1: {1, 2, 5, 7, 8}               for (int i = 0; i < 30; i++) {                   U += u >> i & 1;                   V += v >> i & 1;                   fail |= U < V;               }               printf(fail ?  NO n  :  YES n );           }       }       return 0;   }   /*   3 12   YES   6 9   NO   */
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long m, n;     cin >> m >> n;     long ar[n], br[n];     for (int i = 0; i < n; i++) {       cin >> ar[i] >> br[i];     }     int tmp;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n - 1; j++) {         if (br[j] < br[j + 1]) {           tmp = br[j];           br[j] = br[j + 1];           br[j + 1] = tmp;           tmp = ar[j];           ar[j] = ar[j + 1];           ar[j + 1] = tmp;         }       }     }     int cnt = 0, i = 0;     long sum = 0;     while (cnt != m && i < n) {       while (ar[i] != 0) {         sum += br[i];         ar[i]--;         cnt++;         if (cnt == m) break;       }       i++;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int inp[200200];   int sum[200200];   char str[200200];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &inp[i]);     scanf( %s , str);     int len = strlen(str);     reverse(inp, inp + n);     reverse(str, str + len);     sum[n] = 0;     for (int i = n - 1; ~i; --i) sum[i] = sum[i + 1] + inp[i];     int v = 0, ans = 0;     for (int i = 0; i < len; ++i) {       if (str[i] ==  1 ) {         ans = max(ans, v + sum[i + 1]);         v += inp[i];       }       if (0) printf(  << i %2d, v %2d, ans %2d n , i, v, ans);     }     if (0) {       for (int i = 0; i < n; ++i) printf(  %d n , inp[i]);       puts(  );       for (int i = 0; i < n; ++i) printf(  %d n , sum[i]);       puts(  );     }     if (0) printf( < v %d n , v);     printf( %d n , max(ans, v));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> V[2001010];   int cnt[2002];   long long cum[2002], N;   string s;   void make(int l, int r) {     while (l >= 0 && r < (int)s.size()) {       if (s[l] == s[r]) {         V[N++] = (make_pair(l, r));         cnt[l]++;       } else         break;       l--, r++;     }   }   int main() {     N = 0;     cin >> s;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < (int)s.size(); ++i) {       make(i, i);       make(i - 1, i);     }     cum[0] = 0;     for (int i = 0; i < (int)s.size(); ++i) cum[i + 1] = cum[i] + cnt[i];     long long Sm = cum[s.size()];     long long c = 0;     for (int i = 0; i < N; ++i) {       c += (Sm - cum[V[i].second + 1]);     }     cout << c << endl;   }
#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   char E[1005][1005];   int N, M;   struct Node {     int step[3];   } s[1005][1005];   struct use {     int x, y;   };   void bfs(int x) {     queue<use> que;     use u, v;     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (E[i][j] == x +  1 ) {           u.x = i, u.y = j;           s[i][j].step[x] = 0;           que.push(u);         }       }     }     while (!que.empty()) {       u = que.front();       que.pop();       for (int i = 0; i < 4; i++) {         v = u;         v.x += dx[i];         v.y += dy[i];         if (v.x >= 0 && v.x < N && v.y >= 0 && v.y < M && E[v.x][v.y] !=  # ) {           int t;           if (E[v.x][v.y] ==  . )             t = 1;           else             t = 0;           if (s[v.x][v.y].step[x] == -1 ||               s[u.x][u.y].step[x] + t < s[v.x][v.y].step[x]) {             s[v.x][v.y].step[x] = s[u.x][u.y].step[x] + t;             que.push(v);           }         }       }     }   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 0; i < N; i++) scanf( %s , E[i]);     memset(s, -1, sizeof(s));     for (int i = 0; i < 3; i++) bfs(i);     int ans = 1 << 30;     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) {         if (s[i][j].step[0] != -1 && s[i][j].step[1] != -1 &&             s[i][j].step[2] != -1) {           int t;           if (E[i][j] ==  . )             t = 1;           else             t = 0;           ans = min(ans,                     s[i][j].step[0] + s[i][j].step[1] + s[i][j].step[2] - t * 2);         }       }     if (ans == 1 << 30) {       puts( -1 );       exit(0);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[200][200];   int lef[200], righ[200];   bool is[200];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, bot = 0;     cin >> n >> m;     for (int i = 0; i < n + 1; i++) {       lef[i] = m - 1;       righ[i] = 0;     }     for (int i = 0; i < n; i++) {       bool f = 0;       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  W ) {           lef[i] = min(j, lef[i]);           righ[i] = max(j, righ[i]);           f = 1;           bot = i;         }       }       is[i] = f;     }     int cur = 0, ans = 0;     for (int i = 0; i <= bot; i++) {       if (is[i + 1] == 0 && is[i] == 0) continue;       if (i % 2 == 0) {         ans += abs(cur - max(righ[i + 1], righ[i]));         cur = max(righ[i + 1], righ[i]);       } else {         ans += abs(cur - min(lef[i + 1], lef[i]));         cur = min(lef[i + 1], lef[i]);       }     }     cout << ans + bot;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool cmin(T &a_, T b_) {     return a_ > b_ ? (a_ = b_, true) : false;   }   template <class T>   bool cmax(T &a_, T b_) {     return a_ < b_ ? (a_ = b_, true) : false;   }   template <class T>   void OUT(T s_) {     cout << s_ <<   n ;     exit(0);   }   const int maxn = 1.0001e6;   const long long mod = 998244353;   long long n;   long long gt[maxn];   long long power(long long a, long long b) {     if (!b) return 1LL;     long long c = power(a, b >> 1);     c *= c;     c %= mod;     if (b & 1) {       c *= a;       c %= mod;     }     return c;   }   long long f(long long a, long long b) {     if (a == b) return 1;     return (gt[a] * power((gt[b] * gt[a - b]) % mod, mod - 2)) % mod;   }   void Fan_chipu() {     cin >> n;     gt[0] = 1;     for (int i = (int)(1); i <= (int)(maxn - 1); ++i)       gt[i] = gt[i - 1] * i, gt[i] %= mod;     long long ans = 0LL;     for (int i = (int)(0); i <= (int)(n); ++i) {       ans += (f(n, i) * (((gt[i] - i + mod) * gt[n - i]) % mod)) % mod;       ans %= mod;     }     cout << ans % mod <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     Fan_chipu();   }
#include <bits/stdc++.h>   int main() {     int n, i, j, k = 0, p;     scanf( %d , &n);     int a[n], b[n];     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = n - 1; i >= 0; i--) {       j = i + 1;       p = 1;       while (j <= n - 1) {         if (a[i] == a[j]) {           p = -1;           break;         }         j++;       }       if (p == 1) {         b[k] = a[i];         k++;       }     }     printf( %d n , k);     for (j = k - 1; j >= 0; j--) printf( %d  , b[j]);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int mod = 1000000007, c = 1, n, k;     cin >> n >> k;     for (int i = 1; i <= n - k; i++) c = (c * (n - k)) % mod;     for (int i = 1; i <= k - 1; i++) c = (c * k) % mod;     cout << c;   }
#include <bits/stdc++.h>   bool isVowel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  ||             c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  ||             c ==  y  || c ==  Y );   };   int main() {     char word[100];     scanf( %s , word);     int i;     int length;     length = strlen(word);     for (i = 0; i < length; i++) {       if (!isVowel(word[i])) {         printf( .%c , tolower(word[i]));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, k, cnt[100010], a[100010][4];   void work(int l, int r) {     if (r - l + 1 == 3) {       cnt[++k] = 3;       a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2;       cnt[++k] = 3;       a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2;       return;     }     if (r - l + 1 == 4) {       cnt[++k] = 4;       a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2, a[k][4] = l + 3;       cnt[++k] = 4;       a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 3, a[k][4] = l + 2;       cnt[++k] = 4;       a[k][1] = l, a[k][2] = l + 3, a[k][3] = l + 1, a[k][4] = l + 2;       return;     }     if (3 * t > l) {       work(l + 3, r);       if ((r - l + 1) % 2 == 0) {         cnt[++k] = 3;         a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2;         for (int i = l; i <= l + 2; i++) {           for (int j = l + 3; j < r; j += 2) {             cnt[++k] = 4;             a[k][1] = i;             a[k][2] = j;             a[k][3] = i == l + 2 ? l : i + 1;             a[k][4] = j == r ? l + 3 : j + 1;           }         }         cnt[++k] = 3;         a[k][1] = l, a[k][2] = l + 1, a[k][3] = r;         cnt[++k] = 3;         a[k][1] = l, a[k][2] = l + 2, a[k][3] = r;         cnt[++k] = 3;         a[k][1] = l + 1, a[k][2] = l + 2, a[k][3] = r;       } else {         work(l, l + 2);         for (int i = l; i <= l + 2; i++) {           for (int j = l + 3; j <= r; j += 2) {             cnt[++k] = 4;             a[k][1] = i;             a[k][2] = j;             a[k][3] = i == l + 2 ? l : i + 1;             a[k][4] = j == r ? l + 3 : j + 1;           }         }       }     } else {       work(l, r - 4);       work(r - 3, r);       for (int i = l; i <= r - 4; i++) {         for (int j = r - 3; j <= r; j += 2) {           cnt[++k] = 4;           a[k][1] = i;           a[k][2] = j;           a[k][3] = i == r - 4 ? l : i + 1;           a[k][4] = j == r ? r - 3 : j + 1;         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n / 3; i++) {       if ((n - i * 3) % 4 == 0) {         t = i;         work(1, n);         break;       }     }     if (n == 5) {       printf( 6 n3 5 4 2 n3 3 1 5 n4 4 5 2 3 n4 4 3 2 1 n3 4 2 1 n3 3 1 5 );       return 0;     }     printf( %d n , k);     for (int i = 1; i <= k; i++) {       printf( %d  , cnt[i]);       for (int j = 1; j <= cnt[i]; j++) {         printf( %d  , a[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     cin >> n;     int a = (int)sqrt(n);     if (a * a == n) {       cout << a * 4 << endl;     } else if (a * (a + 1) >= n) {       cout << a * 4 + 2 << endl;     } else {       cout << a * 4 + 4 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void solve() {     string s;     cin >> s;     int cntr1 = 10, cntr2 = 10;     int wt1 = 0, wt2 = 0;     for (int i = 0; i < 10; i++) {       if (i % 2 == 0) {         if (s[i] ==  1  || s[i] ==  ? ) wt1++;       } else {         if (s[i] ==  1 ) wt2++;       }       int left_t1 = 0, left_t2 = 0;       for (int j = i + 1; j < 10; j++) {         if (j % 2 == 0) {           left_t1++;         } else {           left_t2++;         }       }       if (wt1 > wt2 + left_t2) {         cntr1 = i + 1;         break;       }       if (wt2 > wt1 + left_t1) {         cntr1 = i + 1;         break;       }     }     wt1 = 0, wt2 = 0;     for (int i = 0; i < 10; i++) {       if (i % 2 == 0) {         if (s[i] ==  1 ) wt1++;       } else {         if (s[i] ==  1  || s[i] ==  ? ) wt2++;       }       int left_t1 = 0, left_t2 = 0;       for (int j = i + 1; j < 10; j++) {         if (j % 2 == 0) {           left_t1++;         } else {           left_t2++;         }       }       if (wt1 > wt2 + left_t2) {         cntr2 = i + 1;         break;       }       if (wt2 > wt1 + left_t1) {         cntr2 = i + 1;         break;       }     }     cout << min(cntr1, cntr2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t-- > 0) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, maxn = 100001;   typedef long long M[9][9];   const int p = 1e9 + 7, inv2 = 500000004;   void Mul(M &A, M B) {     M C;     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) {         C[i][j] = 0;         for (int k = 0; k < 9; k++) C[i][j] += A[i][k] * B[k][j] % p;       }     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) A[i][j] = C[i][j] % p;   }   void Pow(M &A, long long k) {     M B;     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) B[i][j] = (i == j);     while (k) {       if (k & 1) Mul(B, A);       Mul(A, A);       k >>= 1;     }     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) A[i][j] = B[i][j];   }   M A = {{0, 0, 1, 1, 0, p - 1, 0, 0, 0}, {0, 0, 1, 1, p - 1, 0, 0, 0, 0},          {1, 1, 0, 0, 0, 0, 0, 0, 0},     {1, 1, 0, 0, 0, 0, 0, 0, 0},          {1, 0, 0, 0, 0, 0, 0, 0, 0},     {0, 1, 0, 0, 0, 0, 0, 0, 0},          {0, 0, 1, 0, 0, 0, 0, 0, 0},     {0, 0, 0, 1, 0, 0, 0, 0, 0},          {1, 1, 1, 1, 0, 0, 0, 0, 1}};   int Solve(long long n) {     M B;     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) B[i][j] = A[i][j];     Pow(B, n);     int ans = 0;     for (int i = 0; i < 4; i++) ans = (ans + B[8][i]) % p;     for (int i = 0; i < 9; i++)       for (int j = 0; j < 9; j++) B[i][j] = A[i][j];     Pow(B, (n + 1) / 2);     for (int i = 0; i < 4; i++) ans = (ans + B[8][i] + p) % p;     return (long long)ans * inv2 % p;   }   int main() {     long long L, R;     while (~scanf( %I64d%I64d , &L, &R)) {       int ans = (Solve(R) - Solve(L - 1) + p) % p;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, t = 0, min, d = 0;     cin >> n >> m;     int a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     vector<vector<int>> b(2, vector<int>(m, -1));     vector<vector<int>> c(n, vector<int>(2, -1));     for (int i = 0; i < m; i++) {       min = -1;       for (int j = 0; j < n; j++) {         if (a[j][i] == 1 && min == -1) {           b[0][i] = j;           min = 0;         }         if (a[j][i] == 1) b[1][i] = j;       }     }     for (int i = 0; i < n; i++) {       min = -1;       for (int j = 0; j < m; j++) {         if (a[i][j] == 1 && min == -1) {           c[i][0] = j;           min = 0;         }         if (a[i][j] == 1) c[i][1] = j;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] == 0) {           if (b[0][j] < i && b[0][j] != -1) d++;           if (b[1][j] > i && b[1][j] != -1) d++;           if (c[i][0] < j && c[i][0] != -1) d++;           if (c[i][1] > j && c[i][1] != -1) d++;         }       }     }     cout << d;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, a, b;     cin >> n >> a >> b;     long long int c = 0;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     long long int ans = accumulate(v.begin(), v.end(), 0);     for (long long int i = 0; i < n; i++) {       if (v[i] == 1) {         if (a > 0)           a--, ans--;         else if (b > 0)           b--, c++, ans--;         else if (c > 0)           c--, ans--;       } else {         if (b >= 1) b--, ans -= 2;       }     }     cout << ans;     return 0;   }