malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   int ctz(unsigned x) { return __builtin_ctz(x); }   int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   int clz(unsigned x) { return __builtin_clz(x); }   int clzll(unsigned long long x) { return __builtin_clzll(x); }   int popcnt(unsigned x) { return __builtin_popcount(x); }   int popcntll(unsigned long long x) { return __builtin_popcountll(x); }   int bsr(unsigned x) { return 31 ^ clz(x); }   int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   map<int, long long> in[100016], out[100016];   void do_vertex(int u) {     for (auto i = in[u].begin(), j = out[u].begin();          i != in[u].end() && j != out[u].end();) {       int s, t;       long long fs, ft;       tie(s, fs) = *i;       tie(t, ft) = *j;       long long z = min(fs, ft);       if (z > 0) {         out[s][u] -= z;         in[t][u] -= z;         i->second -= z;         j->second -= z;         if (s != t) {           out[s][t] += z;           in[t][s] += z;         }       }       if (i->second == 0) i = in[u].erase(i);       if (j->second == 0) j = out[u].erase(j);     }   }   int main() {     canhazfast();     int n, m;     vector<pair<pair<int, int>, long long>> ans;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v, w;       cin >> u >> v >> w;       out[u][v] += w;       in[v][u] += w;     }     for (int i = 1; i <= n; ++i) do_vertex(i);     for (int i = 1; i <= n; ++i) {       for (const auto &x : out[i]) {         if (!x.second || x.first == i) continue;         ans.emplace_back(pair<int, int>(i, x.first), x.second);       }     }     cout << ans.size() <<   n ;     for (const pair<pair<int, int>, long long> e : ans) {       cout << e.first.first <<     << e.first.second <<     << e.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #include<string>   #define M 10000000000007   using namespace std;   typedef long long int ll;   int gcd(int a,int b)   {       if (a == 0)           return b;       return gcd(b % a, a);   }   int modpow(int x,int n)   {       int result=1;       while(n>0)       {           if(n % 2 ==1)               result=((result%M) * (x%M))%M;           x=((x%M)*(x%M))%M;           n=n/2;       }       return result;   }   int lcm(int a,int b)   {       return (a*b)/(gcd(a,b));   }   bool isprime(int n)   {       if(n<2)           return false;       for(int i=2; i<=sqrt(n); i++)           if(n%i==0)               return false;       return true;   }   int ctoi(char c)   {       return c-48;   }   bool visited[1000000] {false};   void add_edge(vector<int> v[],int x,int y)   {       v[x].push_back(y);       v[y].push_back(x);   }   void dfs(vector<int> v[],int e)   {       visited[e] = true;       for(int i=0; i<v[e].size(); i++)       {           if(!visited[v[e][i]])           {               dfs(v,v[e][i]);           }       }   }   int func(int n)   {       if(isprime(n))       {           return 2*n;       }       else       {           int idx = 0;           for(int i=2; i<=n; i++)           {               if(n%i==0)               {                   idx = i;                   break;               }           }           return (idx+n);       }   }   int maxSubArraySum(ll a[], ll size)   {       int max_so_far = INT_MIN, max_ending_here = 0,l=0;          for (int i = 0; i < size; i++)       {           max_ending_here = max_ending_here + a[i];           if (max_so_far < max_ending_here)           {               max_so_far = max_ending_here;               l++;           }                 if (max_ending_here < 0)           {               max_ending_here = 0;              }          }       if(l==size)max_so_far=INT_MAX;       return max_so_far;   }      int main()   {    int t;    cin>>t;    while(t--)    {        ll a1,b1,a2,b2,a3,b3;     cin>>a1>>b1>>a2>>b2>>a3>>b3;     ll ans=abs(a1-a2)+abs(b1-b2);     if(a1==a2 && a1==a3 )           {               if((b3>b1 && b3<b2) || (b3>b2 && b3<b1))ans+=2;           }           if(b1==b2 && b1==b3 )           {               if((a3>a1 && a3<a2) || (a3>a2 && a3<a1))ans+=2;           }     cout<<ans<<endl;             }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, x, i;     scanf( %d , &n);     while (n--) {       scanf( %d , &x);       if (x == 1) cnt++;     }     if (cnt)       cout << -1 << endl;     else       cout << 1 << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     double k, b, n, t;     double bacteria = 1;     double time = 0;     scanf( %lf %lf %lf %lf , &k, &b, &n, &t);     while (bacteria <= t) {       bacteria = (k * bacteria + b);       if (bacteria > t) {         break;       } else if (bacteria == t) {         time++;         break;       }       time++;     }     if (time > n) {       n = 0;     } else {       n -= time;     }     printf( %0.0lf n , n);     return 0;   }
#include <bits/stdc++.h>   const static long long INF = 0x3f3f3f3f;   static inline void setio(void);   long long dp[5002][5002];   int main(void) {     setio();     memset(dp, 0, sizeof(dp));     long long n, m;     std::cin >> n >> m;     std::string s;     for (long long i = 0; i < n; ++i) {       std::cin >> s;       for (long long j = 0, k; j < m;) {         if (s[j] !=  1 ) {           ++j;           continue;         }         for (k = j + 1; k < m && s[k] ==  1 ; ++k)           ;         ++dp[j][k - 1];         j = k + 1;       }     }     for (long long j = 0; j < m; ++j) {       for (long long k = m - 2; k >= j; --k) dp[j][k] += dp[j][k + 1];     }     for (long long j = 1; j < m; ++j) {       for (long long k = 0; k < m; ++k) dp[j][k] += dp[j - 1][k];     }     long long best = 0;     for (long long i = 0; i < m; ++i)       for (long long j = 0; j < m; ++j)         best = std::max(best, (j - i + 1) * dp[i][j]);     std::cout << best <<   n ;     return 0;   }   static inline void setio(void) {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cout << std::fixed;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int INT_INF = (int)(2e9);   const ll LL_INF = (ll)(2e18);   const ll mod = 1e9 + 7;   const int NIL = -1;   static mt19937 _g(time(nullptr));   inline ll randint(ll a, ll b) {     ll w = (_g() << 31LL) ^ _g();     return a + w % (b - a + 1);   }   inline void fast_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   };   template <typename T>   inline T sign(T x) {     return T(x > 0) - T(x < 0);   }   template <typename T, typename S>   inline ostream& operator<<(ostream& os, const pair<T, S> p) {     cout <<  [  << p.first <<  ;  << p.second <<  ] ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto el : v) cout << el <<    ;     return os;   }   struct edge {     int v, u;     ll weight;     int id;     edge(int _v, int _u, ll _weight, int _id)         : v(_v), u(_u), weight(_weight), id(_id) {}     bool operator<(const edge& other) const { return weight < other.weight; }   };   const int MAX_N = (int)1e5 + 77;   int n, m;   vector<edge> edges;   namespace dsu {   int p[MAX_N], r[MAX_N];   inline void clear() {     for (int i = 0; i < n; ++i) p[i] = i, r[i] = 1;   }   int get(int v) {     if (p[v] == v) return v;     return (p[v] = get(p[v]));   }   inline void merge(int v, int u) {     v = get(v), u = get(u);     if (v != u) {       if (r[v] > r[u]) swap(v, u);       p[v] = u;     }   }   }  // namespace dsu   namespace mst {   inline ll get(int forced_edge) {     dsu::clear();     ll answ = 0;     if (forced_edge != NIL) {       answ += edges[forced_edge].weight;       dsu::merge(edges[forced_edge].v, edges[forced_edge].u);     }     for (auto edge : edges) {       if (dsu::get(edge.v) != dsu::get(edge.u)) {         answ += edge.weight;         dsu::merge(edge.v, edge.u);       }     }     return answ;   }   }  // namespace mst   inline bool check(ll M) {     int forced = NIL;     for (int i = 0; i < m; ++i)       if (edges[i].id == 0) forced = i;     edges[forced].weight = M;     sort(edges.begin(), edges.end());     for (int i = 0; i < m; ++i)       if (edges[i].id == 0) forced = i;     ll mst_cost = mst::get(NIL);     ll forced_cost = mst::get(forced);     return mst_cost == forced_cost;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int v, u;       ll weight;       cin >> v >> u >> weight;       edges.emplace_back(v - 1, u - 1, weight, i);     }     ll L = 0, R = (ll)1e9 + 77;     while (R - L > 1) {       ll M = (L + R) / 2;       if (check(M))         L = M;       else         R = M;     }     cout << min(L, (ll)1e9) <<   n ;   }   int main() {     fast_io();     solve();     return 0;   }
#include <bits/stdc++.h>   const double eps = (1e-10);   using namespace std;   int dcmp(double a, double b) {     return fabs(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   int setBit0(int num, int idx) { return num & ~(1 << idx); }   int flipBit(int num, int idx) { return num ^ (1 << idx); }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   string str;   vector<string> v1;   vector<pair<string, int> > v;   map<string, int> vis;   int n, num, vs[100];   void put(int vs[]) {     string strr = str;     for (int i = 0; i < n; i++) {       if (!vs[i]) {         strr[i] = (strr[i] ==  0  ?  1  :  0 );       }     }     v1.push_back(strr);   }   void fun(int st, int c) {     if (c == num) {       put(vs);       return;     }     for (int i = st; i < n; i++) {       vs[i] = 1;       fun(i + 1, c + 1);       vs[i] = 0;     }     return;   }   bool check(string s1, string s2, int sam) {     int cnt = 0;     for (int i = 0; i < ((int)(s1).size()); i++) {       if (s1[i] == s2[i]) cnt++;     }     if (cnt == sam) return 1;     return 0;   }   int main() {     int m;     scanf( %d %d , &n, &m);     char stt[39];     string st;     int rig;     for (int i = 0; i < m; i++) {       scanf( %s %d , &stt, &rig);       st = stt;       vis[st] = 1;       v.push_back(make_pair(st, rig));     }     str = v[0].first;     num = v[0].second;     fun(0ll, 0);     long long ans = 0;     for (int i = 0; i < ((int)(v1).size()); i++) {       st = v1[i];       bool ok = 1;       for (int j = 1; j < m && ok; j++) {         if (!check(st, v[j].first, v[j].second)) ok = 0;       }       if (ok) {         if (vis.find(v1[i]) == vis.end()) ans++;       }     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void one();   int main() {     fastio();     int t = 1;     for (int i = 0; i < t; ++i) {       one();     }     return 0;   }   void one() {     long long n;     cin >> n;     long long sum = n;     for (long long i = 2; i * i <= n; i++) {       while (n % i == 0) {         n /= i;         sum += n;       }     }     if (n > 1) {       sum++;     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const long long N = 1e6 + 10;   char s[N];   long long a[N];   long long n, k;   int main() {     long long i, len, j;     long long tmp, flag, len_q = 0;     scanf( %lld%lld , &n, &k);     n++;     for (i = 1; i <= n; i++) {       scanf( %s , s);       len = strlen(s);       if (s[0] ==  ? ) {         a[i] = INF;         len_q++;         continue;       }       flag = 0;       tmp = 0;       for (j = 0; j < len; j++) {         if (s[j] ==  - )           flag = 1;         else {           tmp *= 10;           tmp += s[j] -  0 ;         }       }       if (flag) tmp = -tmp;       a[i] = tmp;     }     if (k == 0) {       if (a[1] == INF) {         if ((n - len_q) % 2) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       } else {         if (a[1] == 0) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       }     } else {       tmp = 0;       if (len_q == 0) {         for (i = n; abs(tmp) < 1e14 && i >= 1; i--) {           tmp *= k;           tmp += a[i];         }         if (tmp == 0)           printf( YES n );         else           printf( NO n );       } else {         if (n % 2 == 0) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T CMP_MIN(T a, T b) {     return a < b;   }   template <class T>   T CMP_MAX(T a, T b) {     return a > b;   }   template <class T>   T MAX(T a, T b) {     return a > b ? a : b;   }   template <class T>   T MIN(T a, T b) {     return a < b ? a : b;   }   template <class T>   T GCD(T a, T b) {     return b ? GCD(b, a % b) : a;   }   template <class T>   T LCM(T a, T b) {     return a / GCD(a, b) * b;   }   const int MAXN = 110000;   const int MAXM = 1000006;   const double eps = 1e-10;   const long long MOD = 1000000007;   int n, k, l, r, sa, sk;   int main() {     while (~scanf( %d %d %d %d %d %d , &n, &k, &l, &r, &sa, &sk)) {       int p = sk % k, v = sk / k;       printf( %d , v + (p ? 1 : 0));       for (int i = 1; i < k; i++) {         printf(  %d , v + (i < p ? 1 : 0));       }       if (k < n) {         p = (sa - sk) % (n - k);         v = (sa - sk) / (n - k);         for (int i = 0; i < n - k; i++) {           printf(  %d , v + (i < p ? 1 : 0));         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int xs[200000], ys[200000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> xs[i] >> ys[i];     }     map<int, int> vert, hor;     for (int i = 0; i < n; i++) {       int x, y;       x = xs[i];       y = ys[i];       int v = x - y + 1;       int h = y + x - 1;       int buf;       buf = vert[v];       vert[v] = buf + 1;       buf = hor[h];       hor[h] = buf + 1;     }     long long res = 0;     for (map<int, int>::iterator it = vert.begin(); it != vert.end(); ++it) {       long long buf = (long long)it->second;       buf--;       long long sum = (buf * buf + buf) / 2;       res += sum;     }     for (map<int, int>::iterator it = hor.begin(); it != hor.end(); ++it) {       long long buf = (long long)it->second;       buf--;       long long sum = (buf * buf + buf) / 2;       res += sum;     }     cout << res;   }
#include <bits/stdc++.h>   int main() {     long long int n, m, i, c = 0;     scanf( %lld %lld , &n, &m);     long long int a[m];     for (i = 0; i < m; i++) {       scanf( %lld , &a[i]);     }     for (i = 0; i < m - 1; i++) {       if (a[i + 1] > a[i]) {         c = c + a[i + 1] - a[i];       } else if (a[i] == a[i + 1]) {         c = c;       } else {         c = c + n + a[i + 1] - a[i];       }     }     c = a[0] + c - 1;     printf( %lld , c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, char> a;   int main() {     string s1, s2;     cin >> s1 >> s2;     int dl = s1.size();     int k = 0;     for (int i = 0; i < dl; i++) {       char p1 = s1[i];       char p2 = s2[i];       map<char, char>::iterator it = a.find(p1);       if (it == a.end()) {         a[p1] = p2;         if (p1 == p2) k++;       } else if (it->second != p2) {         cout << -1;         exit(0);       }       it = a.find(p2);       if (it == a.end()) {         a[p2] = p1;         if (p1 == p2) k++;       } else if (it->second != p1) {         cout << -1;         exit(0);       }     }     cout << (a.size() - k) / 2 <<   n ;     for (map<char, char>::iterator it = a.begin(); it != a.end(); it++) {       if (it->first >= it->second) continue;       cout << it->first <<     << it->second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s;     long long v[100005], a[100005], b[100005];     long long sum = 0;     vector<pair<pair<long long, long long>, pair<long long, long long> > > vvv;     scanf( %lld %lld , &n, &s);     for (int i = 0; i < n; i++) {       scanf( %lld %lld %lld , v + i, a + i, b + i);       vvv.push_back(           make_pair(make_pair(abs(a[i] - b[i]), v[i]), make_pair(a[i], b[i])));       sum += v[i];     }     sort(vvv.begin(), vvv.end());     long long qtd = ceil((sum) / (double)s);     long long ans = 0;     long long qt1 = 0, qt2 = 0, tt = 0;     for (int i = 0; i < n; i++) {       if (vvv[i].second.first > vvv[i].second.second) {         qt1 += vvv[i].first.second;         ans += vvv[i].second.first * vvv[i].first.second;       } else if (vvv[i].second.first < vvv[i].second.second) {         qt2 += vvv[i].first.second;         ans += vvv[i].second.second * vvv[i].first.second;       } else {         tt += vvv[i].first.second;         ans += vvv[i].second.second * vvv[i].first.second;       }     }     long long ans1 = ans, ans2 = ans;     long long qtt1 = qt1 + tt, qtt2 = qt2;     int id = 0;     while (ceil((qtt1) / (double)s) + ceil((qtt2) / (double)s) > qtd) {       if (vvv[id].second.first >= vvv[id].second.second) {         if (vvv[id].first.second >= (qtt1) % s) {           long long aux = (qtt1) % s;           qtt1 -= aux;           ans1 -= vvv[id].second.first * aux;           qtt2 += aux;           ans1 += vvv[id].second.second * aux;           continue;         }         qtt1 -= vvv[id].first.second;         ans1 -= vvv[id].second.first * vvv[id].first.second;         qtt2 += vvv[id].first.second;         ans1 += vvv[id].second.second * vvv[id].first.second;       }       id++;     }     id--;     qtt1 = qt1;     qtt2 = qt2 + tt;     id = 0;     while (ceil((qtt1) / (double)s) + ceil((qtt2) / (double)s) > qtd) {       if (vvv[id].second.first <= vvv[id].second.second) {         if (vvv[id].first.second >= (qtt2) % s) {           long long aux = (qtt2) % s;           qtt2 -= aux;           ans2 -= vvv[id].second.second * aux;           qtt1 += aux;           ans2 += vvv[id].second.first * aux;           continue;         }         qtt2 -= vvv[id].first.second;         ans2 -= vvv[id].second.second * vvv[id].first.second;         qtt1 += vvv[id].first.second;         ans2 += vvv[id].second.first * vvv[id].first.second;       }       id++;     }     id--;     printf( %lld n , max(ans1, ans2));     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 1e5 + 100;   map<int, vector<pair<int, int>>> mp;   pair<pair<int, int>, int> a[N];   pair<pair<int, int>, pair<int, int>> d[N];   int t[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i].first.first, &a[i].first.second);       a[i].second = i;     }     sort(a, a + n);     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &d[i].first.first, &d[i].first.second, &d[i].second.first);       d[i].second.second = i;     }     sort(d, d + m);     int j = 0;     for (int i = 0; i < n; i++) {       while (j < m && d[j].first.first <= a[i].first.first) {         mp[d[j].first.second].push_back({d[j].second.second, d[j].second.first});         j++;       }       auto it = mp.lower_bound(a[i].first.second);       if (it == mp.end()) {         printf( NO );         return 0;       }       it->second.back().second--;       t[a[i].second] = it->second.back().first + 1;       if (it->second.back().second == 0) {         it->second.pop_back();         if (it->second.empty()) mp.erase(it);       }     }     printf( YES n );     for (int i = 0; i < n; i++) printf( %d  , t[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m = -2000000000, n = 2000000000;   int main() {     char useless[100];     int t;     cin >> t;     getchar();     while (t--) {       char a, c;       int k;       char o;       bool flag = true;       scanf( %c%c , &a, &c);       if (c ==  = ) flag = false;       scanf( %d , &k);       scanf( %c%c , &o, &o);       gets(useless);       if (o ==  Y ) {         if (a ==  > )           m = max(m, k + flag);         else           n = min(n, k - flag);       } else {         flag = !flag;         if (a ==  < )           m = max(m, k + flag);         else           n = min(n, k - flag);       }     }     if (m > n)       cout <<  Impossible ;     else       cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int N, M;     string K;     while (cin >> N >> M >> K) {       K = K.substr(2);       stringstream ss(K);       int k;       ss >> k;       map<string, int> inp;       for (int i = 0; i < (int)(N); i++) {         string name;         int level;         cin >> name >> level;         level = (level * k) / 100;         if (level >= 100) {           inp.insert(make_pair(name, level));         }       }       for (int i = 0; i < (int)(M); i++) {         string name;         cin >> name;         if (inp.count(name) == 0) inp[name] = 0;       }       cout << inp.size() << endl;       for (map<string, int>::iterator it = inp.begin(); it != inp.end(); it++) {         cout << it->first <<     << it->second << endl;       }     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int compare(const void *a, const void *b) {     int *p = (int *)a;     int *q = (int *)b;     if (p[0] == q[0]) return p[1] - q[1];     return p[0] - q[0];   }   int main() {     int n, m, c = 0, t, i, x;     scanf( %d%d , &n, &m);     ;     t = 0;     for (i = 0; i < n; i++) {       scanf( %d , &x);       ;       if (x > t) {         c++;         t = m - x;       } else         t -= x;     }     printf( %d n , c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265;   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       cout << fixed << setprecision(7) << (cos(PI / (4 * n)) / sin(PI / (2 * n)))            << endl;     }   }