malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> res, res2, res3;   int x[10005], y[10005], id[35], b[35], vis[10005], r[10005];   bitset<35> c[35], d[35], tmp;   int insert(int x, int y, bitset<35> now) {     for (int i = 0; i <= 30; i++)       if (x & (1 << i)) {         if (!b[i]) {           b[i] = x;           id[i] = y;           vis[y] = 1;           d[i] = now;           d[i][i] = 1;           return i;         }         x ^= b[i];         now ^= d[i];       }     return -1;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &x[i]), r[i] = insert(x[i], i, bitset<35>());     for (int i = 1; i <= n; i++) scanf( %d , &y[i]);     for (int i = 1; i <= n; i++) {       int now = y[i];       for (int j = 0; j <= 30; j++)         if (now & (1 << j)) {           now ^= b[j];           if (~r[i]) c[r[i]] ^= d[j];         }       if (now) {         puts( -1 );         return 0;       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         int now = y[i] ^ x[i];         tmp.reset();         for (int j = 0; j <= 30; j++)           if (now & (1 << j)) now ^= b[j], tmp ^= d[j];         for (int j = 0; j <= 30; j++)           if (tmp[j]) res.push_back({i, id[j]});       }     for (int i = 0; i <= 30; i++) {       if (!c[i][i])         for (int j = 0; j <= 30; j++)           if (c[j][i] && ((!c[j][j]) || j > i)) {             res2.push_back({id[i], id[j]});             res2.push_back({id[j], id[i]});             res2.push_back({id[i], id[j]});             swap(c[i], c[j]);             break;           }       if (!c[i][i]) continue;       for (int j = 0; j <= 30; j++)         if (i != j && c[j][i]) {           c[j] ^= c[i];           res2.push_back({id[j], id[i]});         }     }     for (int i = 1; i <= 30; i++)       for (int j = 0; j < i; j++)         if (c[j][i]) res3.push_back({id[j], id[i]});     for (int i = 0; i <= 30; i++)       if ((id[i]) && (!(c[i][i]))) res2.push_back({id[i], id[i]});     printf( %d n , (int)(res.size() + res2.size() + res3.size()));     reverse(res2.begin(), res2.end());     for (auto i : res) printf( %d %d n , i.first, i.second);     for (auto i : res3) printf( %d %d n , i.first, i.second);     for (auto i : res2) printf( %d %d n , i.first, i.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   using ll = long long;   using ld = long double;   const int maxn = 1e6 + 5;   int n, r;   ll c[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     ll sum = 0;     cin >> n >> r;     for (int i = 0; i < 1 << n; i++) {       cin >> c[i];       sum += c[i];     }     ld res = 1.0 * sum / (1 << n);     cout << res <<   n ;     while (r--) {       int i, g;       cin >> i >> g;       sum -= c[i];       c[i] = g;       sum += c[i];       ld res = 1.0 * sum / (1 << n);       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, row, column;   int a[5005];   int cnt[1005];   int main() {     int i, j, k, l;     int x, y;     int tc, t;     int res = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     j = *(max_element(cnt, cnt + 1001));     if (j > (n + 1) / 2)       puts( NO );     else       puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010, Q = 100010;   int n, q, ac;   int a[N][N * 2];   int ans[Q];   vector<pair<pair<int, int>, pair<int, int>>> seq;   void ch(int j, int k, int x) {     for (; j <= n; j += j & -j)       for (int l = k; l <= n * 2; l += l & -l) a[j][l] += x;   }   int qry(int j, int k) {     int ret = 0;     for (; j; j &= j - 1)       for (int l = k; l; l &= l - 1) ret += a[j][l];     return ret;   }   void add1(int j, int k, int x) {     seq.emplace_back(make_pair(j, k), make_pair(1, x));   }   void add2(int j, int k, int x) {     seq.emplace_back(make_pair(j, k + j), make_pair(2, x));   }   void add3(int j, int k, int x) {     seq.emplace_back(make_pair(j, k - j + n), make_pair(3, x));   }   int main() {     scanf( %d%d , &n, &q);     while (q--) {       int opt;       scanf( %d , &opt);       if (opt == 1) {         int d, x, y, l;         scanf( %d%d%d%d , &d, &x, &y, &l);         if (d == 1) {           add1(x, y, 1);           add2(x, y + l + 1, -1);           add2(x + l + 1, y, 1);           add1(x + l + 1, y, -1);         } else if (d == 2) {           add3(x, y - l, 1);           add1(x, y + 1, -1);           add1(x + l + 1, y + 1, 1);           add3(x + l + 1, y + 1, -1);         } else if (d == 3) {           add1(x - l, y, 1);           add3(x - l, y + 1, -1);           add1(x + 1, y, -1);           add3(x + 1, y + l + 2, 1);         } else {           add2(x - l, y, 1);           add1(x - l, y + 1, -1);           add2(x + 1, y - l - 1, -1);           add1(x + 1, y + 1, 1);         }       } else {         int x, y;         scanf( %d%d , &x, &y);         ++ac;         seq.emplace_back(make_pair(x, y), make_pair(-1, ac));         seq.emplace_back(make_pair(x, y + x), make_pair(-2, ac));         seq.emplace_back(make_pair(x, y - x + n), make_pair(-3, ac));       }     }     for (int id = 1; id <= 3; ++id) {       memset(a, 0, sizeof(a));       for (const auto& pr : seq)         if (pr.second.first == id)           ch(pr.first.first, pr.first.second, pr.second.second);         else if (pr.second.first == -id)           ans[pr.second.second] += qry(pr.first.first, pr.first.second);     }     for (int i = 1; i <= ac; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int p[105];     int n, m, i, j, t;     memset(p, 0, sizeof(p));     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d , &t);       for (j = t; p[j] == 0; j++) p[j] = t;     }     for (i = 1; i < n; i++) printf( %d  , p[i]);     printf( %d n , p[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> odds;   int main() {     int n;     scanf( %d , &n);     long long int sum = 0;     int length_odds = 0;     for (int x = 0; x < n; x++) {       long long int num;       scanf( %lld , &num);       if (num % 2 == 0) {         sum += num;       } else {         odds.push_back(num);         length_odds++;       }     }     sort(odds.begin(), odds.end());     reverse(odds.begin(), odds.end());     for (int x = 1; x < length_odds;) {       sum += odds[0] + odds[1];       odds.erase(odds.begin());       odds.erase(odds.begin());       x += 2;     }     printf( %lld , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct _Box {     int pos, weight;   } Box;   Box arr[200010];   long long int bit1[200010], bit2[200010];   const int mod = 1e9 + 7;   int num;   int getLowbit(int n) { return n & (-n); }   void add(long long int* bitArr, int pos, long long int val, bool shouldMod) {     if (shouldMod) val = (val + mod) % mod;     for (int i = pos; i <= num; i += getLowbit(i)) {       bitArr[i] += val;       if (shouldMod) bitArr[i] = (bitArr[i] + mod) % mod;     }   }   long long int getPrefixSum(long long int* bitArr, int pos, bool shouldMod) {     long long int ans = 0;     for (int i = pos; i > 0; i -= getLowbit(i)) {       ans += bitArr[i];       if (shouldMod) ans = (ans + mod) % mod;     }     return ans;   }   long long int getRangeSum(long long int* bitArr, int qLeftPt, int qRightPt,                             bool shouldMod) {     if (qRightPt < qLeftPt) return 0;     long long int ans = getPrefixSum(bitArr, qRightPt, shouldMod) -                         getPrefixSum(bitArr, qLeftPt - 1, shouldMod);     if (shouldMod) ans = (ans + mod) % mod;     return ans;   }   int getMidPos(int qLeftPt, int qRightPt) {     int leftPt = qLeftPt, rightPt = qRightPt;     int ans = rightPt;     while (leftPt <= rightPt) {       int midPt = (leftPt + rightPt) >> 1;       if (getRangeSum(bit1, qLeftPt, midPt, false) >=           getRangeSum(bit1, midPt + 1, qRightPt, false)) {         ans = midPt;         rightPt = midPt - 1;       } else {         leftPt = midPt + 1;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(bit1, 0, sizeof(bit1));     memset(bit2, 0, sizeof(bit2));     int qNum;     cin >> num >> qNum;     for (int i = 1; i <= num; i++) {       cin >> arr[i].pos;     }     for (int i = 1; i <= num; i++) {       cin >> arr[i].weight;       add(bit1, i, arr[i].weight, false);       add(bit2, i, (long long int)arr[i].weight * (arr[i].pos - i), true);     }     while (qNum--) {       int x, y;       cin >> x >> y;       if (x < 0) {         x = -x;         add(bit1, x, y - arr[x].weight, false);         add(bit2, x, ((long long int)y - arr[x].weight) * (arr[x].pos - x), true);         arr[x].weight = y;       } else {         if (x == y) {           cout << 0 << endl;           continue;         }         int midPos = getMidPos(x, y);         long long int leftAns = (getRangeSum(bit1, x, midPos, true) *                                      abs(arr[midPos].pos - midPos) % mod -                                  getRangeSum(bit2, x, midPos, true) + mod) %                                 mod;         long long int rightAns = (getRangeSum(bit1, midPos, y, true) *                                       abs(arr[midPos].pos - midPos) % mod -                                   getRangeSum(bit2, midPos, y, true) + mod) %                                  mod;         long long int ans = (leftAns - rightAns + mod) % mod;         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10, M = 1e6 + 7, K = 200, p = 1e9 + 7;   int n, e[N], s[M], wf[K], q[N][K], f[N][N], ans[N][M];   bitset<40> op, wq[N][M];   unordered_map<bitset<40>, int> rt[N];   inline int read() {     int num = 0;     char g = getchar();     while (g < 48 || 57 < g) g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     return num;   }   inline long long pows(long long u, int v) {     long long ans = 1;     while (v > 0) {       if (v & 1) ans = ans * u % p;       u = u * u % p, v = v >> 1;     }     return ans;   }   inline void find(int u) {     q[u][0] = 0;     int os = 0, of = 0;     for (int i = 0; i < (1 << n); i++)       if (s[i] == u) q[u][++q[u][0]] = i, wf[i] = ++os;     for (int i = 1; i <= e[u - 1]; i++) {       if (!ans[u - 1][i]) continue;       for (int h = 1; h < (1 << n); h++) {         long long opq = 1;         for (int c = 0; c < n; c++)           if ((1 << c) & h)             opq = opq * f[u][c + 1] % p;           else             opq = opq * (1 - f[u][c + 1] + p) % p;         bitset<40> c = wq[u - 1][i], hc = op;         bool tg = 0;         for (int x = 1; x <= q[u - 1][0]; x++) {           if (c[x] == 1) {             for (int t = 0; t < n; t++)               if (((1 << t) & h) && (!(q[u - 1][x] & (1 << t)))) {                 hc[wf[q[u - 1][x] | (1 << t)]] = 1, tg = 1;               }           }         }         if (!tg) continue;         int pos;         if (rt[u][hc] == 0) rt[u][hc] = ++of, e[u]++, wq[u][e[u]] = hc;         pos = rt[u][hc];         ans[u][pos] = (ans[u][pos] + opq * ans[u - 1][i]) % p;       }     }   }   int main() {     n = read();     for (int i = 0; i <= (1 << n); i++) s[i] = __builtin_popcount(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) f[i][j] = read() * pows(100, p - 2) % p;     q[0][0] = 1;     e[0] = 1, ans[0][1] = 1, wq[0][1][1] = 1;     for (int i = 1; i <= n; i++) find(i);     cout << ans[n][1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int r, x, y, x1, y1, t, u;     double ans = 0;     cin >> r >> x >> y >> x1 >> y1;     t = abs(x - x1);     u = abs(y - y1);     ans = t * t + u * u;     ans = sqrt(ans);     ans = ans / (2 * r);     ans = ceil(ans);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline int32_t rnd(int32_t l = 0, int32_t r = INT_MAX) {     return uniform_int_distribution<int32_t>(l, r)(rng);   }   template <typename T, typename G>   ostream& operator<<(ostream& out, const pair<T, G>& a) {     return out <<  (  << a.first <<   ,   << a.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& a) {     out <<  [ ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& out, const set<T>& a) {     out <<  { ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  } ;   }   template <typename T, typename G>   ostream& operator<<(ostream& out, const map<T, G>& a) {     out <<  < ;     for (const auto& i : a) out << i <<   ,  ;     return out <<  > ;   }   template <typename T, size_t N>   typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,                      ostream&>::type   operator<<(ostream& out, T (&a)[N]) {     out <<  [ ;     for (size_t i = 0; i < N; ++i) out << a[i] <<   ,  ;     out <<  ] ;     return out;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int32_t n, i, first = 0;     cin >> n;     vector<int32_t> a(n), b(n), o, e;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i] / 2;       first += b[i];       if (a[i] & 1) {         if (a[i] > 0) {           o.push_back(i);         } else {           e.push_back(i);         }       }     }     if (first > 0) {       for (i = 0; i < e.size() && first; i++, first--) b[e[i]]--;     } else if (first < 0) {       for (i = 0; i < o.size() && first; i++, first++) b[o[i]]++;     }     for (i = 0; i < n; i++) cout << b[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400;   const int MOD = (int)1e9 + 7;   int n, x;   long long fac[N], c[N][N];   map<int, int> h;   vector<int> d;   int fix(int x) {     for (int i = 2; i * i <= x; i++) {       while (x % (i * i) == 0) {         x /= i * i;       }     }     return x;   }   void add(long long &x, long long y) {     x += y;     x %= MOD;   }   int main() {     memset(c, 0, sizeof c);     fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = fac[i - 1] * i % MOD;     }     for (int i = 0; i < N; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) {         c[i][j] = c[i - 1][j - 1] + c[i - 1][j];         if (c[i][j] >= MOD) {           c[i][j] -= MOD;         }       }     }     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x = fix(x);       if (h.count(x) == 0) {         h[x] = 1;       } else {         int y = h[x];         h[x] = y + 1;       }     }     for (auto it = h.begin(); it != h.end(); it++) {       d.push_back(it->second);     }     sort(d.begin(), d.end());     int now = d[0] + 1;     vector<long long> dp(now + 1, 0);     dp[d[0] - 1] = fac[d[0]];     for (int i = 1; i < d.size(); i++) {       vector<long long> ndp(now + d[i] + 1, 0);       for (int same = 0; same <= now; same++) {         int dif = now - same;         if (dp[same] == 0) {           continue;         }         for (int j = 1; j <= d[i] && j <= now; j++) {           for (int k = 0; k <= same && k <= j; k++) {             int nsame = same - k + d[i] - j;             add(ndp[nsame], dp[same] * c[d[i] - 1][j - 1] % MOD * c[same][k] %                                 MOD * c[dif][j - k] % MOD * fac[d[i]]);           }         }       }       now += d[i];       dp.swap(ndp);     }     printf( %lld n , dp[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int a[N], f[N][21], la[21];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 0; j <= 18; j++)         if (!(a[i] & (1 << j)))           for (int k = 0; k <= 18; k++)             if (a[i] & (1 << k)) f[i][j] = max(f[i][j], f[la[k]][j]);       for (int j = 0; j <= 18; j++)         if (a[i] & (1 << j)) f[i][j] = i, la[j] = i;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       bool flag = false;       for (int j = 0; j <= 18; j++)         if ((a[l] & (1 << j)) && f[r][j] >= l) flag = true;       if (flag)         printf( Shi n );       else         printf( Fou n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 5;   const int MOD = 1000000007;   int a[300005];   int main() {     int n, p;     cin >> n >> p;     for (int i = 1; i <= n; i++) cin >> a[i];     while (p--) {       int l, r, x;       cin >> l >> r >> x;       int lar = r - x;       int num = a[x];       int count = 0;       for (int i = l; i <= r; i++) {         if (a[i] > num) {           count++;         }       }       if (count == lar) {         cout <<  Yes  << endl;       } else         cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int a, b, cost;   };   vector<edge> e;   const int INF = 1e8;   char alphabet[26] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                         j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                         s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };   bool consistence_check = false;   bool size_check = true;   int aristas = 0;   vector<int> d(27, INF);   void Bellman_Ford(vector<edge> e, int n, int m) {     d[26] = 0;     vector<int> p(n);     int x;     for (int i = 0; i < n; ++i) {       x = -1;       for (int j = 0; j < m; ++j)         if (d[e[j].a] < INF) {           if (d[e[j].b] > d[e[j].a] + e[j].cost) {             d[e[j].b] = max(-INF, d[e[j].a] + e[j].cost);             p[e[j].b] = e[j].a;             x = e[j].b;           }         }     }     if (x == -1) {       consistence_check = true;     }   }   void compare_strings(string string1, string string2) {     int size1 = string1.size();     int size2 = string2.size();     int minsize = min(size1, size2);     bool failsafe = true;     for (int a = 0; a < minsize; a++) {       if (string1[a] != string2[a]) {         edge tempedge = {string1[a] -  a , string2[a] -  a , -1};         e.emplace_back(tempedge);         aristas += 1;         failsafe = false;         break;       }     }     if (size1 > size2 and failsafe) {       size_check = false;     }   }   int main() {     vector<string> lexico;     int cantidad;     cin >> cantidad;     string temp;     for (int k = 0; k < cantidad; k++) {       cin >> temp;       lexico.emplace_back(temp);     }     for (int a = 0; a < cantidad - 1; a++) {       compare_strings(lexico[a], lexico[a + 1]);     }     for (int k = 0; k < 26; k++) {       edge tempedge = {26, k, 0};       e.emplace_back(tempedge);     }     aristas += 26;     if (size_check) {       Bellman_Ford(e, 27, aristas);     }     if (consistence_check) {       for (int k = 0; k > -26; k--) {         for (int a = 0; a < 26; a++) {           if (d[a] == k) {             cout << alphabet[a];           }         }       }     } else {       cout <<  Impossible ;     }     return 0;   }
/*  Karmanye vadhikaraste Ma Phaleshu Kadachana | Ma Karmaphalaheturbhurma Te Sangostvakarmani ||*/   //----------------------------------------------------------------------------------------------------------------//      /* this is begining have to survive more and go through long journey*/    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   #include<bits/stdc++.h>   using namespace std;   #define pb push_back   #define vi vector<int>   #define vii vector<vi>   #define vll vector<long long>   #define mx(v) *max_element(v.begin(),v.end())   #define mn(v) *min_element(v.begin(),v.end())   #define st(v) sort(v.begin(),v.end())   #define bg .begin()   #define ed .end()   #define fi first   #define sc second   #define fr(i,l,u) for(i=l;i<u;i++)   #define rfr(i,l,u) for(i=l;i>u;i--)   #define ll long long int   #define lld long long double   #define uld unsigned long long int   #define pii pair<int,int>   #define flash ios_base::sync_with_stdio(0);cin.tie(NULL);   #define mod 1000000007        void solve()   {       ll n,i,x,sum=0,rem=0;       cin>>n;       vi v;       fr(i,0,n)       {           cin>>x;           sum+=x;       }       rem=sum%n;       cout<<(n-rem)*rem<<endl;                 }         int main()   {        int t;      cin>>t;      while(t--) solve();      }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, k;   char s[N];   int chk(char s[]) {     for (int i = 1; i <= n; i += k) {       for (int j = 1; j <= k; j++) {         if (i + j - 1 > n || i + j - 1 + k > n) break;         if (s[i + j - 1] != s[i + j - 1 + k]) {           if (s[i + j - 1] > s[i + j - 1 + k])             return -1;           else             return 1;         }       }     }     return 0;   }   int main() {     cin >> n >> k;     scanf( %s , s + 1);     int flag = chk(s);     if (flag == 0) {       printf( %d n , n);       printf( %s n , s + 1);       return 0;     } else if (flag == -1) {       for (int i = 1; i <= n; i += k) {         for (int j = 1; j <= k; j++) {           if (i + j - 1 > n || i + j - 1 + k > n) break;           s[i + j - 1 + k] = s[i + j - 1];         }       }       printf( %d n , n);       printf( %s n , s + 1);       return 0;     } else {       bool ff = 0;       if (s[k] ==  9 )         s[k] =  0 , ff = 1;       else         s[k]++;       if (ff) {         for (int i = k - 1; i >= 1; i--) {           if (s[i] ==  9 ) {             s[i] =  0 ;             continue;           }           s[i]++;           break;         }       }       for (int i = 1; i <= n; i += k) {         for (int j = 1; j <= k; j++) {           if (i + j - 1 > n || i + j - 1 + k > n) break;           s[i + j - 1 + k] = s[i + j - 1];         }       }       printf( %d n , n);       printf( %s n , s + 1);       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0, ar[100001], n, ll, ars[100001];   string s;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &ars[i]);       ar[i] = ar[i - 1] + ars[i];     }     cin >> s;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         ans = max(ans, ar[i] + ll);       }       if (s[i] ==  1 ) ll += (ars[i + 1]);     }     ans = max(ans, ll);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > a;   long long sum, ans;   int e, deg;   int get_e(int num, int deg) {     if (num == 1) return 0;     if (num == 2) return 1;     int res = num * (num - 1) / 2;     if (deg & 1) {       int bad = num - 2;       res += bad / 2;     }     return res;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int q, w;       scanf( %d %d , &q, &w);       a.push_back(make_pair(w, q));     }     sort(a.rbegin(), a.rend());     for (int i = 1; i <= min(3000, m); i++) {       sum += a[i - 1].first;       deg = i - 1;       e = get_e(i, deg);       if (e + 1 <= n) ans = max(ans, sum);     }     cout << ans;     return 0;   }