#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector e(n), w(m), w_sum(1< v(m); vector v_sum(1<> e[i]; rep(i,0,m){ cin >> v[i] >> w[i]; } rep(i,0,1<>j&1){ v_sum[i]+=v[j]; w_sum[i]+=w[j]; } } } vector cf(n+1, vector(1< 0) { if (cf[i][k] != -1) { cf[i+1][k|j] = j; } k = (k-1) & mask; } if (cf[i][0] != -1) { cf[i+1][j] = j; } } } } int ans = -1; int ansind = -1; rep(i,0,1<= 0) { if(chmax(ans,v_sum[i])) { ansind = i; } } } vector bucket(n, vector(0)); int now = ansind; rrep(i,0,n){ int t = cf[i+1][now]; rep(j,0,m){ if(t>>j&1){ bucket[i].push_back(j+1); } } now = now^t; } cout << ans << '\n'; rep(i,0,n){ cout << (int)bucket[i].size() << ' '; rep(j,0,(int)bucket[i].size()){ cout << bucket[i][j] << ' '; } cout << '\n'; } }