QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613292#9444. Again Permutation Problemucup-team087#AC ✓39ms45692kbC++2023.9kb2024-10-05 13:52:422024-10-05 13:52:43

Judging History

This is the latest submission verdict.

  • [2024-10-05 13:52:43]
  • Judged
  • Verdict: AC
  • Time: 39ms
  • Memory: 45692kb
  • [2024-10-05 13:52:42]
  • Submitted

answer

#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif

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

using ll=long long;
//#define int ll

bool dbg=false;

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;
using vvi=vc<vc<int>>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ";
	dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif

using uint=unsigned;
using ull=unsigned long long;

template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
	return os<<vc<t>(all(a));
}

ll rand_int(ll l, ll r) { //[l, r]
	//#ifdef LOCAL
	static mt19937_64 gen;
	/*#else
	static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	#endif*/
	return uniform_int_distribution<ll>(l, r)(gen);
}

ll rand_int(ll k){ //[0,k)
	return rand_int(0,k-1);
}
string rand_string(int n,char lw,char up){
	string s(n,'?');
	rep(i,n)s[i]=rand_int(lw,up);
	return s;
}

int current_run_id,run_batch_size=1000;
int calc_random_limit(){
	return current_run_id/run_batch_size+1;
}
template<class t>
void generate_single(t&a){
	a=rand_int(1,calc_random_limit());
}
void generate_single(string&a){
	int n;generate_single(n);
	a=rand_string(n,'a','b');
}
template<class t,class u>
void generate_single(pair<t,u>&a){
	generate_single(a.a);
	generate_single(a.b);
}
//https://trap.jp/post/1224/
template<class... Args>
void input(Args&... a){
	if(dbg){
		(generate_single(a),...);
	}else{
		#ifdef USE_FAST_IO
		sc.read(a...);
		#else
		(cin >> ... >> a);
		#endif
	}
}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;input(__VA_ARGS__)
#define overload3(a,b,c,d,...) d
#define VI2(name,size) vi name(size);rep(i_##name,size)input(name[i_##name]);
#define VI3(name,size,offset) vi name(size);rep(i_##name,size)input(name[i_##name]),name[i_##name]+=offset;
#define VI(...) overload3(__VA_ARGS__,VI3,VI2)(__VA_ARGS__)
#define VPI(name,size) vc<pi> name(size);rep(i_##name,size)input(name[i_##name]);
#define VVI(name,sizeN,sizeM) vvi name(sizeN,vi(sizeM));\
rep(i_##name,sizeN)rep(j_##name,sizeM)input(name[i_##name][j_##name]);
#define VS(name,size) vc<string> name(size);rep(i_##name,size)input(name[i_##name]);

#define overload5(a,b,c,d,e,f,...) f
#define VVC4(type,name,sizeN,sizeM) vvc<type> name(sizeN,vc<type>(sizeM));
#define VVC5(type,name,sizeN,sizeM,ini) vvc<type> name(sizeN,vc<type>(sizeM,ini));
#define VVC(...) overload5(__VA_ARGS__,VVC5,VVC4)(__VA_ARGS__)

template<class T>
T vvvc(T v){
	return v;
}

template<class T,class...Args>
auto vvvc(int n,T v,Args...args){
	return vector(n,vvvc(v,args...));
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"{";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<"}";
}

void printsuc(int suc){
	#ifdef USE_FAST_IO
		if(suc==1)pr.write('\n');
		if(suc==2)pr.write(' ');
	#else
		if(suc==1){
			if(dbg)cout<<endl;
			else{
				#ifdef LOCAL
				cout<<endl;
				#else
				cout<<"\n";
				#endif
			}
		}
		if(suc==2)
			cout<<" ";
	#endif
}

template<class t>
void print_single(t x,int suc=1){
	#ifdef USE_FAST_IO
	pr.write(x);
	#else
	cout<<x;
	#endif
	printsuc(suc);
}

template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
	print_single(p.a,2);
	print_single(p.b,suc);
}

template<class T>
void print_single(const vector<T>&v,int suc=1){
	rep(i,v.size())
		print_single(v[i],i==int(v.size())-1?3:2);
	printsuc(suc);
}

template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
	rep(i,N)
		print_single(v[i],i==int(N)-1?3:2);
	printsuc(suc);
}

template<class T>
void print(const T&t){
	print_single(t);
}

template<class T,class ...Args>
void print(const T&t,const Args&...args){
	print_single(t,2);
	print(args...);
}

template<class T>
void printvv(const vvc<T>&vs){
	for(const auto&row:vs)print(row);
}

string readString(){
	string s;
	cin>>s;
	return s;
}

template<class T>
T sq(const T& t){
	return t*t;
}

void YES(bool ex=true){
	cout<<"YES\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void NO(bool ex=true){
	cout<<"NO\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void Yes(bool ex=true){
	cout<<"Yes\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void No(bool ex=true){
	cout<<"No\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
//#define CAPITAL
/*
void yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<"\n";
	#else
	cout<<"Yes"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void no(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<"\n";
	#else
	cout<<"No"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}*/
void possible(bool ex=true){
	#ifdef CAPITAL
	cout<<"POSSIBLE"<<"\n";
	#else
	cout<<"Possible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void impossible(bool ex=true){
	#ifdef CAPITAL
	cout<<"IMPOSSIBLE"<<"\n";
	#else
	cout<<"Impossible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

int topbit(signed t){
	return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
	return t==0?-1:63-__builtin_clzll(t);
}
int topbit(ull t){
	return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
	return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
	return a==0?64:__builtin_ctzll(a);
}
int botbit(ull a){
	return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
	return __builtin_popcount(t);
}
int popcount(ll t){
	return __builtin_popcountll(t);
}
int popcount(ull t){
	return __builtin_popcountll(t);
}
int bitparity(ll t){
	return __builtin_parityll(t);
}
bool ispow2(int i){
	return i&&(i&-i)==i;
}
ll mask(int i){
	return (ll(1)<<i)-1;
}
ull umask(int i){
	return (ull(1)<<i)-1;
}
ll minp2(ll n){
	if(n<=1)return 1;
	else return ll(1)<<(topbit(n-1)+1);
}

bool inc(int a,int b,int c){
	return a<=b&&b<=c;
}

template<class S> void mkuni(S&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

template<class t> bool isuni(vc<t> v){
	int s=si(v);
	mkuni(v);
	return si(v)==s;
}

template<class t>
void myshuffle(vc<t>&a){
	rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}

template<class S,class u>
int lwb(const S&v,const u&a){
	return lower_bound(all(v),a)-v.bg;
}
template<class t,class u>
bool bis(const vc<t>&v,const u&a){
	return binary_search(all(v),a);
}

//VERIFY: yosupo
//KUPC2017J
//AOJDSL1A
//without rank
struct unionfind{
	vi p,s;
	int c;
	unionfind(int n):p(n,-1),s(n,1),c(n){}
	void clear(){
		fill(all(p),-1);
		fill(all(s),1);
		c=si(p);
	}
	int find(int a){
		return p[a]==-1?a:(p[a]=find(p[a]));
	}
	//set b to a child of a
	bool unite(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return false;
		p[b]=a;
		s[a]+=s[b];
		c--;
		return true;
	}
	bool same(int a,int b){
		return find(a)==find(b);
	}
	int sz(int a){
		return s[find(a)];
	}
};

vvc<int> readGraph(int n,int m){
	vvc<int> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		//sc.read(a,b);
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	return g;
}

vvc<int> rand_tree(int n){
	vvc<int> t(n);
	unionfind uf(n);
	while(uf.c>1){
		int a=rand_int(n);
		int b=rand_int(n);
		if(uf.unite(a,b)){
			t[a].pb(b);
			t[b].pb(a);
		}
	}
	return t;
}

vvc<int> readTree(int n){
	if(dbg){
		return rand_tree(n);
	}else{
		return readGraph(n,n-1);
	}
}

vi readRooted(int n){
	assert(!dbg);
	vi par(n,-1);
	rng(i,1,n){
		input(par[i]);
		par[i]--;
		assert(inc(0,par[i],i-1));
	}
	return par;
}

void printTree(const vvc<int> t){
	int n=si(t);
	int degsum=0;
	rep(i,n)degsum+=si(t[i]);
	if(degsum==n-1){
		//directed
		rep(i,si(t))for(auto j:t[i]){
			print(i+1,j+1);
		}
	}else if(degsum==2*(n-1)){
		//undirected
		rep(i,si(t))for(auto j:t[i])if(i<j){
			print(i+1,j+1);
		}
	}else{
		assert(false);
	}
}

template<class t>
vc<t> presum(const vc<t>&a){
	vc<t> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
vc<ll> presum(const vi&a){
	vc<ll> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
	gnr(i,1,si(a))a[i]-=a[i-1];
	return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
	int n=si(a),m=si(a[0]);
	vvc<ll> b(n+1,vc<ll>(m+1));
	rep(i,n)rep(j,m)
		b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
	return b;
}

//verify してないや
void transvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[j][i]=a[i][j];
	}
	a.swap(b);
	transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[m-1-j][i]=a[i][j];
	}
	a.swap(b);
	rotvvc(n,m,args...);
}

//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
	int n=si(a);
	vi idx(n);iota(all(idx),0);
	sort(all(idx),[&](int i,int j){return a[i]<a[j];});
	return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
	int n=si(a);
	assert(si(idx)==n);
	vc<t> vs(n);
	rep(i,n)vs[i]=a[idx[i]];
	return vs;
}
//CF850C
vi invperm(const vi&p){
	int n=si(p);
	vi q(n);
	rep(i,n)q[p[i]]=i;
	return q;
}

template<class t,class s=t>
s SUM(const vc<t>&a){
	return accumulate(all(a),s(0));
}
template<class t,size_t K,class s=t>
s SUM(const array<t,K>&a){
	return accumulate(all(a),s(0));
}

template<class t>
t MAX(const vc<t>&a){
	return *max_element(all(a));
}

template<class t>
pair<t,int> MAXi(const vc<t>&a){
	auto itr=max_element(all(a));
	return mp(*itr,itr-a.bg);
}

template<class A>
auto MIN(const A&a){
	return *min_element(all(a));
}

template<class t>
pair<t,int> MINi(const vc<t>&a){
	auto itr=min_element(all(a));
	return mp(*itr,itr-a.bg);
}

vi vid(int n){
	vi res(n);iota(all(res),0);
	return res;
}

template<class S>
void soin(S&s){
	sort(all(s));
}

template<class S,class F>
void soin(S&s,F&&f){
	sort(all(s),forward<F>(f));
}

template<class S>
S soout(S s){
	soin(s);
	return s;
}

template<class S>
void rein(S&s){
	reverse(all(s));
}

template<class S>
S reout(S s){
	rein(s);
	return s;
}

template<class t,class u>
pair<t,u>&operator+=(pair<t,u>&a,pair<t,u> b){
	a.a+=b.a;a.b+=b.b;return a;}
template<class t,class u>
pair<t,u>&operator-=(pair<t,u>&a,pair<t,u> b){
	a.a-=b.a;a.b-=b.b;return a;}
template<class t,class u>
pair<t,u> operator+(pair<t,u> a,pair<t,u> b){return mp(a.a+b.a,a.b+b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a,pair<t,u> b){return mp(a.a-b.a,a.b-b.b);}
template<class t,class u,class v>
pair<t,u>&operator*=(pair<t,u>&a,v b){
	a.a*=b;a.b*=b;return a;}
template<class t,class u,class v>
pair<t,u> operator*(pair<t,u> a,v b){return a*=b;}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a){return mp(-a.a,-a.b);}
namespace std{
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
	return is>>a.a>>a.b;
}
}

template<class t>
t gpp(vc<t>&vs){
	assert(si(vs));
	t res=move(vs.back());
	vs.pop_back();
	return res;
}

template<class t,class u>
void pb(vc<t>&a,const vc<u>&b){
	a.insert(a.ed,all(b));
}

template<class t,class...Args>
vc<t> cat(vc<t> a,Args&&...b){
	(pb(a,forward<Args>(b)),...);
	return a;
}

template<class t,class u>
vc<t>& operator+=(vc<t>&a,u x){
	for(auto&v:a)v+=x;
	return a;
}

template<class t,class u>
vc<t> operator+(vc<t> a,u x){
	return a+=x;
}

template<class t>
vc<t>& operator+=(vc<t>&a,const vc<t>&b){
	a.resize(max(si(a),si(b)));
	rep(i,si(b))a[i]+=b[i];
	return a;
}

template<class t>
vc<t> operator+(const vc<t>&a,const vc<t>&b){
	vc<t> c(max(si(a),si(b)));
	rep(i,si(a))c[i]+=a[i];
	rep(i,si(b))c[i]+=b[i];
	return c;
}

template<class t,class u>
vc<t>& operator-=(vc<t>&a,u x){
	for(auto&v:a)v-=x;
	return a;
}
template<class t,class u>
vc<t> operator-(vc<t> a,u x){
	return a-=x;
}

template<class t,class u>
vc<t>& operator*=(vc<t>&a,u x){
	for(auto&v:a)v*=x;
	return a;
}
template<class t,class u>
vc<t> operator*(vc<t> a,u x){
	return a*=x;
}

template<class t,class u>
vc<t>& operator/=(vc<t>&a,u x){
	for(auto&v:a)v/=x;
	return a;
}
template<class t,class u>
vc<t> operator/(vc<t> a,u x){
	return a/=x;
}

template<class t>
vc<t>& operator<<=(vc<t>&a,int k){
	assert(k>=0);
	a.insert(a.bg,k,t(0));
	return a;
}
template<class t>
vc<t> operator<<(vc<t> a,int k){
	return a<<=k;
}

template<class t>
vc<t>& operator>>=(vc<t>&a,int k){
	if(si(a)<=k)a.clear();
	else a.erase(a.bg,a.bg+k);
	return a;
}
template<class t>
vc<t> operator>>(vc<t> a,int k){
	return a>>=k;
}

template<class t,class u>
void remval(vc<t>&a,const u&v){
	a.erase(remove(all(a),v),a.ed);
}
//消した要素の個数を返してくれる
//UCUP 2-8-F
template<class t,class F>
int remif(vc<t>&a,F f){
	auto itr=remove_if(all(a),f);
	int res=a.ed-itr;
	a.erase(itr,a.ed);
	return res;
}
template<class t>
void rempos(vc<t>&a,int i){
	assert(inc(0,i,si(a)-1));
	a.erase(a.bg+i);
}

template<class VS,class u>
void fila(VS&vs,const u&a){
	fill(all(vs),a);
}

template<class t,class u>
int findid(const vc<t>&vs,const u&a){
	auto itr=find(all(vs),a);
	if(itr==vs.ed)return -1;
	else return itr-vs.bg;
}

template<class t>
void rtt(vc<t>&vs,int i){
	rotate(vs.bg,vs.bg+i,vs.ed);
}

//Multiuni2023-8 C
//f(lw)=false,...,f(n-1)=false,f(n)=true,...,f(up)=true,
//のときに n を返す
template<class F>
int find_min_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))up=mid;
		else lw=mid;
	}
	return up;
}
//f(lw)=true,f(up)=false
template<class F>
int find_max_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))lw=mid;
		else up=mid;
	}
	return lw;
}

template<class t> using pqmin=priority_queue<t,vc<t>,greater<t>>;
template<class t> using pqmax=priority_queue<t>;
using T=tuple<int,int,int>;

//mint107 は verify してねえ
//#define DYNAMIC_MOD

struct modinfo{uint mod,root;
#ifdef DYNAMIC_MOD
constexpr modinfo(uint m,uint r):mod(m),root(r),im(0){set_mod(m);}
ull im;
constexpr void set_mod(uint m){
	mod=m;
	im=ull(-1)/m+1;
}
uint product(uint a,uint b)const{
	ull z=ull(a)*b;
	uint x=((unsigned __int128)z*im)>>64;
	uint v=uint(z)-x*mod;
	return v<mod?v:v+mod;
}
#endif
};
template<modinfo const&ref>
struct modular{
	static constexpr uint const &mod=ref.mod;
	static modular root(){return modular(ref.root);}
	uint v;
	//modular(initializer_list<uint>ls):v(*ls.bg){}
	modular(ll vv=0){s(vv%mod+mod);}
	modular& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	modular operator-()const{return modular()-*this;}
	modular& operator+=(const modular&rhs){return s(v+rhs.v);}
	modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
	modular&operator*=(const modular&rhs){
		#ifndef DYNAMIC_MOD
		v=ull(v)*rhs.v%mod;
		#else
		v=ref.product(v,rhs.v);
		#endif
		return *this;
	}
	modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
	modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
	modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
	modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
	modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
	modular pow(ll n)const{
		if(n<0)return inv().pow(-n);
		modular res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modular inv()const{return pow(mod-2);}
	/*modular inv()const{
		int x,y;
		int g=extgcd<ll>(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return modular(x);
	}*/
	friend modular operator+(ll x,const modular&y){
		return modular(x)+y;
	}
	friend modular operator-(ll x,const modular&y){
		return modular(x)-y;
	}
	friend modular operator*(ll x,const modular&y){
		return modular(x)*y;
	}
	friend modular operator/(ll x,const modular&y){
		return modular(x)/y;
	}
	friend ostream& operator<<(ostream&os,const modular&m){
		return os<<m.v;
	}
	friend istream& operator>>(istream&is,modular&m){
		ll x;is>>x;
		m=modular(x);
		return is;
	}
	bool operator<(const modular&r)const{return v<r.v;}
	bool operator==(const modular&r)const{return v==r.v;}
	bool operator!=(const modular&r)const{return v!=r.v;}
	explicit operator bool()const{
		return v;
	}
};

#ifndef DYNAMIC_MOD
extern constexpr modinfo base{998244353,3};
//extern constexpr modinfo base{1000000007,0};
//extern constexpr modinfo base{2147483579,1689685080};//2^31 未満の最大の安全素数
//modinfo base{1,0};
#ifdef USE_GOOD_MOD
static_assert(base.mod==998244353);
#endif
#else
modinfo base(1,0);
extern constexpr modinfo base107(1000000007,0);
using mint107=modular<base107>;
#endif
using mint=modular<base>;

mint parity(int i){
	return i%2==0?1:-1;
}

#ifdef LOCAL
const int vmax=10010;
#else
const int vmax=(1<<21)+10;
#endif
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
	const int s=min<int>(vmax,base.mod);
	fact[0]=1;
	rng(i,1,s){
		fact[i]=fact[i-1]*i;
	}
	finv[s-1]=fact[s-1].inv();
	for(int i=s-2;i>=0;i--){
		finv[i]=finv[i+1]*(i+1);
	}
	for(int i=s-1;i>=1;i--){
		invs[i]=finv[i]*fact[i-1];
	}
}
mint choose(int n,int k){
	return inc(0,k,n)?fact[n]*finv[n-k]*finv[k]:0;
}
mint binom(int a,int b){
	return 0<=a&&0<=b?fact[a+b]*finv[a]*finv[b]:0;
}
mint catalan(int n){
	return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}
//対角線を超えず (x,y) に至る方法の数
mint catalan(int x,int y){
	assert(y<=x);
	return binom(x,y)-binom(x+1,y-1);
}
//y=x+c を超えず (x,y) に至る方法の数
mint catalan(int x,int y,int c){
	assert(y<=x+c);
	return binom(x,y)-binom(x+c+1,y-c-1);
}

/*
const int vmax=610;
mint fact[vmax+1],binbuf[vmax+1][vmax+1];
mint choose(int n,int k){
	return 0<=k&&k<=n?binbuf[n-k][k]:0;
}
mint binom(int a,int b){
	return 0<=a&&0<=b?binbuf[a][b]:0;
}
void initfact(int n){
	fact[0]=1;
	rep(i,n)fact[i+1]=fact[i]*(i+1);
	rep(i,n+1)rep(j,n+1){
		if(i==0&&j==0){
			binbuf[i][j]=1;
		}else{
			binbuf[i][j]=0;
			if(i)binbuf[i][j]+=binbuf[i-1][j];
			if(j)binbuf[i][j]+=binbuf[i][j-1];
		}
	}
}
*/

mint p2[vmax],p2inv[vmax];
void initp2(){
	p2[0]=1;
	rep(i,vmax-1)p2[i+1]=p2[i]*2;
	p2inv[vmax-1]=p2[vmax-1].inv();
	per(i,vmax-1)p2inv[i]=p2inv[i+1]*2;
}

int m2i(mint a){
	uint v=a.v;
	return v<mint::mod/2?v:int(v)-int(mint::mod);
}

pi m2f(mint x){
	pi res(inf,inf);
	auto upd=[&](int a,int b){
		if(abs(res.a)+res.b>abs(a)+b){
			res=pi(a,b);
		}
	};
	rng(b,1,1000){
		mint y=x*b;
		upd(y.v,b);
		upd(-int((-y).v),b);
	}
	return res;
}

//https://codeforces.com/gym/421334/problem/A
template<int nmax>
struct permutation_basis{
	using A=array<int,nmax>;
	const int n;
	//(p[q[i]])
	void cp(int lv,const A&p,A&q){
		rng(i,lv,n)q[i]=p[i];
	}
	void cmp(int lv,const A&p,const A&q,A&r){
		rng(i,lv,n)r[i]=p[q[i]];
	}
	void inv(int lv,const A&p,A&q){
		rng(i,lv,n)q[p[i]]=i;
	}
	A tmp,tmp2;
	int cnt[2];
	A ls[2][nmax*nmax];
	A sbuf[2][nmax][nmax],sinvbuf[2][nmax][nmax];
	bool shas[2][nmax][nmax];
	void sclear(int lv){
		const int k=lv&1;
		cnt[k]=0;
		rng(i,lv,n)rng(j,i,n)shas[k][i][j]=false;
	}
	void sims(int lv,A&p){
		const int k=lv&1;
		rng(i,lv,n)if(p[i]!=i){
			auto&x=sbuf[k][i];
			auto&y=sinvbuf[k][i];
			auto&h=shas[k][i];
			if(h[p[i]]){
				cmp(i,y[p[i]],p,tmp);
				cp(i,tmp,p);
			}else{
				cp(i,p,x[p[i]]);
				inv(i,p,y[p[i]]);
				cp(lv,p,ls[k][cnt[k]++]);
				h[p[i]]=true;
				break;
			}
		}
	}
	A obuf[nmax][nmax],oinvbuf[nmax][nmax];
	bool ohas[nmax][nmax];
	//行列で言うところの基底が,順列の集合みたいになっている
	//lv 要素目の基底について
	//ohas[lv][v] x[lv]=v となる順列 x があるか?
	//obuf[lv][v] あるならその順列
	//oinvbuf[lv][v] ↑の inv
	permutation_basis(int nn,const vvc<int>&rw):n(nn),ohas{}{
		assert(inc(1,n,nmax));
		sclear(0);
		for(const auto&p:rw){
			rep(i,n)tmp2[i]=p[i];
			sims(0,tmp2);
		}
		rep(lv,n){
			const int k=lv&1;
			auto&x=obuf[lv];
			auto&y=oinvbuf[lv];
			auto&h=ohas[lv];
			{
				auto dfs=[&](auto self,int v)->void{
					assert(x[v][lv]==v);
					assert(h[v]);
					inv(lv,x[v],y[v]);
					rep(i,cnt[k]){
						const auto&p=ls[k][i];
						int to=p[v];
						if(!h[to]){
							cmp(lv,p,x[v],x[to]);
							h[to]=true;
							self(self,to);
						}
					}
				};
				rng(i,lv,n)x[lv][i]=i;
				h[lv]=true;
				dfs(dfs,lv);
			}
			if(lv+1<n){
				sclear(lv+1);
				rng(v,lv,n)if(h[v]){
					rep(i,cnt[k]){
						const auto&p=ls[k][i];
						cmp(lv,p,x[v],tmp);
						cmp(lv,y[p[v]],tmp,tmp2);
						sims(lv+1,tmp2);
					}
				}
			}
		}
	}
	template<class t>
	t cardinality(){
		t ans=1;
		rep(i,n){
			int num=0;
			rng(j,i,n)if(ohas[i][j])num++;
			ans*=num;
		}
		return ans;
	}
	mint ask(){
		VVC(mint,dp,n,n);
		rep(i,n)rng(j,i+1,n)dp[i][j]=1;
		VVC(mint,nx,n,n);
		rep(lv,n){
			rep(i,n)rep(j,n)nx[i][j]=0;
			rng(v,lv,n)if(ohas[lv][v]){
				rep(i,n)rep(j,n){
					int x=i,y=j;
					if(lv<=x)x=oinvbuf[lv][v][x];
					if(lv<=y)y=oinvbuf[lv][v][y];
					nx[x][y]+=dp[i][j];
				}
			}
			swap(dp,nx);
		}
		mint ans=0;
		rep(i,n)rep(j,i)ans+=dp[i][j];
		return ans;
	}
};

void slv(){
	INT(n,m);
	VVI(p,m,n);
	rep(i,m)rep(j,n)p[i][j]--;
	
	permutation_basis<30> z(n,p);
	
	print(z.ask());
}

signed main(signed argc,char*argv[]){
	if(argc>1&&strcmp(argv[1],"D")==0)dbg=true;
	
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	if(dbg){
		while(1){
			if(current_run_id%run_batch_size==0){
				cerr<<"Current Run "<<current_run_id<<endl;
			}
			slv();
			current_run_id++;
		}
	}else{
		//int t;cin>>t;rep(_,t)
		slv();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 45380kb

input:

3 2
1 2 3
2 3 1

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 4ms
memory: 45632kb

input:

5 2
3 4 5 1 2
1 5 4 3 2

output:

50

result:

ok 1 number(s): "50"

Test #3:

score: 0
Accepted
time: 39ms
memory: 45456kb

input:

30 12
1 2 9 4 5 6 7 8 3 10 11 12 19 14 15 25 17 18 20 26 21 22 23 24 16 29 27 28 13 30
9 2 27 4 5 10 7 8 1 25 11 12 24 14 15 16 17 18 19 20 21 22 23 28 6 26 3 13 29 30
1 5 3 29 2 6 7 8 9 10 11 12 13 16 15 18 17 14 19 20 21 22 28 27 25 26 24 23 4 30
7 2 3 25 5 6 1 28 21 15 11 12 13 14 10 17 16 18 19 ...

output:

701414999

result:

ok 1 number(s): "701414999"

Test #4:

score: 0
Accepted
time: 15ms
memory: 45692kb

input:

1 1
1

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 11ms
memory: 45604kb

input:

2 1
2 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 7ms
memory: 45600kb

input:

5 1
4 2 3 1 5

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 0
Accepted
time: 15ms
memory: 45332kb

input:

6 3
4 2 3 6 5 1
1 4 3 2 6 5
1 2 4 3 5 6

output:

5400

result:

ok 1 number(s): "5400"

Test #8:

score: 0
Accepted
time: 11ms
memory: 45676kb

input:

6 1
1 5 3 4 2 6

output:

5

result:

ok 1 number(s): "5"

Test #9:

score: 0
Accepted
time: 11ms
memory: 45444kb

input:

5 3
1 4 3 2 5
1 2 4 5 3
5 2 3 4 1

output:

600

result:

ok 1 number(s): "600"

Test #10:

score: 0
Accepted
time: 7ms
memory: 45380kb

input:

6 2
2 1 3 4 5 6
1 2 3 4 5 6

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 8ms
memory: 45380kb

input:

6 4
1 6 3 4 5 2
2 1 4 3 5 6
2 6 5 4 3 1
2 1 6 3 5 4

output:

5400

result:

ok 1 number(s): "5400"

Test #12:

score: 0
Accepted
time: 15ms
memory: 45400kb

input:

5 2
3 2 1 4 5
1 5 3 2 4

output:

21

result:

ok 1 number(s): "21"

Test #13:

score: 0
Accepted
time: 11ms
memory: 45676kb

input:

3 3
1 3 2
3 1 2
1 3 2

output:

9

result:

ok 1 number(s): "9"

Test #14:

score: 0
Accepted
time: 9ms
memory: 45404kb

input:

4 2
3 1 4 2
4 2 1 3

output:

72

result:

ok 1 number(s): "72"

Test #15:

score: 0
Accepted
time: 3ms
memory: 45400kb

input:

3 1
2 3 1

output:

4

result:

ok 1 number(s): "4"

Test #16:

score: 0
Accepted
time: 7ms
memory: 45464kb

input:

5 1
2 4 3 5 1

output:

18

result:

ok 1 number(s): "18"

Test #17:

score: 0
Accepted
time: 11ms
memory: 45332kb

input:

5 4
3 5 2 4 1
1 2 5 4 3
5 4 3 2 1
4 2 3 1 5

output:

600

result:

ok 1 number(s): "600"

Test #18:

score: 0
Accepted
time: 15ms
memory: 45448kb

input:

5 1
1 5 3 4 2

output:

5

result:

ok 1 number(s): "5"

Test #19:

score: 0
Accepted
time: 4ms
memory: 45680kb

input:

5 1
5 2 3 4 1

output:

7

result:

ok 1 number(s): "7"

Test #20:

score: 0
Accepted
time: 11ms
memory: 45628kb

input:

4 2
4 3 1 2
3 4 2 1

output:

12

result:

ok 1 number(s): "12"

Test #21:

score: 0
Accepted
time: 15ms
memory: 45436kb

input:

6 3
2 3 1 4 5 6
1 2 3 4 6 5
1 4 3 2 5 6

output:

168

result:

ok 1 number(s): "168"

Test #22:

score: 0
Accepted
time: 4ms
memory: 45460kb

input:

6 2
3 4 1 2 5 6
2 3 1 4 5 6

output:

36

result:

ok 1 number(s): "36"

Test #23:

score: 0
Accepted
time: 11ms
memory: 45604kb

input:

4 2
1 3 4 2
4 2 3 1

output:

72

result:

ok 1 number(s): "72"

Test #24:

score: 0
Accepted
time: 11ms
memory: 45332kb

input:

3 2
2 1 3
2 3 1

output:

9

result:

ok 1 number(s): "9"

Test #25:

score: 0
Accepted
time: 11ms
memory: 45380kb

input:

6 2
1 5 4 6 2 3
2 6 4 3 5 1

output:

5400

result:

ok 1 number(s): "5400"

Test #26:

score: 0
Accepted
time: 16ms
memory: 45376kb

input:

6 4
1 2 3 6 5 4
1 5 3 2 6 4
1 2 4 3 5 6
1 4 2 6 5 3

output:

600

result:

ok 1 number(s): "600"

Test #27:

score: 0
Accepted
time: 11ms
memory: 45464kb

input:

6 5
1 2 3 4 5 6
1 3 2 4 5 6
1 2 5 4 3 6
1 3 6 4 2 5
1 6 3 4 5 2

output:

120

result:

ok 1 number(s): "120"

Test #28:

score: 0
Accepted
time: 0ms
memory: 45444kb

input:

6 2
1 6 3 5 4 2
4 2 3 1 5 6

output:

84

result:

ok 1 number(s): "84"

Test #29:

score: 0
Accepted
time: 11ms
memory: 45368kb

input:

6 5
2 1 5 4 3 6
1 6 3 4 5 2
1 2 5 4 6 3
1 2 6 4 5 3
6 2 4 3 5 1

output:

5400

result:

ok 1 number(s): "5400"

Test #30:

score: 0
Accepted
time: 14ms
memory: 45380kb

input:

6 1
3 6 1 4 5 2

output:

8

result:

ok 1 number(s): "8"

Test #31:

score: 0
Accepted
time: 7ms
memory: 45400kb

input:

6 3
1 2 3 4 6 5
6 2 4 3 1 5
6 2 3 4 5 1

output:

72

result:

ok 1 number(s): "72"

Test #32:

score: 0
Accepted
time: 11ms
memory: 45460kb

input:

6 4
1 2 3 6 5 4
6 2 3 4 5 1
6 1 3 4 5 2
1 5 6 4 2 3

output:

5400

result:

ok 1 number(s): "5400"

Test #33:

score: 0
Accepted
time: 11ms
memory: 45424kb

input:

6 3
1 2 6 4 5 3
2 1 3 4 5 6
1 5 3 4 2 6

output:

72

result:

ok 1 number(s): "72"

Test #34:

score: 0
Accepted
time: 12ms
memory: 45396kb

input:

6 5
3 2 6 4 5 1
1 4 3 6 5 2
1 2 4 3 5 6
1 2 4 3 5 6
4 2 1 5 3 6

output:

5400

result:

ok 1 number(s): "5400"

Test #35:

score: 0
Accepted
time: 14ms
memory: 45460kb

input:

6 6
1 5 3 4 2 6
2 6 3 4 5 1
2 6 3 5 4 1
2 1 3 4 5 6
6 2 1 4 5 3
1 5 4 3 2 6

output:

5400

result:

ok 1 number(s): "5400"

Test #36:

score: 0
Accepted
time: 3ms
memory: 45376kb

input:

6 30
5 2 6 4 1 3
1 3 5 2 4 6
1 6 3 4 5 2
6 5 3 4 2 1
1 4 3 2 5 6
4 2 6 1 3 5
3 2 6 4 5 1
6 2 3 4 5 1
6 1 3 5 4 2
4 5 3 1 2 6
2 6 1 4 5 3
1 2 3 6 5 4
1 2 6 4 5 3
6 2 3 4 5 1
2 5 3 4 1 6
1 2 3 5 4 6
1 6 4 5 3 2
1 4 3 5 2 6
1 2 4 3 5 6
1 2 3 4 5 6
3 1 2 4 5 6
1 3 6 4 2 5
1 2 3 4 5 6
1 3 2 4 5 6
1 3 5 4...

output:

5400

result:

ok 1 number(s): "5400"

Test #37:

score: 0
Accepted
time: 15ms
memory: 45380kb

input:

6 30
1 5 3 4 2 6
1 4 5 2 3 6
3 5 2 4 1 6
1 6 3 2 4 5
6 3 4 2 5 1
6 2 3 4 5 1
1 2 6 4 5 3
1 5 3 4 2 6
1 2 4 6 5 3
1 5 3 6 2 4
4 2 6 1 5 3
1 4 3 2 5 6
1 2 6 4 5 3
2 6 3 4 5 1
4 2 3 1 5 6
1 2 3 4 5 6
1 2 4 3 5 6
1 3 2 5 4 6
1 2 3 4 5 6
5 2 3 4 1 6
6 2 1 4 5 3
4 2 3 1 5 6
2 5 3 4 1 6
4 2 3 1 5 6
4 2 3 5...

output:

5400

result:

ok 1 number(s): "5400"

Test #38:

score: 0
Accepted
time: 4ms
memory: 45464kb

input:

6 30
1 5 3 4 6 2
1 3 4 5 2 6
1 4 3 2 5 6
1 3 4 2 5 6
1 6 5 2 3 4
1 2 3 5 4 6
2 1 3 6 5 4
5 1 2 4 3 6
3 2 5 1 4 6
1 3 2 4 5 6
2 1 3 4 5 6
1 3 2 4 5 6
1 4 5 6 3 2
2 1 3 4 5 6
1 3 5 4 6 2
2 1 3 4 5 6
5 6 3 4 1 2
3 4 1 2 5 6
1 6 3 4 5 2
3 1 6 4 5 2
1 2 6 3 5 4
3 4 1 2 5 6
4 2 3 1 5 6
1 2 3 4 5 6
1 2 3 6...

output:

5400

result:

ok 1 number(s): "5400"

Test #39:

score: 0
Accepted
time: 18ms
memory: 45660kb

input:

6 30
6 2 4 3 5 1
4 2 3 1 5 6
6 2 3 4 5 1
3 2 4 6 5 1
5 3 6 4 1 2
1 2 3 5 4 6
1 2 4 3 5 6
5 6 3 2 1 4
2 1 3 4 6 5
1 2 3 5 4 6
1 2 5 4 3 6
4 2 5 1 3 6
4 2 3 5 1 6
1 2 3 5 4 6
1 6 3 5 4 2
6 2 3 4 5 1
6 5 3 4 2 1
5 6 4 3 1 2
1 6 5 4 3 2
2 3 1 4 5 6
1 2 3 5 4 6
1 4 6 2 5 3
1 4 3 5 2 6
1 6 4 3 5 2
1 6 3 4...

output:

5400

result:

ok 1 number(s): "5400"

Test #40:

score: 0
Accepted
time: 13ms
memory: 45660kb

input:

6 30
1 6 3 4 2 5
1 2 3 4 6 5
6 2 5 4 1 3
1 2 5 4 3 6
6 2 5 4 3 1
1 6 3 4 5 2
1 6 2 4 5 3
2 1 3 4 5 6
1 2 3 4 5 6
1 4 3 2 5 6
5 2 3 4 1 6
1 4 5 2 3 6
6 2 1 4 5 3
1 5 3 4 2 6
2 1 6 4 5 3
1 3 2 4 6 5
5 1 3 4 2 6
3 2 4 1 5 6
1 3 6 2 5 4
2 5 3 4 1 6
1 2 3 5 4 6
1 2 5 4 3 6
1 2 6 4 5 3
2 4 6 1 5 3
5 2 3 6...

output:

5400

result:

ok 1 number(s): "5400"

Test #41:

score: 0
Accepted
time: 7ms
memory: 45472kb

input:

6 30
1 3 2 5 4 6
4 2 6 1 5 3
1 2 4 6 5 3
4 2 3 1 6 5
1 6 3 4 2 5
3 4 1 2 5 6
1 5 3 2 4 6
3 2 5 4 1 6
1 2 3 4 5 6
1 6 3 4 2 5
4 2 6 1 5 3
4 1 3 2 5 6
4 2 5 1 3 6
1 6 3 2 5 4
4 5 3 1 2 6
5 2 3 1 4 6
3 1 2 4 5 6
1 6 2 4 5 3
3 2 6 4 5 1
4 2 3 6 5 1
1 2 3 5 6 4
1 2 3 4 5 6
1 2 3 4 5 6
3 2 5 4 1 6
1 2 3 4...

output:

2700

result:

ok 1 number(s): "2700"

Test #42:

score: 0
Accepted
time: 11ms
memory: 45628kb

input:

6 30
2 4 3 1 5 6
2 4 3 1 5 6
2 5 3 4 1 6
3 5 1 4 2 6
1 2 3 5 6 4
1 3 6 4 5 2
1 4 5 2 3 6
1 2 3 5 6 4
1 4 3 5 2 6
2 3 1 4 5 6
3 2 1 6 5 4
3 2 1 5 4 6
6 1 3 4 5 2
3 2 6 4 5 1
1 2 6 3 5 4
1 5 3 2 4 6
5 1 3 4 2 6
3 1 2 4 5 6
3 4 1 2 5 6
1 4 3 5 2 6
4 2 3 6 5 1
5 1 3 4 2 6
1 5 3 2 4 6
4 3 2 1 5 6
2 3 1 4...

output:

2700

result:

ok 1 number(s): "2700"

Test #43:

score: 0
Accepted
time: 7ms
memory: 45596kb

input:

6 30
6 2 3 5 4 1
1 3 4 2 5 6
1 3 6 4 5 2
5 2 3 6 1 4
3 5 1 4 2 6
3 1 2 4 5 6
1 2 4 3 6 5
1 6 3 2 5 4
3 2 5 4 1 6
4 6 3 1 5 2
4 2 3 5 1 6
1 2 5 3 4 6
2 3 1 4 5 6
1 2 6 3 5 4
2 4 3 1 5 6
1 2 3 4 5 6
3 2 4 1 5 6
4 2 3 1 6 5
5 2 3 6 1 4
1 6 3 4 2 5
1 3 5 4 2 6
6 2 3 4 1 5
3 2 6 4 5 1
5 2 4 3 1 6
1 3 6 4...

output:

2700

result:

ok 1 number(s): "2700"

Test #44:

score: 0
Accepted
time: 7ms
memory: 45680kb

input:

6 30
1 2 3 4 5 6
5 2 1 4 3 6
1 3 5 4 2 6
1 2 4 5 3 6
6 1 3 4 5 2
1 2 3 4 5 6
1 5 4 3 2 6
1 5 3 2 4 6
2 1 3 4 6 5
6 2 3 4 1 5
1 2 5 3 4 6
1 3 2 4 6 5
1 3 2 4 6 5
3 2 1 6 5 4
2 5 3 4 1 6
1 6 2 4 5 3
1 4 3 2 6 5
1 2 3 4 5 6
6 2 3 1 5 4
4 2 1 3 5 6
1 3 6 4 5 2
2 4 3 1 5 6
5 2 6 4 1 3
1 2 6 4 3 5
3 4 1 2...

output:

2700

result:

ok 1 number(s): "2700"

Test #45:

score: 0
Accepted
time: 15ms
memory: 45444kb

input:

6 30
1 4 3 2 6 5
2 1 4 3 5 6
1 4 3 5 2 6
1 3 4 2 5 6
1 3 5 4 2 6
4 1 3 2 5 6
1 6 4 3 5 2
4 2 6 1 5 3
4 1 3 2 5 6
3 1 2 4 5 6
5 3 2 4 1 6
1 6 3 2 5 4
1 5 2 4 3 6
1 6 3 5 4 2
3 1 2 4 5 6
1 3 4 2 5 6
1 2 5 3 4 6
1 2 3 4 5 6
3 2 5 4 1 6
2 1 3 5 4 6
4 6 3 1 5 2
2 3 1 4 5 6
5 2 1 4 3 6
1 2 5 3 4 6
1 4 6 2...

output:

2700

result:

ok 1 number(s): "2700"

Test #46:

score: 0
Accepted
time: 14ms
memory: 45448kb

input:

17 2
1 2 3 4 5 6 7 8 9 10 15 12 13 14 11 16 17
12 2 3 4 5 6 7 8 9 10 11 1 13 14 15 16 17

output:

54

result:

ok 1 number(s): "54"

Test #47:

score: 0
Accepted
time: 11ms
memory: 45400kb

input:

23 2
6 2 3 4 5 1 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
1 20 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 21 22 23

output:

86

result:

ok 1 number(s): "86"

Test #48:

score: 0
Accepted
time: 15ms
memory: 45456kb

input:

29 1
1 2 3 4 5 6 7 8 9 12 15 10 13 14 11 16 17 18 19 20 21 22 23 24 25 26 27 28 29

output:

8

result:

ok 1 number(s): "8"

Test #49:

score: 0
Accepted
time: 7ms
memory: 45376kb

input:

14 4
1 2 3 4 5 6 13 9 8 10 11 12 7 14
1 8 3 4 5 6 10 2 9 7 11 12 13 14
1 2 3 4 5 9 7 8 6 10 11 12 13 14
1 2 3 4 5 7 6 8 9 10 13 12 11 14

output:

846720

result:

ok 1 number(s): "846720"

Test #50:

score: 0
Accepted
time: 15ms
memory: 45440kb

input:

4 3
2 1 3 4
4 2 1 3
3 2 1 4

output:

72

result:

ok 1 number(s): "72"

Test #51:

score: 0
Accepted
time: 14ms
memory: 45388kb

input:

17 4
4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17
8 2 10 4 5 6 7 3 9 1 11 12 13 14 15 16 17
1 2 3 4 8 6 7 5 9 16 11 12 13 14 15 10 17
1 2 3 4 5 6 7 16 9 10 17 12 13 14 15 8 11

output:

1249920

result:

ok 1 number(s): "1249920"

Test #52:

score: 0
Accepted
time: 11ms
memory: 45404kb

input:

16 4
1 14 3 2 5 6 7 8 9 10 11 12 13 4 15 16
1 2 9 4 5 6 7 8 3 10 11 12 13 14 15 16
9 2 3 4 5 6 7 8 10 1 11 12 15 14 13 16
1 2 3 4 5 6 7 11 9 10 8 12 13 14 15 16

output:

8592

result:

ok 1 number(s): "8592"

Test #53:

score: 0
Accepted
time: 11ms
memory: 45680kb

input:

12 2
9 2 3 4 1 6 7 8 5 10 11 12
1 2 3 5 7 6 8 4 9 10 11 12

output:

9960

result:

ok 1 number(s): "9960"

Test #54:

score: 0
Accepted
time: 9ms
memory: 45448kb

input:

19 3
1 2 3 4 5 6 7 8 9 10 15 12 13 14 11 16 17 18 19
1 6 8 4 5 19 7 3 9 10 11 12 13 14 15 16 17 18 2
1 2 3 4 5 6 7 8 9 10 16 12 13 14 15 11 17 18 19

output:

1104

result:

ok 1 number(s): "1104"

Test #55:

score: 0
Accepted
time: 7ms
memory: 45440kb

input:

6 4
1 4 3 2 5 6
1 2 3 5 4 6
5 2 3 6 1 4
1 2 6 3 4 5

output:

5400

result:

ok 1 number(s): "5400"

Test #56:

score: 0
Accepted
time: 14ms
memory: 45404kb

input:

28 4
1 2 3 4 13 6 7 8 9 10 11 12 5 14 15 16 17 18 19 20 21 22 23 26 25 24 27 28
1 2 13 4 5 6 7 8 9 10 11 12 3 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
1 2 9 4 5 6 22 8 3 10 11 12 13 14 15 16 17 18 19 20 21 7 23 24 25 26 27 28
1 2 3 4 5 6 7 8 9 10 11 12 18 14 15 16 17 13 19 20 21 22 23 24 25 26 2...

output:

20256

result:

ok 1 number(s): "20256"

Test #57:

score: 0
Accepted
time: 11ms
memory: 45464kb

input:

23 2
1 2 3 4 5 6 7 8 9 10 17 12 21 14 15 16 11 18 19 20 13 22 23
1 14 3 4 5 6 12 8 9 10 11 7 13 2 15 16 17 19 18 20 21 22 23

output:

108

result:

ok 1 number(s): "108"

Test #58:

score: 0
Accepted
time: 7ms
memory: 45456kb

input:

30 1
1 2 3 18 5 6 7 8 9 10 11 12 13 28 15 16 17 4 19 20 21 22 23 24 25 26 27 14 29 30

output:

52

result:

ok 1 number(s): "52"

Test #59:

score: 0
Accepted
time: 15ms
memory: 45440kb

input:

26 4
1 2 3 4 5 6 7 8 9 10 25 22 13 14 15 16 17 18 19 20 21 12 23 24 11 26
2 1 3 4 5 6 7 8 9 16 11 12 13 17 15 10 14 18 19 20 21 22 23 24 25 26
1 2 22 4 15 6 7 8 9 10 11 12 13 14 5 16 17 18 19 20 21 3 23 24 25 26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 26 24 25 23

output:

2528

result:

ok 1 number(s): "2528"

Test #60:

score: 0
Accepted
time: 14ms
memory: 45468kb

input:

15 1
1 2 3 4 5 6 13 9 8 10 11 12 7 15 14

output:

13

result:

ok 1 number(s): "13"

Test #61:

score: 0
Accepted
time: 3ms
memory: 45376kb

input:

25 1
1 2 3 4 5 6 7 8 9 25 11 12 13 14 15 16 17 18 19 20 21 22 23 24 10

output:

29

result:

ok 1 number(s): "29"

Test #62:

score: 0
Accepted
time: 16ms
memory: 45680kb

input:

15 3
1 14 3 4 5 6 7 8 9 10 11 15 13 12 2
8 2 3 4 5 13 7 1 9 10 11 12 6 14 15
1 2 3 4 5 15 7 8 9 10 11 12 14 13 6

output:

2976

result:

ok 1 number(s): "2976"

Test #63:

score: 0
Accepted
time: 7ms
memory: 45400kb

input:

20 4
1 2 6 4 5 3 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 14 9 10 11 12 13 8 15 16 17 18 19 20
1 2 9 4 5 6 7 8 3 10 13 12 11 14 15 16 17 18 19 20
1 2 20 4 12 5 7 8 9 10 11 6 13 14 15 16 17 18 19 3

output:

106560

result:

ok 1 number(s): "106560"

Test #64:

score: 0
Accepted
time: 11ms
memory: 45388kb

input:

26 2
1 2 3 4 15 7 6 8 9 10 11 12 13 14 5 16 17 18 19 20 21 22 23 24 25 26
26 2 3 4 25 6 7 8 9 10 11 12 13 24 15 16 17 18 19 20 21 22 23 14 5 1

output:

712

result:

ok 1 number(s): "712"

Test #65:

score: 0
Accepted
time: 8ms
memory: 45408kb

input:

20 4
1 2 3 4 17 9 7 8 6 10 11 12 13 14 15 16 5 20 19 18
1 2 3 4 5 6 7 13 9 10 11 12 8 14 15 16 17 18 19 20
3 9 1 4 5 6 7 8 2 15 11 12 13 14 10 16 17 18 19 20
1 2 19 4 5 6 7 17 9 10 11 12 13 14 15 16 8 18 3 20

output:

89040

result:

ok 1 number(s): "89040"

Test #66:

score: 0
Accepted
time: 4ms
memory: 45612kb

input:

30 5
1 2 3 4 23 9 7 8 6 10 11 12 13 14 15 16 17 18 19 20 22 21 5 24 25 26 27 28 29 30
1 2 3 4 5 6 7 14 9 10 11 12 13 8 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 29 15 14 17 18 19 20 21 22 23 24 25 28 27 26 16 30
1 2 3 4 5 6 7 8 9 10 11 12 15 14 13 16 17 18 19 20 2...

output:

65472

result:

ok 1 number(s): "65472"

Test #67:

score: 0
Accepted
time: 7ms
memory: 45452kb

input:

30 6
1 2 3 4 5 6 7 29 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 8 30
8 2 14 4 5 6 7 1 9 10 11 12 13 3 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 24 21 22 23 20 29 26 27 28 25 30
1 2 3 4 5 14 7 8 9 10 11 12 13 6 15 16 17 18 19 20 2...

output:

175104

result:

ok 1 number(s): "175104"

Test #68:

score: 0
Accepted
time: 7ms
memory: 45460kb

input:

30 5
1 2 3 4 5 6 7 8 9 14 11 12 13 10 15 16 17 18 30 20 21 22 23 24 25 26 27 28 29 19
1 7 3 4 5 6 2 15 9 10 11 12 13 14 28 16 17 18 19 20 21 22 23 24 25 26 27 8 29 30
19 2 3 4 5 6 7 8 24 10 11 12 13 14 15 16 17 18 1 20 21 22 23 9 25 26 27 28 29 30
1 2 3 4 29 6 7 8 9 10 11 30 13 14 15 16 17 18 19 20 ...

output:

653376

result:

ok 1 number(s): "653376"

Test #69:

score: 0
Accepted
time: 11ms
memory: 45644kb

input:

30 4
1 2 18 4 5 28 7 8 9 10 11 12 23 14 15 16 17 3 19 20 21 22 13 24 25 26 27 6 29 30
1 2 11 4 5 6 7 30 9 10 3 12 16 14 15 13 17 18 19 20 21 22 23 24 25 26 27 28 29 8
1 2 3 4 5 6 7 8 9 10 11 12 27 14 21 16 17 18 19 20 15 22 23 24 25 26 13 28 29 30
1 2 3 4 5 6 7 8 9 30 11 12 13 14 15 16 27 18 19 20 2...

output:

2538432

result:

ok 1 number(s): "2538432"

Test #70:

score: 0
Accepted
time: 18ms
memory: 45408kb

input:

30 3
1 22 7 4 5 6 3 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 23 24 25 26 27 28 29 30
1 2 21 4 9 6 7 8 5 10 11 12 13 14 15 16 17 18 19 20 3 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 29 19 20 21 22 23 24 25 26 27 28 18 30

output:

5448

result:

ok 1 number(s): "5448"

Test #71:

score: 0
Accepted
time: 11ms
memory: 45408kb

input:

30 5
1 2 3 22 5 6 7 8 9 10 11 15 13 14 12 16 17 18 19 20 21 4 23 24 25 26 27 28 29 30
1 2 3 4 18 6 7 8 9 10 11 12 13 14 15 16 17 5 19 20 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 28 19 20 21 22 23 24 25 26 27 18 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 22 15 16 17 18 19 20 2...

output:

482112

result:

ok 1 number(s): "482112"

Test #72:

score: 0
Accepted
time: 11ms
memory: 45412kb

input:

30 1
19 2 3 30 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 20 21 22 23 24 25 4 27 28 29 26

output:

301

result:

ok 1 number(s): "301"

Test #73:

score: 0
Accepted
time: 15ms
memory: 45472kb

input:

30 4
1 2 3 4 5 6 7 8 9 10 11 12 13 28 20 16 17 18 19 15 21 22 23 24 25 26 27 14 29 30
1 2 3 4 5 6 7 8 9 10 26 12 13 14 15 16 17 18 19 20 21 22 27 24 25 11 23 28 29 30
1 25 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20 21 22 23 24 11 26 27 28 29 30
1 2 18 4 5 6 29 8 9 10 11 12 13 14 15 16 17 3 19 20 ...

output:

8928

result:

ok 1 number(s): "8928"

Test #74:

score: 0
Accepted
time: 4ms
memory: 45640kb

input:

30 4
1 30 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 2
1 2 3 4 5 6 7 11 23 22 8 12 13 14 15 16 17 18 19 20 21 10 9 24 25 26 27 28 29 30
1 2 4 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20 2...

output:

1460

result:

ok 1 number(s): "1460"

Test #75:

score: 0
Accepted
time: 15ms
memory: 45464kb

input:

30 3
1 10 3 4 5 6 7 8 9 2 11 12 13 14 26 16 17 18 19 20 21 22 30 24 25 15 27 28 29 23
1 2 3 4 6 5 7 8 9 10 11 12 13 25 15 16 17 18 19 20 21 22 23 24 14 26 27 28 29 30
1 2 3 4 5 7 6 8 9 10 22 12 11 14 15 16 17 18 19 20 21 13 23 24 25 26 27 28 29 30

output:

3348

result:

ok 1 number(s): "3348"

Test #76:

score: 0
Accepted
time: 11ms
memory: 45452kb

input:

30 1
2 1 3 4 5 10 27 8 7 6 22 23 13 14 15 16 17 9 18 12 21 20 11 24 25 26 19 28 29 30

output:

596

result:

ok 1 number(s): "596"

Test #77:

score: 0
Accepted
time: 15ms
memory: 45452kb

input:

30 2
1 2 17 4 29 24 16 13 9 10 11 12 8 14 15 5 3 18 19 22 21 27 26 23 25 6 28 20 7 30
1 16 3 12 5 26 7 8 14 9 11 15 21 30 4 10 17 18 19 2 13 20 23 24 25 6 27 28 29 22

output:

35632939

result:

ok 1 number(s): "35632939"

Test #78:

score: 0
Accepted
time: 31ms
memory: 45452kb

input:

30 6
29 12 2 20 11 9 24 25 6 22 5 30 21 14 15 23 17 16 19 18 13 10 4 8 3 26 27 28 1 7
1 8 3 22 16 6 15 20 9 14 11 28 13 10 19 26 27 2 7 5 21 4 23 24 25 12 29 18 17 30
1 28 4 2 5 6 19 8 14 10 17 12 13 3 15 16 7 29 30 20 21 22 18 9 25 27 23 24 11 26
1 2 3 4 6 25 7 12 9 8 11 23 13 18 15 17 16 10 19 20 ...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #79:

score: 0
Accepted
time: 19ms
memory: 45404kb

input:

30 1
28 5 16 29 2 6 18 7 15 10 1 12 13 22 25 3 4 20 19 24 21 26 23 27 9 14 8 11 17 30

output:

827

result:

ok 1 number(s): "827"

Test #80:

score: 0
Accepted
time: 33ms
memory: 45340kb

input:

30 5
23 7 3 14 5 6 8 22 15 20 24 12 16 2 26 4 11 18 1 10 21 13 19 17 9 28 27 25 29 30
1 8 15 2 3 6 14 20 24 10 27 12 13 4 11 16 22 18 19 21 23 17 7 9 25 26 5 28 29 30
1 28 19 4 29 6 7 8 9 10 11 12 21 14 15 16 20 30 3 13 18 22 23 27 2 26 24 25 5 17
1 2 8 4 18 11 7 3 20 28 15 6 13 29 17 16 12 19 5 9 2...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #81:

score: 0
Accepted
time: 39ms
memory: 45684kb

input:

30 6
1 5 14 29 2 6 12 16 24 10 11 15 7 3 13 9 20 18 19 17 21 22 23 8 25 26 27 28 4 30
21 11 3 4 5 1 14 8 29 7 27 12 13 18 15 10 17 30 19 20 6 22 23 24 28 26 9 25 16 2
1 2 7 26 5 4 12 3 9 10 18 8 14 17 29 16 20 24 19 30 21 22 23 11 25 6 27 28 15 13
12 3 18 29 1 6 23 28 30 10 5 11 13 14 15 17 4 16 9 2...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #82:

score: 0
Accepted
time: 17ms
memory: 45612kb

input:

30 3
1 2 18 4 5 15 6 23 9 10 13 12 14 25 27 8 11 3 19 28 21 22 17 24 16 26 7 20 29 30
2 17 3 4 28 18 26 8 9 10 29 12 7 14 5 15 20 23 19 24 21 6 1 13 25 22 27 16 11 30
4 2 14 26 5 6 22 8 9 10 21 12 1 18 15 16 23 7 19 17 11 13 24 30 25 3 27 28 29 20

output:

546259602

result:

ok 1 number(s): "546259602"

Test #83:

score: 0
Accepted
time: 0ms
memory: 45392kb

input:

30 1
1 12 3 15 21 20 7 8 9 17 28 2 30 14 4 27 5 18 13 29 10 19 23 24 25 26 16 11 6 22

output:

1246

result:

ok 1 number(s): "1246"

Test #84:

score: 0
Accepted
time: 27ms
memory: 45408kb

input:

30 4
1 2 3 26 21 6 9 25 7 10 22 8 13 14 15 16 17 5 23 20 18 11 19 12 24 4 27 28 29 30
5 28 3 23 25 6 1 14 9 10 11 12 24 8 15 16 17 18 19 20 7 22 4 13 21 30 26 2 29 27
1 10 30 21 23 6 7 11 9 22 5 12 4 14 2 8 20 19 16 27 13 28 24 3 25 26 17 15 29 18
19 24 10 12 2 23 7 9 6 3 17 16 18 13 15 4 22 14 27 2...

output:

738501311

result:

ok 1 number(s): "738501311"

Test #85:

score: 0
Accepted
time: 19ms
memory: 45344kb

input:

30 4
1 30 3 19 6 5 7 15 22 11 4 12 21 14 2 16 20 18 10 17 8 13 23 29 24 26 27 28 25 9
8 6 24 29 5 2 4 15 10 7 11 18 17 14 1 22 28 12 19 20 9 16 23 3 25 26 27 13 21 30
7 3 28 4 5 6 1 8 12 11 14 9 13 23 15 16 17 18 19 2 22 24 10 21 25 26 27 20 29 30
24 28 3 9 5 15 10 30 8 18 11 12 13 17 16 7 14 29 19 ...

output:

968567468

result:

ok 1 number(s): "968567468"

Test #86:

score: 0
Accepted
time: 14ms
memory: 45400kb

input:

30 1
1 2 3 13 7 21 14 5 18 10 11 8 4 25 24 16 17 6 19 20 9 22 23 15 12 26 27 28 29 30

output:

842

result:

ok 1 number(s): "842"

Test #87:

score: 0
Accepted
time: 30ms
memory: 45452kb

input:

30 5
1 8 3 4 5 6 7 2 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 17 23 4 27 6 11 8 2 10 29 7 13 3 5 20 25 18 19 12 21 22 26 24 14 16 9 15 28 30
12 2 14 28 22 25 7 9 8 10 11 29 13 26 15 16 17 23 19 20 1 5 18 24 6 30 27 4 21 3
8 2 28 19 13 6 9 4 25 10 23 12 22 14 15 5 27 18 21 2...

output:

252043928

result:

ok 1 number(s): "252043928"

Test #88:

score: 0
Accepted
time: 11ms
memory: 45612kb

input:

30 1
14 13 2 4 3 8 18 12 26 7 21 30 23 9 15 19 25 6 16 5 22 17 27 24 1 10 20 28 29 11

output:

19432

result:

ok 1 number(s): "19432"

Test #89:

score: 0
Accepted
time: 38ms
memory: 45680kb

input:

30 2
18 16 11 17 28 13 24 26 10 6 29 1 2 23 25 20 15 8 19 4 14 5 21 7 3 30 12 9 22 27
5 2 20 4 21 14 22 26 8 17 19 18 27 12 15 16 11 30 10 25 9 3 7 1 28 23 13 24 29 6

output:

404585645

result:

ok 1 number(s): "404585645"

Test #90:

score: 0
Accepted
time: 23ms
memory: 45468kb

input:

30 5
1 26 14 10 5 18 11 8 28 23 7 12 13 15 3 2 17 21 6 24 20 22 4 27 25 16 19 29 9 30
21 13 2 27 8 14 19 30 15 11 9 23 12 16 24 4 7 25 20 22 1 29 5 17 26 3 10 18 28 6
1 17 3 4 12 6 23 8 9 10 20 2 30 14 22 16 29 18 19 11 21 15 25 27 5 26 13 28 7 24
9 2 3 4 5 6 7 12 17 10 21 20 24 1 15 19 14 18 8 16 1...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #91:

score: 0
Accepted
time: 8ms
memory: 45388kb

input:

30 2
1 11 10 20 30 5 7 8 25 3 27 28 17 14 22 16 13 18 19 9 23 15 21 24 4 26 2 12 29 6
1 2 7 4 21 6 29 8 9 30 17 12 13 14 18 16 28 10 19 20 23 22 3 24 25 26 27 5 15 11

output:

547624285

result:

ok 1 number(s): "547624285"

Test #92:

score: 0
Accepted
time: 7ms
memory: 45684kb

input:

30 1
1 20 12 4 25 30 11 16 9 8 29 3 13 24 15 14 17 23 19 2 21 18 7 10 5 26 27 28 22 6

output:

3823

result:

ok 1 number(s): "3823"

Test #93:

score: 0
Accepted
time: 14ms
memory: 45324kb

input:

30 2
2 12 3 11 9 19 20 6 14 10 4 1 13 5 25 7 17 18 15 16 21 22 23 24 30 26 8 28 29 27
18 2 10 4 29 15 7 6 30 22 11 12 13 14 27 16 9 3 19 20 21 17 23 24 25 26 8 28 5 1

output:

784118547

result:

ok 1 number(s): "784118547"

Test #94:

score: 0
Accepted
time: 38ms
memory: 45480kb

input:

30 5
1 20 10 21 15 3 7 13 29 6 11 12 22 14 4 16 18 26 19 2 30 8 17 24 25 9 27 28 23 5
9 16 18 30 5 19 11 12 15 13 14 27 22 23 20 1 6 21 4 3 7 25 17 2 10 26 24 29 8 28
12 29 8 30 27 18 15 13 6 7 28 26 20 9 11 25 19 4 2 17 24 5 23 3 21 10 14 1 16 22
3 2 5 25 13 6 7 30 9 10 28 12 29 14 15 16 17 18 8 20...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #95:

score: 0
Accepted
time: 27ms
memory: 45408kb

input:

30 6
4 2 9 16 5 30 1 25 15 6 14 3 13 8 27 11 19 26 12 20 7 18 23 24 10 21 22 28 29 17
1 2 18 3 25 5 7 19 9 27 8 12 13 14 15 16 17 4 20 11 21 22 23 10 26 30 6 28 29 24
7 2 28 1 21 5 15 24 11 10 25 3 4 14 18 9 8 6 19 23 26 17 27 13 22 29 30 20 12 16
30 2 21 4 26 17 29 27 9 6 11 12 1 22 13 16 24 23 20 ...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #96:

score: 0
Accepted
time: 39ms
memory: 45392kb

input:

30 30
1 2 3 4 5 6 10 8 9 7 11 12 13 14 15 16 17 18 19 29 21 22 23 24 25 26 27 28 20 30
1 23 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 2 19 20 21 22 18 24 25 26 27 28 29 30
1 2 3 4 5 6 7 13 9 10 11 12 8 14 19 16 17 18 15 20 21 22 27 24 25 26 23 28 29 30
1 12 3 4 5 6 7 8 9 10 23 2 13 14 15 16 17 18 19 20 ...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #97:

score: 0
Accepted
time: 33ms
memory: 45672kb

input:

30 30
1 5 3 4 2 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 25 28 26 27 24 29 30
1 2 3 4 5 6 7 8 24 10 11 9 13 14 15 16 17 18 19 20 21 22 23 12 25 26 27 28 29 30
1 2 14 4 5 6 7 8 9 10 11 12 13 3 15 16 17 18 19 20 29 22 23 24 25 26 27 28 21 30
1 8 3 4 5 6 7 2 9 10 11 12 13 14 15 16 23 18 19 20 ...

output:

264178870

result:

ok 1 number(s): "264178870"

Test #98:

score: 0
Accepted
time: 36ms
memory: 45408kb

input:

30 30
1 2 3 4 5 6 11 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 25 18 19 20 21 22 23 24 17 26 27 28 29 30
1 2 3 4 5 12 7 22 29 10 11 6 13 14 15 16 17 18 19 20 21 8 23 24 25 26 27 28 9 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 16 26 19 23 ...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #99:

score: 0
Accepted
time: 29ms
memory: 45676kb

input:

30 30
1 2 3 4 5 6 24 8 12 10 11 9 13 14 15 16 17 18 19 20 21 22 23 7 25 26 27 28 29 30
1 2 27 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 25 21 22 23 24 20 26 3 28 29 30
16 11 19 4 5 6 7 8 9 10 2 12 13 14 15 1 17 18 3 20 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 29 12 11 13 14 15 16 17 18 19 20 ...

output:

355190935

result:

ok 1 number(s): "355190935"

Test #100:

score: 0
Accepted
time: 33ms
memory: 45676kb

input:

30 30
1 2 22 4 5 6 7 30 9 10 11 12 13 14 15 16 17 18 19 20 21 3 23 24 25 26 27 28 29 8
1 2 3 4 5 6 7 8 9 20 11 12 13 14 15 10 17 18 19 16 21 22 23 24 25 26 27 28 29 30
1 2 27 4 22 6 11 8 9 10 7 12 13 14 15 16 17 18 19 20 21 5 23 24 25 26 3 28 29 30
1 2 3 4 5 6 7 8 9 10 11 18 13 14 15 23 17 12 19 20 ...

output:

404585645

result:

ok 1 number(s): "404585645"

Test #101:

score: 0
Accepted
time: 32ms
memory: 45476kb

input:

30 30
1 2 3 6 5 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 28 24 25 26 27 23 29 30
1 27 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 21 20 19 22 23 24 25 26 2 28 29 30
1 2 3 4 5 26 7 8 9 10 11 12 13 14 15 16 21 18 19 20 17 22 23 24 25 6 27 28 29 30
1 2 3 4 5 6 7 8 29 10 11 30 13 14 15 16 17 18 19 20...

output:

113887022

result:

ok 1 number(s): "113887022"

Test #102:

score: 0
Accepted
time: 30ms
memory: 45672kb

input:

30 30
21 2 3 4 5 6 7 8 9 10 25 12 13 14 15 16 17 18 19 20 1 22 23 24 11 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 27 18 19 20 21 22 23 24 25 26 29 28 17 30
1 2 3 4 5 6 7 8 9 10 25 12 13 14 15 16 17 18 19 20 21 22 23 24 11 26 27 29 28 30
1 2 3 4 5 6 28 8 9 14 11 12 13 10 15 16 17 18 19 20...

output:

701414999

result:

ok 1 number(s): "701414999"

Test #103:

score: 0
Accepted
time: 31ms
memory: 45396kb

input:

30 30
1 2 3 4 5 6 29 8 9 10 11 12 13 14 25 16 17 18 19 20 21 22 23 24 15 26 27 28 7 30
1 2 3 4 5 6 7 18 9 10 11 12 13 14 15 16 17 8 19 20 21 24 23 22 25 26 27 28 29 30
1 2 28 4 5 6 7 8 9 10 3 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 11 29 30
1 2 3 4 5 21 7 8 9 24 11 12 13 14 15 16 17 18 19 20...

output:

701414999

result:

ok 1 number(s): "701414999"

Test #104:

score: 0
Accepted
time: 28ms
memory: 45456kb

input:

30 30
1 2 21 4 5 6 3 8 9 10 11 12 13 14 15 16 17 18 19 20 7 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 26 23 14 15 16 17 18 19 20 21 22 13 24 25 12 27 28 29 30
1 2 3 4 20 6 7 8 9 10 11 12 13 14 15 16 25 18 19 5 21 22 23 24 17 26 27 28 29 30
1 2 3 4 5 6 7 8 9 10 11 27 13 14 15 16 17 18 19 23 ...

output:

156359319

result:

ok 1 number(s): "156359319"

Test #105:

score: 0
Accepted
time: 27ms
memory: 45396kb

input:

30 30
1 2 3 4 5 6 7 8 9 19 11 30 13 14 15 16 17 18 10 20 21 22 23 24 25 26 27 28 29 12
1 2 3 4 5 16 7 8 9 28 11 12 13 14 15 6 17 18 19 20 21 22 23 24 25 26 27 10 29 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 30 23 20 21 22 19 24 25 26 27 28 29 18
1 2 3 4 5 6 7 8 9 10 11 26 13 14 15 16 17 18 19 20 ...

output:

701414999

result:

ok 1 number(s): "701414999"

Test #106:

score: 0
Accepted
time: 11ms
memory: 45480kb

input:

30 2
1 20 6 15 5 22 7 8 13 18 26 23 27 14 4 16 17 10 19 11 12 3 21 24 25 2 29 28 9 30
16 24 3 4 29 6 7 28 23 10 2 25 5 14 15 12 17 18 30 11 21 22 9 20 8 26 27 1 13 19

output:

310634692

result:

ok 1 number(s): "310634692"

Extra Test:

score: 0
Extra Test Passed