#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
#include <sstream>
#include <string.h>
#include <math.h>
#include <map>
#include <list>

using namespace std;

string s;
int charC[200]={0};
int uniqC=0;

int main(){

    cin>>s;
    int i;
    for(i=0;i< s.size();i++){
        charC[(s[i])]++;
        if(charC[(s[i])]==1)
            uniqC++;
        if(uniqC>4){
            printf("No");
            return 0;
        }
    }

    if(uniqC==2){
        for (i = 0; i<200; i++)
        {
            if(charC[i] > 0 && charC[i]<2){
                printf("No");
                return 0;
            }
        }
        printf("Yes");
        return 0;
    }
    else if(uniqC==3){

        int ctr=0;
        for (i = 0; i<200; i++)
        {
            if(charC[i] > 0 && charC[i]<2){
                ctr++;
            }
            if(ctr>2){
                printf("No");
                return 0;
            }
        }
        printf("Yes");
        return 0;

    }
    else if(uniqC==4){
        printf("Yes");
        return 0;

    }
    else{
        printf("No");
        return 0;

    }

    return 0;

}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
#include <sstream>
#include <string.h>
#include <math.h>
#include <map>
#include <list>

using namespace std;

char s[100010];
int charC[200]={0};
int uniqC=0;

int main(){

    scanf("%s",s);
    int i;
    for(i=0;i< strlen(s);i++){
        charC[(s[i])]++;
        if(charC[(s[i])]==1)
            uniqC++;
        if(uniqC>4){
            printf("No");
            return 0;
        }
    }

    if(uniqC==2){
        for (i = 0; i<200; i++)
        {
            if(charC[i] > 0 && charC[i]<2){
                printf("No");
                return 0;
            }
        }
        printf("Yes");
        return 0;
    }
    else if(uniqC==3){

        int ctr=0;
        for (i = 0; i<200; i++)
        {
            if(charC[i] > 0 && charC[i]<2){
                ctr++;
            }
            if(ctr>2){
                printf("No");
                return 0;
            }
        }
        printf("Yes");
        return 0;

    }
    else if(uniqC==4){
        printf("Yes");
        return 0;

    }
    else{
        printf("No");
        return 0;

    }

    return 0;

}


#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int fr[31],nr;
string s;
int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin>>s;
    for(int i=0;i<s.size();i++)
        fr[s[i]-'a']++;
    for(int i=0;i<=27;i++)
        for(int j=i+1;j<=27;j++)
            if(fr[i]&&fr[j]&&abs(fr[i]-fr[j])<2)
            {
                cout<<"Yes";
                return 0;
            }
    cout<<"No";
}


#include<iostream>
#include<iomanip>
using namespace std;
int fr[31],nr;
string s;
int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin>>s;
    for(int i=0;i<s.size();i++)
        fr[s[i]-'a']++;
    for(int i=0;i<=27;i++)
        if(fr[i])
            nr++;
    if(nr==1)
    {
        cout<<"No";
        return 0;
    }
    if(nr>2)
    {
        cout<<"Yes";
        return 0;
    }
    for(int i=0;i<=27;i++)
        if(fr[i]==1)
        {
            cout<<"No";
            return 0;
        }
    cout<<"Yes";
}


#pragma GCC optimize(3)
#include <bits/stdc++.h>

constexpr int N = 105;

int n, m, a[N][N];
int r[N * N], rcnt;
int c[N * N], ccnt;

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0, neg = 1;
	char ch;
	do
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

inline int chkr()
{
	for (int i = 1; i <= n; ++i)
	{
		int s = 0;
		for (int j = 1; j <= m; ++j)
			s += a[i][j];
		if (s < 0) return i;
	}
	return 0;
}

inline int chkc()
{
	for (int j = 1; j <= m; ++j)
	{
		int s = 0;
		for (int i = 1; i <= n; ++i)
			s += a[i][j];
		if (s < 0) return j;
	}
	return 0;
}

int main()
{
	n = read(), m = read();
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			a[i][j] = read();
	while (true)
	{
		int r_t = chkr();
		if (r_t != 0)
		{
			for (int j = 1; j <= m; ++j)
				a[r_t][j] = -a[r_t][j];
			r[++rcnt] = r_t;
		}
		else
		{
			int c_t = chkc();
			if (c_t != 0)
			{
				for (int i = 1; i <= n; ++i)
					a[i][c_t] = -a[i][c_t];
				c[++ccnt] = c_t;
			}
			else break;
		}
	}
	printf("%d ", rcnt);
	for (int i = 1; i <= rcnt; ++i) printf("%d ", r[i]);
	printf("\n%d ", ccnt);
	for (int i = 1; i <= ccnt; ++i) printf("%d ", c[i]);
	return 0;
}


//wtf???
#pragma GCC optimize(3)
#include <bits/stdc++.h>

constexpr int N = 105;

int n, m, a[N][N];
bool rused[N], cused[N];

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0, neg = 1;
	char ch;
	do
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

inline int chkr()
{
	for (int i = 1; i <= n; ++i)
	{
		int s = 0;
		for (int j = 1; j <= m; ++j)
			s += a[i][j];
		if (s < 0) return i;
	}
	return 0;
}

inline int chkc()
{
	for (int j = 1; j <= m; ++j)
	{
		int s = 0;
		for (int i = 1; i <= n; ++i)
			s += a[i][j];
		if (s < 0) return j;
	}
	return 0;
}

int main()
{
	n = read(), m = read();
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			a[i][j] = read();
	while (true)
	{
		int r_t = chkr();
		if (r_t != 0)
		{
			for (int j = 1; j <= m; ++j)
				a[r_t][j] = -a[r_t][j];
			rused[r_t] ^= 1;
		}
		else
		{
			int c_t = chkc();
			if (c_t != 0)
			{
				for (int i = 1; i <= n; ++i)
					a[i][c_t] = -a[i][c_t];
				cused[c_t] ^= 1;
			}
			else break;
		}
	}
	int rcnt = 0, ccnt =0 ;
	for (int i = 1; i <= 100; ++i)
	{
		if (rused[i]) ++rcnt; if (cused[i]) ++ccnt;
	}
	printf("%d ", rcnt);
	for (int i = 1; i <= 100; ++i)
		if (rused[i]) printf("%d ", i);
	printf("\n%d ", ccnt);
	for (int i = 1; i <= 100; ++i)
		if (cused[i]) printf("%d ", i);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define IN   freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 160;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const LL mod = 10007;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
int n,m;
int mp[MAXN][MAXN],r[MAXN],c[MAXN];
bool numr[MAXN],numc[MAXN];
int input()
{
    cler(numr,false),cler(numc,false);
    cler(c,0),cler(r,0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>mp[i][j];
            c[i]+=mp[i][j];
            r[j]+=mp[i][j];
        }
}
int solve()
{
    bool flag=true;
    while(flag)
    {
        flag=false;
        for(int i=1;i<=n&&!flag;i++)
        {
            if(c[i]<0)
            {
                for(int j=1;j<=m;j++)
                    r[j]-=2*mp[i][j],mp[i][j]*=-1;
                numc[i]=!numc[i];
                c[i]*=-1;
                flag=true;
            }
        }
        for(int j=1;j<=m&&!flag;j++)
        {
            if(r[j]<0)
            {
                for(int i=1;i<=n;i++)
                    c[i]-=2*mp[i][j],mp[i][j]*=-1;
                numr[j]=!numr[j];
                r[j]*=-1;
                flag=true;
            }
        }
    }
    int ans[2]={0};
    for(int i=1;i<=n;i++)
        if(numc[i]) ans[0]++;
    for(int i=1;i<=m;i++)
        if(numr[i]) ans[1]++;
    cout<<ans[0];
    for(int i=1;i<=n;i++)
        if(numc[i]) cout<<" "<<i;
    cout<<endl<<ans[1];
    for(int i=1;i<=m;i++)
        if(numr[i]) cout<<" "<<i;
}
int main()
{
    input();
    solve();
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N=105;

int n,m;
int a[N][N];
int sr[N],sc[N];
int r[N],c[N];
#define read(x) scanf("%d",&(x))

int main(){
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  read(n); read(m);
  for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) read(a[i][j]),sr[i]+=a[i][j],sc[j]+=a[i][j];
  while (1){
    int k=0;
    for (int i=1;i<=n;i++) if (sr[i]<0) { k=i; break; }
    if (k){
      sr[k]=-sr[k]; r[k]^=1;
      for (int j=1;j<=m;j++)
    sc[j]-=a[k][j]<<1,a[k][j]=-a[k][j];
      continue;
    }
    k=0;
    for (int j=1;j<=m;j++) if (sc[j]<0) { k=j; break; }
    if (k){
      sc[k]=-sc[k]; c[k]^=1;
      for (int i=1;i<=n;i++)
    sr[i]-=a[i][k]<<1,a[i][k]=-a[i][k];
      continue;
    }
    break;
  }
  int tot=0;
  for (int i=1;i<=n;i++) tot+=r[i];
  printf("%d ",tot);
  for (int i=1;i<=n;i++) if (r[i]) printf("%d ",i); printf("\n");
  tot=0;
  for (int j=1;j<=m;j++) tot+=c[j];
  printf("%d ",tot);
  for (int j=1;j<=m;j++) if (c[j]) printf("%d ",j); printf("\n");
  return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;

int a[105][105];
int n,m;

bool dfs (int i) {
    if(i==n+1) return true;
    int j,ii;bool flag=true;
    for(j=1;j<=m;j++) {
        if(a[i][j]>0) continue;
        for(ii=1;ii<=i;ii++) if(a[ii][j]==2) {flag=false;break;}
        if(!flag) break;
        a[0][j]=a[0][j]^1;
        for(ii=1;ii<=n;ii++) a[ii][j]=2-a[ii][j];
    }
    if(flag&&dfs(i+1)) return true;
    a[i][0]=1;
    for(j=1;j<=m;j++) a[i][j]=2-a[i][j];
    for(j=1;j<=m;j++) {
        if(a[i][j]>0) continue;
        for(ii=1;ii<=i;ii++) if(a[ii][j]==2) return false;
        a[0][j]=a[0][j]^1;
        for(ii=1;ii<=n;ii++) a[ii][j]=2-a[ii][j];
    }
    return dfs(i+1);
}

int main()
{
 //   freopen("aa.txt","r",stdin);
    int i,j,x,y;
    cin>>n>>m;
    for(i=1;i<=n;i++) for(j=1;j<=m;j++) {
        scanf("%d",&x);a[i][j]=x==0?1:(x>0?2:0);
    }
    dfs(1);x=y=0;
    for(i=1;i<=n;i++) if(a[i][0]==1) x++;
    for(j=1;j<=m;j++) if(a[0][j]==1) y++;
    cout<<x;for(i=1;i<=n;i++) if(a[i][0]==1) printf(" %d",i);putchar('\n');
    cout<<y;for(j=1;j<=m;j++) if(a[0][j]==1) printf(" %d",j);putchar('\n');
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

int a[105][105];
int n,m;

struct ope{
    int val,type,num;   // type 1 r, 2 c
    bool operator < (const ope & an) const {
        return val>an.val;
    }
    ope(int v=0,int t=0,int nn=0):val(v),type(t),num(nn){}
};

bool r[105],c[105];

int main()
{
    int i,j,x,y;
    cin>>n>>m;
    for(i=1;i<=n;i++) for(j=1;j<=m;j++) {
        scanf("%d",&a[i][j]);
        a[0][j]+=a[i][j];a[i][0]+=a[i][j];
    }
    priority_queue<ope> q;
    for(i=1;i<=n;i++) if(a[i][0]<0) q.push(ope(a[i][0],1,i));
    for(j=1;j<=m;j++) if(a[0][j]<0) q.push(ope(a[0][j],2,j));
    ope now;
    while(!q.empty()) {
//      cout<<"now.type:"<<now.type<<"  num:"<<now.num<<"   val:"<<now.val<<endl;
        now=q.top();q.pop();
        if(now.type==1) {
            if(a[now.num][0]!=now.val) continue;
            r[now.num]=!r[now.num];i=now.num;
            a[i][0]=-a[i][0];
            for(j=1;j<=m;j++) {
                a[0][j]-=2*a[i][j];
                a[i][j]=-a[i][j];
                if(a[0][j]<0) q.push(ope(a[0][j],2,j));
            }
        } else {
            if(a[0][now.num]!=now.val) continue;
            c[now.num]=!c[now.num];j=now.num;
            a[0][j]=-a[0][j];
            for(i=1;i<=n;i++) {
                a[i][0]-=2*a[i][j];
                a[i][j]=-a[i][j];
                if(a[i][0]<0) q.push(ope(a[i][0],1,i));
            }
        }
    }
    x=y=0;
    for(i=1;i<=n;i++) if(r[i]) x++;
    for(j=1;j<=m;j++) if(c[j]) y++;
    cout<<x;for(i=1;i<=n;i++) if(r[i]) printf(" %d",i);putchar('\n');
    cout<<y;for(j=1;j<=m;j++) if(c[j]) printf(" %d",j);putchar('\n');
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

int a[105][105];
int n,m;

struct ope{
    int val,type,num;   // type 1 r, 2 c
    bool operator < (const ope & an) const {
        return val>an.val;
    }
    ope(int v=0,int t=0,int nn=0):val(v),type(t),num(nn){}
};

bool r[105],c[105];

int main()
{
    int i,j,x,y;
    cin>>n>>m;
    for(i=1;i<=n;i++) for(j=1;j<=m;j++) {
        scanf("%d",&a[i][j]);
        a[0][j]+=a[i][j];a[i][0]+=a[i][j];
    }
    priority_queue<ope> q;
    for(i=1;i<=n;i++) if(a[i][0]<0) q.push(ope(a[i][0],1,i));
    for(j=1;j<=m;j++) if(a[0][j]<0) q.push(ope(a[0][j],2,j));
    ope now;
    while(!q.empty()) {
        now=q.top();q.pop();
        if(now.type==1) {
            if(a[now.num][0]!=now.val) continue;
            r[now.num]=!r[now.num];i=now.num;
            for(j=1;j<=m;j++) {
                a[0][j]-=2*a[i][j];
                a[i][j]=-a[i][j];
                if(a[0][j]<0) q.push(ope(a[0][j],2,j));
            }
        } else {
            if(a[0][now.num]!=now.val) continue;
            c[now.num]=!c[now.num];j=now.num;
            for(i=1;i<=n;i++) {
                a[i][0]-=2*a[i][j];
                a[i][j]=-a[i][j];
                if(a[i][0]<0) q.push(ope(a[i][0],1,i));
            }
        }
    }
    x=y=0;
    for(i=1;i<=n;i++) if(r[i]) x++;
    for(j=1;j<=m;j++) if(c[j]) y++;
    cout<<x;for(i=1;i<=n;i++) if(r[i]) printf(" %d",i);putchar('\n');
    cout<<y;for(j=1;j<=m;j++) if(c[j]) printf(" %d",j);putchar('\n');
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long ll;

int a[105][105];
int n,m;

bool dfs (int i) {
    if(i==n+1) return true;
    int j,ii;bool flag=true;
    for(j=1;j<=m;j++) {
        if(a[i][j]>0) continue;
        for(ii=1;ii<=i;ii++) if(a[ii][j]==2) {flag=false;break;}
        if(!flag) break;
        a[0][j]=a[0][j]^1;
        for(ii=1;ii<=n;ii++) a[ii][j]=2-a[ii][j];
    }
    if(flag&&dfs(i+1)) return true;
    a[i][0]=1;
    for(j=1;j<=m;j++) a[i][j]=2-a[i][j];
    for(j=1;j<=m;j++) {
        if(a[i][j]>0) continue;
        for(ii=1;ii<=i;ii++) if(a[ii][j]==2) return false;
        a[0][j]=a[0][j]^1;
        for(ii=1;ii<=n;ii++) a[ii][j]=2-a[ii][j];
    }
    return dfs(i+1);
}

int main()
{
    int i,j,x,y;
    cin>>n>>m;
    for(i=1;i<=n;i++) for(j=1;j<=m;j++) {
        scanf("%d",&x);a[i][j]=x==0?1:(x>0?2:0);
    }
    dfs(1);x=y=0;
    for(i=1;i<=n;i++) if(a[i][0]==1) x++;
    for(j=1;j<=m;j++) if(a[0][j]==1) y++;
    cout<<x;for(i=1;i<=n;i++) if(a[i][0]==1) printf(" %d",i);putchar('\n');
    cout<<y;for(j=1;j<=m;j++) if(a[0][j]==1) printf(" %d",j);putchar('\n');
}


#include<bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define acpy(y, x) memcpy(y, x, sizeof(y))
#define y1 adjf
#define ws wejgnjn
#define left fhgfj
#define tm shfhf

const int MAXN = 1e2 + 4;

int n, m;
bool used[2][MAXN];
int sum[2][MAXN];
int a[MAXN][MAXN];
int cnt[2];

set<pair<int, int> > s;

int main(){
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fi0(sum); fi0(used); fi0(cnt);
	scanf("%d%d", &n, &m);
	F(i, 0, n){
		F(j, 0, m){
			scanf("%d", &a[i][j]);
		}
	}
	F(i, 0, n){
		F(j, 0, m)sum[0][i] += a[i][j];
		s.ins(mk(sum[0][i], i << 1));
	}
	F(j, 0, m){
		F(i, 0, n)sum[1][j] += a[i][j];
		s.ins(mk(sum[1][j], 1 + (j << 1)));
	}
	while(!s.empty() && s.begin()->X < 0){
		int i = s.begin()->Y;
		s.era(s.begin());
		int ind = i&1;
		i >>= 1;
		if(ind == 0){
			F(j, 0, m){sum[1][j] -= 2 * a[i][j]; a[i][j] = -a[i][j]; s.era(mk(sum[1][j] - 2 * a[i][j], 1 + (j << 1))); s.ins(mk(sum[1][j], 1 + (j << 1)));}
			used[0][i] = !used[0][i]; cnt[0] += (used[0][i]) ? 1 : -1;
		}
		else{
			F(j, 0, n){sum[0][j] -= 2 * a[j][i]; a[j][i] = -a[j][i]; s.era(mk(sum[0][j] - 2 * a[j][i], j << 1)); s.ins(mk(sum[0][j], j << 1));}
			used[1][i] = !used[1][i]; cnt[1] += (used[1][i]) ? 1 : -1;
		}
	}
	printf("%d ", cnt[0]);
	F(i, 0, n)if(used[0][i])printf("%d ", i + 1);
	printf("\n");
	printf("%d ", cnt[1]);
	F(i, 0, m)if(used[1][i])printf("%d ", i + 1);
	ret 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define acpy(y, x) memcpy(y, x, sizeof(y))
#define y1 adjf
#define ws wejgnjn
#define left fhgfj
#define tm shfhf

const int MAXN = 1e2 + 4;

int n, m;
bool used[2][MAXN];
int sum[2][MAXN];
int a[MAXN][MAXN];
int cnt[2];

set<pair<int, int> > s;

int main(){
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fi0(sum); fi0(used); fi0(cnt);
	scanf("%d%d", &n, &m);
	F(i, 0, n){
		F(j, 0, m){
			scanf("%d", &a[i][j]);
		}
	}
	F(i, 0, n){
		F(j, 0, m)sum[0][i] += a[i][j];
		s.ins(mk(sum[0][i], i << 1));
	}
	F(j, 0, m){
		F(i, 0, n)sum[1][j] += a[i][j];
		s.ins(mk(sum[1][j], 1 + (j << 1)));
	}
	while(!s.empty() && s.begin()->X < 0){
		int i = s.begin()->Y;
		s.era(s.begin());
		int ind = i&1;
		i >>= 1;
		if(ind == 0){
			F(j, 0, m){sum[1][j] -= 2 * a[i][j]; a[i][j] = -a[i][j]; s.era(mk(sum[1][j] - 2 * a[i][j], 1 + (j << 1))); s.ins(mk(sum[1][j], 1 + (j << 1)));}
			used[0][i] = !used[0][i]; cnt[0] += (used[0][i]) ? 1 : -1;
		}
		else{
			F(j, 0, n){sum[0][j] -= 2 * a[j][i]; a[j][i] = -a[j][i]; s.era(mk(sum[0][j] - 2 * a[j][i], j << 1)); s.ins(mk(sum[0][j], j << 1));}
			used[1][i] = !used[1][i]; cnt[1] += (used[1][i]) ? 1 : -1;
		}
		sum[ind][i] = -sum[ind][i];
		s.ins(mk(sum[ind][i], ind + (i << 1)));
	}
	printf("%d ", cnt[0]);
	F(i, 0, n)if(used[0][i])printf("%d ", i + 1);
	printf("\n");
	printf("%d ", cnt[1]);
	F(i, 0, m)if(used[1][i])printf("%d ", i + 1);
	ret 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef long double ldb;
typedef unsigned long long uli;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define I(i, a) for(auto i : a)
#define pb push_back
#define rs resize
#define mk make_pair
#define asg assign
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define era erase
#define fi0(x) memset(x, 0, sizeof(x))
#define finf(x) memset(x, 127, sizeof(x))
#define acpy(y, x) memcpy(y, x, sizeof(y))
#define y1 adjf
#define ws wejgnjn
#define left fhgfj
#define tm shfhf

const int MAXN = 1e2 + 4;

int n, m;
bool used[2][MAXN];
int sum[2][MAXN];
int a[MAXN][MAXN];
int cnt[2];

set<pair<int, int> > s;

int main(){
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fi0(sum); fi0(used); fi0(cnt);
	scanf("%d%d", &n, &m);
	F(i, 0, n){
		F(j, 0, m){
			scanf("%d", &a[i][j]);
		}
	}
	F(i, 0, n){
		F(j, 0, m)sum[0][i] += a[i][j];
		s.ins(mk(sum[0][i], i << 1));
	}
	F(j, 0, m){
		F(i, 0, n)sum[1][j] += a[i][j];
		s.ins(mk(sum[1][j], 1 + (j << 1)));
	}
	while(!s.empty() && s.begin()->X < 0){
		int i = s.begin()->Y;
		s.era(s.begin());
		int ind = i&1;
		i >>= 1;
		if(ind == 0){
			F(j, 0, m){sum[1][j] -= 2 * a[i][j]; a[i][j] = -a[i][j]; if(!used[1][j]){s.era(mk(sum[1][j] - 2 * a[i][j], 1 + (j << 1))); s.ins(mk(sum[1][j], 1 + (j << 1)));}}
			used[0][i] = true; cnt[0]++;
		}
		else{
			F(j, 0, n){sum[0][j] -= 2 * a[j][i]; a[j][i] = -a[j][i]; if(!used[0][j]){s.era(mk(sum[0][j] - 2 * a[j][i], j << 1)); s.ins(mk(sum[0][j], j << 1));}}
			used[1][i] = true; cnt[1]++;
		}
	}
	printf("%d ", cnt[0]);
	F(i, 0, n)if(used[0][i])printf("%d ", i + 1);
	printf("\n");
	printf("%d ", cnt[1]);
	F(i, 0, m)if(used[1][i])printf("%d ", i + 1);
	ret 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e2 + 15;
int n, m, a[N][N];
vector <int> ans[2];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);
    for(int i = 1; i <= n; ++i) {
        int sum = 0;
        for(int j = 1; j <= m; ++j)
            sum += a[i][j];
        if(sum < 0) {
            ans[0].push_back(i);
            for(int j = 1; j <= m; ++j)
                a[i][j] = -a[i][j];
        }
    }
    for(int j = 1; j <= m; ++j) {
        int sum = 0;
        for(int i = 1; i <= n; ++i)
            sum += a[i][j];
        if(sum < 0) {
            ans[1].push_back(j);
            for(int i = 1; i <= n; ++i)
                a[i][j] = -a[i][j];
        }
    }
    for(int j = 0; j < 2; ++j, puts("")) {
        printf("%d", (int)ans[j].size());
        for(int i : ans[j])
            printf(" %d", i);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e2 + 15;
int n, m, a[N][N];
set <int> ans[2];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);
    for(int iter = 0; iter <= 100; ++iter) {
        for(int i = 1; i <= n; ++i) {
            int sum = 0;
            for(int j = 1; j <= m; ++j)
                sum += a[i][j];
            if(sum < 0) {
                if(ans[0].find(i) == ans[0].end())
                    ans[0].insert(i);
                else
                    ans[0].erase(i);
                for(int j = 1; j <= m; ++j)
                    a[i][j] = -a[i][j];
            }
        }
        for(int j = 1; j <= m; ++j) {
            int sum = 0;
            for(int i = 1; i <= n; ++i)
                sum += a[i][j];
            if(sum < 0) {
                if(ans[1].find(j) == ans[1].end())
                    ans[1].insert(j);
                else
                    ans[1].erase(j);
                for(int i = 1; i <= n; ++i)
                    a[i][j] = -a[i][j];
            }
        }
    }
    for(int j = 0; j < 2; ++j, puts("")) {
        printf("%d", (int)ans[j].size());
        for(int i : ans[j])
            printf(" %d", i);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e2 + 15;
int n, m, a[N][N];
set <int> ans[2];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);
    for(int i = 1; i <= n; ++i) {
        int sum = 0;
        for(int j = 1; j <= m; ++j)
            sum += a[i][j];
        if(sum < 0) {
            ans[0].insert(i);
            for(int j = 1; j <= m; ++j)
                a[i][j] = -a[i][j];
        }
    }
    for(int j = 1; j <= m; ++j) {
        int sum = 0;
        for(int i = 1; i <= n; ++i)
            sum += a[i][j];
        if(sum < 0) {
            ans[1].insert(j);
            for(int i = 1; i <= n; ++i)
                a[i][j] = -a[i][j];
        }
    }
    for(int i = 1; i <= n; ++i) {
        int sum = 0;
        for(int j = 1; j <= m; ++j)
            sum += a[i][j];
        if(sum < 0) {
            if(ans[0].find(i) == ans[0].end())
                ans[0].insert(i);
            else
                ans[0].erase(i);
            for(int j = 1; j <= m; ++j)
                a[i][j] = -a[i][j];
        }
    }
    for(int j = 1; j <= m; ++j) {
        int sum = 0;
        for(int i = 1; i <= n; ++i)
            sum += a[i][j];
        if(sum < 0) {
            if(ans[1].find(j) == ans[1].end())
                ans[1].insert(j);
            else
                ans[1].erase(j);
            for(int i = 1; i <= n; ++i)
                a[i][j] = -a[i][j];
        }
    }
    for(int j = 0; j < 2; ++j, puts("")) {
        printf("%d", (int)ans[j].size());
        for(int i : ans[j])
            printf(" %d", i);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int> > grid(n+1,vector<int>(m+1));
	vector<int> rowsum(n+1),colsum(m+1);
	vector<int> rowchanges(n+1),colchanges(m+1);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j){
			cin >> grid[i][j];
			rowsum[i] += grid[i][j];
			colsum[j] += grid[i][j];
		}
	bool changed = true;
	while(changed){
		changed = false;
		for(int i = 1; i <= n; ++i){
			if(rowsum[i] < 0){
				changed = true;
				rowchanges[i] ^= 1;
				rowsum[i] = -rowsum[i];
				for(int j = 1; j <= m; ++j){
					colsum[j] -= 2*grid[i][j];
					grid[i][j] = -grid[i][j];
				}
			}
		}
		for(int j = 1; j <= m; ++j){
			if(colsum[j] < 0){
				changed = true;
				colchanges[j] ^= 1;
				colsum[j] = -colsum[j];
				for(int i = 1; i <= n; ++i){
					rowsum[i] -= 2*grid[i][j];
					grid[i][j] = -grid[i][j];
				}
			}
		}
	}
	vector<int> changedrows,changedcols;
	for(int i = 1; i <= n; ++i)
		if(rowchanges[i])
			changedrows.push_back(i);
	for(int i = 1; i <= m; ++i)
		if(colchanges[i])
			changedcols.push_back(i);
	cout << changedrows.size();
	for(int i = 0; i < changedrows.size(); ++i)
		cout << ' ' << changedrows[i];
	cout << '\n';
	cout << changedcols.size();
	for(int i = 0; i < changedcols.size(); ++i)
		cout << ' ' << changedcols[i];
	cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int> > grid(n+1,vector<int>(m+1));
	vector<int> rowsum(n+1),colsum(m+1);
	vector<int> rowchanges(n+1),colchanges(m+1);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j){
			cin >> grid[i][j];
			rowsum[i] += grid[i][j];
			colsum[i] += grid[i][j];
		}
	bool changed = true;
	while(changed){
		changed = false;
		for(int i = 1; i <= n; ++i){
			if(rowsum[i] < 0){
				changed = true;
				rowchanges[i] ^= 1;
				rowsum[i] = -rowsum[i];
				for(int j = 1; j <= m; ++j){
					colsum[j] -= 2*grid[i][j];
					grid[i][j] = -grid[i][j];
				}
			}
		}
		for(int j = 1; j <= m; ++j){
			if(colsum[j] < 0){
				changed = true;
				colchanges[j] ^= 1;
				colsum[j] = -colsum[j];
				for(int i = 1; i <= n; ++i){
					rowsum[i] -= 2*grid[i][j];
					grid[i][j] = -grid[i][j];
				}
			}
		}
	}
	vector<int> changedrows,changedcols;
	for(int i = 1; i <= n; ++i)
		if(rowchanges[i])
			changedrows.push_back(i);
	for(int i = 1; i <= m; ++i)
		if(colchanges[i])
			changedcols.push_back(i);
	cout << changedrows.size();
	for(int i = 0; i < changedrows.size(); ++i)
		cout << ' ' << changedrows[i];
	cout << '\n';
	cout << changedcols.size();
	for(int i = 0; i < changedcols.size(); ++i)
		cout << ' ' << changedcols[i];
	cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f1(i, a, b) for (int i = a; i <= b; i ++)

#define N 105

int n, m, a[N][N], r[N], c[N], gr[N], gc[N];
vector <int> v;

void go(int x) {
    if (x > n) {
        x -= n;
        c[x] = -c[x]; gc[x] ++;
        f1(i, 1, n) r[i] -= 2 * a[i][x], a[i][x] = -a[i][x];
    }
    else {
        r[x] = -r[x]; gr[x] ++;
        f1(i, 1, m) c[i] -= 2 * a[x][i], a[x][i] = -a[x][i];
    }
    return;
}

int main() {
    scanf("%d %d", &n, &m);
    f1(i, 1, n) f1(j, 1, m) {
		scanf("%d", &a[i][j]);
		r[i] += a[i][j], c[j] += a[i][j];
    }
    while (1) {
        int mn = 0, id;
        f1(i, 1, n) if (mn > r[i]) mn = r[i], id = i;
		f1(i, 1, m) if (mn > c[i]) mn = c[i], id = i + n;
        if (!mn) break;
        go(id);
    }
    f1(i, 1, n) if (gr[i] & 1) v.pb(i);
    printf("%d ", v.size());
    for (auto x : v) printf("%d ", x); puts("");
    v.clear();
    f1(i, 1, m) if (gc[i] & 1) v.pb(i);
    printf("%d ", v.size());
    for (auto x : v) printf("%d ", x); puts("");
	return 0;
}


#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#else
#define rall(x,a) for(auto x : a)
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
using namespace std;

const int N = 111;
int a[N][N], mat[N << 1][N << 1];
map<int, bool> ans, anss;
int col[N];
int n, m;

void bfs(int u) {
    queue<int> q;
    q.push(u);
    while(q.size()) {
        int u = q.front();
        q.pop();
        int s = 0;
        rep(v, 1, n + m) {
            s += mat[u][v];
        }
        if(s < 0) {
            if(u <= n) {
                ans[u] = !ans[u];
                if(!ans[u]) ans.erase(u);
            } else {
                anss[u - n] = !anss[u - n];
                if(!anss[u - n]) anss.erase(u - n);
            }
            rep(v, 1, n + m) {
                mat[u][v] *= -1;
                mat[v][u] *= -1;
            }
            rep(v, 1, n + m) {
                if(mat[u][v]) {
                    q.push(v);
                }
            }
        }
    }
    /*col[u] = true;
    col[u] = false;*/
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, 1, n) {
        rep(j, 1, m) {
            cin >> a[i][j];
            mat[i][n + j] = a[i][j];
            mat[n + j][i] = a[i][j];
        }
    }
    rep(i, 1, n + m) {
        bfs(i);
    }
    cout << sz(ans) << " ";
    rall(x, ans) {
        cout << x.first << " ";
    }
    cout << endl;
    cout << sz(anss) << " ";
    rall(x, anss) {
        cout << x.first << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#else
#define rall(x,a) for(auto x : a)
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
using namespace std;

const int N = 111;
int a[N][N], mat[N << 1][N << 1];
set<int> ans, anss;
bool col[N << 1];
int n, m;

void dfs(int u) {
    if(col[u]) return;
    col[u] = true;
    int s = 0;
    rep(v, 1, n + m) {
        s += mat[u][v];
    }
    if(s < 0) {
        if(u <= n) {
            ans.insert(u);
        } else {
            anss.insert(u - n);
        }
        rep(v, 1, n + m) {
            mat[u][v] *= -1;
            mat[v][u] *= -1;
        }
        rep(v, 1, n + m) {
            if(mat[u][v]) {
                dfs(v);
            }
        }
    }
    col[u] = false;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, 1, n) {
        rep(j, 1, m) {
            cin >> a[i][j];
            mat[i][n + j] = a[i][j];
            mat[n + j][i] = a[i][j];
        }
    }
    rep(i, 1, n + m) {
        dfs(i);
    }
    cout << sz(ans) << " ";
    rall(x, ans) {
        cout << x << " ";
    }
    cout << endl;
    cout << sz(anss) << " ";
    rall(x, anss) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}


//lxrtxdy!
//62ms  0KB
#include <cstdio>
#include <cctype>
#define gc() getchar()
typedef long long LL;
const int N=105;

int A[N][N];
bool x[N],y[N];

inline int read()
{
    int now=0,f=1;register char c=gc();
    for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
    for(;isdigit(c);now=now*10+c-48,c=gc());
    return now*f;
}
void Print(bool *a,int n)
{
    int t=0;
    for(int i=1; i<=n; ++i) t+=a[i];
    printf("%d ",t);
    for(int i=1; i<=n; ++i) a[i]&&printf("%d ",i);
    putchar('\n');
}

int main()
{
    const int n=read(),m=read();
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=m; ++j) A[i][j]=read();
    for(; ; )
    {
        bool ok=1;
        for(int i=1; i<=n; ++i)
        {
            int s=0;
            for(int j=1; j<=m; ++j) s+=x[i]^y[j]?-A[i][j]:A[i][j];
            if(s<0) x[i]^=1, ok=0;
        }
        for(int j=1; j<=m; ++j)
        {
            int s=0;
            for(int i=1; i<=n; ++i) s+=x[i]^y[j]?-A[i][j]:A[i][j];
            if(s<0) y[j]^=1, ok=0;
        }
        if(ok) break;
    }
    Print(x,n), Print(y,m);

    return 0;
}
//orzlxr!//hello


#include <bits/stdc++.h>

#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ld EPSLD = 1e-18;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }

struct st{
  int x, y, id, t;
  st(){}
  st( int x , int y , int id , int t ) : x(x) , y(y) , id(id) , t(t) {}
};

bool cmpx( const st &a , const st &b ){
  return a.x < b.x;
}

bool cmpy( const st &a , const st &b ){
  return a.y < b.y;
}

struct rt{
  st a, b;
  int d;
  rt(){}
  rt( st a , st b , int d ) : a(a) , b(b) , d(d) {}
};

const int MAX_N = 100010;

int n;

st v[MAX_N*4];

inline int sq( int a ){ return a*a; }

rt closest_pair( st *a , int s ){
  if( s <= 1 ) return rt( st() , st() , INF );
  int t = s / 2;
  int x = a[t].x;
  rt resa = closest_pair( a , t );
  rt resb = closest_pair( a+t , s-t );
  rt res = resa.d < resb.d ? resa : resb;
  inplace_merge( a , a+t , a+s , cmpy );

  vector<st> b;
  REP( i , s ){
    if( sq( a[i].x - x ) >= res.d ) continue;

    REP( j , SZ(b) ){
      st &bj = b[SZ(b)-1-j];
      int dx = a[i].x - bj.x;
      int dy = a[i].y - bj.y;
      if( dy * dy >= res.d ) break;
      if( a[i].id != bj.id && dx * dx + dy * dy < res.d ) res = rt( a[i] , bj , dx * dx + dy * dy );
    }

    b.pb( a[i] );
  }

  return res;
}

int main(){

  FILE *fp = fopen( "input.txt" , "r" );

  fscanf( fp , "%d" , &n );
  REP( i , n ){
    int x, y;
    fscanf( fp , "%d %d" , &x , &y );
    v[i*4+0] = st(  x ,  y , i , 1 );
    v[i*4+1] = st( -x ,  y , i , 2 );
    v[i*4+2] = st(  x , -y , i , 3 );
    v[i*4+3] = st( -x , -y , i , 4 );
  }

  sort( v , v + 4*n , cmpx );

  rt res = closest_pair( v , 4*n );

  if( res.b.t == 1 ) res.b.t = 4;
  else if( res.b.t == 2 ) res.b.t = 3;
  else if( res.b.t == 3 ) res.b.t = 2;
  else if( res.b.t == 4 ) res.b.t = 1;

  FILE *ofp = fopen( "output.txt" , "w" );

  fprintf( ofp , "%d %d %d %d\n" , res.a.id+1 , res.a.t , res.b.id+1 , res.b.t );

  return 0;
}


#include <bits/stdc++.h>

#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ld EPSLD = 1e-18;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }

const int MAX_N = 128;

int n, m;
int a[MAX_N][MAX_N];

int r[MAX_N], c[MAX_N];

int rf[MAX_N], cf[MAX_N];

vi ansr, ansc;

int main(){

  scanf( "%d %d" , &n , &m );
  REP( i , n ) REP( j , m ) scanf( "%d" , &a[i][j] );

  REP( i , n ) REP( j , m ) r[i] += a[i][j], c[j] += a[i][j];

  while( 1 ){
    int row_or_col = -1;
    int ind = -1;
    int val = 0;

    REP( i , n ) if( r[i] < val ) row_or_col = 0, ind = i, val = r[i];
    REP( j , m ) if( c[j] < val ) row_or_col = 1, ind = j, val = c[j];

    if( val == 0 ) break;

    if( row_or_col == 0 ){
      rf[ind] ^= 1;
      REP( j , m ){
	int del = -( a[ind][j] + a[ind][j] );
	r[ind] += del;
	c[j] += del;
	a[ind][j] += del;
      }
    } else if( row_or_col == 1 ){
      cf[ind] ^= 1;
      REP( i , n ){
	int del = -( a[i][ind] + a[i][ind] );
	c[ind] += del;
	r[i] += del;
	a[i][ind] += del;
      }
    }
  }

  REP( i , n ) if( rf[i] == 1 ) ansr.pb( i );
  REP( j , m ) if( cf[j] == 1 ) ansc.pb( j );

  printf( "%lld" , SZ(ansr) );
  YYS( w , ansr ) printf( " %d" , w+1 );
  printf( "\n" );

  printf( "%lld" , SZ(ansc) );
  YYS( w , ansc ) printf( " %d" , w+1 );
  printf( "\n" );

  return 0;
}


#include<iostream>
using namespace std;
int n,m;
int a[105][105],tot1,tot2;
int s_x[105],s_y[105],used_x[105],used_y[105];
void solve1(int x)
{
    for(int j=1;j<=m;j++)
        a[x][j]*=-1;
    for(int j=1;j<=m;j++)
        s_y[j]+=a[x][j]*2;
    s_x[x]*=-1;
}
void solve2(int y)
{
    for(int i=1;i<=n;i++)
        a[i][y]*=-1;
    for(int i=1;i<=n;i++)
        s_x[i]+=a[i][y]*2;
    s_y[y]*=-1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            s_x[i]=s_x[i]+a[i][j];
            s_y[j]=s_y[j]+a[i][j];
        }
    }
    while(1)
    {
        bool f=1;
        for(int i=1;i<=n;i++)
        {
            if(s_x[i]<0)
            {
                f=0;
                used_x[i]^=1;
                solve1(i);
            }
        }
        for(int i=1;i<=m;i++)
        {
            if(s_y[i]<0)
            {
                f=0;
                used_y[i]^=1;
                solve2(i);
            }
        }
        if(f)
            break;
    }
    for(int i=1;i<=n;i++)
        if(used_x[i])
            tot1++;
    for(int i=1;i<=m;i++)
        if(used_y[i])
            tot2++;
    cout<<tot1<<' ';
    for(int i=1;i<=n;i++)
        if(used_x[i])
            cout<<i<<' ';
    cout<<endl<<tot2<<' ';
    for(int i=1;i<=m;i++)
        if(used_y[i])
            cout<<i<<' ';
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

#define PB push_back
#define MP make_pair
#define L first
#define R second

const int maxn = 100 + 85 - 69;
int row_sum[maxn];
int col_sum[maxn];
set<pii> s;
int n, m;
int a[maxn][maxn];
vector<int> act_col, act_row;

void fix_row(int r){
	s.erase(MP(row_sum[r], r));
	row_sum[r] *= -1;
	for(int j = 0; j < m; j++){
		s.erase(MP(col_sum[j], n + j));
		col_sum[j] -= 2 * a[r][j];
		s.insert(MP(col_sum[j], n + j));
		a[r][j] *= -1;
	}
	s.insert(MP(row_sum[r], r));
	return;
}

void fix_col(int c){
	s.erase(MP(col_sum[c], n + c));
	col_sum[c] *= -1;
	for(int i = 0; i < n; i++){
		s.erase(MP(row_sum[i], i));
		row_sum[i] -= 2 * a[i][c];
		s.insert(MP(row_sum[i], i));
		a[i][c] *= -1;
	}
	s.insert(MP(col_sum[c], n + c));
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
			row_sum[i] += a[i][j];
			col_sum[j] += a[i][j];
		}
	for(int i = 0; i < n; i++)
		s.insert(MP(row_sum[i], i));
	for(int j = 0; j < m; j++)
		s.insert(MP(col_sum[j], n + j));
	while((s.begin()->L) < 0){
		int x = s.begin() -> R;
		if(x >= n){
			fix_col(x - n);
			act_col.PB(x - n);
		}
		else{
			fix_row(x);
			act_row.PB(x);
		}
	}
	sort(act_row.begin(), act_row.end());
	sort(act_col.begin(), act_col.end());
	for(int i = (int)act_row.size() - 2; i >= 0; i--)
		if(act_row[i] == act_row[i + 1])
			act_row.erase(act_row.begin() + i, act_row.begin() + i + 2);
	for(int i = (int)act_col.size() - 2; i >= 0; i--)
		if(act_col[i] == act_col[i + 1])
			act_col.erase(act_col.begin() + i, act_col.begin() + i + 2);
	cout << act_row.size() << ' ';
	for(auto x : act_row)
		cout << x + 1 << ' ';
	cout << endl;
	cout << act_col.size() << ' ';
	for(auto x : act_col)
		cout << x + 1 << ' ';
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

#define PB push_back
#define MP make_pair
#define L first
#define R second

const int maxn = 100 + 85 - 69;
int row_sum[maxn];
int col_sum[maxn];
set<pii> s;
int n, m;
int a[maxn][maxn];
vector<int> act_col, act_row;

void fix_row(int r){
	s.erase(MP(row_sum[r], r));
	row_sum[r] *= -1;
	for(int j = 0; j < m; j++){
		s.erase(MP(col_sum[j], n + j));
		col_sum[j] -= 2 * a[r][j];
		s.insert(MP(col_sum[j], n + j));
		a[r][j] *= -1;
	}
	s.insert(MP(row_sum[r], r));
	return;
}

void fix_col(int c){
	s.erase(MP(col_sum[c], n + c));
	col_sum[c] *= -1;
	for(int i = 0; i < n; i++){
		s.erase(MP(row_sum[i], i));
		row_sum[i] -= 2 * a[i][c];
		s.insert(MP(row_sum[i], i));
		a[i][c] *= -1;
	}
	s.insert(MP(col_sum[c], n + c));
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
			row_sum[i] += a[i][j];
			col_sum[j] += a[i][j];
		}
	for(int i = 0; i < n; i++)
		s.insert(MP(row_sum[i], i));
	for(int j = 0; j < m; j++)
		s.insert(MP(col_sum[j], n + j));
	while((s.begin()->L) < 0){
		int x = s.begin() -> R;
		if(x >= n){
			fix_col(x - n);
			act_col.PB(x - n);
		}
		else{
			fix_row(x);
			act_row.PB(x);
		}
	}
	cout << act_row.size() << ' ';
	for(auto x : act_row)
		cout << x + 1 << ' ';
	cout << endl;
	cout << act_col.size() << ' ';
	for(auto x : act_col)
		cout << x + 1 << ' ';
	cout << endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 105;
int a[N][N];
int sum1[N],sum2[N];
vector <int> A1,A2;
int n,m;
inline int check1(){
	for(int i = 1;i <= n;++i) if(sum1[i] < 0) return i;
	return 0;
}
inline int check2(){
	for(int i = 1;i <= m;++i) if(sum2[i] < 0) return i;
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			scanf("%d",&a[i][j]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j) sum1[i] += a[i][j];
	for(int j = 1;j <= m;++j)
		for(int i = 1;i <= n;++i) sum2[j] += a[i][j];
	int l = check1(),r = check2();
	while(l != 0 || r != 0){
	//	printf("%d %d\n",l,r);
		if(l != 0){
			A1.push_back(l);
			for(int i = 1;i <= m;++i){
				sum2[i] -= a[l][i];
				sum1[l] -= a[l][i],a[l][i] = -a[l][i],sum1[l] += a[l][i];
				sum2[i] += a[l][i];
			}
		}
		if(r != 0){
			A2.push_back(r);
			for(int i = 1;i <= n;++i){
				sum1[i] -= a[i][r];
				sum2[r] -= a[i][r],a[i][r] = -a[i][r],sum2[r] += a[i][r];
				sum1[i] += a[i][r];
			}
		}
		l = check1(),r = check2();
	}
	printf("%d ",A1.size());
	for(int i = 0;i < (int)A1.size();++i) printf("%d ",A1[i]);
	printf("\n");
	printf("%d ",A2.size());
	for(int i = 0;i < (int)A2.size();++i) printf("%d ",A2[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 105;
int a[N][N];
int sum1[N],sum2[N];
bool flag1[N],flag2[N];
vector <int> A1,A2;
int n,m;
inline int check1(){
	for(int i = 1;i <= n;++i) if(sum1[i] < 0 && flag1[i] == 0) return i;
	return 0;
}
inline int check2(){
	for(int i = 1;i <= m;++i) if(sum2[i] < 0 && flag2[i] == 0) return i;
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			scanf("%d",&a[i][j]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j) sum1[i] += a[i][j];
	for(int j = 1;j <= m;++j)
		for(int i = 1;i <= n;++i) sum2[j] += a[i][j];
	int l = check1(),r = check2();
	while(l != 0 || r != 0){
		if(l != 0){
			A1.push_back(l);flag1[l] = 1;
			for(int i = 1;i <= m;++i){
				sum2[i] -= a[l][i];
				sum1[l] -= a[l][i],a[l][i] = -a[l][i],sum1[l] += a[l][i];
				sum2[i] += a[l][i];
			}
		}
		else if(r != 0){
			A2.push_back(r);flag2[r] = 1;
			for(int i = 1;i <= n;++i){
				sum1[i] -= a[i][r];
				sum2[r] -= a[i][r],a[i][r] = -a[i][r],sum2[r] += a[i][r];
				sum1[i] += a[i][r];
			}
		}
		l = check1(),r = check2();
	}
	printf("%d ",A1.size());
	for(int i = 0;i < (int)A1.size();++i) printf("%d ",A1[i]);
	printf("\n");
	printf("%d ",A2.size());
	for(int i = 0;i < (int)A2.size();++i) printf("%d ",A2[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 105;
int a[N][N];
int sum1[N],sum2[N];
int flag1[N],flag2[N];
vector <int> A1,A2;
int n,m;
inline int check1(){
	int now = 0,l = 0;
	for(int i = 1;i <= n;++i)
		if(sum1[i] < 0 && now > sum1[i]) now = sum1[i],l = i;
	return l;
}
inline int check2(){
	int now = 0,r = 0;
	for(int i = 1;i <= m;++i)
		if(sum2[i] < 0 && now > sum2[i]) now = sum2[i],r = i;
	return r;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			scanf("%d",&a[i][j]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j) sum1[i] += a[i][j];
	for(int j = 1;j <= m;++j)
		for(int i = 1;i <= n;++i) sum2[j] += a[i][j];
	int l = check1(),r = check2();
	while(l != 0 || r != 0){
		if(l != 0){
			A1.push_back(l);flag1[l]++;
			for(int i = 1;i <= m;++i){
				sum2[i] -= a[l][i];
				sum1[l] -= a[l][i],a[l][i] = -a[l][i],sum1[l] += a[l][i];
				sum2[i] += a[l][i];
			}
		}
		else if(r != 0){
			A2.push_back(r);flag2[r]++;
			for(int i = 1;i <= n;++i){
				sum1[i] -= a[i][r];
				sum2[r] -= a[i][r],a[i][r] = -a[i][r],sum2[r] += a[i][r];
				sum1[i] += a[i][r];
			}
		}
		l = check1(),r = check2();
	}
	for(int i = 0;i < (int)A1.size();++i) if(flag1[A1[i]] & 1) l++;
	for(int i = 0;i < (int)A2.size();++i) if(flag2[A2[i]] & 1) r++;
 	printf("%d ",l);
	for(int i = 0;i < (int)A1.size();++i) if(flag1[A1[i]] & 1)printf("%d ",A1[i]);
	printf("\n");
	printf("%d ",r);
	for(int i = 0;i < (int)A2.size();++i) if(flag2[A2[i]] & 1)printf("%d ",A2[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 105;
int a[N][N];
int sum1[N],sum2[N];
vector <int> A1,A2;
int n,m;
inline int check1(){
	for(int i = 1;i <= n;++i) if(sum1[i] < 0) return i;
	return 0;
}
inline int check2(){
	for(int i = 1;i <= m;++i) if(sum2[i] < 0) return i;
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			scanf("%d",&a[i][j]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j) sum1[i] += a[i][j];
	for(int j = 1;j <= m;++j)
		for(int i = 1;i <= n;++i) sum2[j] += a[i][j];
	int l = check1(),r = check2();
	while(l != 0 || r != 0){
	//	printf("%d %d\n",l,r);
		if(l != 0){
			A1.push_back(l);
			for(int i = 1;i <= m;++i){
				sum2[i] -= a[l][i];
				sum1[l] -= a[l][i],a[l][i] = -a[l][i],sum1[l] += a[l][i];
				sum2[i] += a[l][i];
			}
		}
		else if(r != 0){
			A2.push_back(r);
			for(int i = 1;i <= n;++i){
				sum1[i] -= a[i][r];
				sum2[r] -= a[i][r],a[i][r] = -a[i][r],sum2[r] += a[i][r];
				sum1[i] += a[i][r];
			}
		}
		l = check1(),r = check2();
	}
	printf("%d ",A1.size());
	for(int i = 0;i < (int)A1.size();++i) printf("%d ",A1[i]);
	printf("\n");
	printf("%d ",A2.size());
	for(int i = 0;i < (int)A2.size();++i) printf("%d ",A2[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 105;
int a[N][N];
int sum1[N],sum2[N];
int flag1[N],flag2[N];
vector <int> A1,A2,A3,A4;
int n,m;
inline int check1(){
	int now = 0,l = 0;
	for(int i = 1;i <= n;++i)
		if(sum1[i] < 0 && now > sum1[i]) now = sum1[i],l = i;
	return l;
}
inline int check2(){
	int now = 0,r = 0;
	for(int i = 1;i <= m;++i)
		if(sum2[i] < 0 && now > sum2[i]) now = sum2[i],r = i;
	return r;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j)
			scanf("%d",&a[i][j]);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j) sum1[i] += a[i][j];
	for(int j = 1;j <= m;++j)
		for(int i = 1;i <= n;++i) sum2[j] += a[i][j];
	int l = check1(),r = check2();
	while(l != 0 || r != 0){
		if(l != 0){
			A1.push_back(l);flag1[l]++;
			for(int i = 1;i <= m;++i){
				sum2[i] -= a[l][i];
				sum1[l] -= a[l][i],a[l][i] = -a[l][i],sum1[l] += a[l][i];
				sum2[i] += a[l][i];
			}
		}
		else if(r != 0){
			A2.push_back(r);flag2[r]++;
			for(int i = 1;i <= n;++i){
				sum1[i] -= a[i][r];
				sum2[r] -= a[i][r],a[i][r] = -a[i][r],sum2[r] += a[i][r];
				sum1[i] += a[i][r];
			}
		}
		l = check1(),r = check2();
	}
	for(int i = 0;i < (int)A1.size();++i)
		if(flag1[A1[i]] & 1) A3.push_back(A1[i]),flag1[A1[i]]--;
	for(int i = 0;i < (int)A2.size();++i)
		if(flag2[A2[i]] & 1) A4.push_back(A2[i]),flag2[A2[i]]--;
 	printf("%d ",A3.size());
	for(int i = 0;i < (int)A3.size();++i) printf("%d ",A3[i]);
	printf("\n");
	printf("%d ",A4.size());
	for(int i = 0;i < (int)A4.size();++i) printf("%d ",A4[i]);
	return 0;
}


//lxrtxdy!
//62ms  0KB
#include <cstdio>
#include <cctype>
#define gc() getchar()
typedef long long LL;
const int N=105;

int A[N][N];
bool x[N],y[N];

inline int read()
{
    int now=0,f=1;register char c=gc();
    for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
    for(;isdigit(c);now=now*10+c-48,c=gc());
    return now*f;
}
void Print(bool *a,int n)
{
    int t=0;
    for(int i=1; i<=n; ++i) t+=a[i];
    printf("%d ",t);
    for(int i=1; i<=n; ++i) a[i]&&printf("%d ",i);
    putchar('\n');
}

int main()
{
    const int n=read(),m=read();
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=m; ++j) A[i][j]=read();
    for(; ; )
    {
        bool ok=1;
        for(int i=1; i<=n; ++i)
        {
            int s=0;
            for(int j=1; j<=m; ++j) s+=x[i]^y[j]?-A[i][j]:A[i][j];
            if(s<0) x[i]^=1, ok=0;
        }
        for(int j=1; j<=m; ++j)
        {
            int s=0;
            for(int i=1; i<=n; ++i) s+=x[i]^y[j]?-A[i][j]:A[i][j];
            if(s<0) y[j]^=1, ok=0;
        }
        if(ok) break;
    }
    Print(x,n), Print(y,m);

    return 0;
}
//orzlxr!//hello//hello


#include<cstdio>
using namespace std;
const int N=110;
int a[N][N];
int sum1[N],sum2[N],op1[N],op2[N];
bool vis1[N],vis2[N];
int n,m,ans1,ans2;
int judge(){
	for (int i=1;i<=n;i++) if (sum1[i]<0) return i;
	for (int j=1;j<=m;j++) if (sum2[j]<0) return -1*j;
	return 0;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) scanf("%d",&a[i][j]),sum1[i]+=a[i][j],sum2[j]+=a[i][j];
	int f=judge();
	while (f){
		if (f>0){
		    sum1[f]*=-1,vis1[f]^=1;
		    for (int j=1;j<=m;j++) sum2[j]-=a[f][j]<<1,a[f][j]*=-1;
		}
		else{
			f*=-1,sum2[f]*=-1,vis2[f]^=1;
		    for (int i=1;i<=n;i++) sum1[i]-=a[i][f]<<1,a[i][f]*=-1;
		}
		f=judge();
	}
	for (int i=1;i<=n;i++) if (vis1[i]) op1[++ans1]=i;
	for (int i=1;i<=m;i++) if (vis2[i]) op2[++ans2]=i;
	printf("%d ",ans1);
	for (int i=1;i<=ans1;i++) printf("%d ",op1[i]);
	printf("\n%d ",ans2);
	for (int j=1;j<=ans2;j++) printf("%d ",op2[j]);
	return 0;
}


#include<cstdio>
using namespace std;
const int N=110;
int a[N][N];
int sum1[N],sum2[N],op1[N],op2[N];
int n,m,ans1,ans2;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) scanf("%d",&a[i][j]),sum1[i]+=a[i][j],sum2[j]+=a[i][j];
	for (int i=1;i<=n;i++){
		if (sum1[i]>=0) continue;
		sum1[i]=-1*sum1[i];
		op1[++ans1]=i;
		for (int j=1;j<=m;j++) sum2[j]-=2*a[i][j],a[i][j]=-1*a[i][j];
	}
	for (int j=1;j<=m;j++){
		if (sum2[j]>=0) continue;
		sum2[j]=-1*sum2[j];
		op2[++ans2]=j;
		for (int i=1;i<=n;i++) sum1[i]-=2*a[i][j],a[i][j]=-1*a[i][j];
	}
	printf("%d ",ans1);
	for (int i=1;i<=ans1;i++) printf("%d ",op1[i]);
	printf("\n%d ",ans2);
	for (int j=1;j<=ans2;j++) printf("%d ",op2[j]);
	return 0;
}


#include<cstdio>
using namespace std;
const int N=110;
int a[N][N];
int sum1[N],sum2[N],op1[N],op2[N];
int n,m,ans1,ans2;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) scanf("%d",&a[i][j]),sum1[i]+=a[i][j],sum2[j]+=a[i][j];
	for (int i=1;i<=n;i++){
		if (sum1[i]>0) continue;
		sum1[i]=-1*sum1[i];
		op1[++ans1]=i;
		for (int j=1;j<=m;j++) sum2[j]-=2*a[i][j],a[i][j]=-1*a[i][j];
	}
	for (int j=1;j<=m;j++){
		if (sum2[j]>0) continue;
		sum2[j]=-1*sum2[j];
		op2[++ans2]=j;
		for (int i=1;i<=n;i++) sum1[i]-=2*a[i][j],a[i][j]=-1*a[i][j];
	}
	printf("%d ",ans1);
	for (int i=1;i<=ans1;i++) printf("%d ",op1[i]);
	printf("\n%d ",ans2);
	for (int j=1;j<=ans2;j++) printf("%d ",op2[j]);
	return 0;
}


#include<cstdio>
#include<string.h>
#include<iostream>
using namespace std;

int number[105][105];
int sum[105][2];
int does[105][2];

int main()
{
    int n,m,s1,s2;
    while (~scanf("%d%d",&n,&m))
    {
        memset(number,0,sizeof(number));
        memset(sum,0,sizeof(sum));
        memset(does,0,sizeof(does));
        s1 = s2 = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                scanf("%d",&number[i][j]);
                sum[i][0] += number[i][j];
                sum[j][1] += number[i][j];
            }
        }
        for (int k = 0; k < n; k++)
        {
            if (sum[k][0] <= 0)
            {
                sum[k][0] = -sum[k][0];
                for (int j = 0; j < m; j++)
                {
                    number[k][j] = -number[k][j];
                    sum[j][1] += number[k][j] * 2;
                }
                does[s1++][0] = k + 1;
            }
        }
        printf("%d",s1);
        for (int p = 0; p < s1; p++) printf(" %d",does[p][0]);
        printf("\n");
        for (int l = 0; l < m; l++)
        {
            if (sum[l][1] <= 0)
            {
                sum[l][1] = -sum[l][1];
                for (int j = 0; j < j; j++)
                {
                    number[j][l] = -number[j][l];
                    sum[l][1] += number[j][l] * 2;
                }
                does[s2++][1] = l + 1;
            }
        }
        printf("%d",s2);
        for (int q = 0; q < s2; q++) printf(" %d",does[q][1]);
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define IN   freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 160;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const LL mod = 10007;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
int n,m;
int mp[MAXN][MAXN],r[MAXN],c[MAXN];
bool numr[MAXN],numc[MAXN];
int input()
{
    cler(numr,false),cler(numc,false);
    cler(c,0),cler(r,0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>mp[i][j];
            c[i]+=mp[i][j];
            r[j]+=mp[i][j];
        }
}
int solve()
{
    bool flag=true;
    while(flag)
    {
        flag=false;
        for(int i=1;i<=n&&!flag;i++)
        {
            if(c[i]<0)
            {
                for(int j=1;j<=m;j++)
                    r[j]-=2*mp[i][j],mp[i][j]*=-1;
                numc[i]=!numc[i];
                c[i]*=-1;
                flag=true;
            }
        }
        for(int j=1;j<=m&&!flag;j++)
        {
            if(r[j]<0)
            {
                for(int i=1;i<=n;i++)
                    c[i]-=2*mp[i][j],mp[i][j]*=-1;
                numr[j]=!numr[j];
                r[j]*=-1;
                flag=true;
            }
        }
    }
    int ans[2]={0};
    for(int i=1;i<=n;i++)
        if(numc[i]) ans[0]++;
    for(int i=1;i<=m;i++)
        if(numr[i]) ans[1]++;
    cout<<ans[0];
    for(int i=1;i<=n;i++)
        if(numc[i]) cout<<" "<<i;
    cout<<endl<<ans[1];
    for(int i=1;i<=m;i++)
        if(numr[i]) cout<<" "<<i;
}
int main()
{
    input();
    solve();
    return 0;
}


#include<cstdio>
#include<string.h>
#include<iostream>
using namespace std;

int number[105][105],sum[105][2],n,m,s1,s2,a,b;
bool does[105][2];

int change0()
{
    for (int i = 0; i < n; i++)
    {
        if (sum[i][0] < 0)
        {
            does[i][0] = !does[i][0];
            sum[i][0] = -sum[i][0];
            for (int j = 0; j < m; j++)
            {
                number[i][j] = -number[i][j];
                sum[j][1] += 2 * number[i][j];
            }
            return 1;
        }
    }
    return 0;
}

int change1()
{
    for (int i = 0; i < m; i++)
    {
        if (sum[i][1] < 0)
        {
            sum[i][1] = -sum[i][1];
            does[i][1] = !does[i][1];
            for (int j = 0; j < n; j++)
            {
                number[j][i] = -number[j][i];
                sum[j][0] += 2 * number[j][i];
            }
            return 1;
        }
    }
    return 0;
}

int main()
{
    while (~scanf("%d%d",&n,&m))
    {
        s1 = s2 = 0;
        memset(number,0,sizeof(number));
        memset(sum,0,sizeof(sum));
        memset(does,0,sizeof(does));
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                scanf("%d",&number[i][j]);
                sum[i][0] += number[i][j];
                sum[j][1] += number[i][j];
            }
        }
        a = b = 1;
        while (a || b)
        {
            a = b = 0;
            a = change0();
            if (!a) b = change1();
        }
        for (int k = 0; k < n; k++) if (does[k][0]) s1++;
        for (int k = 0; k < m; k++) if (does[k][1]) s2++;
        printf("%d",s1);
        for (int k = 0; k < n; k++) if (does[k][0]) printf(" %d",k + 1);
        printf("\n");
        printf("%d",s2);
        for (int k = 0; k < m; k++) if (does[k][1]) printf(" %d",k + 1);
        printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<string.h>
using namespace std;

int number[105][105];
int sum[105][2];
int does[105][2];

int main()
{
    int n,m,s1,s2;
    while (~scanf("%d%d",&n,&m))
    {
        memset(number,0,sizeof(number));
        memset(sum,0,sizeof(sum));
        memset(does,0,sizeof(does));
        s1 = s2 = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                scanf("%d",&number[i][j]);
                sum[i][0] += number[i][j];
                sum[j][1] += number[i][j];
            }
        }
        for (int k = 0; k < n; k++)
        {
            if (sum[k][0] < 0)
            {
                sum[k][0] = -sum[k][0];
                for (int j = 0; j < m; j++)
                {
                    number[k][j] = -number[k][j];
                    sum[j][1] += number[k][j] * 2;
                }
                does[s1++][0] = k + 1;
            }
        }
        printf("%d",s1);
        for (int p = 0; p < s1; p++) printf(" %d",does[p][0]);
        printf("\n");
        for (int l = 0; l < m; l++)
        {
            if (sum[l][1] < 0)
            {
                sum[l][1] = -sum[l][1];
                for (int j = 0; j < j; j++)
                {
                    number[j][l] = -number[j][l];
                    sum[l][1] += number[j][l] * 2;
                }
                does[s2++][1] = l + 1;
            }
        }
        printf("%d",s2);
        for (int q = 0; q < s2; q++) printf(" %d",does[q][1]);
        printf("\n");
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int max_n=105;
int n,m,a[max_n][max_n];
bool flag;
int now,A,B,line[1000],list[1000];
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
	while (1)
	{
		flag=false;
		for (int i=1;i<=n;++i)
		{
			now=0;
			for (int j=1;j<=m;++j) now+=a[i][j];
			if (now<0)
			{
				flag=true;
				line[++A]=i;
				for (int j=1;j<=m;++j) a[i][j]=-a[i][j];
			}
		}
		for (int i=1;i<=m;++i)
		{
			now=0;
			for (int j=1;j<=n;++j) now+=a[j][i];
			if (now<0)
			{
				flag=true;
				list[++B]=i;
				for (int j=1;j<=n;++j) a[j][i]=-a[j][i];
			}
		}
		if (!flag) break;
	}
	if (A==0) printf("0\n");
	else printf("%d ",A);
	sort(line+1,line+A+1);
	for (int i=1;i<=A;++i) printf("%d%c",line[i]," \n"[i==A]);
	if (B==0) printf("0\n");
	else printf("%d ",B);
	sort(list+1,list+B+1);
	for (int i=1;i<=B;++i) printf("%d%c",list[i]," \n"[i==B]);
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int max_n=105;
int n,m,a[max_n][max_n];
int now,k,Max; bool flag;
int A,B,line[1000],list[1000],sumline[max_n],sumlist[max_n],ans1[1000],ans2[1000],tot1,tot2,cnt;
int main()
{
//	freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
		{
			scanf("%d",&a[i][j]);
			sumline[i]+=a[i][j];
			sumlist[j]+=a[i][j];
		}
	while (1)
	{
		flag=false; Max=0;
		for (int i=1;i<=n;++i)
		{
			now=sumline[i];
			for (int j=1;j<=m;++j)
				now=now-a[i][j]-a[i][j];
			if (now-sumline[i]>0) flag=true;
			if (now-sumline[i]>Max)
			{
				Max=now-sumline[i];
				k=i;
			}
		}
		for (int i=1;i<=m;++i)
		{
			now=sumlist[i];
			for (int j=1;j<=n;++j) now=now-a[j][i]-a[j][i];
			if (now-sumlist[i]>0) flag=true;
			if (now-sumlist[i]>Max)
			{
				Max=now-sumlist[i];
				k=n+i;
			}
		}
		if (!flag) break;
		if (k<=n)
		{
			line[++A]=k;
			for (int i=1;i<=m;++i) a[k][i]=-a[k][i];
			sumline[k]=0;
			for (int i=1;i<=m;++i) sumline[k]+=a[k][i];
		}
		else
		{
			k-=n;
			list[++B]=k;
			for (int i=1;i<=n;++i) a[i][k]=-a[i][k];
			sumlist[k]=0;
			for (int i=1;i<=n;++i) sumlist[k]+=a[i][k];
		}
	}
	sort(line+1,line+A+1);
	cnt=0;
	for (int i=1;i<=A;++i)
		if (line[i]!=line[i-1])
		{
			if (cnt%2!=0&&i!=1) ans1[++tot1]=line[i-1];
			cnt=1;
		}
		else cnt++;
	if (cnt%2!=0) ans1[++tot1]=line[A];
	sort(list+1,list+B+1);
	cnt=0;
	for (int i=1;i<=B;++i)
		if (list[i]!=list[i-1])
		{
			if (cnt%2!=0&&i!=1) ans2[++tot2]=list[i-1];
			cnt=1;
		}
		else cnt++;
	if (cnt%2!=0) ans2[++tot2]=list[B];
	if (tot1==0) printf("0\n");
	else printf("%d ",tot1);
	for (int i=1;i<=tot1;++i) printf("%d%c",ans1[i]," \n"[i==tot1]);
	if (tot2==0) printf("0\n");
	else printf("%d ",tot2);
	for (int i=1;i<=tot2;++i) printf("%d%c",ans2[i]," \n"[i==tot2]);
}


#include<cstdio>
const int N=105;
int a[N][N],n,m;
int sum_i[N],sum_j[N],vis_i[N],vis_j[N];
int opt,cnt;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		sum_i[i]+=a[i][j],sum_j[j]+=a[i][j];
	}
	while(true){
		opt=cnt;
		for(int i=1;i<=n;i++)
		if(sum_i[i]<0){
			sum_i[i]=-sum_i[i];
			for(int j=1;j<=m;j++){
				sum_j[j]-=(a[i][j]*2);
				a[i][j]=-a[i][j];
			}
			vis_i[i]^=1;
			opt++;
		}
		for(int j=1;j<=m;j++)
		if(sum_j[j]<0){
			sum_j[j]=-sum_j[j];
			for(int i=1;i<=m;i++){
				sum_i[i]-=(a[i][j]*2);
				a[i][j]=-a[i][j];
			}
			vis_j[j]^=1;
			opt++;
		}
		if(cnt==opt)break;
		cnt=opt;
	}
	cnt=0;
	for(int i=1;i<=n;i++)cnt+=vis_i[i];
	printf("%d ",cnt);
	for(int i=1;i<=n;i++)
	if(vis_i[i])printf("%d ",i);
	putchar('\n');
	cnt=0;
	for(int j=1;j<=m;j++)cnt+=vis_j[j];
	printf("%d ",cnt);
	for(int j=1;j<=m;j++)
	if(vis_j[j])printf("%d ",j);
	putchar('\n');
}


#include<cstdio>
const int N=105;
int a[N][N],n,m;
int sum_i[N],sum_j[N],vis_i[N],vis_j[N];
int opt,cnt;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		sum_i[i]+=a[i][j],sum_j[j]+=a[i][j];
	}
	while(true){
		opt=cnt;
		for(int i=1;i<=n;i++)
		if(sum_i[i]<0){
			sum_i[i]=-sum_i[i];
			for(int j=1;j<=m;j++){
				sum_j[j]-=(a[i][j]*2);
				a[i][j]=-a[i][j];
			}
			vis_i[i]^=1;
			opt++;
		}
		for(int j=1;j<=m;j++)
		if(sum_j[j]<0){
			sum_j[j]=-sum_j[j];
			for(int i=1;i<=n;i++){
				sum_i[i]-=(a[i][j]*2);
				a[i][j]=-a[i][j];
			}
			vis_j[j]^=1;
			opt++;
		}
		if(cnt==opt)break;
		cnt=opt;
	}
	cnt=0;
	for(int i=1;i<=n;i++)cnt+=vis_i[i];
	printf("%d ",cnt);
	for(int i=1;i<=n;i++)
	if(vis_i[i])printf("%d ",i);
	putchar('\n');
	cnt=0;
	for(int j=1;j<=m;j++)cnt+=vis_j[j];
	printf("%d ",cnt);
	for(int j=1;j<=m;j++)
	if(vis_j[j])printf("%d ",j);
	putchar('\n');
}


#include <stdio.h>
#include <string.h>

const int maxn = 4005;
int d[maxn][maxn];
int s[maxn],c[maxn],m,n;
bool vis[maxn],vic[maxn];

bool solve(){
    for(int i=1;i<=n;i++){
        if(s[i]<0) return false;
    }
    return true;
}

int main()
{
    scanf("%d%d",&n,&m);
    memset(s,0,sizeof(s));
    memset(vis,0,sizeof(vis));
    memset(vic,0,sizeof(vic));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&d[i][j]);
            s[i]+=d[i][j];
        }
    }

    while(!solve()){

        for(int i=1;i<=n;i++){
            if(s[i]<0){
                vis[i] = !vis[i];
                for(int j=1;j<=m;j++){
                    d[i][j] = -d[i][j];
                }
            }
        }

        memset(c,0,sizeof(c));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                c[j]+=d[i][j];
            }
        }

        for(int j=1;j<=m;j++){
            if(c[j]<0){
                vic[j] = !vic[j];
                for(int i=1;i<=n;i++){
                    d[i][j] = -d[i][j];
                }
            }
        }

        memset(s,0,sizeof(s));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                s[i]+=d[i][j];
            }
        }

    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(vis[i])ans++;
    }
    printf("%d",ans);
    for(int i=1;i<=n;i++){
        if(vis[i]) printf(" %d",i);
    }
    printf("\n");
    ans = 0;
    for(int i=1;i<=m;i++){
        if(vic[i])ans++;
    }
    printf("%d",ans);
    for(int i=1;i<=m;i++){
        if(vic[i]) printf(" %d",i);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>

const int maxn = 4005;
int d[maxn][maxn];
int s[maxn],c[maxn],m,n;
bool vis[maxn],vic[maxn];

bool solve(){
    for(int i=1;i<=n;i++){
        if(s[i]<0) return false;
    }
    return true;
}

int main()
{
    scanf("%d%d",&n,&m);
    memset(s,0,sizeof(s));
    memset(vis,0,sizeof(vis));
    memset(vic,0,sizeof(vic));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&d[i][j]);
            s[i]+=d[i][j];
        }
    }
    bool frist = true;
    while(!solve() || frist){
        frist = false;
        for(int i=1;i<=n;i++){
            if(s[i]<0){
                vis[i] = !vis[i];
                for(int j=1;j<=m;j++){
                    d[i][j] = -d[i][j];
                }
            }
        }

        memset(c,0,sizeof(c));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                c[j]+=d[i][j];
            }
        }

        for(int j=1;j<=m;j++){
            if(c[j]<0){
                vic[j] = !vic[j];
                for(int i=1;i<=n;i++){
                    d[i][j] = -d[i][j];
                }
            }
        }

        memset(s,0,sizeof(s));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                s[i]+=d[i][j];
            }
        }

    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(vis[i])ans++;
    }
    printf("%d",ans);
    for(int i=1;i<=n;i++){
        if(vis[i]) printf(" %d",i);
    }
    printf("\n");
    ans = 0;
    for(int i=1;i<=m;i++){
        if(vic[i])ans++;
    }
    printf("%d",ans);
    for(int i=1;i<=m;i++){
        if(vic[i]) printf(" %d",i);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 210;
int d[maxn][maxn],a[maxn][maxn];
int s[maxn],ans1=0,ans2=0,c[maxn],l = false;

int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    memset(s,0,sizeof(s));
    memset(c,0,sizeof(c));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
            d[i][j] = a[i][j];
            s[i]+=d[i][j];
        }
        if(s[i]<0)ans1++;
    }

    for(int i=0;i<n;i++){
        if(s[i]<0){
            for(int j=0;j<m;j++)
                d[i][j] = -d[i][j];
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[j]+=d[i][j];
        }
    }

    for(int j=0;j<m;j++) if(c[j]<0) ans2++;

    for(int j=0;j<m;j++){
        if(c[j]<0)
        for(int i=0;i<n;i++)
                d[i][j] = -d[i][j];
    }

    memset(s,0,sizeof(s));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            s[i]+=d[i][j];
        }
    }

    for(int i=0;i<n;i++)
        if(s[i]<0){
            l = true;
            break;
        }

    if(!l){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                d[i][j] = a[i][j];
            }
        }
        ans1 = 0;
        memset(s,0,sizeof(s));
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                s[i]+=d[i][j];
            }
            if(s[i]<0)ans1++;
        }
        printf("%d",ans1);
        for(int i=0;i<n;i++){
            if(s[i]<0){
                printf(" %d",i+1);
                for(int j=0;j<m;j++)
                    d[i][j] = -d[i][j];
            }
        }
        printf("\n");
        memset(c,0,sizeof(c));
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                c[j]+=d[i][j];
            }
        }
        ans2 = 0;
        for(int j=0;j<m;j++) if(c[j]<0) ans2++;
        printf("%d",ans2);
        for(int j=0;j<m;j++){
            if(c[j]<0) printf(" %d",j+1);
        }
        printf("\n");
    }else{
        queue<int> q;
        while(!q.empty())q.pop();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                d[i][j] = a[i][j];
            }
        }
        ans1 = 0;ans2 = 0;
        memset(c,0,sizeof(c));
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                c[j]+=d[i][j];
            }
        }

        for(int j=0;j<m;j++){
            if(c[j]<0){
                q.push(j);
                ans2++;
                for(int i=0;i<n;i++)
                    d[i][j] = -d[i][j];
            }
        }

        memset(s,0,sizeof(s));
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                s[i]+=d[i][j];
            }
        }
        for(int i=0;i<n;i++) if(s[i]<0) ans1++;
        printf("%d",ans1);
        for(int i=0;i<n;i++){
            if(s[i]<0) printf(" %d",i+1);
        }
        printf("\n");
        printf("%d",ans2);
        while(!q.empty()){
            int mid = q.front();
            q.pop();
            printf(" %d",mid+1);
        }
        printf("\n");
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
bool vis1[M],vis2[M],vis3[M],vis4[M];
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
bool check(){
	for(int i=1;i<=n;i++)
		if(r[i]<0)
			return 1;
	for(int j=1;j<=m;j++)
		if(c[j]<0)
			return 1;
	return 0;
}
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j])*2,r[i]+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	p=-tot;
	LL i=1,j=1,tot1=0;
	while(check()){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				vis1[i]=!vis1[i];
				a1[++ans1]=i;
				p+=-4*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				vis2[j]=!vis2[j];
				a2[++ans2]=j;
				p+=-4*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}
	/*
	for(int i=1;i<=n;i++){
		r[i]=0;
		for(int j=1;j<=m;j++)
			r[i]+=s[i][j];
	}
	for(int j=1;j<=m;j++){
		c[j]=0;
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",r[i]);
	puts("");
	for(int i=1;i<=m;i++)
		printf("%lld ",c[i]);
	puts("");*/
	LL p1=0;
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]])
			p1++,vis1[a1[i]]=0,vis3[i]=1;
	write(p1);
	for(int i=1;i<=ans1;i++)
		if(vis3[i]){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	LL p2=0;
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]])
			p2++,vis2[a2[i]]=0,vis4[i]=1;
	write(p2);
	for(int i=1;i<=ans2;i++)
		if(vis4[i]){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
bool vis1[M],vis2[M];
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
bool check(){
	for(int i=1;i<=n;i++)
		if(r[i]<0)
			return 1;
	for(int j=1;j<=m;j++)
		if(c[j]<0)
			return 1;
	return 0;
}
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j])*2,r[i]+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	p=-tot;
	LL i=1,j=1,tot1=0;
	while(p<=tot||check()){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				vis1[i]=!vis1[i];
				a1[++ans1]=i;
				p+=-4*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				vis2[j]=!vis2[j];
				a2[++ans2]=j;
				p+=-4*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}/*
	for(int i=1;i<=n;i++){
		r[i]=0;
		for(int j=1;j<=m;j++)
			r[i]+=s[i][j];
	}
	for(int j=1;j<=m;j++){
		c[j]=0;
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",r[i]);
	puts("");
	for(int i=1;i<=m;i++)
		printf("%lld ",c[i]);
	puts("");
	*/
	LL p1=0;
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]])
			p1++;
	write(p1);
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]]){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	LL p2=0;
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]])
			p2++;
	write(p2);
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]]){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j]),r[i]+=s[i][j],p+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	LL i=1,j=1,tot1=0;
	while(p<tot){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				a1[++ans1]=i;
				p+=-2*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				a2[++ans2]=j;
				p+=-2*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}
	write(ans1);
	for(int i=1;i<=ans1;i++){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	write(ans2);
	for(int i=1;i<=ans2;i++){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j]),r[i]+=s[i][j],p+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	LL i=1,j=1;
	while(p<tot){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				a1[++ans1]=i;
				p+=-2*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				a2[++ans2]=j;
				p+=-2*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					if(s[k][j]<0)
						r[k]+=-2*s[k][j];
					else
						r[k]+=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				break;
			}
			j++;
		}
		if(!f)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}
	write(ans1);
	for(int i=1;i<=ans1;i++){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	write(ans2);
	for(int i=1;i<=ans2;i++){
		putchar(' ');
		write(a2[i]);
	}
        putchar('\n');
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
bool vis1[M],vis2[M];
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j])*2,r[i]+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	p=-tot;
	LL i=1,j=1,tot1=0;
	while(p<=tot){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				vis1[i]=!vis1[i];
				a1[++ans1]=i;
				p+=-4*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				vis2[j]=!vis2[j];
				a2[++ans2]=j;
				p+=-4*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}/*
	for(int i=1;i<=n;i++){
		r[i]=0;
		for(int j=1;j<=m;j++)
			r[i]+=s[i][j];
	}
	for(int j=1;j<=m;j++){
		c[j]=0;
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",r[i]);
	puts("");
	for(int i=1;i<=m;i++)
		printf("%lld ",c[i]);
	puts("");
	*/
	LL p1=0;
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]])
			p1++;
	write(p1);
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]]){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	LL p2=0;
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]])
			p2++;
	write(p2);
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]]){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j]),r[i]+=s[i][j],p+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	LL i=1,j=1;
	while(p<tot){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				a1[++ans1]=i;
				p+=-2*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				a2[++ans2]=j;
				p+=-2*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					if(s[k][j]<0)
						r[k]+=-2*s[k][j];
					else
						r[k]+=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				break;
			}
			j++;
		}
		if(!f)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}
	write(ans1);
	for(int i=1;i<=ans1;i++){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	write(ans2);
	for(int i=1;i<=ans2;i++){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
bool vis1[M],vis2[M];
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j])*2,r[i]+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	p=-tot;
	LL i=1,j=1,tot1=0;
	while(p<=tot){
		bool f=0;
		while(i<=n){
			if(r[i]<0&&!vis1[i]){
				vis1[i]=1;
				a1[++ans1]=i;
				p+=-4*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0&&!vis2[j]){
				vis2[j]=1;
				a2[++ans2]=j;
				p+=-4*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}/*
	for(int i=1;i<=n;i++){
		r[i]=0;
		for(int j=1;j<=m;j++)
			r[i]+=s[i][j];
	}
	for(int j=1;j<=m;j++){
		c[j]=0;
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",r[i]);
	puts("");
	for(int i=1;i<=m;i++)
		printf("%lld ",c[i]);
	puts("");
	*/
	write(ans1);
	for(int i=1;i<=ans1;i++){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	write(ans2);
	for(int i=1;i<=ans2;i++){
		putchar(' ');
		write(a2[i]);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
#define M 105
#define N 86400
void read(LL &x){
	x=0;
	char c=getchar();
	int f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
	return ;
}
LL maxt(LL a,LL b){
	return a>b?a:b;
}
LL mint(LL a,LL b){
	return a<b?a:b;
}
void write(LL x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x<10){
		putchar('0'+x);
		return ;
	}
	write(x/10);
	putchar(x%10+'0');
	return ;
}
bool vis1[M],vis2[M];
LL n,m,tot,s[M][M],c[M],r[M],ans1,ans2,a1[M],a2[M];
bool check(){
	for(int i=1;i<=n;i++)
		if(r[i]<0)
			return 1;
	for(int j=1;j<=m;j++)
		if(c[j]<0)
			return 1;
	return 0;
}
int main(){
	read(n),read(m);
	LL p=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(s[i][j]),tot+=fabs(s[i][j])*2,r[i]+=s[i][j];
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	p=-tot;
	LL i=1,j=1,tot1=0;
	while(check()){
		bool f=0;
		while(i<=n){
			if(r[i]<0){
				vis1[i]=!vis1[i];
				a1[++ans1]=i;
				p+=-4*r[i];
				r[i]=-r[i];
				for(int k=1;k<=m;k++){
					c[k]-=2*s[i][k];
					s[i][k]=-s[i][k];
				}
				f=1;
				tot1=0;
				break;
			}
			i++;
		}
		while(j<=m&&!f){
			if(c[j]<0){
				vis2[j]=!vis2[j];
				a2[++ans2]=j;
				p+=-4*c[j];
				c[j]=-c[j];
				for(int k=1;k<=n;k++){
					r[k]-=2*s[k][j];
					s[k][j]=-s[k][j];
				}
				f=1;
				tot1=0;
				break;
			}
			j++;
		}
		if(!f)
			tot1++;
		if(tot1>1)
			break;
		if(i>n&&j>m){
			i=1;
			j=1;
		}
	}/*
	for(int i=1;i<=n;i++){
		r[i]=0;
		for(int j=1;j<=m;j++)
			r[i]+=s[i][j];
	}
	for(int j=1;j<=m;j++){
		c[j]=0;
		for(int i=1;i<=n;i++)
			c[j]+=s[i][j];
	}
	for(int i=1;i<=n;i++)
		printf("%lld ",r[i]);
	puts("");
	for(int i=1;i<=m;i++)
		printf("%lld ",c[i]);
	puts("");
	*/
	LL p1=0;
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]])
			p1++;
	write(p1);
	for(int i=1;i<=ans1;i++)
		if(vis1[a1[i]]){
		putchar(' ');
		write(a1[i]);
	}
	putchar('\n');
	LL p2=0;
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]])
			p2++;
	write(p2);
	for(int i=1;i<=ans2;i++)
		if(vis2[a2[i]]){
		putchar(' ');
		write(a2[i]);
	}
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    int a[n][m], row[n], col[m], r[n], c[m];
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            row[i] += a[i][j];
            col[j] += a[i][j];
        }
    }

    for(int it = 0; it < (5e3); it++){
        for(int i = 0; i < n; i++){
            if(row[i] < 0){
                r[i] ^= 1;
                row[i] = -row[i];
                for(int j = 0; j < m; j++){
                    col[j] -= 2 * a[i][j] * (r[i] ^ c[j]);
                }
            }
        }

        for(int j = 0; j < m; j++){
            if(col[j] < 0){
                c[j] ^= 1;
                col[j] = -col[j];
                for(int i = 0; i < n; i++){
                    row[i] -= 2 * a[i][j] * (r[i] ^ c[j]);
                }
            }
        }
    }

    vector<int> ans;
    for(int i = 0; i < n; i++){
        if(r[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
    cout << "\n";

    ans.clear();
    for(int i = 0; i < m; i++){
        if(c[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    int a[n][m], row[n], col[m], r[n], c[m];
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            row[i] += a[i][j];
            col[j] += a[i][j];
        }
    }

    for(int it = 0; it < (1e4); it++){
        for(int i = 0; i < n; i++){
            if(row[i] < 0){
                r[i] ^= 1;
                row[i] = -row[i];
                for(int j = 0; j < m; j++){
                    col[j] -= 2 * a[i][j] * ((r[i] ^ c[j]) == 1 ? 1 : -1);
                }
            }
        }

        for(int j = 0; j < m; j++){
            if(col[j] < 0){
                c[j] ^= 1;
                col[j] = -col[j];
                for(int i = 0; i < n; i++){
                    row[i] -= 2 * a[i][j] * ((r[i] ^ c[j]) == 1 ? 1 : -1);
                }
            }
        }
    }

    vector<int> ans;
    for(int i = 0; i < n; i++){
        if(r[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
    cout << "\n";

    ans.clear();
    for(int i = 0; i < m; i++){
        if(c[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    int a[n][m], row[n], col[m], r[n], c[m];
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            row[i] += a[i][j];
            col[j] += a[i][j];
        }
    }

    for(int it = 0; it < (1e4); it++){
        for(int i = 0; i < n; i++){
            if(row[i] < 0){
                r[i] ^= 1;
                row[i] = -row[i];
                for(int j = 0; j < m; j++){
                    col[j] -= 2 * a[i][j] * (r[i] ^ c[j]);
                }
            }
        }

        for(int j = 0; j < m; j++){
            if(col[j] < 0){
                c[j] ^= 1;
                col[j] = -col[j];
                for(int i = 0; i < n; i++){
                    row[i] -= 2 * a[i][j] * (r[i] ^ c[j]);
                }
            }
        }
    }

    vector<int> ans;
    for(int i = 0; i < n; i++){
        if(r[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
    cout << "\n";

    ans.clear();
    for(int i = 0; i < m; i++){
        if(c[i])ans.pb(i + 1);
    }
    cout << ans.size() << " ";
    for(int x : ans){
        cout << x << " ";
    }
}


#include<bits/stdc++.h>
#define N 105
using namespace std;

inline bool rd(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X; return 1;
}

int n,m;
int a[N][N];
int ux[N],uy[N];
int sx[N],sy[N];
int ansx,ansy;

void workx()
{
  for(int i=1;i<=n;i++)
    if(sx[i]<0)
    {
      sx[i]=-sx[i];ux[i]^=1;ux[i] ? ansx++ : ansx--;
      for(int j=1;j<=m;j++)
        sy[j]-=a[i][j],a[i][j]=-a[i][j],sy[j]+=a[i][j];
    }

}
void worky()
{
  for(int i=1;i<=m;i++)
    if(sy[i]<0)
    {
      sy[i]=-sy[i];uy[i]^=1;uy[i] ? ansy++ : ansy--;
      for(int j=1;j<=n;j++)
        sx[j]-=a[j][i],a[j][i]=-a[j][i],sx[j]+=a[j][i];
    }
}

signed main()
{
  rd(n);rd(m);
  for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
        rd(a[i][j]),sx[i]+=a[i][j],sy[j]+=a[i][j];
  for(int i=1;i<=1000;i++)
    workx(),worky();

    printf("%d ",ansx);
    for(int i=1;i<=n;i++)
      if(ux[i]) printf("%d ",i);
    cout<<endl;
    printf("%d ",ansy);
    for(int i=1;i<=m;i++)
      if(uy[i]) printf("%d ",i);
    cout<<endl;
    /*for(int i=1;i<=n;i++,cout<<endl)
      for(int j=1;j<=m;j++)
        printf("%d ",a[i][j]);*/

}


#include<bits/stdc++.h>
#define N 105
using namespace std;

inline bool rd(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X; return 1;
}

int n,m;
int a[N][N];
int ux[N],uy[N];
int sx[N],sy[N];
int ansx,ansy;

void workx()
{
  for(int i=1;i<=n;i++)
    if(sx[i]<0 and !ux[i])
    {
      sx[i]=-sx[i];ux[i]=1;ansx++;
      for(int j=1;j<=m;j++)
        sy[j]-=a[i][j],a[i][j]=-a[i][j],sy[j]+=a[i][j];
    }

}
void worky()
{
  for(int i=1;i<=m;i++)
    if(sy[i]<0 and !uy[i])
    {
      sy[i]=-sy[i];uy[i]=1;ansy++;
      for(int j=1;j<=n;j++)
        sx[j]-=a[j][i],a[j][i]=-a[j][i],sx[j]+=a[j][i];
    }
}

signed main()
{
  rd(n);rd(m);
  for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
        rd(a[i][j]),sx[i]+=a[i][j],sy[j]+=a[i][j];
  for(int i=1;i<=100;i++)
    workx(),worky();

    printf("%d ",ansx);
    for(int i=1;i<=n;i++)
      if(ux[i]) printf("%d ",i);
    cout<<endl;
    printf("%d ",ansy);
    for(int i=1;i<=m;i++)
      if(uy[i]) printf("%d ",i);
    cout<<endl;

}


#include<bits/stdc++.h>
#define N 105
using namespace std;

inline bool rd(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X; return 1;
}

int n,m;
int a[N][N];
int ux[N],uy[N];
int sx[N],sy[N];
int ansx,ansy;

void workx()
{
  for(int i=1;i<=n;i++)
    if(sx[i]<0 and !ux[i])
    {
      sx[i]=-sx[i];ux[i]=1;ansx++;
      for(int j=1;j<=m;j++)
        sy[j]-=a[i][j],a[i][j]=-a[i][j],sy[j]+=a[i][j];
    }

}
void worky()
{
  for(int i=1;i<=m;i++)
    if(sy[i]<0 and !uy[i])
    {
      sy[i]=-sy[i];uy[i]=1;ansy++;
      for(int j=1;j<=n;j++)
        sx[j]-=a[i][j],a[i][j]=-a[i][j],sx[j]+=a[i][j];
    }
}

signed main()
{
  rd(n);rd(m);
  for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
        rd(a[i][j]),sx[i]+=a[i][j],sy[j]+=a[i][j];
  for(int i=1;i<=100;i++)
    workx(),worky();

    printf("%d ",ansx);
    for(int i=1;i<=n;i++)
      if(ux[i]) printf("%d ",i);
    cout<<endl;
    printf("%d ",ansy);
    for(int i=1;i<=m;i++)
      if(uy[i]) printf("%d ",i);
    cout<<endl;

}


#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, m; cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  vector<int> row(n), col(m);
  vector<vector<int>> sum(2, vector<int>(max(n, m)));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sum[0][i] += a[i][j];
      sum[1][j] += a[i][j];
    }
  }
  while (true) {
    auto FlipCol = [&](int idx) {
      for (int i = 0; i < n; ++i) {
        int val = a[i][idx];
        if (row[i] ^ col[idx]) val = -val;
        sum[0][i] -= 2 * val;
      }
      col[idx] = 1 ^ col[idx];
      sum[1][idx] = -sum[1][idx];
    };
    auto FlipRow = [&](int idx) {
      for (int i = 0; i < m; ++i) {
        int val = a[idx][i];
        if (row[idx] ^ col[i]) val = -val;
        sum[1][i] -= 2 * val;
      }
      row[idx] = 1 ^ row[idx];
      sum[0][idx] = -sum[0][idx];
    };
    bool done = true;
    for (int i = 0; i < n; ++i) {
      if (sum[0][i] < 0) {
        FlipRow(i);
        done = false;
      }
    }
    for (int i = 0; i < m; ++i) {
      if (sum[1][i] < 0) {
        FlipCol(i);
        done = false;
      }
    }
    if (done) break;
  }
  cout << count(row.begin(), row.end(), 1) << ' ';
  for (int i = 0; i < n; ++i) if (row[i]) cout << 1 + i << ' ';
  cout << '\n';
  cout << count(col.begin(), col.end(), 1) << ' ';
  for (int i = 0; i < m; ++i) if (col[i]) cout << 1 + i << ' ';
  cout << endl;
}