#include using namespace std; #define pb push_back const int maxN=1001; int n,m,mo; int a[maxN][maxN]; vector ans; int bestAns; int currentArray[maxN]; int visited[maxN]; void reset_data() { for (int i=1; i<=m; i++){ currentArray[i]=0; visited[i]=0; } } void read_data() { freopen("subsetselection.in","r",stdin); cin>>n>>m>>mo; for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) { scanf("%d",&a[i][j]); a[i][j]%=mo; } fclose(stdin); } void print_data() { freopen("subsetselection.out","w",stdout); printf("%d\n",ans.size()); for (int i:ans) printf("%d\n",i); fclose(stdout); } int calc_ans() { int currentAns = 0 ; for (int i=1; i<=m; i++) currentAns+=currentArray[i]*currentArray[i]; return currentAns; } void add_to_currentArray(int row) { for (int i=1; i<=m; i++) currentArray[i]=(currentArray[i]+a[row][i])%mo; } void remove_from_currentArray(int row) { for (int i=1; i<=m; i++) currentArray[i]=(currentArray[i]-a[row][i]+200*mo)%mo; } void brute_solve(int id) { int l; if (id==1) l = n; else l = 14; for (int mask = 1; mask <(1< used; for (int j=0; jbestAns) { bestAns = value; ans.clear(); for (int i:used) ans.pb(i); } } } void do_random() { int iter = 50; if (m<=200) iter = 1000; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); while(iter--) { reset_data(); vector used; for (int i=1; i<=n; i++) { int choose = uniform_int_distribution(0, 1)(rng); add_to_currentArray(i); } int value = calc_ans(); if (value>bestAns) { bestAns = value; ans.clear(); for (int i:used) ans.pb(i); } } } void tri_opt() { int c; if (m<=200) c = 150; else c = 35; for (int i=1; i<=min(n,c); i++) for (int j=i+1; j<=min(n,c); j++) for (int k=j+1; k<=min(n,c); k++) { reset_data(); add_to_currentArray(i); add_to_currentArray(j); add_to_currentArray(k); int value = calc_ans(); if (bestAns used; for (int j=0; jbestAns) { bestAns = value; ans.clear(); for (int i:used) ans.pb(i); } } } void solve3() { int c = 0; if (n<=200) c = 12; else c = 8; for (int i=1;i<=min(n,220);i+=c) brute_force(i,min(n,i+c), min(n,i+c)-i); } void last_chance() { } void solve() { if (n<=20) { brute_solve(1); } else { brute_solve(2); brute_solve(3); tri_opt(); dva_opt(); cetiri_opt(); do_random(); solve3(); last_chance(); } return ; } int main() { read_data(); solve(); print_data(); return 0; }