malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   #define ll long long   #define pii pair<ll,ll>   #define debug(a) cout<<a<<  n    #define maxn 200009 /// I wanna be withma youlu   #define MOD 1000000007   #define F first   #define S second   #define rep(i, a, b) for(ll i = a; i < (b); ++i)   #define per(i, b, a) for(ll i = b-1; i>=a ; i--)   #define trav(a, x) for(auto& a : x)   #define allin(a , x) for(auto a : x)   #define all(x) begin(x), end(x)    #define sz(x) (ll)(x).size()   using namespace std;   const ll INF = 1e9 + 9;   int main(){       ios::sync_with_stdio(false);       cin.tie(0);       ll t;       cin>>t;       while(t--){           ll n;           cin>>n;           string s,s2;           cin>>s>>s2;           ll conta = 0,contb = 0;           rep(i,0,n){               if(s[i] -  0  > s2[i] -  0 )conta++;               else if(s[i] -  0  < s2[i] -  0 )contb++;           }           // cout<<conta<<   <<contb<<endl;           if(conta > contb) cout<< RED n ;           else if(conta == contb) cout<< EQUAL n ;           else cout<< BLUE n ;       }       return 0;     }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (y > x) x = y;   }   const long long inf = (long long)1e18 + 17;   const long long iinf = 1500000000;   const long long dx[] = {1, 0, -1, 0};   const long long dy[] = {0, 1, 0, -1};   const long long mod = 1e9 + 7;   bool test_case = 1;   void solve() {     string a, b;     cin >> a >> b;     long long next[a.size() + 10][26], n1 = a.size();     for (long long i = 0; i < 26; i++) next[n1][i] = inf;     for (long long i = n1 - 1; i >= 0; i--) {       for (long long j = 0; j < 26; j++) next[i][j] = next[i + 1][j];       next[i][a[i] -  a ] = i;     }     long long n = b.size();     long long dp[n + 10][n + 10];     dp[0][0] = 0;     for (long long ii = 0; ii < b.size(); ii++) {       long long l1 = ii + 1, l2 = b.size() - l1;       for (long long i = 0; i <= l1; i++) {         for (long long j = 0; j <= l2; j++) {           if (i == 0 && j == 0) continue;           dp[i][j] = inf;           if (j != 0) {             long long op1 = dp[i][j - 1];             if (op1 != inf && ii + j < b.size()) {               long long nex = b[ii + j] -  a ;               long long pos = next[op1][nex];               amin(dp[i][j], pos + 1);             }           }           if (i != 0) {             long long op1 = dp[i - 1][j];             if (op1 != inf) {               long long nex = b[i - 1] -  a ;               long long pos = next[op1][nex];               amin(dp[i][j], pos + 1);             }           }         }       }       if (dp[l1][l2] != inf) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     if (test_case == true) cin >> t;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5;   long long pr(long long a, long long b, long long c) {     if (b == 0) return 1LL;     long long ans = 1;     while (b > 0) {       if (b % 2) ans = ((ans % c) * (a % c)) % c;       a = ((a % c) * (a % c)) % c;       b /= 2;       a %= c;       ans %= c;     }     return ans;   }   void solve() {     long long k, m, h, l, r, a, b, c, d, w, mini, maxi = INT_MAX, prev, res;     double n;     cin >> n;     n *= 2.0;     double y = (double)3.14159265358979323846 / n;     double ans = tan((3.14159265358979323846 / 2.0) - y);     cout << fixed << setprecision(10) << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, b = 0, p = 0, m, i = 0, matches = 0;     scanf( %d , &n);     scanf( %d , &b);     scanf( %d , &p);     m = n;     while (m != 1) {       matches = matches + m / 2;       m = m / 2 + m % 2;     }     printf( %d %d , b * (matches * 2) + matches, p * n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[200002], cum[200002];     long long int res = 1000000000000LL, count = 0LL, i, j, m;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &arr[i]);     }     for (i = 1; i <= n; i++) {       cum[i] = arr[i];     }     for (i = 2; i <= n; i++) {       cum[i] += cum[i - 1];     }     for (i = 1, j = n; i < n; i++) {       if (arr[i] == 1) {         m = (cum[j] - cum[i + 1]);         count += j - i - m;       }     }     res = min(res, count);     count = 0;     for (i = n; i > 1; i--) {       if (arr[i] == 0) {         count += (cum[i - 1]);       }     }     res = min(res, count);     printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD;   long long getFibb(long long n) {     long long a11 = 1, a12 = 1, a21 = 1, a22 = 0;     long long r11 = 1, r12 = 0;     long long q11 = 0, q12 = 0, q21 = 0, q22 = 0;     while (n > 0) {       if (n & 1) {         q11 = (r11 * a11 + r12 * a21) % MOD;         q12 = (r11 * a12 + r12 * a22) % MOD;         r11 = q11;         r12 = q12;       }       q11 = (a11 * a11 + a12 * a21) % MOD;       q12 = (a11 * a12 + a12 * a22) % MOD;       q21 = (a21 * a11 + a22 * a21) % MOD;       q22 = (a21 * a12 + a22 * a22) % MOD;       a11 = q11;       a12 = q12;       a21 = q21;       a22 = q22;       n >>= 1;     }     return r12;   }   long long m, l, r, k, ans;   long long cnt(long long L, long long R, long long X) {     return ((R / X) - ((L - 1) / X));   }   int main() {     cin >> m >> l >> r >> k;     MOD = m;     for (long long i = 1; i * i <= r; i++) {       if (cnt(l, r, i) >= k) ans = max(ans, i);       if (cnt(l, r, r / i) >= k) ans = max(ans, r / i);     }     cout << getFibb(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, res, s, a, b;     cin >> n;     res = n - 1;     for (i = 1; i < n; i++) {       s = 0;       a = n;       b = i;       while (a != b) {         if (a > b)           a = a - b;         else           b = b - a;         s++;       }       if (a == 1 && b == 1)         if (s < res) res = s;     }     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const int INF = 1e9 + 7;   long long int arr[MAX];   signed main() {     cin.tie(NULL);     cout.tie(NULL);     ios::sync_with_stdio(0);     long long int n1, n2;     cin >> n1 >> n2;     string a, b;     cin >> a >> b;     long long int ans = INF;     long long int pos;     long long int cnt = 0;     for (long long int i = 0; i < n2 - n1 + 1; ++i) {       long long int cnt = 0;       for (long long int j = 0; j < n1; ++j) {         if (a[j] == b[i + j]) {           cnt++;         }       }       cnt = n1 - cnt;       if (cnt < ans) {         ans = cnt;         pos = i;       }     }     cout << ans << endl;     for (long long int i = pos; i < pos + n1; ++i) {       if (b[i] != a[i - pos]) {         cout << i - pos + 1 <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int i, j, n, k, l, s = 0, m = 0, p = 0, r = 0;       cin >> n;       int a[n];       for (i = 0; i < n; i++) {         cin >> a[i];         s += a[i];         if (a[i] == 0) p++;         if (a[i] < -1) r++;         if (a[i] > 0) m++;       }       s += p;       if (s != 0)         cout << p << endl;       else {         cout << p + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     scanf( %d%d , &n, &t);     string s;     cin >> s;     string s1 =   , s2 =   ;     bool ck = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  . )         ck = 1;       else if (ck)         s2 += s[i];       else         s1 += s[i];     }     if (ck == 0) {       cout << s << endl;       return 0;     }     int cnt = 0;     ck = 0;     for (int i = 0; i < s2.size(); i++) {       if (s2[i] >=  5 ) {         cnt = i;         ck = 1;         break;       }     }     int cp = 0;     if (ck) {       while (cnt >= 0) {         if (cp == t) break;         cp++;         cnt--;         int val = (s2[cnt] -  0 ) + 1;         s2[cnt] = (val +  0 );         if (val < 5) break;       }       if (cnt == -1) {         int len = s1.size();         string sl =   ;         for (int i = 0; i < len - 1; i++) sl +=  0 ;         sl +=  1 ;         int ca = 0;         string s9 =   ;         for (int i = len - 1; i >= 0; i--) {           int val = (s1[i] -  0 ) + (sl[i] -  0 ) + ca;           ca = val / 10;           s9 += (val % 10 +  0 );         }         if (ca) s9 += (ca +  0 );         reverse(s9.begin(), s9.end());         cout << s9 << endl;       } else {         cout << s1 <<  . ;         if (ck)           for (int i = 0; i <= cnt; i++) cout << s2[i];         else           cout << s2 << endl;         cout << endl;       }     } else {       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1100000;   long long arr[N];   long long b[N];   long long n, m, w;   bool ok(long long x) {     memset(b, 0, sizeof(b));     long long remain = m;     long long c = 0;     for (int i = 0; i < n; i++) {       c += b[i];       if (c + arr[i] < x) {         long long need = x - (c + arr[i]);         b[i + w] -= need;         remain -= need;         c += need;       }     }     if (remain >= 0)       return true;     else       return false;   }   int main() {     while (cin >> n >> m >> w) {       memset(arr, 0, sizeof(arr));       for (int i = 0; i < n; i++) cin >> arr[i];       long long l = 1;       long long r = (long long)9e9;       while (l < r) {         long long mid = (l + r + 1) / 2;         if (ok(mid)) {           l = mid;         } else {           r = mid - 1;         }       }       cout << l << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const int MAXN = 510;   char grid[MAXN][MAXN];   int n, k;   int component[MAXN][MAXN];   int size[MAXN * MAXN];   int orig_size[MAXN * MAXN];   int last_taken[MAXN * MAXN];   int dr[] = {1, 0, -1, 0};   int dc[] = {0, 1, 0, -1};   inline bool valid(int r, int c) { return 0 <= r && r < n && 0 <= c && c < n; }   void dfs(int r, int c, int cmp) {     component[r][c] = cmp;     size[cmp]++;     for (int i = 0; i < 4; i++) {       int nr = r + dr[i], nc = c + dc[i];       if (!valid(nr, nc)) continue;       if (component[nr][nc] != -1 || grid[nr][nc] ==  X ) continue;       dfs(nr, nc, cmp);     }   }   int main() {     scanf( %d%d , &n, &k);     for (int r = 0; r < n; r++)       for (int c = 0; c < n; c++) scanf(  %c , &grid[r][c]);     memset(component, -1, sizeof(component));     int cnt = 0;     for (int r = 0; r < n; r++) {       for (int c = 0; c < n; c++) {         if (grid[r][c] ==  .  && component[r][c] == -1) {           dfs(r, c, cnt);           orig_size[cnt] = size[cnt];           cnt++;         }       }     }     int best = 0;     int t = 1;     for (int r = 0; r + k - 1 < n; r++) {       for (int i = 0; i < cnt; i++) size[i] = orig_size[i];       for (int rr = 0; rr < k; rr++)         for (int cc = 0; cc < k; cc++)           if (grid[r + rr][cc] ==  . ) size[component[r + rr][cc]]--;       for (int c = 0; c + k - 1 < n; c++) {         int got = k * k;         for (int i = 0; i < k; i++) {           int rr, cc;           rr = r - 1, cc = c + i;           if (valid(rr, cc) && grid[rr][cc] ==  .  &&               last_taken[component[rr][cc]] != t) {             got += size[component[rr][cc]];             last_taken[component[rr][cc]] = t;           }           rr = r + i, cc = c + k;           if (valid(rr, cc) && grid[rr][cc] ==  .  &&               last_taken[component[rr][cc]] != t) {             got += size[component[rr][cc]];             last_taken[component[rr][cc]] = t;           }           rr = r + k, cc = c + i;           if (valid(rr, cc) && grid[rr][cc] ==  .  &&               last_taken[component[rr][cc]] != t) {             got += size[component[rr][cc]];             last_taken[component[rr][cc]] = t;           }           rr = r + i, cc = c - 1;           if (valid(rr, cc) && grid[rr][cc] ==  .  &&               last_taken[component[rr][cc]] != t) {             got += size[component[rr][cc]];             last_taken[component[rr][cc]] = t;           }         }         best = max(best, got);         for (int rr = r; rr < r + k; rr++) {           if (grid[rr][c] ==  . ) size[component[rr][c]]++;           if (c + k < n && grid[rr][c + k] ==  . ) size[component[rr][c + k]]--;         }         t++;       }     }     printf( %d n , best);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long par[200005], sz[200005];   long long root(long long x) {     return (x == par[x] ? x : (par[x] = root(par[x])));   }   long long ans = 0;   void join(long long x, long long y) {     ans -= sz[root(y)] * (sz[root(y)] - 1) / 2;     ans -= sz[root(x)] * (sz[root(x)] - 1) / 2;     sz[root(x)] += sz[root(y)];     par[root(y)] = root(x);     ans += sz[root(x)] * (sz[root(x)] - 1) / 2;   }   long long res[200005];   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<long long, pair<long long, long long>>> sh;     for (long long i = 1; i < n; i++) {       long long x, y, z;       cin >> x >> y >> z;       sh.push_back({z, {x, y}});     }     for (long long i = 1; i <= n; i++) sz[i] = 1, par[i] = i;     sort(sh.begin(), sh.end());     long long l = 0;     vector<pair<long long, long long>> qr;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       qr.push_back({x, i});     }     sort(qr.begin(), qr.end());     for (auto &cv : qr) {       while (l < sh.size() && sh[l].first <= cv.first) {         join(sh[l].second.first, sh[l].second.second);         l++;       }       res[cv.second] = ans;     }     for (long long i = 0; i < m; i++) cout << res[i] << (i == m - 1 ?   n  :    );   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000007;   vector<int> rec[100008];   int dp[2][100008], a[100008];   int fun(int minn, int val) {     int ll = 0, rr, ss = rec[val].size();     if (ss == 0)       return maxn;     else if (rec[val][0] >= minn)       return rec[val][0] + 1;     rr = ss;     while (ll + 1 != rr) {       int mid = (ll + rr) / 2;       if (rec[val][mid] < minn)         ll = mid;       else         rr = mid;     }     if (rr == ss) return maxn;     return rec[val][rr] + 1;   }   int main() {     int n, m, s, e, i, cc, ans;     bool f;     scanf( %d%d%d%d , &n, &m, &s, &e);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i <= 100000; i++) rec[i].clear();     for (i = 0; i < m; i++) {       int tmp;       scanf( %d , &tmp);       rec[tmp].push_back(i);     }     memset(dp, 0, sizeof(dp));     cc = 1;     ans = 0;     f = true;     while (f) {       f = false;       for (i = ans; i < n; i++) {         if (i != 0 && dp[1 - cc][i - 1] != maxn) {           dp[cc][i] = fun(dp[1 - cc][i - 1], a[i]);           if (i != ans) dp[cc][i] = min(dp[cc][i], dp[cc][i - 1]);           if (dp[cc][i] + i + 1 + (ans + 1) * e <= s) f = true;         } else if (i == 0) {           dp[cc][i] = fun(0, a[i]);           if (i != ans) dp[cc][i] = min(dp[cc][i], dp[cc][i - 1]);           if (dp[cc][i] + i + 1 + (ans + 1) * e <= s) f = true;         } else           dp[cc][i] = maxn;       }       if (f) ++ans;       cc = 1 - cc;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int dp[3333];   bool d[3333];   int a[3333];   bool f[3333];   int qu[3333];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       d[x] = true;     }     m = 0;     for (int i = 0; i <= 1000; i++)       if (d[i]) {         a[++m] = i - n;       }     qu[1] = 0;     f[1000] = true;     int l = 1;     int r = 1;     while (l <= r) {       int u = qu[l];       l++;       for (int i = 1; i <= m; i++) {         int v = u + a[i];         if (v >= -1000 && v <= 1000) {           if (f[v + 1000] == false) {             f[v + 1000] = true;             qu[++r] = v;             dp[v + 1000] = dp[u + 1000] + 1;           }         }       }     }     int ret = 1000000001;     for (int i = -1000; i <= 1000; i++)       if (f[i + 1000]) {         bool ok = false;         for (int j = 1; j <= m; j++)           if (i + a[j] == 0) {             ok = true;             break;           }         if (ok) ret = min(ret, dp[i + 1000] + 1);       }     if (ret == 1000000001)       cout << -1;     else       cout << ret;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = (long long)(2e5), MOD = 1e9 + 7;   const long long INF = 1e17;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int cnt = 0;     string copy;     copy += s[0];     for (int i = 1; i < s.size(); i++) {       if (s[i] == copy[copy.size() - 1]) {         copy.erase(copy.begin() + copy.size() - 1);         cnt++;       } else         copy += s[i];     }     if (cnt % 2 == 0)       cout <<  No ;     else       cout <<  Yes ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, q;     cin >> n >> q;     vector<int> a((size_t)n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<pair<int, int>> b((size_t)q);     for (int i = 0; i < q; i++) {       cin >> b[i].first >> b[i].second;       b[i].first--, b[i].second--;     }     int m = 22;     vector<vector<int>> c((size_t)m, vector<int>((size_t)m, n));     vector<vector<int>> d((size_t)m, vector<int>((size_t)m, n));     vector<vector<int>> e((size_t)n, vector<int>((size_t)m, n));     for (int i = n - 1; i >= 0; i--) {       c = vector<vector<int>>((size_t)m, vector<int>((size_t)m, n));       vector<int> x((size_t)m, n);       for (int j = 0; j < m; j++) {         for (int k = 0; k < m; k++) {           if ((a[i] & (1 << j)) != 0 && (a[i] & (1 << k)) != 0) {             c[j][k] = i;           } else if ((a[i] & (1 << j)) != 0 || (a[i] & (1 << k)) != 0) {             if ((a[i] & (1 << j)) != 0) {               c[j][k] = d[j][k];             }             if ((a[i] & (1 << j)) != 0) {               x[k] = min(x[k], c[j][k]);             }           }         }       }       for (int j = 0; j < m; j++) {         for (int k = 0; k < m; k++) {           if ((a[i] & (1 << j)) != 0 && (a[i] & (1 << k)) == 0) {             c[j][k] = min(c[j][k], x[k]);           }           e[i][j] = min(e[i][j], c[j][k]);           e[i][k] = min(e[i][k], c[j][k]);           d[j][k] = min(d[j][k], c[j][k]);         }       }     }     for (int i = 0; i < q; i++) {       bool f = false;       for (int j = 0; j < m; j++) {         if ((a[b[i].second] & (1 << j)) != 0) {           if (e[b[i].first][j] <= b[i].second) {             f = true;             break;           }         }       }       cout << (f ?  Shi  :  Fou ) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     while (cin >> n >> k) {       vector<long long> a(n);       long long total = 0;       for (auto &i : a) {         cin >> i;         total += i;       }       sort(a.begin(), a.end());       long long lo = 0, hi = (total / n);       while (lo < hi) {         long long mid = (lo + hi + 1) >> 1;         long long need = 0;         for (int i = 0; i < n; ++i) {           need += max(0LL, mid - a[i]);         }         if (need > k)           hi = mid - 1;         else           lo = mid;       }       long long tmp1 = lo;       lo = (total + n - 1) / n, hi = total;       while (lo < hi) {         long long mid = (lo + hi) >> 1;         long long need = 0;         for (int i = 0; i < n; ++i) {           need += max(0LL, a[i] - mid);         }         if (need > k)           lo = mid + 1;         else           hi = mid;       }       cout << llabs(lo - tmp1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h;     scanf( %d%d%d , &n, &m, &h);     h--;     n--;     int cnto = 0, cntr = 0, tot;     for (int i = 0; i < m; i++) {       int t;       scanf( %d , &t);       if (i == h)         cntr = t - 1;       else         cnto += t;     }     if (n > cnto + cntr) {       printf( -1.0 n );       return 0;     }     tot = cnto + cntr;     double prob = 1;     for (int i = n; i > 0; i--, cnto--, tot--) {       prob *= (double)cnto / tot;     }     printf( %.8lf n , 1 - prob);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sum;   long long int cnt;   long long int maxs;   long long int a[100001];   map<long long int, long long int> jilu;   long long int maxa(long long int a, long long int b) { return a > b ? a : b; }   int main() {     int i, n;     while (scanf( %d , &n) != EOF) {       cnt = 0;       sum = 0;       maxs = 0;       jilu.clear();       for (i = 1; i < n + 1; i++) {         scanf( %lld , &a[i]);         sum += a[i];         maxs = maxa(maxs, ++jilu[sum]);       }       cnt = n - maxs;       printf( %lld n , cnt);     }     return 0;   }