#include #include #include #include #include using namespace std; using ll = long long; #include using mint = atcoder::modint; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int mod; cin>>mod; mint::set_mod(mod); int n,m; cin>>n>>m; vector> a(n,vector(m,0)); for(int i = 0;i>b; a[i][j] = b; } } auto res = a; bool fn = true; for(int i = 0;i use(n,0); for(int i = 0;i> b(n,vector(cnt,0)); vector now(n,-1); int time = 0; for(int i = 0;i1||!fn) continue; //cout<> c(cnt,vector(m,0)); for(int i = 0;i