malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       if ((a + b) % 2 == 0) {         cout <<  Tidak Tidak ;         if (b || c)           cout <<   Ya ;         else           cout <<   Tidak ;         if (a || d)           cout <<   Ya ;         else           cout <<   Tidak ;       } else {         if (a || d)           cout <<  Ya ;         else           cout <<   Tidak ;         if (b || c)           cout <<   Ya ;         else           cout <<   Tidak ;         cout <<   Tidak Tidak ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 10;   int n, ans;   void swap(int &x, int &y) {     int t = x;     x = y;     y = t;   }   int main() {     cin >> n;     vector<char> x(n), y(n);     for (auto &i : x) cin >> i;     for (auto &i : y) cin >> i;     for (int i = 0; i < n - 1; ++i) {       if (x[i] == y[i]) continue;       if (x[i + 1] == y[i + 1]) {         ans++;         continue;       }       if (x[i] == y[i + 1] && x[i + 1] == y[i])         swap(x[i], x[i + 1]), ans++;       else         ans++;     }     if (x[n - 1] != y[n - 1]) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 202000;   set<int> s;   set<int>::iterator it;   int edg[N];   vector<int> g[N];   int ans[N];   int cur = 1;   int vis[N];   void dfs(int node) {     vis[node] = 1;     ans[cur]++;     vector<int> send;     for (it = s.begin(); it != s.end();) {       if (!binary_search(g[node].begin(), g[node].end(), *it)) {         send.push_back(*it);         s.erase(it++);       } else         it++;     }     for (int el : send) dfs(el);   }   int main() {     int n, e;     scanf( %d%d , &n, &e);     for (int i = 1; i <= n; ++i) s.insert(i);     for (int i = 0; i < e; ++i) {       int temp, temp1;       scanf( %d%d , &temp, &temp1);       edg[temp]++;       edg[temp1]++;       g[temp].push_back(temp1);       g[temp1].push_back(temp);     }     vector<pair<int, int>> go;     for (int i = 1; i <= n; i++) {       go.push_back(make_pair(edg[i], i));       sort(g[i].begin(), g[i].end());     }     sort(go.begin(), go.end());     for (auto el : go) {       if (vis[el.second]) continue;       s.erase(el.second);       ans[0]++;       dfs(el.second);       cur++;     }     cout << ans[0] <<   n ;     sort(ans + 1, ans + ans[0] + 1);     for (int i = 1; i <= ans[0]; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, x, m, count;     scanf( %d %d , &n, &m);     for (x = 1, count = 0; x <= n; x++) {       if (m % x == 0 && (m / x) <= n) {         count = count + 1;       }     }     printf( %d , count);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       int ans = 0;       sort(a.begin(), a.end());       for (int i = 0, j = 0; j < n; j++) {         if (j - i + 1 >= a[j]) {           ++ans;           i = j + 1;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long i, t, n, com, midc;     cin >> n;     map<int, int> m;     set<int> s;     vector<int> x(n);     vector<int> a(3);     for (i = 0; i < n; i++) {       cin >> x[i];       m[x[i]]++;       s.insert(x[i]);     }     t = s.size();     if (t == 1) {       cout << n << endl;       for (i = 0; i < n; i++) cout << x[i] <<    ;       cout << endl;     } else if (t == 2) {       i = 0;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         a[i] = *it;         i++;       }       if (abs(a[0] - a[1]) == 1) {         cout << n << endl;         for (i = 0; i < n; i++) cout << x[i] <<    ;         cout << endl;       } else {         com = min(m[a[0]], m[a[1]]);         cout << n - (2 * com) << endl;         ;         for (i = 0; i < (2 * com); i++) cout << a[0] + 1 <<    ;         for (i = 0; i < m[a[0]] - com; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[1]] - com; i++) cout << a[1] <<    ;         cout << endl;       }     } else {       i = 0;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         a[i] = *it;         i++;       }       midc = m[a[1]] / 2;       com = min(m[a[0]], m[a[2]]);       if (midc > com) {         cout << n - (midc * 2) << endl;         for (i = 0; i < midc; i++) {           cout << a[0] <<    ;           cout << a[2] <<    ;         }         for (i = 0; i < m[a[0]]; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[2]]; i++) cout << a[2] <<    ;         if (m[a[1]] % 2) cout << a[1];         cout << endl;       } else {         cout << n - (2 * com) << endl;         for (i = 0; i < m[a[1]]; i++) cout << a[1] <<    ;         for (i = 0; i < (2 * com); i++) cout << a[1] <<    ;         for (i = 0; i < m[a[0]] - com; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[2]] - com; i++) cout << a[2] <<    ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long int INF = 1e12;   int n, k;   int memo[101][101][101];   int solve(string &str, int i, int N, int _max) {     _max = max(N, _max);     int &a = memo[i][N][_max];     if (a != -1) return a;     if (i == n) return a = (_max == k);     if (str[i] !=  N ) {       bool temp1 = solve(str, i + 1, 0, _max);       if (str[i] ==  Y  || temp1) return a = temp1;     }     return a = solve(str, i + 1, N + 1, _max);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(memo, -1, sizeof(memo));     cin >> n >> k;     string str;     cin >> str;     cout << (solve(str, 0, 0, 0) ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 1000000000;   long long INFF = 8000000000000000000LL;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   inline string IntToString(int a) {     char x[100];     sprintf(x,  %d , a);     string s = x;     return s;   }   inline int StringToInt(string a) {     char x[100];     int res;     strcpy(x, a.c_str());     sscanf(x,  %d , &res);     return res;   }   inline string GetString(void) {     char x[1000005];     scanf( %s , x);     string s = x;     return s;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int k, n1, n2, n3, t1, t2, t3;   priority_queue<int, vector<int>, greater<int> > satu, dua, tiga;   int t[100005];   bool can(int T) {     if ((int)satu.size() == n1 && satu.top() + t1 > T) return false;     if ((int)dua.size() == n2 && dua.top() + t2 > T + t1) return false;     if ((int)tiga.size() == n3 && tiga.top() + t3 > T + t1 + t2) return false;     return true;   }   int main() {     scanf( %d %d %d %d %d %d %d , &k, &n1, &n2, &n3, &t1, &t2, &t3);     int bef = 0;     for (int(i) = (0); (i) < (k); ++(i)) {       int ambil = bef;       int L = t[i - 1];       int R = INF;       while (L <= R) {         int M = (L + R) >> 1;         if (can(M)) {           ambil = M;           R = M - 1;         } else           L = M + 1;       }       if ((int)satu.size() == n1) {         satu.pop();       }       satu.push(ambil);       if ((int)dua.size() == n2) {         dua.pop();       }       dua.push(ambil + t1);       if ((int)tiga.size() == n3) {         tiga.pop();       }       tiga.push(ambil + t1 + t2);       if (i == k - 1) {         printf( %d n , ambil + t1 + t2 + t3);       }       bef = ambil;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(int x, int y, int n) {     vector<int> ans(n + 1);     ans[x] = 1;     ans[y] = 2;     for (int i = 1, j = 3; i <= n; i++) {       if (ans[i] == 0) {         ans[i] = j++;       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     ans[y] = 1;     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     exit(0);   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     if (n == 0 || n * (n - 1) / 2 == m) {       cout <<  NO n ;     } else {       cout <<  YES n ;       set<pair<int, int>> st;       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         if (x > y) swap(x, y);         st.insert({x, y});       }       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           if (st.find({i, j}) == st.end()) {             solve(i, j, n);           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp, vis;   vector<long double> vv;   vector<pair<long long, long long> > vp;   string s, q;   char c;   int main() {     long double t = 0, n, m, l, r, mn = 0, mx = 0, ans = 0, nm = 0, cnt = 0, x, y,                 z, d, v, g;     cin >> l >> d >> v >> g >> r;     l -= d;     t += d / v;     long long p = (long long)t / (long long)(g + r);     x = t - (p * (g + r));     if (x >= g) t += r - (x - g);     t += l / v;     cout << setprecision(10) << fixed << t;   }
#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int min(long long int a, long long int b) {     if (a < b)       return a;     else       return b;   }   int main() {     long long int t, a, b, x, y;     cin >> t;     while (t--) {       long long int k1 = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0, k6 = 0, k7 = 0, c1,                     c2, c3, c4;       cin >> a >> b >> x >> y;       c1 = max(x, y);       c2 = min(x, y);       c3 = max(a, b);       c4 = min(a, b);       if (min(a, b) >= max(x, y)) {         k1 = (a - x - 1) * b;         k2 = x * b;         k3 = (b - y - 1) * a;         k4 = y * a;         k5 = max(k1, k2);         k6 = max(k3, k4);         k7 = max(k5, k6);       } else {         k1 = (c3 - c1 - 1) * c4;         k2 = c1 * c4;         k3 = (c4 - c2 - 1) * c3;         k4 = c2 * c3;         k5 = max(k1, k2);         k6 = max(k3, k4);         k7 = max(k5, k6);       }       cout << k7;       if (t != 0) cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[26][26] = {0}, n, mini = -1;     cin >> n;     while (n--) {       char c[11];       scanf( %s , c);       int k = strlen(c), i = c[0] -  a , j = c[k - 1] -  a ;       for (int m = 0; m < 26; m++)         if (a[m][i]) a[m][j] = max(a[m][j], a[m][i] + k);       a[i][j] = max(a[i][j], k);       mini = max(mini, a[j][j]);     }     cout << mini;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   int dist[maxn][maxn];   long long ans;   void modify(int u, int v, int w) {     if (dist[u][v] > w) {       ans -= (dist[v][u] - w);       dist[u][v] = w;     }     return;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> dist[i][j];         if (j > i) {           ans += dist[i][j];         }       }     }     int k;     cin >> k;     for (int i = 1; i <= k; i++) {       int u, v, w;       cin >> u >> v >> w;       modify(u, v, w);       if (dist[u][v] != dist[v][u]) {         dist[v][u] = dist[u][v];       }       for (int p = 1; p <= n; p++) {         for (int q = 1; q <= n; q++) {           modify(p, q, dist[p][u] + dist[v][q] + w);           if (dist[p][q] != dist[q][p]) {             dist[q][p] = dist[p][u] + dist[v][q] + w;           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 239;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   const int ABC = 26;   int cnt = 0, len, s, f;   vector<int> g[N];   void solve(int k) {     if (k == 1) {       g[0].push_back(1);       g[1].push_back(0);       s = 0;       f = 1;       len = 1;       cnt += 2;     } else if (k % 2 == 0) {       solve(k / 2);       g[cnt].push_back(s);       g[s].push_back(cnt);       g[cnt + 1].push_back(s);       g[s].push_back(cnt + 1);       g[cnt + 2].push_back(cnt);       g[cnt].push_back(cnt + 2);       g[cnt + 2].push_back(cnt + 1);       g[cnt + 1].push_back(cnt + 2);       s = cnt + 2;       len += 2;       cnt += 3;     } else {       solve(k - 1);       for (int i = 0; i < len; i++) {         if (i == len - 1) {           g[cnt - 1].push_back(f);           g[f].push_back(cnt - 1);         } else {           g[cnt - 1].push_back(cnt);           g[cnt].push_back(cnt - 1);           cnt++;         }       }     }   }   char ans[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int k;     cin >> k;     solve(k);     int id[cnt];     int curr = 2;     for (int i = 0; i < cnt; i++)       if (i == s)         id[i] = 0;       else if (i == f)         id[i] = 1;       else         id[i] = curr++;     for (int i = 0; i < cnt; i++)       for (int j = 0; j < cnt; j++) ans[i][j] =  N ;     for (int i = 0; i < cnt; i++)       for (int j : g[i]) ans[id[i]][id[j]] =  Y ;     cout << cnt <<   n ;     for (int i = 0; i < cnt; i++) {       for (int j = 0; j < cnt; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   inline int Get() {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     int Num = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 )       Num = (Num << 3) + (Num << 1) + ch -  0 ;     return Num;   }   const int N = 1e5 + 5;   int n, m, a[N], count[N << 2], sum[N << 2], rev[N << 2];   std ::vector<int> vec0[N], vec1[N];   void build(int k, int l, int r) {     sum[k] = r - l + 1;     if (l == r) return;     int mid = l + r >> 1;     build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);   }   void down(int k) {     if (rev[k]) {       count[k << 1] = sum[k << 1] - count[k << 1], rev[k << 1] ^= 1;       count[k << 1 | 1] = sum[k << 1 | 1] - count[k << 1 | 1],                      rev[k << 1 | 1] ^= 1;       rev[k] = 0;     }   }   void modify(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) {       rev[k] ^= 1, count[k] = sum[k] - count[k];       return;     }     int mid = l + r >> 1;     down(k);     if (x <= mid) modify(k << 1, l, mid, x, y);     if (y > mid) modify(k << 1 | 1, mid + 1, r, x, y);     count[k] = count[k << 1] + count[k << 1 | 1];   }   int query(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) return count[k];     int mid = l + r >> 1;     down(k);     if (y <= mid) return query(k << 1, l, mid, x, y);     if (x > mid) return query(k << 1 | 1, mid + 1, r, x, y);     return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);   }   int main() {     n = Get(), m = Get();     for (int i = 1; i <= n; ++i) a[i] = Get();     std ::sort(a + 1, a + n + 1);     for (int i = 1; i <= m; ++i) {       int l = std ::lower_bound(a + 1, a + n + 1, Get()) - a;       int r = std ::upper_bound(a + 1, a + n + 1, Get()) - a - 1;       if (1 <= l && l <= n && 1 <= r && r <= n && l <= r)         vec0[l].push_back(r), vec1[r].push_back(l);     }     long long ans = (long long)n * (n - 1) * (n - 2) / 6;     build(1, 1, n);     for (int i = 1; i <= n; ++i) {       for (int k = 0, sze = vec0[i].size(); k < sze; ++k)         modify(1, 1, n, i, vec0[i][k]);       int res = (i > 1 ? i - 1 - query(1, 1, n, 1, i - 1) : 0) +                 (i < n ? query(1, 1, n, i + 1, n) : 0);       ans -= (long long)res * (res - 1) / 2;       for (int k = 0, sze = vec1[i].size(); k < sze; ++k)         modify(1, 1, n, vec1[i][k], i);     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   void upd(int& a, int b) { a = max(a, b); }   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     for (int i = 0; i < (int)n; ++i) cin >> a[i];     for (int i = 0; i < (int)m; ++i) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<int> to_seg(n);     int seg = 0;     vector<int> start, end;     for (int i = 0; i < (int)a.size(); ++i) {       if (i == 0 || a[i] != a[i - 1] + 1) {         seg++;         if (i != 0) end.push_back(i - 1);         start.push_back(i);       }       to_seg[i] = seg - 1;     }     end.push_back(n - 1);     vector<int> z(start.size()), d(start.size());     for (int segment = 0; segment < (int)start.size(); ++segment) {       int first = -1;       int cnt = 0;       for (int i = 0; i < (int)m; ++i) {         if (b[i] < a[start[segment]])           first = i;         else if (b[i] <= a[end[segment]])           cnt++;       }       int cnt_orig = cnt;       upd(d[segment], cnt);       if (segment) upd(d[segment], cnt + z[segment - 1]);       if (first != -1) {         for (int i = first; i >= 0; --i) {           ++cnt;           int r = a[start[segment]];           int l = b[i];           if (start[segment] - (r - l) >= 0) {             int Q = 0;             int X = to_seg[start[segment] - (r - l)] - 1;             if (X >= 0) Q = z[X];             upd(d[segment], cnt + Q);           }         }       }       cnt = 0;       for (int i = first + cnt_orig + 1; i < m; ++i) {         ++cnt;         int l = a[end[segment]];         int r = b[i];         if (end[segment] + (r - l) < n) {           upd(z[to_seg[end[segment] + (r - l)]], d[segment] + cnt);         }       }       upd(z[segment], d[segment]);     }     cout << *max_element(z.begin(), z.end()) << endl;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> my;   int n, m;   string var[5006];   string bit[5006];   int op[5006][2];   int opera[5006];   int ans[5005][1003];   int print1[1005], print2[1005];   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= n; i++) {       string z;       cin >> z;       my[z] = i;       var[i] = z;       cin >> z;       cin >> z;       if (z[0] ==  ? ) {         op[i][0] = 0;         cin >> z;         if (z[0] ==  A )           opera[i] == 1;         else if (z[0] ==  O )           opera[i] = 2;         else           opera[i] = 3;         cin >> z;         if (z[0] ==  ? )           op[i][1] = 0;         else           op[i][1] = my[z];       } else if (z[0] ==  0  || z[0] ==  1 )         bit[i] = z;       else {         op[i][0] = my[z];         cin >> z;         if (z[0] ==  A )           opera[i] = 1;         else if (z[0] ==  O )           opera[i] = 2;         else           opera[i] = 3;         cin >> z;         if (z[0] ==  ? )           op[i][1] = 0;         else           op[i][1] = my[z];       }     }     for (int i = 0; i < m; i++) {       int cnt[2];       cnt[0] = cnt[1] = 0;       for (int j = 0; j <= 1; j++) {         for (int k = 1; k <= n; k++) {           if (opera[k] == 0) {             ans[k][i] = bit[k][i] -  0 ;             cnt[j] += ans[k][i];           } else {             int v1 = op[k][0], v2 = op[k][1];             if (v1 == 0) ans[v1][i] = j;             if (v2 == 0) ans[v2][i] = j;             if (opera[k] == 1)               ans[k][i] = ans[v1][i] & ans[v2][i];             else if (opera[k] == 2)               ans[k][i] = ans[v1][i] | ans[v2][i];             else               ans[k][i] = ans[v1][i] ^ ans[v2][i];             cnt[j] += ans[k][i];           }         }       }       if (cnt[0] > cnt[1]) {         print1[i] = 0;         print2[i] = 1;       } else if (cnt[0] < cnt[1]) {         print1[i] = 1;         print2[i] = 0;       } else {         print1[i] = 0;         print2[i] = 0;       }     }     for (int i = 0; i < m; i++) cout << print2[i];     cout << endl;     for (int i = 0; i < m; i++) cout << print1[i];   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) ans *= a;       a = a * a;       b >>= 1;     }     return ans;   }   long long powm(long long a, long long b) {     a %= MOD;     long long ans = 1;     while (b > 0) {       if (b & 1) ans = (ans * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return ans;   }   void IO() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     IO();     ;     long long n, k;     cin >> n >> k;     long long A[k];     for (long long &x : A) cin >> x;     long long pos = 0, res = LLONG_MAX;     for (long long i = 0; i < k; i++) {       if (n % A[i] < res) {         pos = i + 1;         res = n % A[i];       }     }     cout << pos <<     << n / A[pos - 1] <<   n ;     return 0;   }