func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) {     for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {       os << p->first <<  :   << p->second <<    ;     }     return os;   }   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) {     os << v.first <<  :   << v.second <<    ;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << endl;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] <<    ;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const set<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const deque<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   int main() {     long long N, M;     while (cin >> N >> M) {       long long lo = 1, hi = M + 1;       while (lo + 1 < hi) {         long long mid = (lo + hi) / 2;         long long edges = mid * (mid - 1) / 2;         if (mid % 2 == 0 && mid - 2 > 0) edges += (mid - 2) / 2;         if (edges <= N - 1)           lo = mid;         else           hi = mid;       }       vector<long long> w(M);       for (int i = 0, _n = (M); (i) < (int)_n; ++i) {         long long v;         cin >> v >> w[i];       }       sort((w).rbegin(), (w).rend());       cout << accumulate(&w[0], &w[lo], 0) << endl;     }     return 0;   }   