malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, n, i, x;     cin >> t;     while (t--) {       cin >> n;       i = n - 1;       x = n;       cout <<  2  << endl;       while (i != 0) {         cout << i <<     << x << endl;         x = ceil((i + x) / 2.0);         i--;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class DS {    public:     DS(int rows, int cols) : _rows(rows), _cols(cols), _ans(0) {       int n = rows + cols;       _p.resize(n, -1);       _r.resize(n, 0);       _nr.resize(n, 0);       _nc.resize(n, 0);       for (int i = 0; i < rows; ++i) _nr[i] = 1;       for (int i = 0; i < cols; ++i) _nc[rows + i] = 1;     }     long long ans() { return _ans; }     int find(int i) {       while (_p[i] >= 0) i = _p[i];       return i;     }     void merge(int r, int c) {       int i = find(r);       int j = find(_rows + c);       if (i == j) return;       if (_r[i] > _r[j]) swap(i, j);       _rb.push_back({i, j, _r[j]});       _p[i] = j;       if (_r[i] == _r[j]) ++_r[j];       _ans += (long long)_nr[i] * _nc[j] + (long long)_nc[i] * _nr[j];       _nr[j] += _nr[i];       _nc[j] += _nc[i];     }     int current_snapshot() { return _rb.size(); }     void rollback(int snapshot) {       while (_rb.size() > snapshot) {         int i = _rb.back().i;         int j = _rb.back().j;         int r = _rb.back().r;         _rb.pop_back();         _p[i] = -1;         _r[j] = r;         _nr[j] -= _nr[i];         _nc[j] -= _nc[i];         _ans -= (long long)_nr[i] * _nc[j] + (long long)_nc[i] * _nr[j];       }     }       private:     int _rows, _cols;     vector<int> _p, _r, _nr, _nc;     struct rb_t {       int i, j, r;     };     vector<rb_t> _rb;     long long _ans;   };   class Solution {    public:     Solution(vector<pair<int, int>> const& p, int mx, int my)         : _n(p.size()), _p(p), _seg(4 * _n), _ds(mx + 1, my + 1) {}     void solve() {       map<pair<int, int>, int> t;       for (int i = 0; i < _n; ++i) {         auto it = t.find(_p[i]);         if (it == t.end()) {           t[_p[i]] = i;           continue;         }         int j = it->second;         t.erase(it);         add_pt(0, 0, _n, j, i, _p[i]);       }       for (const auto& ti : t) {         add_pt(0, 0, _n, ti.second, _n, ti.first);       }       dfs(0, 0, _n);     }       private:     void add_pt(int u, int a, int b, int A, int B, const pair<int, int>& pt) {       if (a >= B || A >= b) return;       if (A <= a && b <= B) {         _seg[u].push_back(pt);         return;       }       int c = (a + b) >> 1;       add_pt(2 * u + 1, a, c, A, B, pt);       add_pt(2 * u + 2, c, b, A, B, pt);     }     void dfs(int u, int a, int b) {       int snapshot = _ds.current_snapshot();       for (const pair<int, int>& pt : _seg[u]) _ds.merge(pt.first, pt.second);       if (a + 1 == b) {         cout << _ds.ans() <<    ;       } else {         int c = (a + b) >> 1;         dfs(2 * u + 1, a, c);         dfs(2 * u + 2, c, b);       }       _ds.rollback(snapshot);     }       private:     int _n;     vector<pair<int, int>> const& _p;     vector<vector<pair<int, int>>> _seg;     DS _ds;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     vector<pair<int, int>> p(q);     int mx = 0, my = 0;     for (pair<int, int>& pi : p) {       cin >> pi.first >> pi.second;       mx = max(mx, pi.first);       my = max(my, pi.second);     }     Solution(p, mx, my).solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     if (a[1] ==  8  || a[1] ==  1 ) {       if (a[0] ==  a  || a[0] ==  h )         cout << 3 << endl;       else         cout << 5 << endl;       return 0;     }     if (a[0] ==  a  || a[0] ==  h )       cout << 5 << endl;     else       cout << 8 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, b[110][10010], i, j, k, minn, l, p, w, ind;   string a[10005];   int main() {     cin >> n >> m;     p = false;     w = false;     for (i = 0; i < n; i++) {       k = -1;       cin >> a[i];       for (j = 0; j < m; j++) {         if (a[i][j] ==  1 ) {           p = true;           b[i][j] = 0;           k = 0;           k++;           ind = j;         } else {           b[i][j] = k;           if (k > 0) k++;         }       }       j = 0;       while (b[i][j] != 0) {         b[i][j] = m - ind + j;         j++;       }       if (p == false) {         w = true;         break;       }       p = false;       k = -1;       for (j = m - 1; j >= 0; j--) {         if (a[i][j] ==  1 ) {           b[i][j] = 0;           k = 0;           k++;           ind = j;         } else {           if (b[i][j] < 0 || (k < b[i][j] && k >= 0)) b[i][j] = k;           if (k > 0) k++;         }       }       j = m - 1;       while (b[i][j] != 0) {         if (b[i][j] > ind + m - j) b[i][j] = ind + m - j;         j--;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         b[i][j] = min(b[i][j], m - b[i][j]);       }     }     minn = 9999999;     for (i = 0; i < m; i++) {       l = 0;       for (j = 0; j < n; j++) l = l + b[j][i];       if (l < minn) minn = l;     }     if (w == true)       cout <<  -1 ;     else       cout << minn;   }
#include <bits/stdc++.h>   using namespace std;   char s[20][20];   long long n;   long long tmp1[15][16400][65];   long long tmp2[15][16400][65];   long long visit[20];   long long a[20];   long long k;   long long fst;   long long all;   void dfs(long long pos, long long msk, long long ans) {     if (pos == k) {       tmp1[fst][msk][ans]++;     }     if (pos == n - k) {       tmp2[visit[pos - 1]][msk][ans]++;       return;     }     for (long long i = 0; i < n; i++) {       if (msk & (1 << i)) continue;       visit[pos] = i;       dfs(pos + 1, msk | (1 << i), (ans << 1) | s[i][visit[pos - 1]]);     }   }   long long cnt[20000];   signed main() {     cin >> n;     all = (1 << n) - 1;     k = n / 2;     long long allk = (1 << (k - 1));     long long allkk = (1 << (n - k - 1));     for (long long i = 0; i < n; i++) {       cin >> s[i];     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) s[i][j] -=  0 ;     for (fst = 0; fst < n; fst++) {       visit[0] = fst;       dfs(1, 1 << fst, 0);     }     for (long long msk = 0; msk < all; msk++) {       long long c = 0;       for (long long i = 0; i < n; i++)         if (msk & (1 << i)) c++;       if (c != k) continue;       for (long long i = 0; i < n; i++)         if (msk & (1 << i))           for (long long j = 0; j < n; j++) {             if (msk & (1 << j)) continue;             for (long long mk = 0; mk < allk; mk++) {               if (tmp1[i][msk][mk] == 0) continue;               for (long long mkk = 0; mkk < allkk; mkk++) {                 cnt[mkk << (k) | s[i][j] << (k - 1) | mk] +=                     tmp2[j][all ^ msk][mkk] * tmp1[i][msk][mk];               }             }           }     }     for (long long i = 0; i < (1 << (n - 1)); i++) printf( %lld  , cnt[i]);     return ~~(0 ^ 0 ^ 0);   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n, T;   int t[5005];   double p[5005];   double dp[5005][5005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> T;     for (int i = 1; i <= n; i++) cin >> p[i] >> t[i], p[i] *= 0.01;     dp[0][0] = 1;     double ex = 0;     for (int i = 1; i <= n; i++) {       double r = 1.0;       for (int j = 0; j < t[i]; j++) r *= (1.0 - p[i]);       double sum = 0;       for (int j = 1; j <= T; j++) {         sum = sum * (1.0 - p[i]) + dp[i - 1][j - 1];         if (j > t[i]) sum = sum - r * dp[i - 1][j - t[i] - 1];         dp[i][j] = sum * p[i];         if (j >= t[i]) dp[i][j] += r * dp[i - 1][j - t[i]];         ex += dp[i][j];       }     }     cout << setprecision(13) << fixed << ex;   }
#include <bits/stdc++.h>   using namespace std;   int vis[10], A[300], B[300];   int ct[300], mrk[300];   vector<pair<int, int>> ans;   int main() {     int n, x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         scanf( %d , &x);         A[i] |= (1 << j) * x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         scanf( %d , &x);         B[i] |= (1 << j) * x;       }     }     vis[7] = ct[0] = vis[0] = mrk[0] = 1;     for (int i = 1; i <= 7; i++) {       for (int j = 1; j <= 7; j++) {         for (int k = 0; !vis[j] && k < n; k++) {           if (vis[A[k]] && (A[k] & B[k]) == j) {             vis[j] = k + 1;             ct[k] = mrk[k] = 1;             ans.push_back({vis[A[k]], k + 1});           }           for (int _k = (A[k] - 1) & A[k]; _k != 0 && !vis[j];                _k = (_k - 1) & A[k]) {             if (vis[A[k] ^ _k] && vis[_k] && (B[k] & A[k]) == j) {               vis[j] = k + 1;               ct[k] = mrk[k] = 1;               ans.push_back({vis[_k], k + 1});               ans.push_back({vis[A[k] ^ _k], k + 1});             }             if (!vis[j] && vis[A[k] ^ _k] && vis[_k] && A[k] == j) {               vis[j] = k + 1;               mrk[k] = 1;               ans.push_back({vis[_k], k + 1});               ans.push_back({vis[A[k] ^ _k], k + 1});             }           }         }       }     }     for (int i = 0; i < n; i++) {       if (!vis[A[i]]) return !printf( Impossible n );       if (!mrk[i] && A[i] != 0) ans.push_back({vis[A[i]], i + 1});     }     printf( Possible n );     for (int i = 0; i < n; i++) printf( %d  , ct[i]);     printf(  n%d n , (int)ans.size());     for (auto it : ans) printf( %d %d n , it.first, it.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   const int mxN = 1000;   int prnt[mxN];   int rnk[mxN];   vector<int> adj[mxN];   vector<pair<int, int>> ans;   int vis[mxN];   int find(int i) {     if (prnt[i] != i) prnt[i] = find(prnt[i]);     return prnt[i];   }   void join(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (rnk[xroot] < rnk[yroot])       prnt[xroot] = yroot;     else if (rnk[xroot] > rnk[yroot])       prnt[yroot] = xroot;     else {       prnt[yroot] = xroot;       rnk[xroot]++;     }   }   void dfs(int u, int e) {     for (auto ad = adj[u].begin(); ad != adj[u].end(); ad++) {       if (*ad == e || vis[*ad]) continue;       int adprnt = find(*ad);       int uprnt = find(u);       if (adprnt == uprnt) {         ans.push_back(make_pair(u, *ad));         continue;       }       join(*ad, u);       dfs(*ad, u);     }     vis[u] = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 0; i < n; i++) {       prnt[i] = i;     }     for (int i = 0; i < n; i++) {       if (!vis[i]) {         dfs(i, -1);       }     }     cout << ans.size() << endl;     int id = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int x = find(i);         int y = find(j);         if (x != y) {           cout << ans[id].first + 1 <<     << ans[id].second + 1 <<     << i + 1                <<     << j + 1 << endl;           id++;           join(i, j);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   clock_t time_p = clock();   void time_taken() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   const long long mod = 1e9 + 7;   const long long INF = 1e18;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int mn = *min_element((a).begin(), (a).end());     vector<int> inds, b;     for (int i = 0; i < n; i++) {       if (a[i] % mn == 0) inds.push_back(i), b.push_back(a[i]);     }     sort((b).begin(), (b).end());     int j = 0;     for (int x : inds) {       a[x] = b[j++];     }     if (is_sorted((a).begin(), (a).end())) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     time_taken();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932384626433832795;   const double EPS = 1e-9;   set<int> good;   void gen(int x) {     good.insert(x);     if (x > 100 * 1000 * 1000) {       return;     }     gen(10 * x + 4);     gen(10 * x + 7);   }   vector<pair<int, int> > swaps;   void addSwap(int i, int j) {     if (i != j) {       swaps.push_back(pair<int, int>(i, j));     }   }   bool fail;   vector<pair<int, int> > solve(const vector<int>& seq____) {     vector<int> seq = seq____;     swaps.clear();     fail = false;     int where_good = -1;     int n = seq.size();     bool sorted = true;     for (int i = 0; i < n; ++i) {       if (i > 0 && seq[i] < seq[i - 1]) {         sorted = false;       }       if (good.count(seq[i])) {         where_good = i;       }     }     if (where_good == -1) {       if (!sorted) {         fail = true;       }       return swaps;     }     int goodNumber = seq[where_good];     int amountLess = 0;     for (int i = 0; i < n; ++i) {       if (seq[i] < goodNumber) {         ++amountLess;       }     }     vector<int> positions;     for (int i = 0; i < n; ++i) {       if (i != amountLess) {         positions.push_back(i);       }     }     set<pair<int, int> > unsorted;     for (int i = 0; i < n; ++i) {       if (i == where_good) {         continue;       }       unsorted.insert(pair<int, int>(seq[i], i));     }     int idInPositions = 0;     while (!unsorted.empty()) {       pair<int, int> cur = *unsorted.begin();       unsorted.erase(unsorted.begin());       if (cur.second == positions[idInPositions]) {         ++idInPositions;         continue;       }       int firstSwapPosition = positions[idInPositions];       bool firstErased = unsorted.count(           pair<int, int>(seq[firstSwapPosition], firstSwapPosition));       unsorted.erase(pair<int, int>(seq[firstSwapPosition], firstSwapPosition));       swap(seq[where_good], seq[firstSwapPosition]);       if (firstErased) {         unsorted.insert(pair<int, int>(seq[where_good], where_good));       }       addSwap(where_good, positions[idInPositions]);       where_good = firstSwapPosition;       int secondSwapPosition = cur.second;       bool secondErased = unsorted.count(           pair<int, int>(seq[secondSwapPosition], secondSwapPosition));       unsorted.erase(pair<int, int>(seq[secondSwapPosition], secondSwapPosition));       swap(seq[where_good], seq[secondSwapPosition]);       if (secondErased) {         unsorted.insert(pair<int, int>(seq[where_good], where_good));       }       addSwap(where_good, secondSwapPosition);       where_good = secondSwapPosition;       ++idInPositions;     }     return swaps;   }   int main() {     int n;     gen(4);     gen(7);     while (cin >> n) {       vector<int> seq(n);       for (int i = 0; i < seq.size(); ++i) {         scanf( %d , &seq[i]);       }       vector<pair<int, int> > res = solve(seq);       if (fail) {         cout << -1 << endl;       } else {         cout << res.size() << endl;         for (int i = 0; i < res.size(); ++i) {           printf( %d %d n , res[i].first + 1, res[i].second + 1);         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 2 * (1e5) + 7, mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     {       long long n, x1, x2;       cin >> n >> x1 >> x2;       vector<pair<long long, long long>> v;       v.push_back({-1, -1});       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         v.push_back({x, i});       }       sort(v.begin(), v.end());       bool ok = 0;       for (long long i = 1; i <= n - 1; i++) {         long long lo = i, hi = n - 1;         while (lo <= hi) {           long long mid = (lo + hi) / 2;           long long x = (mid - i + 1);           long long y = (n - mid);           long long lo1 = v[i].first, lo2 = v[mid + 1].first;           long double p = x1 / (long double)x;           long double q = x2 / (long double)y;           if (lo1 >= p && lo2 >= q) {             ok = 1;             cout <<  Yes                   <<   n ;             cout << x <<     << y <<   n ;             for (long long j = i; j <= mid; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             for (long long j = mid + 1; j <= n; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             return 0;           }           if (p <= lo1)             hi = mid - 1;           else             lo = mid + 1;         }       }       swap(x1, x2);       for (long long i = 1; i <= n - 1; i++) {         long long lo = i, hi = n - 1;         while (lo <= hi) {           long long mid = (lo + hi) / 2;           long long x = (mid - i + 1);           long long y = (n - mid);           long long lo1 = v[i].first, lo2 = v[mid + 1].first;           long double p = x1 / (long double)x;           long double q = x2 / (long double)y;           if (lo1 >= p && lo2 >= q) {             ok = 1;             cout <<  Yes                   <<   n ;             cout << y <<     << x <<   n ;             for (long long j = mid + 1; j <= n; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             for (long long j = i; j <= mid; j++) {               cout << v[j].second <<    ;             }             cout <<   n ;             return 0;           }           if (p <= lo1)             hi = mid - 1;           else             lo = mid + 1;         }       }       if (!ok)         cout <<  No               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int MX = 1e6 + 23;   const long long MOD = 998244353;   int read() {     char k = getchar();     int x = 0;     while (k <  0  || k >  9 ) k = getchar();     while (k >=  0  && k <=  9 ) x = x * 10 + k -  0 , k = getchar();     return x;   }   int n, m, c[MX], w[MX];   int a[MX], b[MX];   struct Choice {     int w, id;     bool operator<(const Choice &B) const { return w > B.w; }   };   int cho[MX];   void solve() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) {       c[i] = read();       a[i] = c[i] / 100;       b[i] = c[i] % 100;       if (!b[i]) cho[i] = 1;     }     long long ans = 0;     std::priority_queue<Choice> q;     for (int i = 1; i <= n; ++i) {       w[i] = read();       if (m >= b[i]) {         if (b[i]) {           q.push((Choice){(100 - b[i]) * w[i], i});         }       } else {         if (!q.empty() && q.top().w <= (100 - b[i]) * w[i]) {           ans += q.top().w;           q.pop();           q.push((Choice){(100 - b[i]) * w[i], i});         } else {           ans += (100 - b[i]) * w[i];         }         m += 100;       }       m -= b[i];     }     printf( %lld n , ans);     while (!q.empty()) {       cho[q.top().id] = 1;       q.pop();     }     for (int i = 1; i <= n; ++i) {       if (cho[i]) {         printf( %d %d n , a[i], b[i]);       } else         printf( %d %d n , a[i] + 1, 0);     }   }   int main() {     int T = 1;     for (int i = 1; i <= T; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, j = 1;     string x;     cin >> n >> x;     for (int i = 1; i <= n; i += j) {       cout << x[i - 1];       j++;     }     return 0;   }
#include <bits/stdc++.h>   int Flag, sum, flag[105], n, m, a, b, A[105], map[105][105];   void dfs(int last_last, int last) {     int S;     flag[last] = 1;     for (int i = 1; i <= n; i++) {       if (!map[last][i]) continue;       if (map[i][last_last]) {         S = A[i] + A[last] + A[last_last];         if (S < sum) sum = S;       }       if (!flag[i]) dfs(last, i);     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(flag, 0, sizeof(flag));       memset(map, 0, sizeof(map));       for (int i = 1; i <= n; i++) scanf( %d , &A[i]);       for (int i = 1; i <= m; i++) {         scanf( %d%d , &a, &b);         map[a][b] = 1;         map[b][a] = 1;       }       Flag = 0;       sum = 99999999;       dfs(0, 1);       if (sum == 99999999)         printf( -1 n );       else         printf( %d n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int vs, ve;     int t, d;     cin >> vs >> ve >> t >> d;     int cur = vs;     int sm = vs;     int pre = vs;     for (int i = 2; i <= t; i++) {       while (cur < ve && abs(pre - cur) < d) cur++;       if (cur >= ve) {         while ((t - i) * d > cur - ve && abs(pre - cur) < d) cur++;         while ((t - i) * d < cur - ve && abs(pre - cur) < d) cur--;       }       pre = cur;       sm += cur;     }     assert(cur == ve);     cout << sm;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long tree[4 * 100100];   long long a[100100];   int n;   void build(int from, int to, int node) {     if (from == to) {       tree[node] = a[from];       return;     }     int mid = (from + to) / 2;     build(from, mid, 2 * node);     build(mid + 1, to, 2 * node + 1);     tree[node] = max(tree[2 * node], tree[2 * node + 1]);   }   long long val;   void update(int from, int to, int node) {     if (from == to) {       tree[node] = val;       return;     }     int mid = (from + to) / 2;     update(from, mid, 2 * node);     tree[node] = max(tree[2 * node], tree[2 * node + 1]);   }   long long query(int from, int to, int node, int low, int high) {     if (low > to || from > high) {       return 0;     }     if (from >= low && to <= high) {       return tree[node];     }     int mid = (from + to) / 2;     return max(query(from, mid, 2 * node, low, high),                query(mid + 1, high, 2 * node + 1, low, high));   }   long long b[100100];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     b[0] = a[0];     b[1] = a[1];     for (int i = 2; i < n; i++) {       b[i] = max(b[i - 1], a[i]);     }     int Q;     scanf( %d , &Q);     while (Q--) {       long long w, h;       cin >> w >> h;       cout << max(b[0], b[w - 1]) << endl;       b[0] = (max(b[0], b[w - 1]) + h);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct gam {     int o;     long long k;     int nez;     long long bd;     long long kd;     gam() {       o = 0;       k = 0;       nez = 0;       bd = 0;       kd = 0;     }   };   bool mycomp(gam i, gam j) { return (i.k < j.k); }   int main() {     long long n;     long long r;     long long tr;     long long sum = 0;     cin >> n;     cin >> r;     cin >> tr;     gam* a = new gam[n + 1];     a[0].k = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i].o;       cin >> a[i].k;       a[i].nez = r - a[i].o;       sum = sum + a[i].o;     }     sort(a + 1, a + n + 1, mycomp);     long long nug = tr * n - sum;     if (nug > 0) {       int cur;       for (int i = 1; i <= n; i++) {         a[i].bd = a[i - 1].bd + a[i].nez;         a[i].kd = a[i - 1].kd + a[i].k * a[i].nez;         if (a[i].bd >= nug) {           cur = i;           break;         }       }       long long enug = nug - a[cur - 1].bd;       long long rez = a[cur - 1].kd + enug * a[cur].k;       cout << rez;     } else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename X>   inline X abs(const X& a) {     return a < 0 ? -a : a;   }   template <typename X>   inline X sqr(const X& a) {     return a * a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     double first = (sqrt(8.0 * n + 1) - 1) / 2;     int out = (first - floor(first)) * (first + 1);     if (out == 0)       cout << (int)first;     else       cout << out;   }