malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct fenwick_tree_1D {     long long n, log_n;     vector<long long> tree;     fenwick_tree_1D(long long _n)         : n(_n), log_n((long long)(log2(_n) + 1.0L)), tree(_n + 5) {}     void update(long long x, long long v) {       while (x <= n) {         tree[x] += v;         x += x & (-x);       }     }     long long prefix_sum(long long x) {       long long r = 0;       while (x) {         r += tree[x];         x -= x & (-x);       }       return r;     }     long long range_sum(long long l, long long r) {       return prefix_sum(r) - prefix_sum(l - 1);     }   };   const long long bs = 300;   fenwick_tree_1D bit(100005);   long long a[100005], nxt[100005], last[100005] = {0}, dl[2 * bs + 5],                                     id[100005], dc = 0, result[100005] = {0};   set<long long> s[100005];   long long qc;   struct query {     long long t, l, r, qno;   } q[bs + 5];   long long q2c;   struct query2 {     long long l, r, qno;   } q2[bs + 5];   vector<long long> ans;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       s[a[i]].insert(i);     }     for (long long h = 0; h < m; h += bs) {       qc = min(bs, m - h);       for (long long j = 0; j < qc; j++) {         cin >> q[j].t >> q[j].l >> q[j].r;         q[j].qno = h + j;         if (q[j].t == 1) {           if (!id[a[q[j].l]]) dl[dc] = a[q[j].l], id[a[q[j].l]] = 1, dc++;           if (!id[q[j].r]) dl[dc] = q[j].r, id[q[j].r] = 1, dc++;         } else           q2[q2c].l = q[j].l, q2[q2c].r = q[j].r, q2[q2c].qno = q[j].qno,           ans.push_back(q[j].qno), q2c++;       }       for (long long i = n; i >= 1; i--) {         if (id[a[i]]) {           nxt[i] = 0;           continue;         }         nxt[i] = last[a[i]];         if (nxt[i]) bit.update(nxt[i], nxt[i] - i);         last[a[i]] = i;       }       sort(q2, q2 + q2c,            [](const query2 &l, const query2 &r) { return l.l < r.l; });       long long pos = 1;       for (long long i = 0; i < q2c; i++) {         while (pos < q2[i].l) {           if (id[a[pos]] || !nxt[pos]) {             pos++;             continue;           }           bit.update(nxt[pos], pos - nxt[pos]);           pos++;         }         result[q2[i].qno] = bit.prefix_sum(q2[i].r);       }       for (long long i = 0; i < qc; i++) {         if (q[i].t == 1) {           s[a[q[i].l]].erase(q[i].l);           a[q[i].l] = q[i].r;           s[a[q[i].l]].insert(q[i].l);         } else {           for (long long j = 0; j < dc; j++) {             auto it1 = s[dl[j]].lower_bound(q[i].l);             auto it2 = s[dl[j]].upper_bound(q[i].r);             if (it1 != s[dl[j]].end() && it2 != s[dl[j]].begin()) {               it2--;               if (*it2 > *it1) result[q[i].qno] += *it2 - *it1;             }           }         }       }       for (long long i = 0; i < dc; i++) id[dl[i]] = 0;       dc = 0;       q2c = 0;       for (long long i = 1; i <= n; i++) bit.tree[i] = 0, last[i] = 0;     }     for (auto &k : ans) cout << result[k] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n;     cin >> n;     int k;     cin >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int lift;     cin >> lift;     vector<int> c(n);     for (int i = 0; i < n; i++) cin >> c[i];     set<int> second;     ll ans = 0;     int joker;     for (int i = 0; i < n; i++) {       second.insert(c[i]);       if (v[i] <= k)         continue;       else {         joker = (v[i] - k) / lift;         if ((v[i] - k) % lift != 0) joker++;         if (joker > second.size()) {           ans = -1;           break;         }         k += (joker * lift);         int mini;         while (joker--) {           mini = *min_element(second.begin(), second.end());           ans += mini;           second.erase(mini);         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100004;   int n, m, c = 0;   char s[24][24];   set<unsigned long long> st, ns;   bool fun(int x, int y) {     st.clear();     for (int i = 0; i < n; i += x)       for (int j = 0; j < m; j += y) {         ns.clear();         unsigned long long sum = 0;         for (int u = 0; u < x; u++) {           unsigned long long p = 0;           for (int v = 0; v < y; v++) p = p * 131 + s[i + u][j + v];           sum = sum * 997 + p;         }         ns.insert(sum);         sum = 0;         for (int u = x - 1; u >= 0; u--) {           unsigned long long p = 0;           for (int v = y - 1; v >= 0; v--) p = p * 131 + s[i + u][j + v];           sum = sum * 997 + p;         }         ns.insert(sum);         if (x == y) {           sum = 0;           for (int v = y - 1; v >= 0; v--) {             unsigned long long p = 0;             for (int u = 0; u < x; u++) p = p * 131 + s[i + u][j + v];             sum = sum * 997 + p;           }           ns.insert(sum);           sum = 0;           for (int v = 0; v < y; v++) {             unsigned long long p = 0;             for (int u = x - 1; u >= 0; u--) p = p * 131 + s[i + u][j + v];             sum = sum * 997 + p;           }           ns.insert(sum);         }         for (auto it = ns.begin(); it != ns.end(); it++) {           if (st.count(*it)) return 0;           st.insert(*it);         }       }     return 1;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     int x = 100, y = 100, ans = 40000;     for (int i = 1; i <= n; i++)       if (n % i == 0)         for (int j = 1; j <= m; j++)           if (m % j == 0) {             if (fun(i, j)) {               ++c;               if (i * j < ans || i * j == ans && i < x) {                 ans = i * j;                 x = i;                 y = j;               }             }           }     printf( %d n%d %d n , c, x, y);   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807;   const long long MOD = 1000000007;   const long long FMOD = 998244353;   const long long MAXN = 1e5 + 5;   const long double eps = 1e-9;   const long double PI = acos(-1);   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::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<pair<int, int>> a(n);     vector<pair<char, int>> arr;     int cnt = 0;     for (long long i = 0; i < n; i++) {       char c;       cin >> c;       int ind;       cin >> ind;       ind--;       if (c ==  + ) {         a[ind].first++;       } else {         a[ind].second++;         cnt++;       }       arr.push_back({c, ind});     }     bool ok = true;     map<int, int> chorhaibc;     for (long long i = 0; i < n; i++) {       if (cnt - a[i].second + a[i].first == m) {         chorhaibc[i] = 1;       }     }     if (chorhaibc.size() == 1) {       int killer = chorhaibc.begin()->first;       for (long long i = 0; i < n; i++) {         if (arr[i].first ==  + ) {           if (arr[i].second == killer)             cout <<  Truth ;           else             cout <<  Lie ;         }         if (arr[i].first ==  - ) {           if (arr[i].second == killer)             cout <<  Lie ;           else             cout <<  Truth ;         }         cout << endl;       }     } else {       for (long long i = 0; i < n; i++) {         if (arr[i].first ==  +  && chorhaibc[arr[i].second] == 0) {           cout <<  Lie ;         } else {           if (arr[i].first ==  -  && chorhaibc[arr[i].second] == 0) {             cout <<  Truth ;           } else {             cout <<  Not defined ;           }         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ex_gcd(long long a, long long b, long long &x, long long &y) {     int d = a;     if (b == 0) {       x = 1;       y = 0;     } else {       d = ex_gcd(b, a % b, y, x);       y -= a / b * x;     }     return d;   }   int main() {     long long a, b, c;     long long x, y;     cin >> a >> b >> c;     int gcd = ex_gcd(a, b, x, y);     if (-c % gcd)       cout << -1;     else {       long long k = (-c) / gcd;       cout << k * x <<     << k * y;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   bool a[2000][2000], use[2000][2000][6][6];   vector<pair<int, int> > go;   void dfs(int x, int y, int way, int cnt) {     if (cnt == 3) return;     use[x][y][way][cnt] = 1;     for (int i = 1; i <= 4; i++)       if (i == way) {         if (a[x + go[i - 1].first][y + go[i - 1].second] &&             !use[x + go[i - 1].first][y + go[i - 1].second][i][cnt])           dfs(x + go[i - 1].first, y + go[i - 1].second, i, cnt);       } else if (abs(i - way) != 2) {         if (a[x + go[i - 1].first][y + go[i - 1].second] &&             !use[x + go[i - 1].first][y + go[i - 1].second][i][cnt + 1])           dfs(x + go[i - 1].first, y + go[i - 1].second, i, cnt + 1);       }   }   signed main() {     int n = 0, m = 0;     cin >> n >> m;     int si = 0, sj = 0, fi = 0, fj = 0;     for (int i = 1; i <= n; i++) {       string st =   ;       cin >> st;       for (int j = 1; j <= m; j++)         if (st[j - 1] !=  * ) a[i][j] = 1;       for (int j = 1; j <= m; j++)         if (st[j - 1] ==  S ) {           si = i;           sj = j;         } else if (st[j - 1] ==  T ) {           fi = i;           fj = j;         }     }     go.push_back({1, 0});     go.push_back({0, 1});     go.push_back({-1, 0});     go.push_back({0, -1});     dfs(si, sj, 1, 0);     dfs(si, sj, 2, 0);     dfs(si, sj, 3, 0);     dfs(si, sj, 4, 0);     for (int way = 1; way <= 4; way++)       for (int cnt = 0; cnt <= 2; cnt++)         if (use[fi][fj][way][cnt]) {           cout <<  YES ;           return (0);         }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 50, inf = 1e9;   int n, m, be[N], f[N], cnt, sub[N], SUB[N], vfa[N], q[N * 2], l, r;   bool vis[N], tp[N];   vector<int> e[N], v[N], vv;   void cmax(int &x, int y) { y > x ? x = y : 0; }   void dfs1(int x) {     vis[x] = 1;     if (f[x]) e[x].erase(find(e[x].begin(), e[x].end(), f[x]));     for (int i = 0, y; i < e[x].size(); i++) {       if (!vis[y = e[x][i]])         f[y] = x, dfs1(y);       else if (!be[y]) {         be[y] = ++cnt;         tp[y] = 1;         v[cnt].push_back(y);         for (int z = x; z != y; z = f[z]) be[z] = cnt, v[cnt].push_back(z);       }     }     if (!be[x]) be[x] = ++cnt, tp[x] = 1, v[cnt].push_back(x);   }   void calc1(int x) {     int id = be[x], sz = v[id].size();     for (int i = 0; i < sz; i++) {       int mx0 = 0, mx1 = -inf;       int z = v[id][i];       for (int j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id) {           int val = SUB[y] + 1;           if (val > mx0)             mx1 = mx0, mx0 = val;           else if (val > mx1)             mx1 = val;         }       sub[z] = mx0;       cmax(SUB[x], mx0 + min(i, sz - i));       for (int j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id)           cmax(vfa[y], SUB[y] + 1 != mx0 ? mx0 + 1 : mx1 + 1);     }   }   void dfs2(int x) {     vis[x] = 1;     for (int i = 0, y; i < e[x].size(); i++)       if (!vis[y = e[x][i]]) dfs2(y);     if (tp[x]) calc1(x);   }   void calc2(int x) {     cmax(sub[x], vfa[x]);     vv.clear();     int id = be[x], sz = v[id].size();     for (int i = 0; i < 2; i++)       for (int j = 0; j < v[id].size(); j++) vv.push_back(v[id][j]);     l = 1;     r = 0;     for (int i = 0; i < vv.size(); i++) {       if (i - q[l] > sz / 2) l++;       if (l <= r) cmax(vfa[vv[i]], i - q[l] + sub[vv[q[l]]]);       while (l <= r && sub[vv[q[r]]] - q[r] < sub[vv[i]] - i) r--;       q[++r] = i;     }     l = 1;     r = 0;     for (int i = vv.size() - 1; ~i; i--) {       if (q[l] - i > sz / 2) l++;       if (l <= r) cmax(vfa[vv[i]], q[l] - i + sub[vv[q[l]]]);       while (l <= r && sub[vv[q[r]]] + q[r] < sub[vv[i]] + i) r--;       q[++r] = i;     }     for (int i = 0; i < v[id].size(); i++)       for (int z = v[id][i], j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id) cmax(vfa[y], vfa[z] + 1);   }   void dfs3(int x) {     vis[x] = 1;     if (tp[x]) calc2(x);     for (int i = 0, y; i < e[x].size(); i++)       if (!vis[y = e[x][i]]) dfs3(y);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, x, y; i <= m; i++)       scanf( %d%d , &x, &y), e[x].push_back(y), e[y].push_back(x);     dfs1(1);     memset(vis, 0, sizeof(vis));     dfs2(1);     memset(vis, 0, sizeof(vis));     dfs3(1);     for (int i = 1; i <= n; i++) printf( %d  , max(sub[i], vfa[i]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void out(long long arr[], long long length) {     for (int i = 0; i < length; i++) cout << arr[i] <<    ;   }   int main() {     int tt;     cin >> tt;     while (tt--) {       int x1, y1, z1, x2, y2, z2, ans;       cin >> x1 >> y1 >> z1;       cin >> x2 >> y2 >> z2;       if (y2 >= z1) {         int t1;         ans = (z1 * 2);         int d1 = (y2 - z1);         if ((d1 + x2) >= y1)           cout << ans;         else {           int d2 = y1 - (d1 + x2);           t1 = (min(d2, z2) * 2);           ans = ans - t1;           cout << ans;         }       } else if (y2 < z1) {         int t1;         ans = (y2 * 2);         int d1 = (z1 - y2);         if ((d1 + x1) >= z2)           cout << ans;         else {           int d2 = z2 - (d1 + x1);           t1 = (min(d2, z2) * 2);           ans = ans - t1;           cout << ans;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1ll;     long long _tmp = mypow(_a, _x / 2, _mod);     _tmp = (_tmp * _tmp) % _mod;     if (_x & 1) _tmp = (_tmp * _a) % _mod;     return _tmp;   }   bool equal(double _x, double _y) { return _x > _y - 1e-7 && _x < _y + 1e-7; }   int __ = 1, cs;   int n, m, deg[100010];   multiset<int> S[100010];   vector<int> odd;   void build() {}   void init() {     n = getint();     m = getint();     while (m--) {       int u, v;       u = getint();       v = getint();       S[u].insert(v);       S[v].insert(u);       deg[u]++;       deg[v]++;     }     for (int i = 1; i <= n; i++)       if (deg[i] % 2) odd.push_back(i);     if ((int)odd.size() % 2) assert(1 == 0);     for (int i = 0, j = (int)odd.size() - 1; i < j; i++, j--) {       S[odd[i]].insert(odd[j]);       S[odd[j]].insert(odd[i]);     }   }   vector<pair<int, int> > ans;   int got;   void DFS(int now) {     while (S[now].size()) {       multiset<int>::iterator it = S[now].begin();       int des = *it;       S[now].erase(S[now].find(des));       S[des].erase(S[des].find(now));       DFS(des);       got++;       if (got % 2)         ans.push_back(make_pair(des, now));       else         ans.push_back(make_pair(now, des));     }   }   void find_circle() {     for (int i = 1; i <= n; i++)       while ((int)S[i].size() > 0) {         got = 0;         DFS(i);         if (got % 2) ans.push_back(make_pair(i, i));       }   }   void solve() {     find_circle();     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);   }   int main() {     build();     while (__--) {       init();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long MOD = 1e9 + 7;   vector<int> g[N];   bool col[N];   int her[N], p[N];   set<int> s;   queue<int> q;   bool mp[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     bool bl = false;     for (int i = 0; i < (n); ++i) {       int tv;       cin >> tv;       vector<int> vc;       for (int j = 2; j * j <= tv; j++) {         if (tv % j == 0) {           int qan = 0;           while (tv % j == 0) {             tv /= j;             qan++;           }           if (qan % 2) vc.push_back(j);         }       }       if (tv != 1) vc.push_back(tv);       if (vc.size() == 0) {         cout << 1 << endl;         return 0;       }       if (vc.size() == 1) vc.push_back(1);       int z = vc[0] * vc[1];       if (mp[z]) bl = true;       mp[z] = true;       g[vc[0]].push_back(vc[1]);       g[vc[1]].push_back(vc[0]);       if (vc[0] <= 1000) s.insert(vc[0]);       if (vc[1] <= 1000) s.insert(vc[1]);     }     if (bl) {       cout << 2 << endl;       return 0;     }     int ans = INT_MAX;     for (auto tv : s) {       q.push(tv);       memset(her, 0, sizeof(her));       memset(col, 0, sizeof(col));       memset(p, 0, sizeof(p));       col[tv] = true;       her[tv] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (col[to]) {             if (to == p[v]) continue;             ans = min(ans, her[to] + her[v] + 1);             continue;           }           q.push(to);           col[to] = true;           her[to] = her[v] + 1;           p[to] = v;         }       }     }     if (ans == INT_MAX)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool maximize(T &x, const T &y) {     if (x < y)       x = y;     else       return false;     return true;   }   const int N = 5e5 + 10;   int n, q, md;   int dx[N];   int d[N][21];   int query(int x, int y) {     if (d[x][20] < y) return -1;     int ret = 0;     for (int i = 20; i >= 0; i--)       if (d[x][i] < y) {         x = d[x][i];         ret += 1 << i;       }     return ret + 1;   }   int main() {     if (fopen( exam.inp ,  r ))       freopen( exam.inp ,  r , stdin), freopen( exam.out ,  w , stdout);     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       maximize(dx[x], y);       maximize(md, y);     }     for (int i = 1; i <= md; i++) maximize(dx[i], dx[i - 1]);     for (int i = 0; i <= md; i++) d[i][0] = dx[i];     for (int j = 1; j <= 20; j++)       for (int i = 0; i <= md; i++) d[i][j] = d[d[i][j - 1]][j - 1];     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       printf( %d n , query(x, y));     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   const T& max(const T& a, const T& b, const T& c) {     return max(a, max(b, c));   }   template <class T>   const T& min(const T& a, const T& b, const T& c) {     return min(a, min(b, c));   }   long long stoi(string& str) {     istringstream second(str);     long long i;     second >> i;     return i;   }   string itos(long long i) {     stringstream second;     second << i;     return second.str();   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long poww(long long a, long long b) {     if (b == 0) return 1;     long long tmp = poww(a, b / 2);     return (b & 1 ? a * tmp * tmp : tmp * tmp);   }   long long sumOfDigs(string s) {     long long sum = 0;     for (int i = 0; i < s.length(); i++) sum += s[i] -  0 ;     return sum;   }   long long sumOfDigs(long long n) {     return (n < 10 ? n : n % 10 + sumOfDigs(n / 10));   }   long long mod = poww(10, 9) + 7;   int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   using namespace std;   void t() { freopen( test.txt ,  r , stdin); }   long long a[1000 * 100 + 1][20];   pair<long long, long long> aa[1000 * 100 + 1][20];   int main() {     string t1, t2, s, tt, second;     cin >> t1 >> t2;     s += t1;     reverse(t2.begin(), t2.end());     s += t2;     cin >> t1 >> t2;     tt += t1;     reverse(t2.begin(), t2.end());     tt += t2;     second = s;     if (second == tt) {       return cout <<  YES  << endl, 0;     }     int pos = second.find( X );     if (pos < 3) {       swap(second[pos], second[pos + 1]);       pos++;     } else {       swap(second[pos], second[0]);       pos = 0;     }     if (second == tt) {       return cout <<  YES  << endl, 0;     }     while (second != s) {       if (pos < 3) {         swap(second[pos], second[pos + 1]);         pos++;       } else {         swap(second[pos], second[0]);         pos = 0;       }       if (second == tt) {         return cout <<  YES  << endl, 0;       }     }     return cout <<  NO  << endl, 0;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, x;       cin >> n >> x;       string s;       cin >> s;       int a[100001] = {0};       int b[100001] = {0};       int f = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  0 ) {           a[i + 1] = a[i] + 1;           b[i + 1] = b[i];         } else {           a[i + 1] = a[i];           b[i + 1] = b[i] + 1;         }       }       long long ans = 0;       int c0 = 1;       for (int i = 1; i <= n; i++) {         if (a[i] - b[i] == 0) {           c0++;         }         int g = a[i] - b[i];         long double h;         h = (x - g);         h *= 1.0;         if (a[n] - b[n] == 0) {           if (g == x) ans++;           continue;         }         h /= (long double)(a[n] - b[n]);         if (h < 0) continue;         if (ceil(h) == floor(h)) {           ans++;         }       }       if (a[n] - b[n] == 0) {         for (int i = 1; i <= n; i++)           if (a[i] - b[i] == x) {             cout << -1 <<   n ;             f = 1;             break;           }       }       if (x == 0) ans++;       if (f) continue;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int v[1100][1100];   int main() {     int n, k;     cin >> n >> k;     if (n > k + k) {       cout << n * k << endl;       for (int i = 1; i <= n; i++) {         int t = k;         for (int j = 1; j <= n; j++)           if (i != j && !v[i][j] && !v[j][i] && t) {             t--;             v[i][j] = v[j][i] = 1;             printf( %d %d n , i, j);           }       }     } else       printf( -1 n );   }