malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long INF = (long long)1e20;   long long mod = (long long)1e9 + 7;   pair<long long, long long> solve(       long long v, vector<vector<pair<long long, long long>>> &nodes, long long p,       long long k) {     vector<pair<pair<long long, long long>, long long>> a;     vector<pair<pair<long long, long long>, long long>> b;     for (int i = 0; i < nodes[v].size(); ++i) {       if (nodes[v][i].first != p) {         pair<long long, long long> kek = solve(nodes[v][i].first, nodes, v, k);         kek.first += nodes[v][i].second;         if (kek.second > kek.first) {           b.push_back({kek, nodes[v][i].second});         } else {           a.push_back({kek, nodes[v][i].second});         }       }     }     vector<pair<pair<long long, long long>, pair<long long, long long>>> vv(         a.size());     for (int i = 0; i < a.size(); ++i) {       vv[i] = {{a[i].first.first - a[i].first.second, a[i].second}, {a[i].first}};     }     sort(vv.rbegin(), vv.rend());     long long sum1 = 0;     for (int i = 0; i < a.size(); ++i) {       if (i < k) {         sum1 += vv[i].second.first;       } else {         sum1 += vv[i].second.second;       }     }     for (int i = 0; i < b.size(); ++i) {       sum1 += b[i].first.second;     }     long long sum = 0;     if (a.size() < k) {       sum = sum1;     }     for (int i = 0; i < a.size(); ++i) {       if (i < k) {         long long nw = sum1 - vv[i].second.first;         nw += vv[i].second.second;         sum = max(sum, nw);       } else         break;     }     return {sum, sum1};   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long n, k;       cin >> n >> k;       vector<vector<pair<long long, long long>>> nodes(n);       for (int i = 0; i < n - 1; ++i) {         long long u, v, w;         cin >> u >> v >> w;         nodes[u - 1].push_back({v - 1, w});         nodes[v - 1].push_back({u - 1, w});       }       pair<long long, long long> ans = solve(0, nodes, 0, k);       cout << max(ans.first, ans.second) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   ;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int maxn = 3e5 + 5;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   struct EDGE {     int v, nxt;   } edge[maxn << 1];   int head[maxn], tot;   void add_edge(int u, int v) {     edge[tot].v = v, edge[tot].nxt = head[u], head[u] = tot++;   }   long long bit[maxn];   int lowbit(int x) { return x & (-x); }   void add(int pos, int val) {     while (pos < maxn) {       bit[pos] += val, pos += lowbit(pos);     }   }   long long sum(int pos) {     long long ans = 0;     while (pos) {       ans += bit[pos], pos -= lowbit(pos);     }     return ans;   }   pair<int, int> p[maxn];   set<pair<int, int> > s;   void dfs(int l, int r) {     int mid = (l + r) >> 1;     for (int i = l; i <= r; i++) {       s.insert(make_pair(p[mid].first, p[i].second));     }     if (l < mid) dfs(l, mid - 1);     if (r > mid) dfs(mid + 1, r);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     dfs(0, n - 1);     cout << s.size() << endl;     set<pair<int, int> >::iterator it;     for (it = s.begin(); it != s.end(); it++)       cout << it->first <<     << it->second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = double;   const ll MODBASE = 1000000007LL;   const int MAXN = 100010;   const int MAXM = 1010;   const int MAXK = 110;   const int MAXQ = 200010;   int n, a[MAXN], b[MAXN], f[MAXN], t[MAXN];   void update(int u, int gt) {     while (u) {       t[u] += gt;       u = u - (u & (-u));     }   }   int get(int u) {     int res = 0;     while (u <= 100000) {       res += t[u];       u = u + (u & (-u));     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cin >> n;     for (int i = (1); i <= (n); i++) cin >> a[i];     for (int i = (1); i <= (n); i++) {       cin >> b[i];       f[b[i]] = i;     }     for (int i = (1); i <= (n); i++) update(i, 1);     int res = 0;     for (int i = (n); i >= (1); i--) {       int g = a[i];       int pos = f[g];       if (get(pos + 1)) res++;       update(pos, -1);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int maxt = 1 << 20;   int p[maxn], t[maxn];   bool vis[maxn], cut[maxn];   long long x[maxn], l[maxn], cal[maxn], bit1[maxt], bit2[maxt];   vector<int> son[maxn];   void dfs1(int u, long long rem) {     rem -= l[u] << 1;     for (int i = t[u]; i < maxt; i += (i & -i))       bit1[i] += x[u], bit2[i] += x[u] * t[u];     if (rem > 0) {       int l = 0, r = maxt - 1;       long long sum = 0;       for (int i = r; i; i -= (i & -i)) cal[u] += bit1[i], sum += bit2[i];       if (sum > rem) {         while (r - l ^ 1) {           int mid = l + r >> 1;           sum = 0;           for (int i = mid; i; i -= (i & -i)) sum += bit2[i];           if (sum > rem)             r = mid;           else             l = mid;         }         cal[u] = sum = 0;         for (int i = l; i; i -= (i & -i)) cal[u] += bit1[i], sum += bit2[i];         cal[u] += (rem - sum) / r;       }     }     for (auto v : son[u]) dfs1(v, rem);     for (int i = t[u]; i < maxt; i += (i & -i))       bit1[i] -= x[u], bit2[i] -= x[u] * t[u];   }   long long dfs2(int u) {     long long max1 = 0, max2 = 0;     for (auto v : son[u]) {       long long temp = dfs2(v);       if (max2 < temp) max2 = temp;       if (max1 < max2) swap(max1, max2);     }     return max(max2, cal[u]);   }   int main() {     int n;     long long T;     cin >> n >> T;     for (int i = 1; i <= n; ++i) cin >> x[i];     for (int i = 1; i <= n; ++i) cin >> t[i];     for (int i = 2; i <= n; ++i) {       cin >> p[i] >> l[i];       son[p[i]].push_back(i);     }     dfs1(1, T);     son[1].push_back(0);     cal[0] = 0x3f3f3f3f3f3f3f3f;     cout << dfs2(1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e6 + 7;   const int mod = 1e9 + 7;   int a[N];   int l[N];   int c[N];   int f[N];   int binpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) {         ret = (ret * 1LL * a) % mod;         --b;       }       a = (a * 1LL * a) % mod;       b >>= 1;     }     return ret;   }   int main() {     f[0] = 1;     for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * 1LL * i) % mod;     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     c[0] = 1;     for (int i = 1; i < n; ++i) {       l[i] = a[i] == a[i - 1] ? l[i - 1] : l[i - 1] + c[i - 1];       c[i] = a[i] == a[i - 1] ? c[i - 1] + 1 : 1;     }     int res = 0;     for (int i = 0; i < n; ++i) {       if (a[i] == a[n - 1]) break;       int v = (a[i] * 1LL * f[l[i]]) % mod;       v = (v * 1LL * f[n - l[i] - 1]) % mod;       v = (v * 1LL * f[n]) % mod;       v = (v * 1LL * binpow((f[n - l[i]] * 1LL * f[l[i]]) % mod, mod - 2)) % mod;       res = (res + v) % mod;     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;      #define pb push_back   #define ff first   #define ss second   #define lli long long int   #define ll long long   #define st string   #define vi vector<int>   #define vll vector<long long>   #define tll tuple<ll,ll,ll>   #define pii pair<int,int>   #define pll pair<ll,ll>   #define vpii vector<pii>   #define vpll vector<pll>   #define take(n) ll n;cin>>n;   #define takeinp(arr,n) for(long long int i=0;i<n;i++) cin>>arr[i];   #define gcd(a,b) __gcd(a,b)   #define mii map<int,int>   #define mll map<ll,ll>   #define all(x) x.begin(),x.end()   #define allr(x) x.rbegin(),x.rend()   #define mllitr mll::iterator itr;   #define repm(itr,mp) for(itr=mp.begin();itr!=mp.end();itr++)   #define rep(i,a,b) for(ll i=a;i<b;i++)   #define repo(i,a,b) for(ll i=a;i>b;i--)                  //GL HF//      void solve(){       string s;cin>>s;       ll n=s.length()-1;       // cout<<char( a +n)<<  n ;       if(n==0){           if(s[0]!= a ) {cout<< NO n ;return;}       }       while(n>=0){           char tmp =  a +n;           if(s[0]==tmp){               s.erase(s.begin()+0);           }else if(s[n]==tmp){               s.erase(s.begin()+n);           }else{               cout<< NO n ;               return;           }           n--;       }       cout<< YES n ;       // cout<< a +0<<  n ;   }      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       ll t=1;       cin>>t;       while(t--){           solve();       }   }
#include <bits/stdc++.h>   using namespace std;   char a[1111];   int main() {     int h = 0, i = 0, j;     bool isopen = false;     gets(a);     while (i < strlen(a) - 1) {       if (a[i] ==  <  && a[i + 1] !=  / ) {         if (isopen) h += 2;         for (j = 0; j < h; j++) printf(   );         printf( < );         i++;         while (i < strlen(a) && a[i] !=  < ) printf( %c , a[i]), i++;         printf(  n );         isopen = true;       } else if (a[i] ==  < ) {         if (!isopen) h -= 2;         for (j = 0; j < h; j++) printf(   );         printf( < );         i++;         while (i < strlen(a) && a[i] !=  < ) printf( %c , a[i]), i++;         printf(  n );         isopen = false;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   int getlength(int x, int y, int z) { return (x - y + 1) / (z); }   int main() {     int n, a, b, right, left;     cin >> n >> a >> b;     set<int> M;     int sh = (n + 1) / (b + 1);     n++;     b++;     M.insert(0);     M.insert(n);     int m, x;     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> x;       auto ptr = M.upper_bound(x);       right = *ptr;       left = *--ptr;       sh -= (right - left) / b;       sh += (right - x) / b;       sh += (x - left) / b;       M.insert(x);       if (sh < a) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0,                     z = 0, ans = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0,                     hi = 0;       string s;       bool flag = false;       cin >> n;       for (i = 0; i <= n; i++) x = (i + 1) * (n - i), cnt = max(cnt, x);       cout << cnt << endl;       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool debug = false;   int main() {     scanf( %d , &n);     int x, y;     long long sum = 0, ss = 0, px = 0, py = 0;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       sum += (long long)x * x + (long long)y * y;       ss += px * x + py * y;       px += (long long)x;       py += (long long)y;     }     sum = sum * (n - 1);     sum -= 2 * ss;     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 2e5;   const long long inf = 1e15;   inline int read() {     char ch = getchar();     int f = 1, x = 0;     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct Point {     long long x, y;     Point() : x(0), y(0) {}     Point(long long X, long long Y) : x(X), y(Y) {}     inline long long Len() { return x * x + y * y; }   };   bool operator<(Point a, Point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   inline long long Dis(Point a, Point b) {     return Point(a.x - b.x, a.y - b.y).Len();   }   int n;   long long ans = 1e15, sum[Maxn + 5];   Point P[Maxn + 5], st[Maxn + 5];   inline long long Divide(int l, int r) {     int mid = (l + r) >> 1, i, j, tot = 0;     if (l == r) return inf;     long long d;     Point pnt = P[mid];     d = min(Divide(l, mid), Divide(mid + 1, r));     i = l, j = mid + 1;     while (i <= mid && j <= r) {       if (P[i].y < P[j].y)         st[++tot] = P[i++];       else         st[++tot] = P[j++];     }     while (i <= mid) st[++tot] = P[i++];     while (j <= r) st[++tot] = P[j++];     for (int i = l; i <= r; ++i) P[i] = st[i - l + 1];     tot = 0;     for (int i = l; i <= r; ++i)       if ((pnt.x - P[i].x) * (pnt.x - P[i].x) < d) st[++tot] = P[i];     for (int i = 1; i <= tot; ++i)       for (int j = i + 1;            (st[j].y - st[i].y) * (st[j].y - st[i].y) < d && j <= tot; ++j)         d = min(d, Dis(st[i], st[j]));     return d;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + read();     for (int i = 1; i <= n; ++i) P[i] = Point(i, sum[i]);     sort(P + 1, P + n + 1);     ans = Divide(1, n);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[160][160];   int lowbit(int x) { return x & -x; }   int sum(int x, int y) {     int ans = 0;     for (int i = x; i; i -= lowbit(i)) {       for (int j = y; j; j -= lowbit(j)) {         ans += c[i][j];       }     }     return ans;   }   void add(int x, int y, int v) {     for (int i = x; i < 160; i += lowbit(i)) {       for (int j = y; j < 160; j += lowbit(j)) {         c[i][j] += v;       }     }   }   char grid[160][160];   int dp[2][160][160];   int n, m, ans;   void dfs(int x, int y, int id) {     if (grid[x][y] ==  W ) {       add(x, y, -1);     }     if (sum(n, m) == 0) return;     if (id == 1) {       if (x + 1 <= n && y + 1 <= m) {         int tmp = sum(x + 1, m) - sum(x + 1, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else if (x + 1 > n && y + 1 <= m) {         int tmp = sum(x, m) - sum(x, y);         if (x - 1 > 0) tmp = tmp - sum(x - 1, m) + sum(x - 1, y);         if (tmp > 0)           dfs(x, y + 1, 1);         else           dfs(x + 1, y, 0);       } else {         dfs(x + 1, y, 0);       }     } else {       if (x + 1 <= n && y - 1 > 0) {         int tmp = sum(x + 1, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else if (x + 1 > n && y - 1 > 0) {         int tmp = sum(x, y - 1);         if (tmp > 0)           dfs(x, y - 1, 0);         else           dfs(x + 1, y, 1);       } else         dfs(x + 1, y, 1);     }     ans++;   }   int main() {     setvbuf(stdout, NULL, _IONBF, 0);     while (scanf(  %d %d , &n, &m) == 2) {       for (int i = 1; i <= n; i++) {         scanf(  %s , grid[i] + 1);       }       memset(c, 0, sizeof(c));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (grid[i][j] ==  W ) {             add(i, j, 1);           }         }       }       ans = 0;       dfs(1, 1, 1);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, l, r, c, pl, pr, cl, cr;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> a >> b >> l >> r, c = a + b;     cl = --l / c;     pl = l % c;     cr = --r / c;     pr = r % c;     if (cl == cr)       cout << min(r - l + 1, max(a - pl, 1));     else if (a <= b) {       if (cl < cr - 1)         cout << a + 1;       else {         int x = max(1, a - pl);         int y = min(a, pr + 1);         cout << min(a, x + y) + (y == a);       }     } else {       int d = a - b;       if (cl == cr - 1)         cout << max(1, min(d, a - pl)) + min(a, pr + 1);       else if (cl == cr - 2)         cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));       else         cout << a + d;     }   }
#include <bits/stdc++.h>   using namespace std;   bool conn[4001][4001];   vector<int> path[4001];   struct Edge {     int a, b;   } edge[4001];   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       edge[i].a = a;       edge[i].b = b;       conn[a][b] = conn[b][a] = true;       path[a].push_back(b);       path[b].push_back(a);     }     int ans = 1000000;     for (int i = 0; i < M; i++) {       if (path[edge[i].a].size() >= 2 && path[edge[i].b].size() >= 2)         for (int k = 0; k < M; k++) {           if (path[edge[k].a].size() >= 2 && path[edge[k].b].size() >= 2)             if (i == k) continue;           int original = -1;           int total = original = path[edge[i].a].size() + path[edge[i].b].size() +                                  path[edge[k].b].size() + path[edge[k].a].size() -                                  6;           if (edge[i].a == edge[k].a) {             if (conn[edge[i].b][edge[k].b])               ans = min(ans, total - (int)path[edge[i].a].size());           } else if (edge[i].a == edge[k].b) {             if (conn[edge[i].b][edge[k].a])               ans = min(ans, total - (int)path[edge[i].a].size());           } else if (edge[i].b == edge[k].a) {             if (conn[edge[i].a][edge[k].b])               ans = min(ans, total - (int)path[edge[i].b].size());           } else if (edge[i].b == edge[k].b) {             if (conn[edge[i].a][edge[k].a])               ans = min(ans, total - (int)path[edge[i].b].size());           }         }     }     if (ans == 1000000) ans = -1;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 4 == 1 || n % 4 == 0) {       int *result = new int[n + 1];       if (n % 2 == 1) {         result[(n + 1) / 2] = n / 2 + 1;       }       for (int i = 1; i < (n + 1) / 2; i += 2) {         result[i] = i + 1;         result[i + 1] = n + 1 - i;         result[n + 1 - i] = n - i;         result[n - i] = i;       }       for (int i = 1; i <= n; i++) cout << result[i] <<    ;       delete[] result;     } else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5003, mod = 1e9 + 7;   long long n, k, S[N][N], ans;   inline long long kasumi(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (long long)res * a % mod;       a = (long long)a * a % mod;       b >>= 1;     }     return res;   }   signed main() {     scanf( %d%d , &n, &k);     S[0][0] = 1;     for (register long long i = 1; i <= k; i++)       for (register long long j = 1; j <= i; j++)         S[i][j] = ((long long)S[i - 1][j] * j + S[i - 1][j - 1]) % mod;     long long fac = 1, cho = 1;     for (register long long i = 1; i <= k && i <= n; i++) {       cho = (long long)cho * (n - i + 1) % mod * kasumi(i, mod - 2) % mod;       fac = (long long)fac * i % mod;       ans = (ans + (long long)fac * cho % mod * kasumi(2, n - i) % mod * S[k][i] %                        mod) %             mod;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int dp[500][500] = {0}, arr[500], n;   int check(int i, int j) {     if (dp[i][j] != 0) return dp[i][j];     if (i > j) return 0;     if (i == j) {       dp[i][j] = 1;       return 1;     }     int a = 1 + check(i + 1, j);     int m = 1e9, it;     for (it = i + 2; it <= j; it++) {       if (arr[i] == arr[it]) {         if (m > check(i + 1, it - 1) + check(it + 1, j)) {           m = check(i + 1, it - 1) + check(it + 1, j);         }       }     }     int c = 1e9;     if (arr[i] == arr[i + 1]) c = 1 + check(i + 2, j);     dp[i][j] = min(min(c, a), m);     return dp[i][j];   }   int main() {     cin >> n;     int i, j, k, l;     for (i = 0; i < n; i++) {       cin >> arr[i];     }     check(0, n - 1);     cout << dp[0][n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 2e5 + 10;   long long sum[N];   long long a[N], b[N];   long long f[N][20];   int n, k, top;   long long MAX(long long x, long long y) {     if (x < y) return y;     return x;   }   void advan() {     for (int i = 1; i <= top; ++i) f[i][0] = b[i];     for (int i = 1; (1 << i) <= top; ++i) {       for (int j = 1; j + (1 << i) - 1 <= top; ++j)         f[j][i] = f[j][i - 1] < f[j + (1 << (i - 1))][i - 1]                       ? f[j + (1 << (i - 1))][i - 1]                       : f[j][i - 1];     }   }   long long query(int l, int r) {     int k = 0;     k = log2(double(r - l + 1));     return MAX(f[l][k], f[r - (1 << k) + 1][k]);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     top = 0;     for (int i = k; i <= n; ++i) b[++top] = sum[i] - sum[i - k];     advan();     long long maxx = 0, L = 0, R = 0, be, res = 0, en;     for (int i = 1; i <= top - k; ++i) {       L = b[i];       R = query(i + k, top);       if (L + R > maxx) {         maxx = L + R;         res = R;         be = i;       }     }     for (int i = be + k; i <= top; ++i) {       if (b[i] == res) {         en = i;         break;       }     }     printf( %lld %lld n , be, en);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, c, ans1, ans2, ans3, a[100005], dp[5];   pair<long long, long long> p[300005];   vector<long long> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (m == 0) {       cout << -1 <<   n ;       return 0;     }     for (long long i = 1; i <= m; i++) {       cin >> p[i].first >> p[i].second;       if (p[i].first == 1) {         v.push_back(p[i].second);       } else if (p[i].second == 1) {         v.push_back(p[i].first);       }     }     sort(v.begin(), v.end());     v.push_back(n + 1);     a[1] = 1;     for (int i = 2; i <= n; i++) {       if (i != v[k]) {         a[i] = 1;       } else {         k++;       }     }     c = v[0];     for (long long i = 1; i <= m; i++) {       if (p[i].first == c && a[p[i].second] == 0) {         a[p[i].second] = 2;       } else if (p[i].second == c && a[p[i].first] == 0) {         a[p[i].first] = 2;       }     }     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) {         a[i] = 3;       }     }     for (long long i = 1; i <= n; i++) {       dp[a[i]]++;     }     if (dp[1] == 0 || dp[2] == 0 || dp[3] == 0 ||         dp[1] * dp[2] + dp[2] * dp[3] + dp[1] * dp[3] != m) {       cout << -1 <<   n ;       return 0;     }     for (long long i = 1; i <= m; i++) {       if (a[p[i].first] == a[p[i].second]) {         cout << -1 <<   n ;         return 0;       }     }     for (long long i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }