malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int x[3], y[3];   map<pair<int, int>, bool> cleaned;   int cost(int cx, int cy) {     int sum = 0;     for (int i = 0; i < (3); i++)       sum += ((cx - x[i]) > 0 ? (cx - x[i]) : -(cx - x[i])) +              ((cy - y[i]) > 0 ? (cy - y[i]) : -(cy - y[i]));     return sum;   }   void clean(int x1, int y1, int x2, int y2) {     cleaned[pair<int, int>(x1, y1)] = true;     if (x1 == x2 && y1 == y2) return;     if (x1 < x2)       clean(x1 + 1, y1, x2, y2);     else if (x1 > x2)       clean(x1 - 1, y1, x2, y2);     else if (y1 < y2)       clean(x1, y1 + 1, x2, y2);     else       clean(x1, y1 - 1, x2, y2);   }   int main() {     ios_base::sync_with_stdio(false);     int bestX = 0, bestY = 0, bestCost;     for (int i = 0; i < (3); i++) cin >> x[i] >> y[i];     bestCost = cost(0, 0);     for (int ix = 0; ix < (1001); ix++)       for (int iy = 0; iy < (1001); iy++) {         int curCost = cost(ix, iy);         if (curCost < bestCost) {           bestCost = curCost;           bestX = ix;           bestY = iy;         }       }     for (int i = 0; i < (3); i++) clean(x[i], y[i], bestX, bestY);     cout << ((cleaned).size()) << endl;     for (map<pair<int, int>, bool>::iterator it = cleaned.begin();          it != cleaned.end(); ++it) {       cout << it->first.first <<     << it->first.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   int n, l[N], t[N];   long long r;   int main() {     scanf( %d%lld , &n, &r);     for (int i = 0; i < n; i++) scanf( %d , l + i);     for (int i = 0; i < n; i++) {       scanf( %d , t + i);       if (t[i] < l[i]) return puts( -1 );     }     vector<long long> out;     long long cur = 0, time = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       int x = min((long long)l[i], cur);       cur -= x;       l[i] -= x;       t[i] -= x;       time += x;       x = l[i] + l[i];       time += min(x, t[i]);       int d = x - t[i];       if (d <= 0) continue;       int need = (d + r - 1) / r;       ans += need;       long long lo = time - d;       for (int j = 0; j < need; j++) {         if (out.size() > 100000) break;         out.push_back(lo);         lo += r;       }       cur = need * r - d;     }     printf( %lld n , ans);     if (ans <= 100000) {       for (int i = 0; i < ans; i++) printf( %lld  , out[i]);     }   }
#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   std::vector<ul> v;   std::string s;   int main() {     std::getline(std::cin, s);     std::stringstream ss(s);     while (std::getline(ss, s,  , )) {       std::stringstream ss(s);       ul t;       ss >> t;       v.push_back(t);     }     std::sort(v.begin(), v.end());     bool flag = false;     for (ul i = 0, j = 0; i != v.size(); i = j) {       for (++j; j != v.size() && v[j - 1] + 1 >= v[j]; ++j)         ;       if (flag) {         std::putchar( , );       }       flag = true;       if (v[j - 1] == v[i]) {         std::printf( %u , v[i]);       } else {         std::printf( %u-%u , v[i], v[j - 1]);       }     }     std::putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)4e2;   const int INF = (int)1e9;   int n, m, a[N][N], p;   int dyn[N][N], last[N];   vector<pair<int, int> > q[N * N];   int len[N][N];   int main() {     cin >> n >> m >> p;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         q[a[i][j]].push_back(make_pair(i, j));         dyn[i][j] = INF;       }     }     for (int i = 0; i < m; ++i) {       dyn[0][i] = i;     }     for (int lvl = 1; lvl <= p; ++lvl) {       int x, y;       for (auto tmp : q[lvl]) {         tie(x, y) = tmp;         int ans = INF;         for (int row = 0; row < n; ++row) {           if (last[row] == lvl - 1) {             ans = min(ans, dyn[row][y] + abs(row - x));           }         }         len[x][y] = ans;       }       for (auto tmp : q[lvl]) {         tie(x, y) = tmp;         if (last[x] != lvl) {           last[x] = lvl;           for (int col = 0; col < m; ++col) {             dyn[x][col] = len[x][y] + abs(y - col);           }         } else {           for (int col = 0; col < m; ++col) {             dyn[x][col] = min(dyn[x][col], len[x][y] + abs(y - col));           }         }       }     }     cout << len[q[p][0].first][q[p][0].second] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   long long binary_expo(long long base, long long expo) {     long long res = 1;     while (expo) {       if (expo % 2) {         res = mul(res, base);       }       expo /= 2;       base = mul(base, base);     }     return res;   }   long long A[202];   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= 2 * n; i++) {       cin >> A[i];     }     long long ans = 0;     for (long long i = 1; i <= 2 * n; i += 2) {       long long index = -1;       for (long long j = i + 1; j <= 2 * n; j++) {         if (A[i] == A[j]) {           index = j;           break;         }       }       for (long long j = index - 1; j >= i + 1; j--) {         swap(A[j], A[j + 1]);         ans++;       }     }     cout << ans <<   n ;   }   signed main() {     long long t;     t = 1;     while (t--) {       solve();     }   }
#include<bits/stdc++.h>   using namespace std;      long long t,n,k,pos;   string s;   bool mode;      char best(int pos){    char c=s[pos];        return min({c,char((c- a +1)%k+ a ),char(((c- a -1)%k+k)%k+ a )});   }      int main(){       ios::sync_with_stdio(false);    cin.tie(0);       cin>>t;        while(t--){     cin>>n>>k>>s;          mode=false;     pos=0;          while(pos<s.size()){      if(mode==false){       if((pos+1>=s.size() || best(pos)<= best(pos+1)) && (pos+2>=s.size() || best(pos)<=s[pos+2])){        s[pos]=best(pos);        pos++;        mode=false;       }else if(pos+2>=s.size() || best(pos+1)<=s[pos+2]){        if(best(pos+1)==s[pos+1]){         s[pos]=best(pos);         swap(s[pos],s[pos+1]);         pos++;         mode=true;        }else{         s[pos+1]=best(pos+1);         swap(s[pos],s[pos+1]);         mode=true;         pos++;        }       }else{        s[pos]=best(pos);        swap(s[pos+1],s[pos+2]);        swap(s[pos],s[pos+1]);        pos+=2;        mode=true;       }      }else{       if((pos+1>=s.size() || s[pos]<=s[pos+1]) && (pos+2>=s.size() || s[pos]<=s[pos+2])){        pos++;        mode=false;       }else if(pos+2>=s.size() || s[pos+1]<=s[pos+2]){        swap(s[pos],s[pos+1]);        pos++;        mode=true;       }else{        swap(s[pos+1],s[pos+2]);        swap(s[pos],s[pos+1]);        pos+=2;        mode=true;       }      }            //cout<<s<<  n ;      //cout<<pos<<   <<mode<<  ecco  n ;     }          cout<<s<<  n ;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nMax = 2000005;   int p[nMax];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       p[i] = i + 1;     }     int s = 0;     for (int j = 2; j < n + 1; ++j) {       int curr = p[s];       p[n + s] = p[n + s - n % j];       for (int i = s; i <= n + s; i += j) {         int t = p[i];         p[i] = curr;         curr = t;       }       ++s;     }     for (int i = s; i < n + s; ++i) {       cout << p[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool debug = false;   int dp[1005][1005];   char a[1005], b[1005];   int main() {     scanf( %s%s , a + 1, b + 1);     int n = strlen(a + 1);     int m = strlen(b + 1);     for (int i = 1; i <= n; i++) dp[i][0] = i;     for (int i = 1; i <= m; i++) dp[0][i] = i;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]) + 1,                        dp[i - 1][j - 1] + (a[i] != b[j]));       }     }     printf( %d n , dp[n][m]);     while (n != 0 || m != 0) {       if (m != 0 && dp[n][m] == dp[n][m - 1] + 1) {         printf( INSERT %d %c n , n + 1, b[m]);         m--;       } else if (n != 0 && dp[n][m] == dp[n - 1][m] + 1) {         printf( DELETE %d n , n);         n--;       } else if (a[n--] != b[m--]) {         printf( REPLACE %d %c n , n + 1, b[m + 1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long MOD = 1e9 + 7;   long long n, m, cnt = 0;   long long a[N], comp[N], vis[N];   vector<long long> g[N], rg[N], v[N];   vector<long long> todo;   void dfs(long long k) {     vis[k] = 1;     for (auto it : g[k]) {       if (!vis[it]) {         dfs(it);       }     }     todo.push_back(k);   }   void dfs2(long long k, long long val) {     comp[k] = val;     v[val].push_back(a[k]);     for (long long w : rg[k]) {       if (comp[w] == -1) {         dfs2(w, val);       }     }   }   void sccAddE(long long from, long long to) {     g[from].push_back(to);     rg[to].push_back(from);   }   void scc() {     for (long long i = 1; i <= n; i++) {       comp[i] = -1;     }     for (long long i = 1; i <= n; i++) {       if (!vis[i]) dfs(i);     }     reverse(todo.begin(), todo.end());     for (long long i : todo) {       if (comp[i] == -1) {         dfs2(i, i);         cnt++;       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     cin >> m;     for (long long i = 1; i <= m; i++) {       long long u, v;       cin >> u >> v;       sccAddE(u, v);     }     scc();     long long ans1 = 0;     long long ans2 = 1;     for (long long i = 1; i <= n; i++) {       if (!v[i].size()) continue;       sort(v[i].begin(), v[i].end());       long long min1 = v[i][0];       ans1 += min1;       cnt = 0;       for (auto it : v[i])         if (it == min1) cnt++;       ans2 *= cnt;       ans2 %= MOD;     }     cout << ans1 <<     << ans2;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   unsigned long long min(unsigned long long x, unsigned long long y) {     if (x < y) return x;     return y;   }   unsigned long long max(unsigned long long x, unsigned long long y) {     if (x < y) return y;     return x;   }   long long min(long long x, long long y) {     if (x < y) return x;     return y;   }   long long max(long long x, long long y) {     if (x < y) return y;     return x;   }   double min(double x, double y) {     if (x < y) return x;     return y;   }   double max(double x, double y) {     if (x < y) return y;     return x;   }   unsigned long long gcd(unsigned long long x, unsigned long long y) {     if (!x) return y;     if (!y) return x;     if (x > y) swap(x, y);     return gcd(x, y % x);   }   unsigned long long inv(unsigned long long a, unsigned long long c) {     if (a == 1) {       return 1;     }     return ((c - (c / a)) * inv(c % a, c)) % c;   }   void printv(vector<int> &a) {     int n = a.size();     for (int i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     cout <<   END n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     for (int t = 1; t <= T; ++t) {       int n;       cin >> n;       int a[n + 1];       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       bool sorted = true;       for (int i = 1; i < n; ++i) {         if (a[i] > a[i + 1]) sorted = false;       }       int ans = 0;       while (!sorted) {         ans++;         if (ans & 1) {           for (int i = 1; i <= n - 2; i += 2) {             if (a[i] > a[i + 1]) {               swap(a[i], a[i + 1]);             }           }         } else {           for (int i = 2; i <= n - 1; i += 2) {             if (a[i] > a[i + 1]) {               swap(a[i], a[i + 1]);             }           }         }         sorted = true;         for (int i = 1; i < n; ++i) {           if (a[i] > a[i + 1]) sorted = false;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int str1 = n;     int str2 = -1;     int st1 = m;     int st2 = -1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           if (str1 > i) {             str1 = i;           }           if (str2 < i) {             str2 = i;           }           if (st1 > j) {             st1 = j;           }           if (st2 < j) {             st2 = j;           }         }       }     }     if (str2 == -1) {       cout << 1;     } else {       if (str2 - str1 + 1 > m || st2 - st1 + 1 > n) {         cout << -1;       } else {         int b = 0;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             if (a[i][j] ==  B ) {               b++;             }           }         }         int ma = max(str2 - str1 + 1, st2 - st1 + 1);         cout << ma * ma - b;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> no;     long long int n, m, s = 0, a[100000], l = 1, i;     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (i = 1; i <= m; i++) {       if (a[l] == i)         l++;       else {         s += i;         if (s <= m)           no.push_back(i);         else           break;       }     }     cout << no.size() << endl;     for (int j = 0; j < no.size(); j++) cout << no[j] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long total = n * k;       std::vector<long long> v(total);       for (long long i = 0; i < total; i++) {         cin >> v[i];       }       long long med;       if (n % 2 == 0) {         med = n / 2;       } else {         med = n / 2 + 1;       }       sort(v.begin(), v.end());       long long sum = 0;       if (n == 1) {         for (int i = 0; i < total; i++) {           sum += v[i];         }       } else {         for (long long i = total - n + med - 1; i >= ((med - 1) * k) - 1;              i -= (n - med + 1)) {           sum += v[i];         }       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n];     long long int sum = 0;     for (long int i = 0; i < n; i++) scanf( %lld , &a[i]), sum += a[i];     long long int ans[n];     long long int l = 0, r = 1e12;     long long int mid = 0;     while (l <= r) {       mid = (l + r) / 2;       long long int temp1 = mid * n;       long long int temp2 = temp1 + (n * (n - 1)) / 2;       if (temp1 <= sum && temp2 >= sum) {         r = mid - 1;       }       if (temp2 < sum)         l = mid + 1;       else         r = mid - 1;     }     mid = l;     long long int aa = 0;     for (long int i = 0; i < n; i++) {       long long int temp1 = mid * (n - i);       long long int temp2 = temp1 + ((n - i) * (n - i - 1)) / 2;       if (temp1 <= sum - aa && temp2 >= sum - aa)         ans[i] = mid;       else         ans[i] = ++mid;       aa += ans[i];     }     for (long int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   int n, k;   int a[maxn], b[maxn];   map<int, bool> MAP;   int main() {     int ans = 0;     scanf( %d%d , &k, &n);     for (int i = 0; i < k; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     vector<int> p;     if (k < n) {       cout << 0 << endl;       return 0;     }     for (int i = 0; i < k; i++) {       MAP.clear();       for (int i = 1; i < n; i++) {         MAP[b[i]] = true;       }       bool ok = true;       int t = b[0];       for (int j = i; j > 0; j--) {         t -= a[j];         MAP.find(t)->second = false;       }       int m = t - a[0];       t = b[0];       for (int j = i + 1; j < k; j++) {         t += a[j];         MAP.find(t)->second = false;       }       for (map<int, bool>::iterator it = MAP.begin(); it != MAP.end(); it++) {         if (it->second) {           ok = false;           break;         }       }       if (ok) {         p.push_back(m);       }     }     sort(p.begin(), p.end());     for (int i = 0; i < p.size(); i++) {       if (i == p.size() - 1 || p[i] != p[i + 1]) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[15];   void f(int fg, int x) {     if (fg == 1) {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) != 0) {           a[i] = 1;         }       }     } else if (fg == 2) {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) == 0) {           a[i] = 0;         }       }     } else {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) != 0) {           if (a[i] == 0 || a[i] == 1)             a[i] ^= 1;           else             a[i] = -a[i];         }       }     }   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i <= 10; i++) a[i] = 5;       for (int i = 0; i < n; i++) {         char ch;         int tp;         getchar();         scanf( %c , &ch);         scanf( %d , &tp);         if (ch ==  | )           f(1, tp);         else if (ch ==  & )           f(2, tp);         else           f(3, tp);       }       int ansor = 0;       int ansand = 1023;       int ansxor = 0;       for (int i = 0; i < 10; i++) {         if (a[i] == 1) {           ansor += (1 << i);         } else if (a[i] == 0) {           ansand -= (1 << i);         } else if (a[i] == -5) {           ansxor += (1 << i);         }       }       printf( 3 n );       printf( | %d n , ansor);       printf( & %d n , ansand);       printf( ^ %d n , ansxor);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long limita = 998244353;   long long n, v[200], st, dr, mij, mul, ans, maxDegree;   long long GCD(long long x, long long y) {     if (y != 0)       return GCD(y, x % y);     else       return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     for (int i = 1; i <= n; i++) {       ans = 180 / GCD(180LL, v[i]);       mul = 0;       st = 1;       dr = limita / ans;       while (st <= dr) {         mij = (st + dr) / 2;         maxDegree = (mij * ans - 2) * 180 / (mij * ans);         if (maxDegree >= v[i]) {           dr = mij - 1;           mul = mij;         } else           st = mij + 1;       }       if (mul == 0)         cout << -1 <<   n ;       else         cout << mul * ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[200000 + 5], x[200000 + 5], ada[35];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (i > 0)         x[i] = x[i - 1] ^ arr[i];       else         x[i] = arr[i];     }     if (x[n - 1] == 0)       printf( -1 n );     else {       for (int i = 0; i < n; i++) {         for (int j = 30; j >= 0; j--) {           if (x[i] & (1 << j)) {             if (!ada[j]) {               ada[j] = x[i];               break;             } else               x[i] ^= ada[j];           }         }       }       int res = 0;       for (int i = 0; i <= 30; i++) {         if (ada[i]) {           res++;         }       }       printf( %d n , res);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r, x, y, k;     cin >> l >> r >> x >> y >> k;     for (long long int i = x; i <= y; ++i) {       if (k * i >= l && k * i <= r) {         cout <<  YES  << endl;         exit(0);       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solutionC();   int main() {     solutionC();     return EXIT_SUCCESS;   }   int n, a[500002], b[500002];   bool check() {     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) return false;       if (s == 1 && a[i] != 0) return false;     }     return true;   }   void change() {     b[0] = a[0];     b[n - 1] = a[n - 1];     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) {         b[i] = 1;         continue;       }       if (s == 1 && a[i] != 0) {         b[i] = 0;         continue;       }       b[i] = a[i];     }     for (int i = 0; i < n; ++i) a[i] = b[i];   }   void out() {     for (int i = 0; i < n; ++i) {       if (i) cout <<    ;       cout << a[i];     }     cout << endl;   }   void solve() {     int l = 1;     vector<pair<int, int>> e;     for (int i = 1; i < n; ++i) {       if (a[i] != a[i - 1]) {         ++l;       } else {         if (l >= 3) e.emplace_back(i - l, i - 1);         l = 1;       }     }     if (l >= 3) e.emplace_back(n - l, n - 1);     int ans = 0;     for (auto it : e) {       int d = it.second - it.first;       if (d % 2 == 0) {         ans = max(ans, d / 2);         assert(a[it.first] == a[it.second]);         for (int i = it.first; i <= it.second; ++i) a[i] = a[it.first];       } else {         assert(a[it.first] != a[it.second]);         ans = max(ans, (d - 1) / 2);         for (int i = it.first; i <= it.second; ++i)           if (i - it.first < it.second - i)             a[i] = a[it.first];           else             a[i] = a[it.second];       }     }     cout << ans << endl;     out();   }   void bf() {     for (int l = 3; l < 24; ++l) {       n = l;       int mx = 0;       cout <<  n:   << l << endl;       for (int bm = 0; bm < (1 << l); ++bm) {         for (int i = 0; i < n; ++i) a[i] = (bm & (1 << i)) > 0;         int cnt = 0;         while (!check()) {           cnt++;           change();           if (cnt > n * n * 2) {             cout <<  fnd:  ;             out();             break;           }         }         mx = max(mx, cnt);       }       cout <<  mx:   << mx << endl;     }   }   void solutionC() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     solve();   }