malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[60][60];   bool isRowChecked[60];   bool isColChecked[60];   bool doCheck(int r, int c) {     bool isRowRegard[60];     bool isColRegard[60];     memset(isRowRegard, false, sizeof(isRowRegard));     memset(isColRegard, false, sizeof(isColRegard));     std::vector<int> rows;     std::vector<int> cols;     for (int rr = r; rr < n; rr++) {       if (a[rr][c] ==  # ) {         isRowRegard[rr] = true;         rows.push_back(rr);       }     }     for (int cc = c; cc < m; cc++) {       if (a[r][cc] ==  # ) {         isColRegard[cc] = true;         cols.push_back(cc);       }     }     for (int i = 0; i < rows.size(); i++) {       for (int cc = 0; cc < m; cc++) {         if ((a[rows[i]][cc] ==  . ) && (isColRegard[cc] == true)) return false;         if ((a[rows[i]][cc] ==  # ) && (isColRegard[cc] == false)) return false;       }     }     for (int j = 0; j < cols.size(); j++) {       for (int rr = 0; rr < n; rr++) {         if ((a[rr][cols[j]] ==  . ) && (isRowRegard[rr] == true)) return false;         if ((a[rr][cols[j]] ==  # ) && (isRowRegard[rr] == false)) return false;       }     }     for (int i = 0; i < rows.size(); i++) isRowChecked[rows[i]] = true;     for (int j = 0; j < cols.size(); j++) isColChecked[cols[j]] = true;     return true;   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 0; i < n; i++) scanf( %s n , a[i]);     memset(isRowChecked, false, sizeof(isRowChecked));     memset(isColChecked, false, sizeof(isColChecked));     for (int r = 0; r < n; r++) {       if (isRowChecked[r]) continue;       for (int c = 0; c < m; c++) {         if (isColChecked[c]) continue;         if (a[r][c] ==  # ) {           if (doCheck(r, c) == false) {             printf( No n );             return 0;           }         }       }     }     printf( Yes n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long md = 1000000007) {     long long res = 1;     x %= md;     while (y > 0) {       if (y & 1) res = (res * x) % md;       x = (x * x) % md;       y = y >> 1;     }     return res % md;   }   signed main() {     long long n, m;     cin >> n >> m;     long long root = sqrt(n) + 1;     std::vector<long long> factors;     std::vector<pair<int, int> > v(m);     for (int i = 1; i < root; i++) {       if (n % i) continue;       long long temp = n / i;       factors.push_back(i);       if (i != temp && temp != n) factors.push_back(temp);     }     std::vector<long long> check(m, 0);     std::map<pair<long long, long long>, long long> map;     for (int i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       if (b < a) swap(a, b);       v[i] = make_pair(a, b);       map[v[i]] = i;     }     for (int i = 0; i < factors.size(); i++) {       for (int j = 0; j < m; j++) check[i] = 0;       long long x = factors[i];       long long first = 1;       for (int j = 0; j < m; j++) {         long long a = min((v[j].first + x) % n, (v[j].second + x) % n);         long long b = max((v[j].first + x) % n, (v[j].second + x) % n);         std::map<pair<long long, long long>, long long>::iterator it =             map.find(make_pair(a, b));         if (it == map.end()) {           first = 0;           break;         }       }       if (first) {         cout <<  Yes ;         return 0;       }     }     cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   struct Node {     int to;     long long dis;     int type;     Node(int a = 0, long long b = 0, int c = 0) {       to = a;       dis = b;       type = c;     }     friend bool operator<(Node a, Node b) {       if (a.dis != b.dis) return a.dis > b.dis;       return a.type > b.type;     }   };   int n, m, k;   int vis[100005], p[100005];   long long dis[100005];   vector<Node> v[100005];   void djs(int x) {     memset(vis, 0, sizeof(vis));     memset(p, 0, sizeof(p));     for (int i = 0; i <= n; i++) dis[i] = INF;     priority_queue<Node> q;     q.push(Node(x, 0, 0));     dis[x] = 0;     Node u, w;     while (!q.empty()) {       u = q.top();       q.pop();       if (u.dis != dis[u.to] || vis[u.to]) continue;       vis[u.to] = 1;       for (int i = 0; i < v[u.to].size(); i++) {         w = v[u.to][i];         if (!vis[w.to]) {           if (u.dis + w.dis < dis[w.to]) {             dis[w.to] = u.dis + w.dis;             q.push(Node(w.to, dis[w.to], 0));             p[w.to] = w.type;           } else if (u.dis + w.dis == dis[w.to] && w.type == 0) {             p[w.to] = w.type;           }         }       }     }   }   int main() {     while (~scanf( %d%d%d , &n, &m, &k)) {       for (int i = 0; i <= n; i++) {         while (!v[i].empty()) v[i].clear();       }       int a, b;       long long c;       for (int i = 0; i < m; i++) {         scanf( %d%d%lld , &a, &b, &c);         v[a].push_back(Node(b, c, 0));         v[b].push_back(Node(a, c, 0));       }       for (int i = 0; i < k; i++) {         scanf( %d%lld , &b, &c);         v[1].push_back(Node(b, c, 1));         v[b].push_back(Node(1, c, 1));       }       djs(1);       for (int i = 2; i <= n; i++) {         k -= p[i];       }       printf( %d n , k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     int arr[m];     for (int i = 0; i < m; i++) cin >> arr[i];     long long res = arr[0];     for (int i = 1; i < m; i++) {       if (arr[i] - arr[i - 1] < 0) {         res += (n - arr[i - 1]) + arr[i];       } else         res += (arr[i] - arr[i - 1]);     }     cout << res - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a1, a2, a3, sum = 0, a12, a23, a31;   int main() {     cin >> a1 >> a2 >> a3;     sum = a1 + a2 + a3;     if (sum % 2) {       cout <<  Impossible ;       return 0;     }     sum /= 2;     a12 = sum - a3;     a23 = sum - a1;     a31 = sum - a2;     if (a12 < 0 || a23 < 0 || a31 < 0) {       cout <<  Impossible ;       return 0;     } else       cout << a12 <<     << a23 <<     << a31;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   char a[N];   int n, k, delta, top, st[N];   bool vis[N];   int main() {     scanf( %d%d , &n, &k), scanf( %s , a + 1);     delta = (n - k) / 2, top = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] ==  ( )         st[++top] = i;       else {         if (delta) {           --delta, vis[i] = 1;           vis[st[top]] = 1;         }         --top;       }     }     for (int i = 1; i <= n; ++i)       if (!vis[i]) printf( %c , a[i]);     puts(  );     return 0;   }
//AYUSH VERMA       //*********************************************  *********************************       //***************/A **************************  ******   *********///*************       //**************//Y  ************************  ********   *******///**************       //*************///U   **********************  **********   **A**///***************       //************///*S*   ********************  ************   *M*///****************       //***********/////H     ******************  **************   R///*****************       //**********///*******   ****************  ****************  E//******************       //*********///*********   **************  ****************** V/*******************       //*************************************  *****************************************       #include<bits//stdc++.h>       #define till(condition) while(condition)       #define ull unsigned long long int       #define ll long long int       #define space printf(   )       #define nl printf(  n )       #define MOD 1000000007       using namespace std;       int main()       {           int t;           cin>>t;           till(t--)           {               int n;               cin>>n;               ll a[100001],want[100001];               ll max=0;               ll maxtest=0;               for(int i=0;i<n;i++)               {                   cin>>a[i];                   if(a[i]>maxtest)                   {                       maxtest=a[i];                   }               }               sort(a,a+n,greater<int>());               ll wantsum=0;               for(int i=0;i<n;i++)               {                   want[i]=(maxtest-a[i]);                   wantsum+=(want[i]);               }               for(int i=0;i<n;i++)               {                   ll temp=a[i],fill;                   ll tempwantsum=wantsum-want[i];                   if(i!=0)                   {                       fill=a[0];                   }                   else                   {                       fill=a[1];                   }                   ll subs=(n-1)*(temp-fill);                   if(subs>0)                   {                       tempwantsum-=(subs);                   }                                      // cout<< * <<temp;                   // nl;                   if(tempwantsum<=temp)                   {                       temp-=(tempwantsum);                       if(temp%(n-1)!=0)                       {                           ll ans=(n-1)-(temp%(n-1));                           if(ans>max)                           {                               max=ans;                           }                       }                   }                   else                   {                       if((tempwantsum-temp)>max)                       {                           max=(tempwantsum-temp);                       }                   }               //     cout<< ** <<max;               // nl;               }               cout<<max;               nl;                                            }                  }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   const int maxn = 100000 + 10;   int go[maxn][26], fail[maxn];   int I[maxn], F[maxn], S[maxn], FIN[maxn];   int total;   void push(string &s, int index, int freq) {     int u = 0;     for (auto c : s) {       int x = c -  a ;       if (!go[u][x]) go[u][x] = total++;       u = go[u][x];     }     I[u] = index, F[u] = freq, S[u] = s.length(), FIN[u] = u;   }   void build() {     queue<pair<int, int> > q;     for (int i = 0; i < 26; ++i) {       if (go[0][i]) q.push({go[0][i], 0});     }     while (!q.empty()) {       auto x = q.front();       q.pop();       int u = x.first, f = x.second;       fail[u] = f;       if (!FIN[u]) FIN[u] = FIN[f];       for (int i = 0; i < 26; ++i) {         if (go[u][i])           q.push({go[u][i], go[f][i]});         else           go[u][i] = go[f][i];       }     }   }   int ANSWER[maxn];   queue<int> deq[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     total = 1;     string s;     cin >> s;     int q;     cin >> q;     for (int i = 1; i <= q; ++i) {       int f;       string t;       cin >> f >> t;       push(t, i, f);     }     build();     memset(ANSWER, 0x3f, sizeof ANSWER);     for (int i = 0, u = 0; i < (int)s.length(); ++i) {       u = go[u][s[i] -  a ];       int v = FIN[u];       while (v) {         int idx = I[v];         deq[idx].push(i);         if (deq[idx].size() > F[v]) deq[idx].pop();         if (deq[idx].size() == F[v]) {           int beg = deq[idx].front();           ANSWER[idx] = min(ANSWER[idx], i - beg + S[v]);         }         v = FIN[fail[v]];       }     }     for (int i = 1; i <= q; ++i) {       if (ANSWER[i] == oo)         cout << -1 <<   n ;       else         cout << ANSWER[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e18;   const long long mod = 1e9;   long long dp[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long i;       long long a[n];       set<long long> s;       long long c = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);         if (i > 0) {           if (a[i] != a[i - 1]) {             c++;           }         }       }       long long d = s.size();       if (d <= k) {         cout << 1 << endl;       } else {         if (k == 1 && (d != k)) {           cout <<  -1  << endl;         } else {           cout << (((c % (k - 1)) == 0) ? (c / (k - 1)) : (c / (k - 1) + 1))                << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 10, M = 2097152 + 10;   long long n, x, ans, ar[N], mark[M][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) cin >> ar[i];     mark[0][1]++;     for (long long i = 0; i < n; i++) {       x ^= ar[i];       mark[x][i & 1]++;     }     for (long long i = 0; i < M; i++) {       ans += (mark[i][0] * (mark[i][0] - 1)) / 2;       ans += (mark[i][1] * (mark[i][1] - 1)) / 2;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a, b, c, d, e, y = 0, x = 0, l = 0, z = 0, k = 0, m = 0;       cin >> a >> b >> c >> d >> e;       if (d > e) {         while (a > 1 && b > 0) {           y++;           a = a - 2;           b = b - 1;         }         while (a > 1 && c > 0) {           x++;           a = a - 2;           c = c - 1;         }         l = (d * y) + (x * e);         cout << l << endl;       } else {         while (a > 1 && c > 0) {           z++;           a = a - 2;           c = c - 1;         }         while (a > 1 && b > 0) {           k++;           a = a - 2;           b = b - 1;         }         m = (e * z) + (k * d);         cout << m << endl;       }       y = 0, x = 0, l = 0, z = 0, k = 0, m = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7, N = 1e5 + 10;   const ll MX = 1e8;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     ll ans = 0;     for (ll i = 0; i < MX; i += 25) {       string k = to_string(i);       if (k.length() != s.length()) continue;       set<ll> se;       ll bad = 1;       42;       for (ll j = 0; j < k.length(); j++) {         if (s[j] ==  _ ) continue;         if (s[j] ==  X ) {           se.insert(k[j] -  0 );           if (se.size() > 1) break;           continue;         }         if (s[j] != k[j]) bad = 0;       }       ans += (se.size() <= 1 and bad);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c1[1005], c2[1005];   long long f[100005][2], ans, k, l;   bool pd;   int main() {     scanf( %s , c1);     scanf( %s , c2);     scanf( %lld , &k);     l = strlen(c1);     f[0][0] = 1;     for (register long long i = 1; i <= k; i = -~i) {       f[i][0] = ((l - 1) * f[i - 1][1]) % 1000000007;       f[i][1] = (((l - 2) * f[i - 1][1]) % 1000000007 + f[i - 1][0]) % 1000000007;     }     for (register long long i = 0; i < l; i = -~i) {       pd = false;       for (register long long j = 0; j < l; j = -~j)         if (c1[(i + j) % l] != c2[j]) {           pd = true;           break;         }       if (!pd) {         if (i)           ans = (ans + f[k][1]) % 1000000007;         else           ans = (ans + f[k][0]) % 1000000007;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 257;   string rec[mxn][3];   bool been[mxn][3];   inline int G(string s) {     int t = 0;     for (int i = 0; i < s.size(); ++i) t = t * 2 + s[i] -  0 ;     return t;   }   priority_queue<pair<int, int> > pq;   bool changed;   string Min(string a, string b) {     if (a.size() != b.size()) {       if (a.size() < b.size())         return a;       else         return b;     }     return min(a, b);   }   inline void upd(string& a, string b) {     if (a == b) return;     if (Min(a, b) == b) {       changed = 1;       a = b;     }   }   inline void prep() {     int n = 256;     for (int i = 0; i < n; ++i)       for (int j = 0; j < 3; ++j)         rec[i][j] =  zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz ;     rec[G( 00001111 )][0] =  x ;     rec[G( 00110011 )][0] =  y ;     rec[G( 01010101 )][0] =  z ;     for (changed = 1; changed;) {       changed = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j < 2; ++j) upd(rec[i][j + 1], rec[i][j]);       for (int i = 0; i < n; ++i) upd(rec[i ^ 255][0],  !  + rec[i][0]);       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           upd(rec[i & j][1], rec[i][1] +  &  + rec[j][0]),               upd(rec[i | j][2], rec[i][2] +  |  + rec[j][1]);       for (int i = 0; i < n; ++i) upd(rec[i][0],  (  + rec[i][2] +  ) );     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T = 1;     cin >> T;     prep();     for (; T--;) {       string s;       cin >> s;       int t = G(s);       cout << Min(Min(rec[t][0], rec[t][1]), rec[t][2]) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e6 + 5;   const int inf = 0x3f3f3f3f;   int main() {     int n;     scanf( %d , &n);     char a;     getchar();     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %c , &a);       if (a ==  - )         ans--;       else         ans++;       ans = max(0, ans);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   char s[200005];   int n, k;   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s);     if (n == 1) {       if (k == 0)         printf( %c n , s[0]);       else         printf( 0 n );     } else {       if (k == 0)         printf( %s n , s);       else {         if (s[0] !=  1 ) k--;         s[0] =  1 ;         int t = 1;         while (t < n && k) {           if (s[t] !=  0 ) {             s[t] =  0 ;             k--;           }           t++;         }         printf( %s , s);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const long long LINF = (1LL << 62);   const int INF = 1 << 30;   const int NS = 100010;   const int MS = 19;   const int MOD = 1000000007;   const double PI = acos(-1.0);   int n, m, q, h[NS];   pair<int, int> s[NS];   int L[NS], R[NS];   int solve() {}   int main() {     while (~scanf( %d %d , &n, &q)) {       m = n - 1;       for (int i = 1; i <= n; i++) {         scanf( %d , &h[i]);         if (i > 1) {           h[i - 1] = abs(h[i - 1] - h[i]);           s[i - 1] = make_pair(h[i - 1], i - 1);         }       }       sort(s + 1, s + m + 1);       set<int> idSet;       idSet.insert(0);       idSet.insert(n);       for (int i = m; i >= 1; i--) {         int pos = s[i].second;         idSet.insert(pos);         __typeof(idSet.begin()) it = idSet.find(pos);         L[pos] = *(--it);         it++, it++;         R[pos] = *(it);       }       int x, y;       for (int qi = 0; qi < q; qi++) {         scanf( %d %d , &x, &y);         long long ans = 0;         for (int i = x; i < y; i++) {           int lb = i - max(L[i], x - 1);           int rb = min(R[i], y) - i;           ans += 1LL * h[i] * lb * rb;         }         printf( %I64d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2 * 1e5 + 10;   int a[M];   int main() {     long long s, n, p1, c, pos1, pos2, p2, i, ans = 1, d, x, j;     scanf( %I64d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     if (a[0] != -1) {       p1 = a[0];       pos1 = 0;       c = 1;     } else       c = 0;     s = 0;     ans = 1;     for (i = 1; i < n; i++) {       if (i == 10) i = 10;       if (c == 0) {         if (a[i] != -1) {           c = 1;           p1 = a[i];           pos1 = i;         }         continue;       }       if (c == 1) {         if (a[i] != -1) {           if ((a[i] - p1) % (i - pos1) != 0) {             ans++;             s = i;             c = 1;             p1 = a[i];             pos1 = i;           } else {             c = 2;             p2 = a[i];             pos2 = i;             d = (p2 - p1) / (pos2 - pos1);             x = p1 + d * (s - pos1);             if (x <= 0) {               ans++;               c = 1;               p1 = a[i];               pos1 = i;               s = i;             }           }         }         continue;       }       d = (p2 - p1) / (pos2 - pos1);       x = p1 + d * (i - pos1);       if (a[i] == -1) {         if (x <= 0) {           ans++;           c = 0;           s = i;         }         continue;       } else {         if (x != a[i]) {           ans++;           s = i;           c = 1;           p1 = a[i];           pos1 = i;         }       }     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   int main() {     int l_a, r_a, t_a;     int l_b, r_b, t_b;     int l_x, r_x, t_x;     cin >> l_a >> r_a >> t_a;     cin >> l_b >> r_b >> t_b;     if (r_b - l_b < r_a - l_a) {       l_x = l_b, r_x = r_b, t_x = t_b;       l_b = l_a, r_b = r_a, t_b = t_a;       l_a = l_x, r_a = r_x, t_a = t_x;     }     int g = gcd(t_a, t_b);     int c = l_b - l_a;     int c_1, c_2;     if (l_b - l_a >= 0) {       c_1 = c % g;       c_2 = (-(c % g - g)) % g;     } else {       c_1 = g - (-c) % g;       c_2 = (-(c_1 - g)) % g;     }     int answer = r_a - l_a + 1 - c_1;     answer = max(answer, min(r_b - l_b + 1 - c_2, r_a - l_a + 1));     cout << max(answer, 0);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 10000;   const long long M = 60;   vector<long long> v;   long long n, first, t, a[N], second, cn, p;   void val(long long first) {     long long second, z;     second = first;     first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1;     ;     second = (second - v[first] + a[first]) % v[first];     z = second + v[first];     while (1) {       second = z - v[first];       p = (second - a[first] >= 0) ? (v[first] + (second - a[first]))                                    : (v[first] * 2 - (a[first] - second));       cout << p <<    ;       if (p == 1) break;       first--;       z >>= 1;     }   }   int main() {     cin >> n;     for (long long i = (long long)0; i <= (long long)M; i++)       v.push_back((1LL << i));     for (long long i = (long long)1; i <= (long long)n; i++) {       cin >> t;       if (t <= 2) {         cin >> first >> second;         first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1;         ;         for (long long j = (long long)first; j <= (long long)M; j++) {           a[j] += (second % v[j]) * (1LL << (j - first));           if (a[j] < 0) a[j] %= v[j], a[j] += v[j];           a[j] %= v[j];           if (t == 1) break;         }       } else {         cn++;         cin >> first;         val(first);         cout <<                 <<   n ;       }     }   }