malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   pair<int, int> temp[102][102];   int ans[102][102];   int main() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         temp[i][j].first = i;         temp[i][j].second = j;       }     }     while (q--) {       int t;       cin >> t;       if (t == 1) {         int r;         cin >> r;         pair<int, int> p;         p = temp[r][1];         for (int j = 1; j < m; j++) {           temp[r][j] = temp[r][j + 1];         }         temp[r][m] = p;       } else if (t == 2) {         int c;         cin >> c;         pair<int, int> p;         p = temp[1][c];         for (int j = 1; j < n; j++) {           temp[j][c] = temp[j + 1][c];         }         temp[n][c] = p;       } else {         int r, c, x;         cin >> r >> c >> x;         int indx1 = temp[r][c].first;         int indx2 = temp[r][c].second;         ans[indx1][indx2] = x;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   using namespace std;   long long powmod(long long a, long long b, long long mod) {     if (b == 0 || a == 1) {       if (mod == 1)         return 0;       else         return 1;     }     if (b % 2 == 0) {       long long k = powmod(a, b / 2, mod);       return (k * k) % mod;     } else {       long long k = powmod(a, b / 2, mod);       return ((k * k) % mod * a) % mod;     }   }   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);     else       return gcd(b % a, a);   }   long long prime(long long p) {     for (long long i = 2; i * i <= p; i++) {       if (p % i == 0 && i < p) return i;     }     return 1;   }   long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); }   void solve(long long ppppppppp = 1) {     long long a, b;     cin >> a >> b;     if (a + b == 2) {       cout << 0;       return;     }     if (a == 1) {       for (long long i = 0; i < b; i++) cout << i + 2 <<    ;       return;     }     if (b == 1) {       for (long long i = 0; i < a; i++) cout << i + 2 <<    ;       return;     }     for (long long i = 0; i < a; i++) {       for (long long j = 0; j < b; j++) cout << (i + 1) * (a + j + 1) <<    ;       cout <<   n ;     }     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tututu;     tututu = 1;     for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   pair<pair<int, int>, int> queries[N];   long long arr[N], acc[N], in[N];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       in[i] = x;     }     for (int i = 0; i < m; ++i) {       scanf( %d %d %d , &queries[i].first.first, &queries[i].first.second,             &queries[i].second);       --queries[i].first.first;       --queries[i].first.second;     }     for (int i = 0; i < k; ++i) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       acc[a] += 1;       acc[b + 1] -= 1;     }     for (int i = 1; i < m; ++i) {       acc[i] += acc[i - 1];     }     for (int i = 0; i < m; ++i) {       int a = queries[i].first.first;       int b = queries[i].first.second;       long long x = queries[i].second * acc[i];       arr[a] += x;       arr[b + 1] -= x;     }     for (int i = 1; i < n; ++i) {       arr[i] += arr[i - 1];     }     for (int i = 0; i < n - 1; ++i) {       cout << arr[i] + in[i] <<    ;     }     cout << arr[n - 1] + in[n - 1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dig[15];   int qpow(int digit) {     int a = 2, b = digit, ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b >>= 1;     }     return ans;   }   int getDigit(int x) {     int ans = 0;     while (x) {       x /= 10;       ans++;     }     return ans;   }   void getHead(int x, int len) {     int index = len;     while (x) {       dig[index--] = x % 10;       x /= 10;     }   }   int main() {     int n;     while (~scanf( %d , &n)) {       int len = getDigit(n);       int ans = 0;       for (int i = 1; i <= len - 1; i++) ans += qpow(i);       if (ans == 1) ans -= 1;       getHead(n, len);       for (int i = 1; i <= len; i++) {         if (dig[i] > 7) {           ans += qpow(len - i + 1);           break;         } else if (dig[i] == 7) {           ans += qpow(len - i);           if (i == len) ans += 1;         } else if (dig[i] > 4) {           ans += qpow(len - i);           break;         } else if (dig[i] == 4) {           if (i == len) ans += 1;           continue;         } else           break;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   int n, m, k, ct[200010], cnt;   vector<pair<int, int> > e[200010];   vector<int> mp[200010];   char bf[100000], *p1 = bf, *p2 = bf;   inline int read() {     int x = 0;     char ch =         (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)              ? -1              : *p1++);     for (; ch <  0  || ch >  9 ;          ch =              (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)                   ? -1                   : *p1++))       ;     for (; ch <=  9  && ch >=  0 ;          x = x * 10 + ch - 48,          ch =              (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)                   ? -1                   : *p1++))       ;     return x;   }   int ans, O = 1;   int hah, val[10][200010];   void dfs(int x, int f) {     if (x == k + 1) {       if (f == hah) ++ans;       return;     }     if (mp[x].size() == 0) {       dfs(x + 1, f);       return;     }     for (auto i = (1); i <= (x); ++i) {       int flag = 1;       dfs(x + 1, f + val[x][i]);     }   }   int hsh[200010];   inline void solve() {     n = read(), m = read(), k = read();     for (auto i = (1); i <= (n); ++i) hsh[i] = rand(), hah += hsh[i];     for (auto i = (1); i <= (m); ++i) {       int u = read(), v = read(), w = read();       e[u].push_back({w, v});     }     for (auto i = (1); i <= (n); ++i) sort(e[i].begin(), e[i].end());     for (auto i = (1); i <= (n); ++i) mp[e[i].size()].push_back(i);     for (auto i = (1); i <= (k); ++i)       for (auto j = (1); j <= (i); ++j) {         val[i][j] = 0;         for (auto v : mp[i]) val[i][j] += hsh[e[v][j - 1].second];       }     for (auto i = (1); i <= (k); ++i)       if (mp[i].size() == 0) O *= i;     dfs(1, 0);     printf( %d n , ans * O);   }   int main() {     int T = 1;     while (T--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   long long MOD;   inline void Inc(long long &x, long long y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(long long &x, long long y) {     x -= y;     if (x < 0) x += MOD;   }   inline long long Add(long long x, long long y) {     Inc(x, y);     return x;   }   inline long long Sub(long long x, long long y) {     Dec(x, y);     return x;   }   inline long long Mul(long long x, long long y) { return x * y % MOD; }   }  // namespace ModCalculator   using namespace ModCalculator;   int n, d;   long long C[N][N], dp[N][N], sum[N], ans;   void init() {     read(n);     read(d);     read(MOD);     for (int i = 0; i <= n; ++i) {       C[i][0] = 1;       for (int j = 1; j <= i; ++j) {         C[i][j] = Add(C[i - 1][j], C[i - 1][j - 1]);       }     }   }   void solve() {     dp[1][0] = sum[1] = 1;     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= d; ++j) {         for (int k = 1; k < i; ++k) {           Inc(dp[i][j], Mul(C[i - 2][k - 1], Mul(sum[k], dp[i - k][j - 1])));         }         if (j < d) Inc(sum[i], dp[i][j]);       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= d; ++j) {         for (int k = 0; k + j <= d; ++k) {           if (k == 1) continue;           Inc(ans, Mul(dp[i][j], dp[n - i + 1][k]));         }       }     }     printf( %lld n , Mul(ans, 2LL * n * (n - 1)));   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int A, B, C, D, E, H, W, M, K, L, R, N, X, Y, Z, num = 0, sum = 0,                                                                flag = 0;     string S, T;     cin >> Z;     while (Z--) {       cin >> N >> M;       vector<long long int> P(N, 0);       vector<long long int> Q(M, 0);       for (long long int i = 0; i < N; i++) cin >> P[i];       for (long long int i = 0; i < M; i++) cin >> Q[i];       sort(P.begin(), P.end());       sort(Q.begin(), Q.end());       num = -1;       for (long long int i = 0; i < N; i++)         for (long long int j = 0; j < M; j++)           if (P[i] == Q[j]) num = P[i];       if (num == -1)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         cout << 1 <<     << num << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     while (cin >> n) {       long flag = 0, count = 0, a[100005] = {0}, i;       for (i = 0; i < n; i++) cin >> a[i];       for (i = n - 1; i > 0; i--) {         if (a[i - 1] > a[i])           break;         else           count++;       }       cout << n - count - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b;   int main() {     cin >> a >> b;     long long v = (a * (a + 1) / 2) % 1000000007;     long long rs = b * (b - 1) / 2;     rs %= 1000000007;     long long res = 0;     for (long long i = 1; i <= a; ++i)       res = (res + rs * (i * b % 1000000007 + 1) % 1000000007) % 1000000007;     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t, x, n;     cin >> t;     while (t--) {       cin >> n;       vector<int> v(109, 0);       while (n--) {         cin >> x;         v[x] += 1;       }       int sum = 0;       for (int i = 0; i < v.size(); i++) {         if (v[i] == 0) {           sum += i;           break;         }       }       for (int i = 0; i < v.size(); i++) {         if (v[i] <= 1) {           sum += i;           break;         }       }       cout << sum <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 6010;   const int mod = 1000000007;   int n;   long long k[MAXN], k2[MAXN];   int main() {     string asd;     string asd2;     cin >> asd;     cin >> asd2;     n = ((int)(asd2.size()));     long long res = 0;     for (int i = 0; i < ((int)(asd.size())); i++) {       for (int j = 0; j < ((int)(asd2.size())); j++) {         if (asd2[j] == asd[i]) {           k2[j] = (k2[j] + k[j - 1] + 1) % mod;         }         k2[j + 1] = (k2[j + 1] + k2[j]) % mod;       }       res = (res + k2[n]) % mod;       for (int j = 0; j < ((int)(asd2.size())); j++) k[j] = k2[j];       memset(k2, 0, sizeof k2);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   int Case, n, a[N], la[N], fn[N];   int f[N][N];   int main() {     scanf( %d , &Case);     while (Case--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) fn[i] = 0;       for (int i = 1; i <= n; ++i) {         scanf( %d , a + i);         if (a[i] == a[i - 1]) {           --i;           --n;         } else {           la[i] = fn[a[i]];           fn[a[i]] = i;         }       }       for (int i = n; i; --i) {         for (int j = i + 1; j <= n; ++j) {           f[i][j] = f[i][j - 1];           for (int k = la[j]; k >= i; k = la[k]) {             f[i][j] = max(f[i][j], f[i][k] + f[k][j - 1] + 1);           }         }       }       printf( %d n , n - 1 - f[1][n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n >> ws;       string str;       cin >> str;       int flag = 0, i;       for (i = 0; i < str.size() - 1; i++) {         if (str[i] > str[i + 1]) {           flag = 1;           break;         }       }       if (flag == 0) {         cout << str << endl;         continue;       }       string clean_str;       for (i = 0; i < str.size(); i++) {         if (str[i] ==  1 ) break;         clean_str.push_back( 0 );       }       clean_str.push_back( 0 );       for (i = str.size() - 1; i >= 0; i--) {         if (str[i] ==  0 ) break;         clean_str.push_back( 1 );       }       cout << clean_str << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nax = 4e5 + 5;   int ans[nax];   int b[nax];   int n;   bool solve(int bb) {     vector<int> a;     int val = (1 << (bb));     int val2 = val * 2;     int val3 = val * 3;     int val4 = val * 4;     for (int i = 1; i <= n; i++) {       a.push_back(b[i] & ((1 << (bb + 1)) - 1));     }     sort(a.begin(), a.end());     int hi2 = n - 1;     int hi1 = n - 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       hi1 = min(hi1, n - 1);       while (hi1 >= i && a[i] + a[hi1] >= val) hi1--;       if (a[i] + a[hi1] < val) hi1++;       hi1 = max(hi1, i + 1);       while (hi2 >= 0 && a[i] + a[hi2] >= val2) hi2--;       ans += max(0, hi2 - hi1 + 1);     }     hi2 = n - 1;     hi1 = n - 1;     for (int i = 0; i < n; i++) {       hi1 = min(hi1, n - 1);       while (hi1 >= i && a[i] + a[hi1] >= val3) hi1--;       if (a[i] + a[hi1] < val3) hi1++;       hi1 = max(hi1, i + 1);       while (hi2 >= 0 && a[i] + a[hi2] >= val4) hi2--;       ans += max(0, hi2 - hi1 + 1);     }     return ans % 2;   }   void brut() {     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) ans ^= (b[i] + b[j]);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int ans = 0;     for (int i = 0; i <= 27; i++) {       if (solve(i)) ans += (1 << i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long ind = 0, xtr = 0;     sort(a, a + n);     while (ind < n) {       for (long long i = ind; i < n; i++) {         if (a[i] > 2 * k) {           ind = i;           break;         } else if (i == n - 1 and a[i] <= 2 * k) {           ind = n;           break;         }         k = max(k, a[i]);       }       if (ind != n) {         if (ind > 0) k = max(k, a[ind - 1]);         k = 2 * k;         xtr++;       }     }     cout << xtr << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long MAXN = 1123456;   const long long N = 2e6;   const long long inf = 3e18;   const long long mod = 998244353;   const long long MOD = mod * (mod - 2);   mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());   template <typename T>   void vout(T s) {     cout << s << endl;     exit(0);   }   void main_solve() {     long long n;     cin >> n;     vector<long long> a(n + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     vector<bool> f(n + 1);     vector<long long> c, ans;     long long s = 1;     while (1) {       c.push_back(s);       if (f[s]) break;       f[s] = 1;       s = s - a[s];     }     reverse(c.begin(), c.end());     ans.push_back(c[0]);     for (int i = 1; i < (int)c.size(); i++)       if (c[i] != c[0]) {         ans.push_back(c[i]);       } else         break;     cout << (int)ans.size() <<   n ;     for (auto i : ans) cout << i <<    ;     cout <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       main_solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char field[8][8];     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> field[i][j];       }     }     int minDist = 10;     for (int j = 0; j < 8; j++) {       for (int i = 0; i < 8; i++) {         if (field[i][j] ==  B ) {           break;         }         if (field[i][j] ==  W ) {           if (minDist > i) minDist = i;         }       }     }     int blackMinDist = -1;     for (int j = 0; j < 8; j++) {       for (int i = 7; i >= 0; i--) {         if (field[i][j] ==  W ) {           break;         }         if (field[i][j] ==  B ) {           if (blackMinDist < i) blackMinDist = i;         }       }     }     blackMinDist = 7 - blackMinDist;     if (blackMinDist >= minDist) {       cout <<  A ;       return 0;     }     cout <<  B ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e15;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n, k;     cin >> n >> k;     vector<int> first(n);     for (int i = 0; i < n; i++) cin >> first[i];     vector<long long> pr(n + 1);     for (int i = 0; i < n; i++) pr[i + 1] = pr[i] + first[i];     map<long long, int> how;     for (int i = 0; i < n; i++) {       how[pr[i + 1]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (k == 1) {         ans += how[k + pr[i]];       } else {         if (k == -1) {           ans += how[k + pr[i]];           ans += how[-k + pr[i]];         } else {           for (long long p = 1; p <= MAX; p *= k) {             ans += how[p + pr[i]];           }         }       }       how[pr[i + 1]]--;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<pair<int, bool> > adj[maxn];   vector<pair<pair<int, int>, bool> > edge;   int dp[maxn], dis[maxn], par[maxn];   bool mark[maxn], in_path[maxn];   int n, m, ans = 0;   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, w;       cin >> a >> b >> w;       adj[a - 1].push_back(make_pair(b - 1, 1 - w));       adj[b - 1].push_back(make_pair(a - 1, 1 - w));       edge.push_back(make_pair(make_pair(a - 1, b - 1), 1 - w));       if (w) ans++;     }   }   void bfs() {     queue<int> q;     q.push(0);     mark[0] = true;     dis[0] = 0;     dp[0] = 0;     while (!q.empty()) {       int v = q.front();       q.pop();       for (auto u : adj[v]) {         if (!mark[u.first]) {           q.push(u.first);           mark[u.first] = true;           dis[u.first] = dis[v] + 1;           par[u.first] = v;           dp[u.first] = dp[v] + u.second;         } else if ((dp[u.first] > dp[v] + u.second) &&                    (dis[u.first] == dis[v] + 1)) {           par[u.first] = v;           dp[u.first] = dp[v] + u.second;         }       }     }   }   void check() {     for (int i = 0; i < n; i++) cout <<  par   << par[i] << endl;   }   void pp(int v) {     if (par[v] == v) return;     in_path[v] = true;     pp(par[v]);   }   void output() {     cout << ans - dis[n - 1] + 2 * dp[n - 1] << endl;     in_path[0] = true;     in_path[n - 1] = true;     pp(n - 1);     for (int i = 0; i < m; i++) {       int a = edge[i].first.first, b = edge[i].first.second, w = edge[i].second;       if (!in_path[a] || !in_path[b])         if (!w) cout << a + 1 <<     << b + 1 <<     << w << endl;       if (in_path[a] && in_path[b])         if (w) cout << a + 1 <<     << b + 1 <<     << w << endl;     }     return;   }   int main() {     input();     bfs();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   template <typename T, typename... Args>   void read(T &first, Args &...args) {     read(first);     read(args...);   }   template <typename T>   void write(T arg) {     T x = arg;     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   template <typename T, typename... Ts>   void write(T arg, Ts... args) {     write(arg);     if (sizeof...(args) != 0) {       putchar(   );       write(args...);     }   }   const long long MOD = 998244353;   const int MAXN = 5e5 + 50;   long long n, k, fac[MAXN], inv[MAXN];   long long qpow(long long a, long long p) {     long long sum = 1;     while (p) {       if (p & 1) {         sum = sum * a % MOD;       }       a = a * a % MOD;       p >>= 1;     }     return sum;   }   long long get_inv(long long k) { return qpow(k, MOD - 2); }   void pre() {     fac[0] = 1;     for (register int i = 1; i <= n; ++i) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = get_inv(fac[i]);     }   }   long long C(long long n, long long m) {     if (m > n) {       return 0;     } else {       return fac[n] * get_inv(fac[n - m] * fac[m] % MOD) % MOD;     }   }   int main() {     read(n, k);     pre();     long long ans = 0;     for (register int i = 1; i <= n; ++i) {       long long p = n / i - 1;       ans = (ans + C(p, k - 1)) % MOD;     }     write(ans), putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int cnt;   int getdeal(long long c) {     int ret = 0;     while (c) {       ret += c % 10;       c /= 10;     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     long long temp = 0;     while (temp * 10 + 9 <= n) {       temp = temp * 10 + 9;     }     cout << getdeal(temp) + getdeal(n - temp);   }