malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int di[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dj[] = {1, -1, 0, 0, -1, 1, 1, -1};   const double PI = 3.14159265359, EPS = 1e-9;   const int N = 1000006, M = 1000006, Mod = 1000000007;   vector<int> adj[N];   pair<int, int> tree[4 * N];   int n;   string str;   void build(int idx, int s, int e) {     if (s == e) {       if (str[s] ==  ( ) ++tree[idx].first;       if (str[s] ==  ) ) ++tree[idx].second;       return;     }     int m = (s + e) / 2;     build(idx << 1, s, m);     build(idx << 1 | 1, m + 1, e);     tree[idx].first = tree[idx << 1 | 1].first +                       max(0, tree[idx << 1].first - tree[idx << 1 | 1].second);     tree[idx].second = tree[idx << 1].second +                        max(0, tree[idx << 1 | 1].second - tree[idx << 1].first);   }   pair<int, int> maxx(int l, int r, int idx, int s, int e) {     if (l > e || r < s) return pair<int, int>(0, 0);     if (l <= s && r >= e) return tree[idx];     int m = (s + e) / 2;     pair<int, int> p1 = maxx(l, r, idx << 1, s, m);     pair<int, int> p2 = maxx(l, r, idx << 1 | 1, m + 1, e);     pair<int, int> ret;     ret.first = p2.first + max(0, p1.first - p2.second);     ret.second = p1.second + max(0, p2.second - p1.first);     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),         cout << fixed;     cin >> str;     str =  s  + str;     n = (int)str.size();     build(1, 1, n);     int m;     cin >> m;     int l, r;     while (m--) {       cin >> l >> r;       pair<int, int> p = maxx(l, r, 1, 1, n);       cout << r - l + 1 - p.first - p.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, x, i, min = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       min += 15;       if (min >= x)         min = x;       else         break;     }     if (i == n) min += 15;     if (min >= 90)       printf( 90 n );     else       printf( %d n , min);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n, k;     cin >> n >> k;     string ans;     ans += to_string(k);     if (k == 10 && n == 1) {       cout << -1;       return 0;     }     int bound = n - 1;     if (k == 10) bound--;     for (int i = 1; i <= bound; i++) {       ans +=  0 ;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < 7; i++) {       cin >> arr[i];     }     int day = 1;     int i = 0;     while (n > 0) {       n = n - arr[i];       i++;       if (n > 0) {         day++;       }       if (day > 7) {         day = 1;       }       if (i == 7) {         i = 0;       }     }     cout << day;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d = 2, m = 4127, f = 0, c = 0;     cin >> n;     while (n--) {       int a, b;       cin >> a >> b;       if (f == 0) {         f = 1;         m = a;       } else {         if (a < m) m = a;       }       if (b != a) c = 1;       if (a > m) d = 0;     }     if (c == 1)       cout <<  rated ;     else {       if (d == 0)         cout <<  unrated ;       else         cout <<  maybe ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (1 << 20) + 10;   const double PI = acos(-1);   double dp[MAXN];   int N;   double L, R;   double x[22], y[22], a[22];   int main() {     memset(dp, 0, sizeof(dp));     scanf( %d%lf%lf , &N, &L, &R);     for (int ni = 0; ni < N; ni++) {       scanf( %lf%lf%lf , x + ni, y + ni, a + ni);       a[ni] = a[ni] * PI / 180;     }     int imax = 1 << N;     for (int i = 0; i < imax; i++) dp[i] = L;     bool flag = false;     double ans = L;     for (int i = 0; i < imax; i++) {       if (flag) break;       for (int j = 0; j < N; j++) {         int tmpj = 1 << j;         if (i & tmpj) continue;         double dist = sqrt((dp[i] - x[j]) * (dp[i] - x[j]) + y[j] * y[j]);         double alpha = acos((dp[i] - x[j]) / dist);         if (alpha <= a[j]) {           flag = true;           ans = R;           break;         }         double beta = alpha - a[j];         int tmpi = i | tmpj;         dp[tmpi] = max(dp[tmpi], dp[i] + dist * sin(a[j]) / sin(beta));         ans = max(dp[tmpi], ans);         if (fabs(ans - R) < 1e-6 || ans >= R) {           flag = true;           ans = R;           break;         }       }     }     printf( %.9lf n , ans - L);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t) {       int n, m;       cin >> n >> m;       vector<pair<int, int>> v;       vector<int> orig;       for (int i = 0; i < m; i++) {         int a;         cin >> a;         orig.push_back(a);         v.push_back({a, -i});       }       sort(v.begin(), v.end());       vector<int> rank(m);       for (int i = 0; i < m; i++) rank[-v[i].second] = i;       int ans = 0;       vector<int> s;       for (int i = 0; i < m; i++) {         int pos = rank[i];         for (int i = 0; i < s.size(); i++) {           if (pos > s[i]) ans++;         }         s.push_back(pos);       }       cout << ans <<   n ;       t--;     }   }
#include <bits/stdc++.h>   using namespace std;   bool prime(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   int main() {     int n;     vector<int> ans;     cin >> n;     for (int i = 2; i <= n; ++i) {       if (prime(i)) {         for (int j = i; j <= n; j *= i) {           ans.push_back(j);         }       }     }     cout << ans.size() << endl;     for (auto i : ans) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   const double eps = 0.0001;   void swap(double &a, double &b) {     double t = a;     a = b;     b = t;   }   int main() {     double x1, x2, x3;     double y1, y2, y3;     double a1, a2, a3;     double l1, l2, l3;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     l1 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);     l2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);     l3 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     a1 = acos((l2 + l3 - l1) / (2 * sqrt(l2) * sqrt(l3))) * 2;     a2 = acos((l1 + l3 - l2) / (2 * sqrt(l1) * sqrt(l3))) * 2;     a3 = acos((l1 + l2 - l3) / (2 * sqrt(l1) * sqrt(l2))) * 2;     double r2 = l1 / (2 * (1 - cos(a1)));     int i = 0;     int count;     double ang, z2, z3;     if (a1 > a2) swap(a1, a2);     if (a1 > a3) swap(a1, a3);     while (true) {       ang = a1 / (++i);       z2 = a2 / ang;       z3 = a3 / ang;       if (abs(z3 - round(z3)) < eps && abs(z2 - round(z2)) < eps) {         count = round(z2) + round(z3) + i;         break;       }     }     double s = count * (r2 * sin(ang)) / 2;     printf( %.6lf n , s);     return 0;   }
#include <stdio.h>   // #include <iostream>   #include <algorithm>   // #include <cmath>   // #include <string>   // #include <string.h>   // #include <vector>   // #include <bits/stdc++.h>   using namespace std;      // const int INF32 = 2000000000;   // const int INF64 = 2000000000000000000;   // const int MOD17 = 1000000007;      int tc, n, arr[200002];      int main(){    //freopen( input.txt ,  r , stdin);    //freopen( output.txt ,  w , stdout);    scanf( %d , &tc);    while(tc--){     scanf( %d , &n);     for(int i = 0; i < n; i++){      scanf( %d , &arr[i]);     }     if(n == 1 || n == 2){      printf( 0 n );      continue;     }     sort(arr, arr+n);     int j = 0;     long long ans = 0;     for(int i = 0; i < n; i++){      if(j < i) j = i;      while(j+1 < n && arr[j+1] - arr[i] <= 2) j++;      if(j - i > 1){       ans += (long long) (j-i-1)*(j-i)>>1;      }     }     printf( %lld n , ans);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000 * 1000 * 1000 + 7;   long long n, k;   vector<long long> ans;   long long positive(long long n) {     n %= mod;     (n < 0) && (n += mod);     return n;   }   long long gcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long g = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return g;   }   long long binpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   void calc() {     long long x = 0;     ans.push_back(0);     for (int i = 0; i < k + 1; ++i) {       x = (x + binpow(i + 1, k)) % mod;       ans.push_back(x);     }   }   long long solve(vector<long long> ans, long long y) {     long long x = 0;     long long cur = 1;     for (int j = 1; j < (long long)ans.size(); ++j) {       cur = (cur * positive(y - j)) % mod;       cur = (cur * binpow(positive(0 - j), mod - 2)) % mod;     }     for (int i = 0; i < (long long)ans.size(); ++i) {       x = (x + (ans[i] * cur) % mod) % mod;       if (i + 1 >= (long long)ans.size()) break;       long long t =           (positive(y - i) * binpow(positive(y - (i + 1)), mod - 2)) % mod;       cur = (cur * t) % mod;       long long v = (positive(i - ((long long)ans.size() - 1)) *                      binpow(positive(i + 1), mod - 2)) %                     mod;       cur = (cur * v) % mod;     }     return x;   }   int main() {     cin >> n >> k;     calc();     if (n < ans.size()) {       cout << ans[n];     } else {       cout << solve(ans, n);     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   vector<int> adj[105];   int n, k, dp[105][50], tmp[50];   void dfs(int u, int p) {     dp[u][0] = dp[u][k + 1] = 1;     for (int x = 0; x < adj[u].size(); x++) {       int v = adj[u][x];       if (v == p) continue;       dfs(v, u);       memset(tmp, 0, sizeof tmp);       for (int i = 0; i <= 2 * k; i++) {         for (int j = 0; j <= 2 * k; j++) {           if (i + j <= 2 * k)             tmp[min(i, j + 1)] =                 (tmp[min(i, j + 1)] + 1ll * dp[u][i] * dp[v][j]) % mod;           else             tmp[max(i, j + 1)] =                 (tmp[max(i, j + 1)] + 1ll * dp[u][i] * dp[v][j]) % mod;         }       }       for (int i = 0; i <= 2 * k; i++) dp[u][i] = tmp[i];     }   }   int main() {     scanf( %d %d , &n, &k);     int i, ans = 0;     for (i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     for (i = 0; i <= k; i++) ans = (ans + dp[1][i]) % mod;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Fast_IO() {     ios::sync_with_stdio(0);     cin.tie(0);   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) {     if (a == 0 || b == 0) return 0;     return ((a / gcd(a, b)) * b);   }   int main() {     Fast_IO();     long long n, m;     cin >> n >> m;     string s[n], t[m];     for (long long i = (long long)0; i <= (long long)n - 1; i++) cin >> s[i];     for (long long i = (long long)0; i <= (long long)m - 1; i++) cin >> t[i];     long long q;     cin >> q;     while (q--) {       long long y;       cin >> y;       y %= lcm(n, m);       y += lcm(n, m);       long long ni = 0, mi = 0;       for (long long i = (long long)2; i <= (long long)y; i++) {         ni++;         mi++;         ni %= n;         mi %= m;       }       cout << s[ni] + t[mi] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m;   int a[55], b[55];   int aa[55], bb[55];   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 2; i <= n; i++) aa[i] = a[i] - a[i - 1], bb[i] = b[i] - b[i - 1];     aa[1] = m - a[n] + a[1];     bb[1] = m - b[n] + b[1];     for (int j = 0; j < n; j++) {       bool flag = 0;       for (int i = 1; i <= n; i++) {         int x = i, y = x + j;         if (y > n) y -= n;         if (aa[x] != bb[y]) {           flag = 1;           break;         }       }       if (!flag) {         printf( YES n );         return 0;       }     }     printf( NO n );     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1000005];   int cnt[11] = {0};   int m[7] = {1869, 8196, 8916, 8691, 6198, 1689, 1968};   int main() {     scanf( %s , s);     int len = strlen(s);     int n = len;     for (int i = 0; i < len; i++) cnt[s[i] -  0 ]++;     if (cnt[0] + 4 == n) {       printf( 1869 );       for (int i = 0; i < cnt[0]; i++) printf( 0 );       puts(  );     } else {       int t = 0;       cnt[1]--;       cnt[6]--;       cnt[8]--;       cnt[9]--;       for (int i = 1; i <= 10; i++) {         int p = i % 10;         for (int j = 1; j <= cnt[p]; j++) {           printf( %d , p);           t = (t * 10 + p) % 7;         }       }       t = t * (10000 % 7) % 7;       printf( %d n , m[t]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, L = 0, R = 0;     string key;     cin >> n;     cin >> key;     for (i = 0; i < n; i++) {       if (key[i] ==  L )         L++;       else         R++;     }     cout << abs(R + L) + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100086;   int z[maxn], n, m, num, order[maxn][2], last[maxn], ans[maxn], len, in[maxn];   bool flag, ok[maxn];   char s[2];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s);       scanf( %d , &num);       if (s[0] ==  - ) {         if (z[num] == 0) z[num] = -1;         order[i][0] = -1;         order[i][1] = num;       } else {         if (z[num] == 0) z[num] = 1;         order[i][0] = 1;         order[i][1] = num;       }     }     num = 0;     for (int i = 1; i <= n; i++) {       if (z[i] == 0)         ans[++len] = i;       else {         if (z[i] == -1) {           in[i] = 1;           num++;         }         ok[i] = 1;       }     }     for (int i = 1; i <= m; i++) {       if (order[i][0] == -1) {         num--;         in[order[i][1]] = 0;         if (num) ok[order[i][1]] = 0;         last[order[i][1]] = i;         if ((i != m) && (order[i + 1][1] != order[i][1])) ok[order[i][1]] = 0;       } else {         in[order[i][1]] = 1;         if (num) ok[order[i][1]] = 0;         if (last[order[i][1]] != i - 1) ok[order[i][1]] = 0;         num++;         last[order[i][1]] = i;       }     }     for (int i = 1; i <= n; i++)       if (ok[i]) ans[++len] = i;     sort(ans + 1, ans + 1 + len);     printf( %d n , len);     if (len) {       for (int i = 1; i < len; i++) printf( %d  , ans[i]);       printf( %d n , ans[len]);     }     return 0;   }
#include <bits/stdc++.h>   int32_t get_economy(std::vector<int32_t> joined_roots, int32_t** tree) {     if (joined_roots.size() == 1) return 0;     int32_t res = joined_roots.size() - 1;     std::vector<int32_t> join_lists[26];     for (int32_t i = 0; i < joined_roots.size(); i++)       for (int32_t j = 0; j < 26; j++)         if (tree[joined_roots[i]][j] != -1)           join_lists[j].push_back(tree[joined_roots[i]][j]);     for (int32_t i = 0; i < 26; i++)       if (join_lists[i].size() > 0) res += get_economy(join_lists[i], tree);     return res;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int32_t n;     std::cin >> n;     int32_t** tree = new int32_t*[n];     for (int32_t i = 0; i < n; i++) {       tree[i] = new int32_t[26];       for (int32_t j = 0; j < 26; j++) tree[i][j] = -1;     }     int32_t* parents = new int32_t[n];     for (int32_t i = 0; i < n - 1; i++) {       int32_t src, dst;       char ch;       std::cin >> src >> dst >> ch;       src--;       dst--;       parents[dst] = src;       tree[src][ch -  a ] = dst;     }     std::vector<int32_t> removed;     for (int32_t j = 0; j < 26; j++)       if (tree[0][j] != -1) removed.push_back(tree[0][j]);     int32_t min_size = n, best_cut = -1;     int32_t cur_cut = 0;     while (removed.size() > 0) {       std::map<int32_t, std::vector<int32_t> > groups_per_parent;       for (int32_t i = 0; i < removed.size(); i++)         groups_per_parent[parents[removed[i]]].push_back(removed[i]);       int32_t total_economy = removed.size();       for (auto it = groups_per_parent.begin(); it != groups_per_parent.end();            it++) {         std::vector<int32_t> join_lists[26];         for (int32_t i = 0; i < it->second.size(); i++)           for (int32_t j = 0; j < 26; j++)             if (tree[it->second[i]][j] != -1)               join_lists[j].push_back(tree[it->second[i]][j]);         for (int32_t i = 0; i < 26; i++)           if (join_lists[i].size() > 0)             total_economy += get_economy(join_lists[i], tree);       }       if (n - total_economy < min_size) {         min_size = n - total_economy;         best_cut = cur_cut;       }       std::vector<int32_t> new_removed;       for (int32_t i = 0; i < removed.size(); i++)         for (int32_t j = 0; j < 26; j++)           if (tree[removed[i]][j] != -1)             new_removed.push_back(tree[removed[i]][j]);       removed = new_removed;       cur_cut++;     }     std::cout << min_size <<   n  << best_cut + 1;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool setmax(T &_a, T _b) {     if (_a < _b) {       _a = _b;       return true;     }     return false;   }   inline void Boost() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     int n, k;     cin >> n >> k;     map<string, pair<vector<int>, vector<int> > > m1;     map<string, vector<int> > m2;     for (int i = 0; i < n; i++) {       string s, rs;       int val;       cin >> s >> val;       rs = s;       reverse(rs.begin(), rs.end());       if (s == rs) {         auto it = m2.find(s);         if (it == m2.end())           m2.insert({s, {val}});         else           it->second.push_back(val);       } else {         auto it = m1.find(s);         if (it != m1.end()) {           it->second.first.push_back(val);         } else {           it = m1.find(rs);           if (it != m1.end())             it->second.second.push_back(val);           else             m1.insert({s, {{val}, {}}});         }       }     }     int ans = 0, bonus = 0;     for (auto &it : m1) {       auto &v1 = it.second.first;       auto &v2 = it.second.second;       sort(v1.begin(), v1.end());       sort(v2.begin(), v2.end());       while (!v1.empty() && !v2.empty()) {         int cur = v1.back() + v2.back();         if (cur < 0) break;         ans += cur;         v1.pop_back();         v2.pop_back();       }     }     for (auto &it : m2) {       auto &v = it.second;       sort(v.begin(), v.end());       while (v.size() >= 2 && v[v.size() - 2] > 0) {         ans += v[v.size() - 2] + v[v.size() - 1];         v.pop_back();         v.pop_back();       }       if (v.size() >= 2 && v[v.size() - 2] + v[v.size() - 1] > 0) {         assert(v[v.size() - 2] <= 0);         ans += v[v.size() - 2] + v[v.size() - 1];         setmax(bonus, -v[v.size() - 2]);       } else if (v.size() >= 1 && v.back() > 0)         setmax(bonus, v.back());     }     cout << ans + bonus;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, u, v, a[200005], el, ans;   vector<int> adj[200005];   queue<int> q;   bool vis[200005];   int depth[200005], depthn[200005];   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) {       cin >> a[i];     }     for (int i = 1; i <= m; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       vis[i] = 0;     }     q.push(1);     vis[1] = 1;     depth[1] = 0;     int node;     while (!q.empty()) {       node = q.front();       q.pop();       for (int x : adj[node]) {         if (vis[x]) continue;         vis[x] = 1;         depth[x] = depth[node] + 1;         q.push(x);       }     }     for (int i = 1; i <= n; i++) {       vis[i] = 0;     }     q.push(n);     vis[n] = 1;     depthn[n] = 0;     while (!q.empty()) {       node = q.front();       q.pop();       for (int x : adj[node]) {         if (vis[x]) continue;         vis[x] = 1;         depthn[x] = depthn[node] + 1;         q.push(x);       }     }     vector<pair<int, int> > v;     int cek = 0, ee = 0, cekn = 0, een = 0;     for (int i = 1; i <= k; i++) {       if (depth[a[i]] >= depth[n]) {         cek++;         ee = a[i];       }       if (depthn[a[i]] >= depthn[1]) {         cekn++;         een = a[i];       }       if (cek == 2 || cekn == 2) {         cout << depth[n] << endl;         return 0;       }       if (ee != a[i] && een != a[i]) v.push_back(make_pair(depth[a[i]], a[i]));     }     sort(v.begin(), v.end());     int minn = 1e9;     for (int i = 1; i < v.size(); i++) {       minn = min(minn, v[i].first - v[i - 1].first);     }     if (minn < 1e9) ans = depth[n] - max(0, minn - 1);     if (cek == 0 && cekn == 0) {       cout << ans << endl;       return 0;     }     if (cek == 1 && cekn == 0) {       cout << max(ans, min(depth[n], v[k - 2].first + 1 + depthn[ee])) << endl;     } else if (cek == 0 && cekn == 1) {       cout << max(ans, min(depth[n], depthn[v[0].second] + 1 + depth[een]))            << endl;     } else {       ans = max(ans, min(depth[een] + 1 + depthn[ee], depth[n]));       if (v.size() > 0) {         ans = max(ans, min(depth[n], v[k - 3].first + 1 + depthn[ee]));         ans = max(ans, min(depth[n], depthn[v[0].second] + 1 + depth[een]));       }       cout << ans << endl;     }   }