func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 0x7f7f7f7f;   const int maxn = 1111;   const int mod = 1000000007;   const double eps = 1e-8;   bool vis[maxn][maxn];   int n, k;   vector<pair<int, int> > ans;   bool solve() {     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = 1; j <= n; j++) {         if (vis[i][j]) continue;         if (i == j) continue;         vis[i][j] = vis[j][i] = true;         cnt++;         ans.push_back(make_pair(i, j));         if (cnt == k) break;       }       if (cnt != k) return false;     }     return true;   }   int main() {     while (cin >> n >> k) {       if (!solve())         puts( -1 );       else {         cout << ((int)ans.size()) << endl;         for (int i = 0; i < ((int)ans.size()); i++)           printf( %d %d n , ans[i].first, ans[i].second);       }     }   }   