#include <stdio.h>
f(int m,int n,int**a,int*r){for(*r=m;n*m;a[m][n]?m--:--n);*r-=m;}
/* usage:
m = number of rows
n = number of columns
a = 1-based 2D array such that a[i][j] gives the value at the ith row and jth column
r = address of return value */
int main()
{
int flat[4*4] = {0, 0, 1, 0,
0, 0, 1, 0,
1, 0, 1, 1,
1, 1, 1, 1};
int*twoD[4] = {flat-1,flat+3,flat+7,flat+11};
int ret;
f(4,4,twoD-1,&ret);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmYoaW50IG0saW50IG4saW50KiphLGludCpyKXtmb3IoKnI9bTtuKm07YVttXVtuXT9tLS06LS1uKTsqci09bTt9CgovKiB1c2FnZToKICAgIG0gPSBudW1iZXIgb2Ygcm93cwogICAgbiA9IG51bWJlciBvZiBjb2x1bW5zCiAgICBhID0gMS1iYXNlZCAyRCBhcnJheSBzdWNoIHRoYXQgYVtpXVtqXSBnaXZlcyB0aGUgdmFsdWUgYXQgdGhlIGl0aCByb3cgYW5kIGp0aCBjb2x1bW4KICAgIHIgPSBhZGRyZXNzIG9mIHJldHVybiB2YWx1ZSAqLwoKaW50IG1haW4oKQp7CiAgICBpbnQgZmxhdFs0KjRdID0gezAsIDAsIDEsIDAsCiAgICAgICAgICAgICAgICAgICAgIDAsIDAsIDEsIDAsCiAgICAgICAgICAgICAgICAgICAgIDEsIDAsIDEsIDEsCiAgICAgICAgICAgICAgICAgICAgIDEsIDEsIDEsIDF9OwogICAgaW50KnR3b0RbNF0gPSB7ZmxhdC0xLGZsYXQrMyxmbGF0KzcsZmxhdCsxMX07CiAgICBpbnQgcmV0OwogICAgZig0LDQsdHdvRC0xLCZyZXQpOwogICAgcHJpbnRmKCIlZCIsIHJldCk7CiAgICByZXR1cm4gMDsKfQo=