malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   vector<string> vr;   int n, m;   int a[105][105], b[105][105];   int xx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   int yy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   bool check(int i, int j) {     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != -2 && a[i][j] != -6)       return true;     return false;   }   bool Check(int i, int j) {     if (i >= 0 && i < n && j >= 0 && j < m && b[i][j] == -6) return true;     return false;   }   void dfs(int x, int y) {     int X, Y, i;     for (i = 0; i < 8; i++) {       X = x + xx[i];       Y = y + yy[i];       if (check(X, Y)) b[X][Y]++;     }   }   int main() {     char ma[105][105];     while (~scanf( %d%d , &n, &m)) {       int f = 0;       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       for (int i = 0; i < n; i++) {         cin >> ma[i];       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           a[i][j] = ma[i][j] -  0 ;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] == -6) {             b[i][j] = -6;             dfs(i, j);           }           if (a[i][j] == -2) b[i][j] = -2;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (b[i][j] == -2) {             for (int k = 0; k < 8; k++) {               int X = xx[k] + i;               int Y = yy[k] + j;               if (Check(X, Y)) {                 f = 1;                 break;               }             }           }           if (a[i][j] != b[i][j]) {             f = 1;             break;           }           if (f == 1) break;         }         if (f == 1) break;       }       if (f)         printf( NO n );       else         printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int a, b, c, d;       cin >> a >> b >> c >> d;       string w, x, y, z, k =  Ya , l =  Tidak ;       if (a == 0 && d == 0) {         if (b % 2 == 1) {           cout <<  Tidak Ya Tidak Tidak n ;         } else {           cout <<  Tidak Tidak Ya Tidak n ;         }       } else if (b == 0 && c == 0) {         if (a % 2 == 1) {           cout <<  Ya Tidak Tidak Tidak n ;         } else {           cout <<  Tidak Tidak Tidak Ya n ;         }       } else {         if ((a + b) % 2 == 1) {           cout <<  Ya Ya Tidak Tidak n ;         } else {           cout <<  Tidak Tidak Ya Ya n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   pair<long long, int> arr[N];   long long t[4 * N] = {};   inline void update(int v, int vl, int vr, int pos, long long val) {     if (vl == vr) {       t[v] = val;       return;     }     int vm = vl + (vr - vl) / 2;     if (pos <= vm)       update(2 * v + 1, vl, vm, pos, val);     else       update(2 * v + 2, vm + 1, vr, pos, val);     t[v] = max(t[2 * v + 1], t[2 * v + 2]);   }   inline long long get(int v, int vl, int vr, int l, int r) {     if (r < vl || vr < l) return 0;     if (l <= vl && vr <= r) return t[v];     int vm = vl + (vr - vl) / 2;     long long ql = get(2 * v + 1, vl, vm, l, r);     long long qr = get(2 * v + 2, vm + 1, vr, l, r);     return max(ql, qr);   }   inline bool c(pair<long long, int> x, pair<long long, int> y) {     if (x.first != y.first)       return x.first < y.first;     else       return x.second > y.second;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long r, h;       cin >> r >> h;       arr[i] = {1ll * r * r * h, i};     }     sort(arr, arr + n, c);     for (int i = 0; i < n; i++) {       long long res = get(0, 0, n - 1, 0, max(0, arr[i].second - 1));       update(0, 0, n - 1, arr[i].second, res + arr[i].first);     }     cout << fixed << setprecision(6) << 3.14159265 * get(0, 0, n - 1, 0, n - 1)          <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int n;   char s[20];   int ans[300100];   vector<int> dep[300100];   int G[300100][26], siz[300100], son[300100];   vector<int *> a;   void dfs(int o, int depth) {     dep[depth].push_back(o);     siz[o] = 1;     for (int i = 0; i < 26; ++i) {       if (G[o][i] == -1) continue;       dfs(G[o][i], depth + 1);       if (son[o] == -1 || siz[son[o]] < siz[G[o][i]]) {         son[o] = G[o][i];       }       siz[o] += siz[G[o][i]];     }   }   int DFS(int u, int v) {     int ret = 0;     for (int i = 0; i < 26; ++i) {       if (G[u][i] == -1) continue;       if (G[v][i] == -1) {         G[v][i] = G[u][i];         ret += siz[G[u][i]];         a.push_back(&G[v][i]);       } else {         ret += DFS(G[u][i], G[v][i]);       }     }     return ret;   }   int main() {     memset(G, -1, sizeof(G));     memset(son, -1, sizeof(son));     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d%s , &u, &v, s);       G[u][s[0] -  a ] = v;     }     dfs(1, 0);     int tmp = 0;     for (int i = 0; i <= n; ++i) {       a.clear();       ans[i] += tmp;       for (auto &j : dep[i]) {         if (son[j] != -1) ans[i + 1] += siz[son[j]] - 1;         for (int k = 0; k < 26; ++k) {           if (G[j][k] == -1 || son[j] == G[j][k]) continue;           ans[i + 1] += DFS(G[j][k], son[j]);         }       }       for (auto &i : a) {         *i = -1;       }       tmp += (int)dep[i].size();     }     tmp = 1;     for (int i = 2; i <= n; ++i) {       if (ans[tmp] > ans[i]) {         tmp = i;       }     }     printf( %d n%d n , ans[tmp], tmp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string cad;     cin >> n >> cad;     int res = 0;     for (int i = 0; i < n; ++i) {       if (cad[i] ==  0 ) {         res++;         break;       } else {         res++;       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, ss;   int m, l, r, k, i, j, n, p;   int main() {     cin >> s;     cin >> m;     ss = s;     for (i = 1; i <= m; i++) {       cin >> l >> r >> k;       r--;       l--;       for (j = l; j <= r; j++) {         p = r - l + 1;         ss[j] = s[l + ((j - l - k) % p + p) % p];       }       s = ss;     }     cout << ss << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   const int MAX = 10000000;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     while (cin >> n) {       map<string, int> m;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         m[s]++;       }       int mx = 0;       for (map<string, int>::iterator it = m.begin(); it != m.end(); it++)         mx = max(mx, it->second);       cout << mx <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, i = 0, last = 0, current = 0;   int main() {     int x, y, z = 0, a = 0, c = 1;     long long b;     cin >> x;     for (int i = 0; i < x; i++) {       cin >> y >> z;       a = z * 2;       c = y * 2;       if (a > c) {         if (z > c)           cout << z * z << endl;         else           cout << c * c << endl;       } else {         if (y > a)           cout << y * y << endl;         else           cout << a * a << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, a[1000005];   multiset<long long int> st;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> a[i];     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       st.insert(a[i]);       auto it = st.begin();       if (*it < a[i]) {         ans += a[i] - *it;         st.erase(it);         st.insert(a[i]);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   int main() {     ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int n, cnt = 0;     cin >> n;     int sv = n;     while (n--) {       int x, y;       cin >> x >> y;       if (x < 0) ++cnt;     }     cout << (min(cnt, sv - cnt) <= 1 ?  Yes n  :  No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200010];   int main() {     long long n, k;     cin >> n >> k;     n -= k * (k + 1) / 2;     if (n < 0) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < k; i++) {       a[i] = i + 1 + n / k + (i >= (k - n % k));     }     bool ok = 1;     for (int i = 1; i < k; i++) {       if (a[i] > a[i - 1] * 2) {         if (i == k - 1) ok = 0;         a[k - 1]++;         a[i]--;       }     }     if (ok) {       cout <<  YES  << endl;       for (int i = 0; i < k; i++) cout << a[i] << endl;     } else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int s1 = count(arr, arr + n, 1);     int s2 = count(arr, arr + n, -1);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       if ((b - a + 1) % 2 != 0) {         printf( %d n , 0);       } else {         int c = (b - a + 1) / 2;         if (s1 >= c && s2 >= c) {           printf( %d n , 1);         } else {           printf( %d n , 0);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp;   int main() {     long long k, i;     cin >> k;     string s;     cin >> s;     long long ans = 0, cnt = 0;     long long n = s.length();     mp[0] = 1;     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         cnt++;       }       if (cnt >= k) {         ans += mp[cnt - k];       }       mp[cnt]++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = (long long)1e5 + 5;   long long a[N];   inline void solve() {     long long n;     cin >> n;     queue<pair<long long, long long> > negative, positive;     long long pos_sum = 0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       if (a[i] == 0) {         continue;       }       if (a[i] > 0) {         pos_sum += a[i];         positive.push({i, a[i]});       } else {         negative.push({i, a[i]});       }     }     while (!positive.empty()) {       long long p = positive.front().first;       long long x = positive.front().second;       while (!negative.empty() && negative.front().first < p) {         negative.pop();       }       if (negative.empty()) {         break;       }       long long relax = min(x, -negative.front().second);       positive.front().second -= relax;       pos_sum -= relax;       if (positive.front().second == 0) {         positive.pop();       }       if (relax >= -negative.front().second) {         negative.pop();       } else {         negative.front().second += relax;       }     }     cout << pos_sum << endl;   }   signed main() {     long long Q;     cin >> Q;     while (Q--) {       solve();     }   }
/*...................................................................*    *............___..................___.....____...______......___....*    *.../|....../... ........./|...../... ...|.............|..../... ...*    *../.|...../..... ......./.|....|.....|..|.............|.../........*    *....|....|.......|...../..|....|.....|..|............/...|.........*    *....|....|.......|..../...|..... ___/...|___......../....|..___....*    *....|....|.......|.../....|...../... ....... ....../.....|./... ...*    *....|....|.......|../_____|__..|.....|.......|..../......|/..... ..*    *....|..... ...../.........|....|.....|.......|.../........ ...../..*    *..__|__.... ___/..........|..... ___/... ___/.../.......... ___/...*    *...................................................................*    */       #include <bits/stdc++.h>   using namespace std;   #define int long long   #define INF 1000000000000000000      const int M = 200005;   const int MOD = 1000000007;   int dp[10][M];      int recur(int d,int m)   {       if(m==0)       {           dp[d][m]=1;           return 1;       }       if(dp[d][m]!=-1)       {           return dp[d][m];       }       if(d==9)       {           dp[d][m]=(recur(0,m-1)+recur(1,m-1))%MOD;       }       else       {           dp[d][m]=recur(d+1,m-1);       }       return dp[d][m];   }      int32_t main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       memset(dp,-1,sizeof(dp));       for(int i=0;i<10;i++)       {           for(int j=0;j<M;j++)           {               if(dp[i][j]==-1)                   recur(i,j);           }       }       int tt=1;       cin >> tt;       while(tt--)       {           int n,m;           cin >> n >> m;           int ans=0;           while(n>0)           {               int d=n%10;               ans=(ans+dp[d][m])%MOD;               n=n/10;           }           cout << ans <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lst[200005], nxt[400005], to[400005], tol;   int sz[200005], f[200005];   long long dp[200005];   int vis[200005];   int qu[200005];   int N, K;   void adde(int u, int v) {     nxt[tol] = lst[u];     to[tol] = v;     lst[u] = tol;     ++tol;   }   void solve() {     cin >> N >> K;     memset(lst, 0xff, sizeof(lst));     tol = 0;     memset(sz, 0, sizeof(sz));     for (int i = 0; i < (K * 2); ++i) {       int u;       scanf( %d , &u);       sz[u] = 1;     }     for (int i = 0; i < (N - 1); ++i) {       int u, v;       scanf( %d%d , &u, &v);       adde(u, v);       adde(v, u);     }     memset(vis, 0, sizeof(vis));     memset(dp, 0, sizeof(dp));     int tail = 0;     f[1] = 0;     vis[1] = 1;     qu[tail++] = 1;     for (int i = 0; i < (tail); ++i) {       int u = qu[i];       for (int p = lst[u]; p != -1; p = nxt[p]) {         int v = to[p];         if (!vis[v]) {           vis[v] = 1;           f[v] = u;           qu[tail++] = v;         }       }     }     for (int i = tail - 1; i >= 0; --i) {       int u = qu[i];       dp[u] += min(sz[u], 2 * K - sz[u]);       sz[f[u]] += sz[u];       dp[f[u]] += dp[u];     }     cout << dp[1] << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, ans, now;   int v[505][505];   int main() {     scanf( %d%d , &n, &k);     now = n * n;     for (int i = n; i >= 1; i--)       for (int h = n; h >= k; h--) v[i][h] = now--;     now = 1;     for (int i = 1; i <= n; i++)       for (int h = 1; h < k; h++) v[i][h] = now++;     for (int i = 1; i <= n; i++) ans += v[i][k];     printf( %d n , ans);     for (int i = 1; i <= n; i++) {       for (int h = 1; h <= n; h++) cout << v[i][h] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[31][31], used[31][31];   long long n, m;   vector<pair<int, int> > zz = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   int check(long long x, long long y) {     if (x >= 1 && x <= n && y >= 1 && y <= m && used[x][y] == 0) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (; t > 0; t--) {       long long ans = 0;       cin >> n >> m;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           cin >> a[i][j];           used[i][j] = 0;         }       if (n == 1 && m == 1) {         cout << 0 <<   n ;         continue;       }       queue<int> x, y, dep;       int k = 0;       x.push(1);       y.push(1);       dep.push(1);       x.push(n);       y.push(m);       dep.push(1);       used[1][1] = 1;       used[n][m] = 1;       long long z = n + m - 1;       z /= 2;       while (k + 1 <= z) {         k++;         long long ed = 0;         long long nul = 0;         while (!dep.empty() && dep.front() == k) {           long long xx = x.front();           x.pop();           long long yy = y.front();           y.pop();           long long d = dep.front();           dep.pop();           if (a[xx][yy] == 1)             ed++;           else             nul++;           for (int i = 0; i < 4; i++) {             xx += zz[i].first;             yy += zz[i].second;             if (check(xx, yy)) {               x.push(xx);               y.push(yy);               dep.push(d + 1);               used[xx][yy] = 1;             }             xx -= zz[i].first;             yy -= zz[i].second;           }         }         ans += min(ed, nul);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100010];   inline int read() {     char c = getchar();     int x = 0, flag = 1;     while (!isdigit(c)) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return x * flag;   }   int main() {     int n = read(), k = read(), lst = 1, ans = 0;     for (int i = 1; i <= n; i++) {       a[i] = read();       if (a[i] == a[i - 1]) lst = i;       ans = max(ans, i - lst + 1);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   struct lazy_seg {    public:     vector<T> st, lazy;     lazy_seg(int n) { st.resize(4 * n + 1, 0), lazy.resize(4 * n + 1, 0); }     lazy_seg() = default;     void push(int l, int r, int curr) {       if (lazy[curr] != 0) {         st[curr] += lazy[curr] * (r - l + 1);         if (l != r)           lazy[2 * curr] += lazy[curr], lazy[2 * curr + 1] += lazy[curr];         lazy[curr] = 0;       }     }     void pull(int l, int r, int curr) {       push(l, r, curr);       int mid = l + (r - l) / 2;       if (l != r) push(l, mid, 2 * curr), push(mid + 1, r, 2 * curr + 1);       st[curr] = (st[2 * curr] + st[2 * curr + 1]);     }     void upd(int x, int y, T v, int l, int r, int curr) {       int mid = (l + r) / 2;       push(l, r, curr);       if (l == x && r == y) {         lazy[curr] += v;         push(l, r, curr);         return;       }       if (y <= mid)         upd(x, y, v, l, mid, 2 * curr);       else if (x > mid)         upd(x, y, v, mid + 1, r, 2 * curr + 1);       else         upd(x, mid, v, l, mid, 2 * curr),             upd(mid + 1, y, v, mid + 1, r, 2 * curr + 1);       pull(l, r, curr);     }     T qry(int x, int y, int l, int r, int curr) {       int mid = (l + r) / 2;       push(l, r, curr);       if (l == x && r == y) return st[curr];       if (y <= mid)         return qry(x, y, l, mid, 2 * curr);       else if (x > mid)         return qry(x, y, mid + 1, r, 2 * curr + 1);       return (qry(x, mid, l, mid, 2 * curr) +               qry(mid + 1, y, mid + 1, r, 2 * curr + 1));     }     void build(int l, int r, int curr) {       int mid = (l + r) / 2;       if (l == r) {         st[curr] = 0;         return;       }       build(l, mid, 2 * curr);       build(mid + 1, r, 2 * curr + 1);       st[curr] = (st[2 * curr] + st[2 * curr + 1]);     }   };   const int N = 500005;   int n;   string s;   lazy_seg<long long> f(N);   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> s;     long long ans = 0;     int curl = 0;     bool has = false;     stack<pair<int, int> > opt_range;     opt_range.push({-1000000000, -1});     for (int i = 0; i < n; i++) {       long long fa = ans;       if (s[i] ==  0 ) {         if (has) {           opt_range.push({curl, i - 1});         }         ans += f.qry(0, i, 0, n - 1, 1);         has = false;       } else {         if (!has) {           has = 1;           curl = i;         }         if (opt_range.top().second != -1) {           auto u = opt_range.top();           f.upd(u.second + 1, i, +1, 0, n - 1, 1);           u.second--;           if (u.first > u.second) {             opt_range.pop();           } else {             opt_range.pop();             opt_range.push(u);           }         } else {           f.upd(0, i, 1, 0, n - 1, 1);         }         ans += f.qry(0, i, 0, n - 1, 1);       }     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e3 + 5;   const int INF = (int)1e9 + 7;   int x[N], y[N];   int n;   map<pair<int, int>, int> id;   vector<pair<int, int> > g[2][2];   int dist(int i, int j) {     return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);   }   void calc(vector<pair<int, int> > g[2][2]) {     bool flag = 0;     int sz00 = (int)g[0][0].size();     int sz11 = (int)g[1][1].size();     int sz01 = (int)g[0][1].size();     int sz10 = (int)g[1][0].size();     int fx, fy;     if (sz00 == n) {       flag = 1, fx = 0, fy = 0;     }     if (sz11 == n) {       flag = 1, fx = 1, fy = 1;     }     if (sz01 == n) {       flag = 1, fx = 0, fy = 1;     }     if (sz10 == n) {       flag = 1, fx = 1, fy = 0;     }     if (flag) {       vector<pair<int, int> > nw[2][2];       for (auto x : g[fx][fy]) {         int a = x.first, b = x.second;         a /= 2, b /= 2;         id[{a, b}] = id[{x.first, x.second}];         nw[abs(a) % 2][abs(b) % 2].push_back({a, b});       }       calc(nw);     }     if (sz00 + sz11 && sz01 + sz10) {       cout << sz00 + sz11 << endl;       for (pair<int, int> c : g[0][0]) {         cout << id[c] <<    ;       }       for (pair<int, int> c : g[1][1]) {         cout << id[c] <<    ;       }       exit(0);     }     if (sz00 && sz11) {       cout << sz00 << endl;       for (pair<int, int> c : g[0][0]) {         cout << id[c] <<    ;       }       exit(0);     }     if (sz01 && sz10) {       cout << sz01 << endl;       for (pair<int, int> c : g[0][1]) {         cout << id[c] <<    ;       }       exit(0);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       x[i] += 1e6, y[i] += 1e6;       g[abs(x[i]) % 2][abs(y[i]) % 2].push_back({x[i], y[i]});       id[{x[i], y[i]}] = i;     }     calc(g);   }