malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> P;   vector<int> vis;   vector<vector<int> > C;   vector<int> lab, sz;   void getCycle() {     vis = vector<int>(N, 0);     lab = vector<int>(N, 0);     for (int i = 0; i < N; i++) {       if (vis[i]) continue;       C.push_back(vector<int>());       sz.push_back(0);       int u = i;       while (!vis[u]) {         vis[u] = 1;         lab[u] = C.size() - 1;         C.back().push_back(u);         sz.back()++;         u = P[u];       }     }   }   vector<int> tmp;   void mrg() {     printf( 1  );     for (int i = 1; i < N; i++) {       if (lab[i] != lab[0]) {         printf( %d  , i + 1);         tmp.clear();         tmp.push_back(0);         for (int j = 1; j < C[lab[i]].size(); j++) {           tmp.push_back(C[lab[i]][j]);         }         tmp.push_back(i);         for (int j = 1; j < C[lab[0]].size(); j++) {           tmp.push_back(C[lab[0]][j]);         }         C[lab[i]].clear();         for (int j = 0; j < tmp.size(); j++) {           lab[tmp[j]] = lab[0];         }         C[lab[0]] = tmp;         return;       }     }   }   void split() {     for (int i = 0; i < N; i++) {       if (sz[lab[i]] > 1) {         printf( %d  , i + 1);         int idx = 1;         for (int j = 1; j < C[lab[i]].size(); j++) {           if (C[lab[i]][idx] > C[lab[i]][j]) {             idx = j;           }         }         printf( %d  , C[lab[i]][idx] + 1);         tmp.clear();         tmp.push_back(C[lab[i]][idx]);         for (int j = 1; j < idx; j++) {           tmp.push_back(C[lab[i]][j]);         }         C.push_back(tmp);         sz.push_back(tmp.size());         for (int j = 0; j < tmp.size(); j++) lab[tmp[j]] = C.size() - 1;         tmp.clear();         for (int j = 0; j < C[lab[i]].size(); j++) {           if (lab[C[lab[i]][j]] == lab[i]) {             tmp.push_back(C[lab[i]][j]);           }         }         C[lab[i]] = tmp;         sz[lab[i]] = tmp.size();         return;       }     }   }   int main() {     scanf( %d , &N);     P.resize(N);     for (int i = 0; i < N; i++) {       scanf( %d , &P[i]);       P[i]--;     }     getCycle();     scanf( %d , &M);     M = N - M;     if (C.size() < M) {       printf( %d n , M - C.size());       for (int i = C.size(); i < M; i++) split();     } else {       printf( %d n , C.size() - M);       for (int i = C.size(); i > M; i--) mrg();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     cin >> p;     bool yon;     for (int i = 0; i < p.length(); i++) {       if (p[i] ==  H  || p[i] ==  Q  || p[i] ==  9 ) {         yon = true;         break;       } else         yon = false;     }     if (yon)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int mod = 1e6 + 3;   string mm(char c) {     if (c ==  > ) return  1000 ;     if (c ==  < ) return  1001 ;     if (c ==  + ) return  1010 ;     if (c ==  - ) return  1011 ;     if (c ==  . ) return  1100 ;     if (c ==  , ) return  1101 ;     if (c ==  [ ) return  1110 ;     if (c ==  ] ) return  1111 ;   }   long long pow2(long long a, long long b, long long c = 0) {     c = mod;     long long res = 1;     a %= c;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   int main() {     string tmp;     cin >> tmp;     string ans =   ;     for (auto &i : tmp) {       ans += mm(i);     }     int sz = ans.length();     int cnt = 0;     long long res = 0;     for (int i = sz - 1; i >= 0; i--) {       if (ans[i] ==  1 ) {         res += pow2(2, cnt);         res %= mod;       }       cnt++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using vl = vector<ll>;   using pll = pair<ll, ll>;   using vll = vector<pll>;   using MAP = map<ll, ll>;   using sl = set<ll>;   using sll = set<pll>;   using MAPs = map<ll, sl>;   using MAPv = map<ll, vl>;   const ll inf = LLONG_MAX;   const ll mod = 1e9 + 7;   const ll N = 2e5 + 5;   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   int n, a[N];   void MAIN() {     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]);     sort((v).begin(), (v).end());     int ind1 = 0, ind2 = 0, cnt = 0;     for (int i = 0; i < n; i++) {       if (a[i] != v[i]) {         cnt++;         if (!ind1)           ind1 = i;         else           ind2 = i;       }     }     if (cnt > 2) {       cout <<  NO n ;       return;     }     swap(a[ind1], a[ind2]);     for (int i = 0; i < n - 1; i++) {       if (a[i] > a[i + 1]) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t-- > 0) {       MAIN();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, d[128][128][8];   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 0; k <= 4; k++) {           if (s[i - 1] ==  . ) continue;           if (!k) {             d[i][j][k] = 1;             continue;           }           if (i >= j) d[i][j][k] |= d[i - j][j][k - 1];           if (k == 4 && d[i][j][k]) {             cout <<  yes  << endl;             return 0;           }         }     cout <<  no  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[100100];   int d[100100];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i <= n; i++) {       d[i] = 100100;     }     d[0] = 0;     for (int i = 0; i < n; i++) {       int l = 0;       int r = n - 1;       while (l < r) {         int m = (l + r + 1) / 2;         if (d[m] > a[i]) {           r = m - 1;         } else {           l = m;         }       }       d[r + 1] = a[i];     }     int ans = 0;     for (int i = 0; i <= n; i++) {       if (d[i] < 100100) {         ans = i;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int a[10000], b = 1, i, n;     for (i = 1; i < 1000; i++) {       a[b] = i;       if (a[b] >= 100) {         a[b + 2] = a[b] % 10;         a[b + 1] = a[b] / 10 - a[b] / 100 * 10;         a[b] = a[b] / 100;         b += 3;       } else if (a[b] >= 10) {         a[b + 1] = a[b] % 10;         a[b] = a[b] / 10;         b += 2;       } else         b++;     }     scanf( %d , &n);     printf( %d , a[n]);   }
#include <bits/stdc++.h>      using ll=long long;   #define MOD 1000000007      using namespace std;      void calc(double c, double m, double p, double v, double *exp, double prob, int n, int x){       if(x==1){           prob *= p;           *exp += prob*n;           return;       }       else if(x>1){           double prob1 = prob;           prob1 *= p;           *exp += prob1*n;           if(c>0){               double prob2 = prob;               prob2 *= c;               if(c-v>1e-7){                   calc(c-v, ((m==0)?(0):(m+(v/2))), ((m==0)?(p+v):(p+(v/2))), v, exp, prob2, n+1, x);               }               else{                   calc(0, ((m==0)?(0):(m+(c/2))), ((m==0)?(p+c):(p+(c/2))), v, exp, prob2, n+1, x-1);               }           }           if(m>0){               double prob3 = prob;               prob3 *= m;               if(m-v>1e-7){                   calc(((c==0)?(0):(c+(v/2))), m-v, ((c==0)?(p+v):(p+(v/2))), v, exp, prob3, n+1, x);               }               else{                   calc(((c==0)?(0):(c+(m/2))), 0, ((c==0)?(p+m):(p+(m/2))), v, exp, prob3, n+1, x-1);               }           }           return;       }       else return;   }      void solve() {       // Write your solution here       double c, m, p, v;       cin>>c>>m>>p>>v;       double exp = 0.0;       int n = 1;       int x=3;       calc(c, m, p, v, &exp, 1, 1, x);       cout<<setprecision(10)<<exp<<  n ;       return ;   }      int main() {       cin.tie(nullptr)->sync_with_stdio(false);          int t = 1;       cin >> t;  // Comment out if single test case       while (t--) {           solve();       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long sum = 0;   int main() {     scanf( %lld%lld , &n, &m);     long long max_add = (n - 1) * n / 2;     long long min_add;     if (n % 2) min_add = (n / 2 + 1) * (n / 2);     if (n % 2 == 0) {       long long a1 = (n / 2 + 1) * (n / 2) / 2;       long long a2 = (n / 2 - 1) * (n / 2) / 2;       min_add = a1 + a2;     }     for (int i = 1; i <= m; i++) {       long long x, d;       scanf( %lld%lld , &x, &d);       sum += x * n;       if (d >= 0)         sum += (long long)d * max_add;       else         sum += (long long)d * min_add;     }     double ans = sum / 1.0;     ans = ans / n;     printf( %.15lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   long long O_O[N][N];   const long long mod = 1e9 + 7;   int main() {     int o_o;     memset(O_O, 0, sizeof(O_O));     O_O[0][0] = 1;     for (int i = 1; i <= 4000; ++i) {       if (i < 4000)         o_o = i;       else         o_o = 4000;       for (int j = 1; j <= o_o; ++j) {         O_O[i][j] =             ((long long)j * O_O[i - 1][j] % mod + O_O[i - 1][j - 1]) % mod;       }     }     int n;     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans = (ans + (O_O[n][i] * i) % mod) % mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 17;   int n, m, x, y, z, inf;   int bin[N], d[N][N], du[N], f[1 << N], q[N];   int main() {     for (register int i = 1; i <= 16; ++i) bin[i] = 1 << (i - 1);     int sum = 0;     scanf( %d , &n);     scanf( %d , &m);     memset(d, 60, sizeof(d));     inf = d[0][0];     for (register int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &z);       sum += z;       du[x]++;       du[y]++;       d[x][y] = d[y][x] = min(d[x][y], z);     }     for (register int k = 1; k <= n; ++k)       for (register int i = 1; i <= n; ++i)         for (register int j = 1; j <= n; ++j)           d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     for (register int i = 2; i <= n; ++i)       if (du[i] && d[1][i] == inf) {         puts( -1 );         return 0;       }     int tot = 0;     for (register int i = 1; i <= n; ++i)       if (du[i] & 1) q[++tot] = i;     int max_statue = bin[tot + 1] - 1;     memset(f, 60, sizeof(f));     f[0] = 0;     for (register int p = 0; p < max_statue; ++p) {       for (register int i = 1; i <= tot; ++i)         if (!(bin[i] & p)) {           for (register int j = i + 1; j <= tot; ++j)             if (!(bin[j] & p))               f[p | bin[i] | bin[j]] =                   min(f[p | bin[i] | bin[j]], f[p] + d[q[i]][q[j]]);           break;         }     }     sum += f[max_statue];     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   int n, m;   long long b;   struct node {     int money, monitors, pre;     vector<int> G;   } a[202];   bool cmp(node x, node y) { return x.monitors > y.monitors; }   long long dp[2][1 << 20];   int setbit(int x, int pos) { return x | (1 << pos); }   bool checkbit(int x, int pos) { return x & (1 << pos); }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int has[25];   int main() {     int i, j, fl, test, index, mask, cnt = 0;     scanf( %d%d%lld , &n, &m, &b);     for (i = 0; i < n; i++) {       scanf( %d%d%d , &a[i].money, &a[i].monitors, &j);       while (j--) {         scanf( %d , &fl);         fl--;         a[i].pre = setbit(a[i].pre, fl);         a[i].G.push_back(fl);         if (has[fl] == 0) {           cnt++;           has[fl] = 1;         }       }     }     if (cnt < m) {       printf( -1 n );       return 0;     }     sort(a, a + n, cmp);     int tmask, touse;     for (index = n; index >= 0; index--) {       for (mask = 0; mask < (1 << m); mask++) {         touse = index % 2;         if (mask == (1 << m) - 1) {           dp[touse][mask] = 0ll;           continue;         }         if (index == n) {           dp[touse][mask] = -2;           continue;         }         int i;         long long op1, op2 = a[index].money, op3;         op1 = dp[(touse + 1) % 2][mask];         if (mask == 0) op2 += a[index].monitors * b;         tmask = mask;         tmask = tmask | a[index].pre;         op3 = dp[(touse + 1) % 2][tmask];         if (op1 == -2 && op3 == -2)           dp[touse][mask] = -2;         else if (op1 != -2 && op3 != -2)           dp[touse][mask] = min(op1, op2 + op3);         else if (op1 == -2)           dp[touse][mask] = op2 + op3;         else           dp[touse][mask] = op1;       }     }     long long ans = dp[0][0];     if (ans == -2)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) solve();   }   void solve() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     string c = a, d = b;     sort(c.begin(), c.end());     sort(d.begin(), d.end());     if (c != d) {       cout << -1 <<   n ;       return;     }     long long ans[n], mx = n;     for (long long l = 0; l < n; l++)       for (long long k = 0; k < n; k++) {         ans[l] = n;         long long i = l, j = k;         while (j != n && b[j] != a[i]) j++;         if (j != n) {           ans[l]--;           i++;           j++;         }         while (i != n && j != n) {           while (i != n && j != n && a[i] != b[j]) i++;           if (i != n) ans[l]--, j++, i++;         }         mx = min(ans[l], mx);       }     cout << mx <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 305;   int c[N], a[N], d[N];   bool cmp(int first, int second) {     if (a[first] != a[second]) return a[first] < a[second];     return first > second;   }   inline int lowbit(int first) { return first & -first; }   int query(int first) {     int res = 0;     for (int i = first; i; i -= lowbit(i)) res += c[i];     return res;   }   void modify(int first, int v) {     for (int i = first; i < N; i += lowbit(i)) c[i] += v;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, m;       scanf( %d%d , &n, &m);       for (int i = 1; i <= m; ++i) scanf( %d , &a[i]), d[i] = i, c[i] = 0;       sort(d + 1, d + m + 1, cmp);       long long res = 0;       for (int i = 1; i <= m; ++i) {         res += query(d[i]);         modify(d[i], 1);       }       printf( %lld n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<vector<pair<int, int>>> pos(n, vector<pair<int, int>>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         pos[i][j] = {i, j};       }     }     vector<vector<int>> val(n, vector<int>(m, 0));     for (int i = 0; i < q; ++i) {       int t;       cin >> t;       if (t == 1) {         int r;         cin >> r;         --r;         auto tmp = pos[r][0];         for (int i = 1; i < m; ++i) {           pos[r][i - 1] = pos[r][i];         }         pos[r][m - 1] = tmp;       } else if (t == 2) {         int c;         cin >> c;         --c;         auto tmp = pos[0][c];         for (int i = 1; i < n; ++i) {           pos[i - 1][c] = pos[i][c];         }         pos[n - 1][c] = tmp;       } else {         int r, c, x;         cin >> r >> c >> x;         --r, --c;         auto p = pos[r][c];         val[p.first][p.second] = x;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cout << val[i][j] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int gru0[] = {0, 1, 2};   int gru1[] = {0, 1, 0, 1, 2};   int grundy(int x) {     if (K) {       if (x < 5) {         return gru1[x];       } else if (x & 1) {         return 0;       } else {         return grundy(x / 2) == 1 ? 2 : 1;       }     } else {       return x <= 2 ? x : !(x & 1);     }   }   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N >> K;     K %= 2;     int ans = 0;     for (int i = 0, x; i < N; i++) {       cin >> x;       ans ^= grundy(x);     }     cout << (ans ?  Kevin  :  Nicky ) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m, n;     cin >> h >> m >> n;     int* id = new int[n];     int* hash = new int[n];     int* hsh = new int[h];     int nc = 0;     int res = 0;     char z;     int i, j, k, l;     for (i = 0; i < h; i++) {       hsh[i] = 0;     }     for (i = 0; i < n; i++) {       cin >> z;       if (z ==  + ) {         cin >> id[nc] >> hash[nc];         int chash = hash[nc];         while (hsh[chash] == 1) {           res++;           chash = (chash + m) % h;         }         hsh[chash] = 1;         hash[nc] = chash;         nc++;       } else {         int cid;         cin >> cid;         for (j = 0; j < nc; j++) {           if (id[j] == cid) {             hsh[hash[j]] = 0;             break;           }         }       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 10;   int n;   long long k;   char s[N], t[N];   int main() {     scanf( %d%lld%s%s , &n, &k, s + 1, t + 1);     long long ans = 0, tot = 1, INF = 1e15;     for (int i = 1; i <= n; ++i) {       tot <<= 1;       if (s[i] ==  b ) --tot;       if (t[i] ==  a ) --tot;       ans += min(k, tot);       tot = min(tot, INF);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[int(1e5 + 2)][2];   int a[int(1e5 + 2)];   vector<int> v[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int mod = 998244353;     int t;     cin >> t;     while (t--) {       v[0].clear();       v[1].clear();       for (int i = 0; i < int(1e5 + 2); i++) dp[i][0] = dp[i][1] = 0;       int n;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       long long ans = 0;       for (int i = n - 1; i >= 0; i--) {         int one = i % 2;         dp[a[i]][one] = 1;         v[one].push_back(a[i]);         for (auto x : v[1 - one]) {           int k = a[i] / x;           if (a[i] % x != 0) k++;           int x_ = a[i] / k;           if (dp[x_][one] == 0) v[one].push_back(x_);           dp[x_][one] += dp[x][1 - one];           ans = (ans + (i + 1) * dp[x][1 - one] * (k - 1)) % mod;           dp[x][1 - one] = 0;         }         v[1 - one].clear();       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       int q, ans = 0;       cin >> q;       if (q % 2) q -= 9, ans++;       if (q < 0)         ans = -1;       else         ans += q / 4;       if (q == 2) ans = -1;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 998244353;   long long power(long long a, long long b, long long m) {     long long res = 1;     a %= m;     while (b) {       if (b & 1LL) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     m = power(m, M - 2, M);     vector<vector<long long>> dp(k + 1, vector<long long>(k + 1, 0));     for (long long i = 0; i <= k; ++i) {       for (long long j = 0; j <= k; ++j) {         long long N = n - k + i, K = j;         if (N <= 0 || K == 0) {           dp[i][j] = 0;           continue;         }         if (K == 1) {           dp[i][j] = N * m % M;           continue;         }         if (i > 0)           dp[i][j] =               (dp[i][j - 1] - dp[i - 1][j - 1] * (1 - m + M) % M + M) % M * N % M;       }     }     cout << dp[k][k] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T min_(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T max_(T a, T b) {     return (a > b ? a : b);   }   const int MAX_N = 1e5 + 1;   vector<pair<unsigned long long, unsigned long long> > notes;   int main(int argc, char *argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(0);     int days, nnotes;     cin >> days >> nnotes;     notes.resize(nnotes);     int day, h;     int max_h = 0;     for (int i = 0; i < nnotes; ++i) {       cin >> day >> h;       max_h = max(max_h, h);       notes[i] = {day, h};     }     int new_h;     int day1, day2, h1, h2;     day1 = notes[0].first;     if (day1 != 1) {       h1 = notes[0].second;       new_h = h1 + day1 - 1;       max_h = max(max_h, new_h);     }     for (int i = 0; i < nnotes; ++i) {       day1 = notes[i].first;       h1 = notes[i].second;       if (i == nnotes - 1) {         day2 = days;         new_h = h1 + (day2 - day1);         max_h = max(max_h, new_h);         break;       }       day2 = notes[i + 1].first;       h2 = notes[i + 1].second;       int ddiff = day2 - day1;       int hdiff = abs(h2 - h1);       if (hdiff > ddiff) {         cout <<  IMPOSSIBLE n ;         return 0;       } else {         if (h1 < h2) {           day1 = day1 + hdiff;           ddiff = day2 - day1;           h1 = h2;         } else if (h1 > h2) {           day2 = day2 - hdiff;           ddiff = day2 - day1;           h2 = h1;         }         new_h = h1 + (ddiff / 2);         max_h = max(max_h, new_h);       }     }     cout << max_h <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> ans;     for (int c = 1; c < k; c++) {       int r = 0;       int C = c;       while (ans.size() < n) {         ans.emplace_back(r + 1, C + 1);         if (C == k - 1) break;         r++, C++;       }       r = k - 1;       C = k - c - 1;       while (ans.size() < n) {         ans.emplace_back(r + 1, C + 1);         if (C == 0) break;         r--, C--;       }     }     if (ans.size() != n) {       cout <<  NO  << endl;       return (0);     }     cout <<  YES  << endl;     for (auto pp : ans) cout << pp.first <<     << pp.second <<   n ;     return (0);   }