malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma optimize( Ofast )   using namespace std;   unsigned int start = clock();   using ll = unsigned long long;   struct obj {     int fi, se;     obj() { fi = se = 0; }   };   void gettime(string s) {     cout << endl << s << (clock() - start) / 1000000.0 << endl;   }   void insert() {}   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> pref(n, 0);     for (int i = 1; i < n - 1; i++) {       pref[i] = pref[i - 1] + (a[i - 1] < a[i] && a[i] > a[i + 1] ? 1 : 0);     }     pref[n - 1] = pref[n - 2];     int l = 0;     int ans = pref[k - 2];     for (int i = k - 1; i < n; i++) {       if (ans < pref[i - 1] - pref[i - k + 1]) {         ans = pref[i - 1] - pref[i - k + 1];         l = i - k + 1;       }     }     cout << ans + 1 <<     << l + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int q = 1;     cin >> q;     while (q--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= M;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % M;       a = a * a % M;     }     return res % M;   }   const long long N = 1e5;   int main() {     int n;     cin >> n;     map<string, int> m;     int c = 0;     set<string> st[21], st1[21];     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (m.count(s))         ;       else         m[s] = c++;       int nn;       cin >> nn;       for (int j = 0; j < nn; ++j) {         string ss;         cin >> ss;         st[m[s]].insert(ss);       }     }     for (int i = 0; i < c; ++i) {       for (set<string>::iterator it = st[i].begin(); it != st[i].end(); ++it) {         bool flag = 0;         for (set<string>::iterator it1 = st[i].begin(); it1 != st[i].end();              ++it1) {           if (*it != *it1) {             string s1 = *it, s2 = *it1;             if (s1.size() <= s2.size()) {               int k = s2.size() - s1.size();               int j = 0;               for (; k < s2.size(); ++k) {                 if (s2[k] == s1[j])                   j++;                 else                   break;               }               if (j == s1.size()) flag = 1;             }           }         }         if (flag == 0) st1[i].insert(*it);       }     }     cout << c << endl;     for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << st1[it->second].size() <<    ;       for (set<string>::iterator it1 = st1[it->second].begin();            it1 != st1[it->second].end(); ++it1)         cout << *it1 <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   constexpr ll INF = (1LL << 30) - 1LL;   constexpr ll LINF = (1LL << 60) - 1LL;   constexpr ll MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   struct Median {     priority_queue<T> smq;     priority_queue<T, vector<T>, greater<T>> lgq;     void push(T x) {       if (smq.empty()) {         smq.push(x);         return;       }       T t = smq.top();       if (smq.size() > lgq.size()) {         if (t <= x) {           lgq.push(x);         } else {           lgq.push(t);           smq.pop();           smq.push(x);         }       } else {         if (t >= x) {           smq.push(x);         } else {           lgq.push(x);           smq.push(lgq.top());           lgq.pop();         }       }     }     inline T get() { return smq.top(); }   };   template <typename T>   struct BinaryIndexedTree {     vector<T> node;     int n;     BinaryIndexedTree(int n) : n(n) { node.assign(++n, 0); }     void add(int k, T x) {       for (++k; k < n; k += k & -k) {         node[k] += x;       }     }     T sum(int k) {       if (k < 0) {         return 0;       }       T res = 0;       for (++k; k > 0; k -= k & -k) {         res += node[k];       }       return res;     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> p(n), pos(n + 1);     for (int i = 0; i < n; i++) {       cin >> p[i];       pos[p[i]] = i;     }     BinaryIndexedTree<ll> bit(n + 1), bit2(n + 1);     for (int i = 0; i < n; i++) {       bit2.add(i, 1);     }     ll res = 0;     Median<ll> med;     for (int k = 1; k <= n; k++) {       res += bit.sum(n - 1) - bit.sum(pos[k]);       res -= min(bit.sum(pos[k] - 1), bit.sum(n - 1) - bit.sum(pos[k]));       bit.add(pos[k], 1);       bit2.add(pos[k], -1);       int t;       if (k % 2 > 0) {         med.push(pos[k]);       }       if (k > 1) {         t = med.get();         if (t < pos[k]) {           res += bit2.sum(pos[k]) - bit2.sum(t - 1);         } else {           res += bit2.sum(t) - bit2.sum(pos[k] - 1);         }         if (k % 2 == 0) {           med.push(pos[k]);         }       }       cout << res;       if (k < n) {         cout <<    ;       } else {         cout << endl;       }     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   void solve() {     long long n, k;     cin >> n >> k;     if (n == 1 && k == 10) {       cout <<  -1             <<   n ;       return;     }     if (k == 10) {       cout << 1;       for (int i = 1; i <= n - 1; i++) {         cout << 0;       }     } else {       for (int i = 1; i <= n; i++) {         cout << k;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, a;     cin >> n;     vector<int> c(3 * 1e5, 0);     for (int i = 1; i <= n / 2; i++) {       cin >> a;       if (a >= i) c[1e5 + a - i]++;     }     if (n % 2) {       cin >> a;       if (a >= n / 2 + 1) c[1e5 + a - (n / 2) - 1]++;     }     for (int i = n / 2; i > 0; i--) {       cin >> a;       if (a >= i) c[1e5 + a - i]++;     }     int ans = 0;     for (int i = 0; i < 3 * 1e5; i++) ans = max(ans, c[i]);     cout << n - ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int sumo[maxn], sume[maxn];   int main() {     int n;     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int t;       cin >> t;       if (i % 2)         sumo[i] = sumo[i - 1] + t;       else         sumo[i] = sumo[i - 1];       if (i % 2 == 0)         sume[i] = sume[i - 1] + t;       else         sume[i] = sume[i - 1];     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int cnto = sumo[i - 1] + (sume[n] - sume[i]);       int cnte = sume[i - 1] + (sumo[n] - sumo[i]);       if (cnto == cnte) {         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int BIG = 1e9 + 239;   const int M = 2010;   int n, m, kol[M], id[M][M];   vector<int> v[M];   bitset<M> a[M];   string s;   bool used[M], need[M];   vector<pair<int, int> > ans;   inline void upd(int s, int f) {     used[s] = false;     for (int i = 0; i < n; i++)       if (used[i]) {         if (id[s][i] == -1) continue;         int bk = (int)v[i].back();         id[bk][i] = id[s][i];         v[i][id[s][i]] = bk;         v[i].pop_back();         id[s][i] = -1;       }     for (int i = 0; i < m; i++)       if (a[s][i]) kol[i]--;     bool ch = false;     for (int i = 0; i < m; i++)       if (kol[i] < 2 && a[f][i] == 1) a[f][i] = 0, ch = true;     if (ch) {       for (int i = 0; i < n; i++) need[i] = true;       for (int i : v[f]) need[i] = false;       for (int i = 0; i < n; i++)         if (need[i] && used[i] && i != f && ((a[f] & a[i]) == a[f])) {           id[i][f] = (int)v[f].size();           v[f].push_back(i);         }     }   }   inline void solve() {     ans.clear();     cin >> n >> m;     for (int i = 0; i < n; i++) v[i].clear();     for (int i = 0; i < n; i++) a[i] = 0;     for (int i = 0; i < m; i++) kol[i] = 0;     for (int i = 0; i < m; i++) {       cin >> s;       for (int x = 0; x < n; x++) {         a[x][i] = (s[x] -  0 );         if (s[x] ==  1 ) kol[i]++;       }     }     for (int i = 0; i < m; i++)       if (kol[i] < 2)         for (int x = 0; x < n; x++) a[x][i] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) id[i][j] = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j)           if ((a[i] & a[j]) == a[i]) {             id[j][i] = (int)v[i].size();             v[i].push_back(j);           }     for (int i = 0; i < n; i++) used[i] = true;     for (int iter = 0; iter < n - 1; iter++) {       int s = -1;       for (int i = 0; i < n; i++)         if (used[i] && !v[i].empty()) {           s = i;           break;         }       if (s == -1) {         cout <<  NO n ;         return;       }       int f = v[s].back();       ans.push_back(make_pair(s, f));       upd(s, f);     }     cout <<  YES n ;     for (pair<int, int> t : ans)       cout << (t.first + 1) <<     << (t.second + 1) <<   n ;   }   int main() {     cin.sync_with_stdio(0);     int T;     cin >> T;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     cin >> N >> M;     if (N == 1) {       if (M == 2) {         cout << 0 << endl;         cout <<  1 1  << endl <<  1 2  << endl <<  1 1  << endl;         return 0;       }       cout << 1 << endl;       cout << 1 <<     << M <<     << 1 <<     << 1 << endl;       for (int i = 0; i < M; i++) cout << 1 <<     << i + 1 << endl;       cout << 1 <<     << 1 << endl;     } else if (M == 1) {       if (N == 2) {         cout << 0 << endl;         cout <<  1 1  << endl <<  2 1  << endl <<  1 1  << endl;         return 0;       }       cout << 1 << endl;       cout << N <<     << 1 <<     << 1 <<     << 1 << endl;       for (int i = 0; i < N; i++) cout << i + 1 <<     << 1 << endl;       cout << 1 <<     << 1 << endl;     } else if (N % 2 == 0) {       cout << 0 << endl;       int k = 1;       cout << 1 <<     << 1 << endl;       while (k <= N) {         for (int i = 2; i <= M; i++) cout << k <<     << i << endl;         k++;         for (int i = M; i >= 2; i--) cout << k <<     << i << endl;         k++;       }       for (int i = N; i >= 1; i--) cout << i <<     << 1 << endl;     } else if (M % 2 == 0) {       cout << 0 << endl;       int k = 1;       cout << 1 <<     << 1 << endl;       while (k <= M) {         for (int i = 2; i <= N; i++) cout << i <<     << k << endl;         k++;         for (int i = N; i >= 2; i--) cout << i <<     << k << endl;         k++;       }       for (int i = M; i >= 1; i--) cout << 1 <<     << i << endl;     } else {       cout << 1 << endl;       cout << N <<     << M <<     << 1 <<     << 1 << endl;       int i = 1;       while (i <= N) {         for (int j = 1; j <= M; j++) cout << i <<     << j << endl;         i++;         if (i > N) break;         for (int j = M; j >= 1; j--) cout << i <<     << j << endl;         i++;       }       cout << 1 <<     << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int x[1000000];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int sol = x[n - 1] - x[0];     int p = n / 2 - 1;     for (int i = 0; i <= p; i++) sol = min(sol, x[n - 1 - (p - i)] - x[i]);     cout << sol << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, inF = 1e6 + 10;   int n, k, u, v, c, maxi, a[N], sz[N];   bool ok;   vector<int> nei[N];   int get_sz(int v, int par = -1) {     for (int u : nei[v])       if (u != par) sz[v] += get_sz(u, v);     return ++sz[v];   }   int dfs(int v, int par = -1) {     int dp = (a[v] < c ? -inF : 1);     int mx1 = 0, mx2 = 0;     for (int u : nei[v])       if (u != par) {         int DP = dfs(u, v);         if (DP == sz[u])           dp += DP;         else {           mx2 = max(mx2, DP);           if (mx2 > mx1) swap(mx1, mx2);         }       }     ok |= (dp + mx1 + mx2) >= k;     if (a[v] < c) return 0;     return dp + mx1;   }   bool check() {     ok = false;     dfs(min_element(a, a + n) - a);     return ok;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       nei[--u].push_back(--v);       nei[v].push_back(u);     }     get_sz(min_element(a, a + n) - a);     int l = 0, r = inF;     while (r - l > 1) {       c = (l + r) >> 1;       if (check())         l = c;       else         r = c;     }     cout << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 8;   int a[N], fa[N][20];   vector<int> E[N];   long long res;   void dfs(int x, int f) {     fa[x][0] = f;     long long temp = a[f];     for (int i = 1; i < 20; i++) {       fa[x][i] = fa[fa[x][i - 1]][i - 1];       temp = min(temp, (i + 1ll) * a[fa[x][i]]);     }     if (f != x) res += temp + a[x];     for (int &e : E[x])       if (e != f) dfs(e, x);   }   int main() {     ios::sync_with_stdio(false);     int n, rt = 0;     a[0] = INT_MAX;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], rt = a[rt] < a[i] ? rt : i;     for (int i = 1, u, v; i < n; i++)       cin >> u >> v, E[u].push_back(v), E[v].push_back(u);     dfs(rt, rt);     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 5;   const long long LINF = LLONG_MAX;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (360 % (180 - n) == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long int k, col = 0;     cin >> n >> m >> k;     vector<int> desk;     for (int i = 1; i < n + 1; ++i) {       desk.push_back(m * i);     }     for (int i = 1; i < desk.size() + 1; ++i) {       if (k <= desk[i - 1] * 2) {         cout << i <<    ;         if (k % 2 == 0) {           if (i > 1)             cout << (k - desk[i - 2] * 2) / 2 <<   R ;           else             cout << k / 2 <<   R ;         } else {           if (i > 1)             cout << ((k + 1) - desk[i - 2] * 2) / 2 <<   L ;           else             cout << (k + 1) / 2 <<   L ;         }         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   using namespace std;   int main() {     int q;     long long int a, b, c;     long long int ans = 0;     cin >> q;     while (q--) {       cin >> a >> b >> c;       ans = (a + b + c) / 2;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, bt[1000001] = {}, ar[1000001] = {};   vector<int> v;   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> ar[i];         ar[i] = i - ar[i];         bt[i] = 0;       }       int x = 0;       while (!bt[x]) {         v.push_back(x);         bt[x] = v.size();         x = ar[x];       }       cout << v.size() - bt[x] + 1 <<   n ;       for (int i = bt[x] - 1; i < v.size(); i++) {         cout << v[i] + 1;         if (i < v.size() - 1) {           cout <<    ;         }       }       cout <<   n ;       v.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }   void solve() {     int r1, r2, c1, c2, d1, d2;     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     int a;     bool ans = false;     for (a = 1; a <= 9; ++a) {       int b = r1 - a;       int c = c1 - a;       int d = d1 - a;       if (a > 0 && a < 10 && b > 0 && b < 10 && c > 0 && c < 10 && d > 0 &&           d < 10) {         if (a != b && b != c && c != d && b != d && a != d && a != c) {           if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&               a + d == d1 && b + c == d2) {             cout << a <<     << b <<   n ;             cout << c <<     << d <<   n ;             ans = true;           }         }       }     }     if (!ans) cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     while (cin >> s) {       int ans = 1e6;       for (int i =  a ; i <=  z ; i++) {         int t = 0, k = 0;         for (int j = 0; j < s.length(); j++) {           if (s[j] == i)             t = 0;           else             t++;           k = max(k, t);         }         ans = min(ans, k);       }       cout << ans + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   void solve() {     long long int i, a, b, c, d, n;     cin >> a >> b >> c >> d;     n = a + b + c + d;     string s =   ;     while (a > 0) {       s +=  0 ;       a--;     }     while (c > 0) {       s +=  2 ;       c--;     }     i = 0;     while (b > 0 && i < s.length()) {       if (s[i] ==  0 ) {         s.insert(i + 1, 1,  1 );         b--;       } else {         break;       }       i = i + 2;     }     while (d > 0 && i < s.length()) {       if (s[i] ==  2 ) {         s.insert(i + 1, 1,  3 );         d--;       }       i = i + 2;     }     while (b > 0 && i < s.length()) {       if (s[i] ==  2 ) {         s.insert(i + 1, 1,  1 );         b--;       }       i = i + 2;     }     if (d > 0 && s[0] ==  2 ) {       s.insert(0, 1,  3 );       d--;     }     if (b > 0 && (s[0] ==  0  || s[0] ==  2 )) {       s.insert(0, 1,  1 );       b--;     }     if (b > 0 && (s[s.length() - 1] ==  0  || s[s.length() - 1] ==  2 )) {       s.insert(s.length() - 1, 1,  1 );       b--;     }     while (b > 0) {       s +=  1 ;       b--;     }     while (d > 0) {       s +=  3 ;       d--;     }     for (i = 1; i < n; i++) {       if (abs(s[i] - s[i - 1]) != 1) {         cout <<  NO ;         return;       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) cout << s[i] <<    ;   }   int main() {     long long int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> E[65600];   vector<pair<int, int> > V;   int main() {     int n;     scanf( %d , &n);     queue<int> Q;     int degree[65600 + 10], Xsum[65600 + 10];     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       degree[i] = a;       Xsum[i] = b;       if (degree[i] == 1) Q.push(i);     }     while (!Q.empty()) {       int u = Q.front();       Q.pop();       if (degree[u] == 0) continue;       int othernode = Xsum[u];       V.push_back(make_pair(u, othernode));       degree[othernode]--;       degree[u]--;       Xsum[othernode] = Xsum[othernode] ^ u;       if (degree[othernode] == 1) Q.push(othernode);     }     printf( %d n , V.size());     for (int i = 0; i < V.size(); i++) printf( %d %d n , V[i].first, V[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using dl = double;   const int N = 2e5 + 10;   ll aarray[200000 + 10];   ll magic[101][101];   vector<ll> primes;   bool prime[1000001];   int main() {     ios_base::sync_with_stdio(false);     string str, ptr, ans =    ;     ll a, b, c, d, e, f, x = INT_MAX, y, k, t, A = 0, mod, B = 0, L, j, i, l, r,                          m, n, C = 0, sum = 0, sum1 = 0;     vector<ll> v, v1;     queue<ll> qu;     cin >> str;     cin >> n;     ll cnt = 0, fla = 0;     for (i = 1; i <= n; i++) {       cin >> ptr;       if (ptr.size() >= str.size()) {         if (ptr.substr(0, str.size()) == str) {           if (ptr < ans || ans ==    ) ans = ptr;         }       }     }     if (ans ==    )       cout << str << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int t = 1;     while (t--) {       long long int k, b, n;       cin >> k >> b >> n;       long long int s = 0;       long long int a[n];       map<long long int, vector<long long int> > mp;       mp[0].push_back(-1);       for (long long int i = 0; i < n; i++) {         cin >> a[i];         s = s + a[i];         s = s % (k - 1);         mp[s].push_back(i);       }       long long int an = 0;       if (b == k - 1 || b == 0) {         map<long long int, long long int> mp;         mp[0]++;         long long int an = 0, z = 0, ts = 0;         for (long long int i = 0; i < n; i++) {           ts = (ts + a[i]) % (k - 1);           if (a[i] == 0)             z++;           else             z = 0;           long long int tmp = (ts + (k - 1) - b) % (k - 1);           if (b == 0)             an += z;           else             an = an + mp[tmp] - z;           mp[ts]++;         }         cout << an;       } else {         for (auto x : mp) {           long long int y = x.first;           y = (y + b) % (k - 1);           for (long long int i = 0; i < x.second.size(); i++) {             long long int l =                 lower_bound(mp[y].begin(), mp[y].end(), x.second[i]) -                 mp[y].begin();             an = an + max(0ll, (long long int)(mp[y].size() - l));           }         }         cout << an;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_set<long long int> s;   void fun(long long int l, long long int r, long long int n) {     if (n > r)       return;     else if (n <= r and n >= l) {       s.insert(n);     }     fun(l, r, n * 2);     fun(l, r, n * 3);   }   void solve() {     long long int l, r;     cin >> l >> r;     fun(l, r, 1);     cout << s.size() << endl;   }   signed main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }