Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negative the sum of the numbers in each row and each column using these spells.

Alone, the boy can not cope. Help the young magician!

Input

The first line contains two integers n and m (1 ≤ n,  m ≤ 100) — the number of rows and the number of columns.

Next n lines follow, each contains m integers: j-th integer in the i-th line is ai, j (|ai, j| ≤ 100), the number in the i-th row and j-th column of the table.

The rows of the table numbered from 1 to n. The columns of the table numbered from 1 to m.

Output

In the first line print the number a — the number of required applications of the first spell. Next print a space-separated integers — the row numbers, you want to apply a spell. These row numbers must be distinct!

In the second line print the number b — the number of required applications of the second spell. Next print b space-separated integers — the column numbers, you want to apply a spell. These column numbers must be distinct!

If there are several solutions are allowed to print any of them.

Examples

Input

Copy
4 1
-1
-1
-1
-1
Output

Copy
4 1 2 3 4 
0
Input

Copy
2 4
-1 -1 -1 2
1 1 1 1
Output

Copy
1 1 
1 4

题目解析

输出有点玄学。

大概意思就是先输出行、列最小交换几次,然后输出交换了哪一行

我的做法是贪心,反复judge每一行、列的和,发现负的就翻转次数++,不停地翻转小于0的行列,总会让每行每列都变得大于0的。

最后,因为翻转两次=不翻转,所以最后要输出次数&1。挺好玩的,神题。

Code

#include<iostream>
#include<cstdio>
using namespace std; int n,m;
int a[][];
int sumx[],sumy[];
int flagx[],flagy[];
int ans1,ans2; inline int judge_x() {
for(int i = ;i <= n;i++) {
if(sumx[i] < ) return i;
}
return ;
} inline int judge_y() {
for(int i = ;i <= m;i++) {
if(sumy[i] < ) return i;
}
return ;
} int main() {
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i++) {
for(int j = ;j <= m;j++) {
scanf("%d",&a[i][j]);
sumx[i] += a[i][j];
sumy[j] += a[i][j];
}
}
while() {
int tmpx = judge_x();
int tmpy = judge_y();
if(!tmpx && !tmpy) break;
if(tmpx) {
flagx[tmpx]++;
sumx[tmpx] = ;
for(int i = ;i <= m;i++) {
int k = -a[tmpx][i];
sumy[i] = sumy[i] - a[tmpx][i] + k;
a[tmpx][i] = k;
sumx[tmpx] += k;
}
} else {
flagy[tmpy]++;
sumy[tmpy] = ;
for(int i = ;i <= n;i++) {
int k = -a[i][tmpy];
sumx[i] = sumx[i] - a[i][tmpy] + k;
a[i][tmpy] = k;
sumy[tmpy] += k;
}
}
}
for(int i = ;i <= n;i++) if(flagx[i] & ) ans1++;
for(int i = ;i <= m;i++) if(flagy[i] & ) ans2++;
printf("%d ",ans1);
for(int i = ;i <= n;i++) {
if(flagx[i] & ) printf("%d ",i);
}
printf("\n%d ",ans2);
for(int i = ;i <= m;i++) {
if(flagy[i] & ) printf("%d ",i);
}
printf("\n");
return ;
}

最新文章

  1. java正则表达式【大全】
  2. State Threads——异步回调的线性实现
  3. Chrome Restful Api 测试工具 Postman-REST-Client离线安装包下载,Axure RP Extension for Chrome离线版下载
  4. JQuery Jsonp 跨域
  5. C语言qsort函数用法
  6. iOS9横竖屏设置的处理方法
  7. 智能卡 APTU命令
  8. Linux 编译安装 apache 2.4
  9. 分析java.lang.NullPointerException thrown in RelativeLayout measure()
  10. Maven项目问题
  11. iview render Datepicker 起止时间限制
  12. redis实战笔记
  13. js判断一个图片是否已经存在于缓存
  14. Linux将公网ip映射到局域网ip
  15. P1226快速幂取余
  16. The role of the inter-controller consensus in the placement of distributed SDN controllers
  17. win7下PHP+MySQL+CoreSeek中文检索引擎配置
  18. 关于IIS下字体跨域问题
  19. POJ 1080( LCS变形)
  20. Spark shuffle调优

热门文章

  1. 如何用分布式缓存服务实现Redis内存优化
  2. Codeforces Round #211 (Div. 2)B. Fence
  3. 分析智能卡的ATR格式【转】
  4. tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】
  5. 选择排序(2)——堆排序(heap sort)
  6. poj3539 Elevator——同余类bfs
  7. 在PL/SQL使用游标获取数据及动态SQL
  8. Magnetic Storms
  9. [jzoj NOIP2018模拟10.23]
  10. redis+php实现秒杀