#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector> solve(ll n, ll k){ ll l = n/k; vector> ans(k); if(l%2 == 0){ for(int i = 0; i < l; i++){ for(int j = 0; j < k; j++){ ll x = i*k+j; if(i%2 == 0){ ans[j].push_back(x+1); }else{ ans[k-1-j].push_back(x+1); } } } return ans; } if(l < k){ return {}; } for(int i = 0; i < k; i++){ for(int j = 0; j < k; j++){ ll x = i*k+j; ans[(i+j)%k].push_back(x+1); } } if(k != l){ auto ans1 = solve(n-k*k, k); for(int i = 0; i < k; i++){ for(int x: ans1[i]) ans[i].push_back(x+k*k); } } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll n, k; cin >> n >> k; ll m = (n*(n+1))/2; if(m%k != 0){ cout << "No" << endl; return 0; } auto ans = solve(n, k); if(ans.empty()){ cout << "No" << endl; return 0; } cout << "Yes" << endl; for(int j = 0; j < k; j++){ print_vector(ans[j]); } }