QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113260#6193. Junk ProblemmaroonrkAC ✓166ms3704kbC++2014.1kb2023-06-16 20:04:572023-06-16 20:04:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 20:04:59]
  • 评测
  • 测评结果:AC
  • 用时:166ms
  • 内存:3704kb
  • [2023-06-16 20:04:57]
  • 提交

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

#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>;

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));
}

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<<"}";
}

ll read(){
	ll i;
	cin>>i;
	return i;
}

vi readvi(int n,int off=0){
	vi v(n);
	rep(i,n)v[i]=read()+off;
	return v;
}

pi readpi(int off=0){
	int a,b;cin>>a>>b;
	return pi(a+off,b+off);
}

template<class t>
void print_single(t x,int suc=1){
	cout<<x;
	if(suc==1)
		cout<<"\n";
	if(suc==2)
		cout<<" ";
}

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?suc:2);
}

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

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?suc:2);
}

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...);
}

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 t> void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

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);
}

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

template<class t>
int lwb(const vc<t>&v,const t&a){
	return lower_bound(all(v),a)-v.bg;
}
template<class t>
bool bis(const vc<t>&v,const t&a){
	return binary_search(all(v),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> readTree(int n){
	return readGraph(n,n-1);
}

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>
t MAX(const vc<t>&a){
	return *max_element(all(a));
}

template<class t>
t MIN(const vc<t>&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);
}

template<class t,class u>
pair<t,u> operator+(const pair<t,u>&a,const pair<t,u>&b){
	return mp(a.a+b.a,a.b+b.b);
}

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

template<class S>
S getrev(S s){
	reverse(all(s));
	return s;
}

pi operator+(pi a,pi b){return pi(a.a+b.a,a.b+b.b);}

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

//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,0};//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;
}

template<class t>
void mat0(vvc<t>&a,int n,int m){
	static vvc<t> pool;
	while(si(a)<n){
		if(pool.empty())a.resize(n);
		else a.pb(gpp(pool));
	}
	while(si(a)>n)pool.pb(gpp(a));
	rep(i,n){
		a[i].resize(m);
		fill(all(a[i]),0);
	}
}

//VERIFY: Yukicoder No.1773
int matrank(const vvc<mint>&rw){
	if(rw.empty())return 0;
	int h=rw.size(),w=rw[0].size(),r=0;
	static vvc<mint> a;
	mat0(a,h,w);
	rep(i,h)rep(j,w)a[i][j]=rw[i][j];
	rep(i,w){
		if(r==h)break;
		rng(j,r,h)if(a[j][i].v){
			swap(a[r],a[j]);
			break;
		}
		if(a[r][i].v==0)continue;
		rng(j,r+1,h){
			mint z=-a[j][i]/a[r][i];
			rng(k,i,w)
				a[j][k]+=a[r][k]*z;
		}
		r++;
	}
	return r;
}

//VERIFY: yosupo
mint det(const vvc<mint>&rw){
	const int n=rw.size();
	static vvc<mint> a;
	mat0(a,n,n);
	rep(i,n)rep(j,n)a[i][j]=rw[i][j];
	mint ans(1);
	rep(i,n){
		rng(j,i+1,n)if(a[j][i]){
			ans=-ans;
			swap(a[j],a[i]);
			break;
		}
		if(a[i][i]==0)return 0;
		ans*=a[i][i];
		mint z=a[i][i].inv();
		rng(j,i+1,n){
			mint w=-a[j][i]*z;
			rng(k,i,n)
				a[j][k]+=a[i][k]*w;
		}
	}
	return ans;
}

//CF459D
mint eval(const vc<mint>&f,mint x){
	mint a=0;
	per(i,si(f)){
		a*=x;
		a+=f[i];
	}
	return a;
}

//CF459D
vc<mint> interpolate_f(const vc<mint>&x,const vc<mint>&y){
	int n=si(x);
	assert(si(y)==n);
	vc<mint> res(n);
	vc<mint> cur(n+1);
	cur[0]=1;
	rep(i,n){
		per(j,i+1){
			cur[j+1]+=cur[j];
			cur[j]*=-x[i];
		}
	}
	vc<mint> tmp(n);
	rep(i,n){
		mint pre=0;
		per(j,n)pre=tmp[j]=cur[j+1]+pre*x[i];
		mint w=y[i]/eval(tmp,x[i]);
		rep(j,n)res[j]+=tmp[j]*w;
	}
	return res;
}

void slv(){
	int n,m,l,k;cin>>n>>m>>l>>k;
	vi a=readvi(l,-1);
	vi b=readvi(l,-1);
	vvc<int> special(n,vi(m));
	rep(i,k){
		int x,y;cin>>x>>y;
		x--;y--;
		special[x][y]=1;
	}
	vc<mint> xs,ys;
	vvc<mint> dp(n,vc<mint>(m));
	rng(sub,2,2+2*k+1){
		xs.pb(sub);
		mint wei=mint(1-sq(sub)).inv();
		
		auto calc=[&](int start){
			rep(i,n)rep(j,m)dp[i][j]=0;
			dp[0][start]=1;
			rep(i,n)rep(j,m){
				if(special[i][j]){
					dp[i][j]+=dp[i][j+1]*sub;
					dp[i][j]*=wei;
					if(i+1<n)dp[i+1][j]+=dp[i][j];
					if(j+1<m)dp[i][j+1]+=dp[i][j]*sub;
				}else{
					if(i+1<n)dp[i+1][j]+=dp[i][j];
					if(j+1<m)dp[i][j+1]+=dp[i][j];
				}
			}
		};
		vvc<mint> mat(l,vc<mint>(l));
		rep(i,l){
			calc(a[i]);
			rep(j,l)mat[i][j]=dp[n-1][b[j]];
		}
		
		ys.pb(det(mat)*mint(1-sq(sub)).pow(k));
	}
	auto f=interpolate_f(xs,ys);
	print(SUM(f));
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	//int t;cin>>t;rep(_,t)
	slv();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3464kb

input:

2 2 1 2
2
1
1 1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

3 4 2 1
1 4
1 4
2 2

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

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

output:

388035318

result:

ok 1 number(s): "388035318"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

10 10 5 0
1 2 3 4 8
4 6 8 9 10

output:

534075044

result:

ok 1 number(s): "534075044"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3548kb

input:

10 10 5 10
1 2 3 6 9
6 7 8 9 10
5 7
1 7
8 8
8 1
9 2
9 7
10 1
7 2
6 7
6 1

output:

113105350

result:

ok 1 number(s): "113105350"

Test #6:

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

input:

10 10 5 20
1 2 4 6 8
1 3 4 6 8
9 6
6 5
9 8
2 9
7 6
9 3
8 3
5 4
3 8
4 5
5 9
3 3
4 2
4 8
8 5
10 7
1 8
7 3
5 2
1 5

output:

312012

result:

ok 1 number(s): "312012"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

10 10 5 30
1 3 5 6 8
6 7 8 9 10
9 9
8 7
4 8
10 6
3 9
9 6
7 1
1 5
5 4
2 9
7 5
3 3
8 2
2 5
1 9
6 2
8 5
6 5
8 9
3 7
3 1
10 2
4 3
2 2
6 9
7 3
7 8
1 7
4 1
4 6

output:

720108525

result:

ok 1 number(s): "720108525"

Test #8:

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

input:

10 10 1 0
1
3

output:

55

result:

ok 1 number(s): "55"

Test #9:

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

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

10 10 3 20
3 4 5
4 6 9
2 3
3 2
1 9
7 5
10 7
6 9
3 4
5 1
1 6
5 6
8 4
10 1
5 3
7 7
4 7
9 6
10 5
3 6
5 8
8 8

output:

0

result:

ok 1 number(s): "0"

Test #11:

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

input:

10 10 4 30
1 2 3 4
5 6 7 9
10 1
8 1
1 2
5 7
2 3
10 8
7 9
5 3
6 2
9 9
9 1
2 7
10 4
4 4
4 8
7 7
6 7
7 1
4 2
5 1
9 6
9 3
2 9
3 9
3 7
3 5
7 4
1 4
1 9
8 5

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

10 10 6 30
3 4 5 6 7 8
5 6 7 8 9 10
3 4
10 8
9 6
6 5
6 9
1 9
2 4
10 6
7 4
7 6
6 7
3 8
7 2
5 5
1 1
2 1
8 1
4 3
8 6
5 9
2 6
8 4
1 7
5 2
3 2
1 4
2 8
8 9
6 1
4 5

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

10 10 7 30
1 2 3 4 5 9 10
2 3 4 7 8 9 10
9 3
10 4
2 3
2 8
5 3
2 6
1 4
7 1
6 4
3 5
6 9
10 2
4 6
5 6
7 6
4 3
8 7
6 6
9 5
8 4
7 4
1 8
5 8
3 7
9 8
7 8
8 1
3 3
10 6
8 9

output:

58415340

result:

ok 1 number(s): "58415340"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

10 10 4 20
1 2 5 7
5 7 8 10
10 3
3 2
10 6
9 7
9 4
1 4
8 6
6 3
7 5
3 8
2 3
4 6
6 8
7 8
3 6
8 8
6 6
4 2
4 9
1 1

output:

212921229

result:

ok 1 number(s): "212921229"

Test #15:

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

input:

10 10 6 20
1 2 4 7 8 9
3 4 5 8 9 10
3 5
6 5
4 5
6 1
1 8
8 8
2 5
4 9
6 3
4 2
4 7
5 2
9 7
3 8
2 2
9 4
7 6
1 4
8 5
2 7

output:

215578944

result:

ok 1 number(s): "215578944"

Test #16:

score: 0
Accepted
time: 2ms
memory: 3564kb

input:

100 10 6 20
1 2 3 4 6 7
2 4 5 6 7 9
17 6
46 9
76 2
75 4
27 6
22 4
5 1
33 7
78 1
38 7
83 9
32 5
97 3
25 8
90 3
50 7
87 1
61 3
39 1
28 9

output:

266132935

result:

ok 1 number(s): "266132935"

Test #17:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

100 10 5 20
1 2 3 4 5
2 5 6 8 9
73 2
56 8
57 9
60 3
5 8
74 3
92 2
72 9
17 4
61 8
41 7
88 8
91 4
52 7
50 4
94 9
64 7
27 6
14 7
4 2

output:

558957370

result:

ok 1 number(s): "558957370"

Test #18:

score: 0
Accepted
time: 1ms
memory: 3524kb

input:

100 10 3 20
6 7 9
6 9 10
90 4
72 2
19 1
19 9
64 3
85 3
66 7
66 5
19 6
84 5
16 1
55 6
74 4
31 3
73 4
52 2
32 9
87 2
4 8
70 2

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

100 10 4 30
2 5 6 7
2 6 8 9
52 1
26 6
39 8
44 9
38 5
11 9
47 3
46 5
42 9
14 2
65 7
68 5
44 1
20 2
42 7
12 4
6 8
73 5
87 2
17 2
28 8
100 4
25 1
3 1
8 2
12 6
36 3
3 3
86 1
95 7

output:

803776201

result:

ok 1 number(s): "803776201"

Test #20:

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

input:

100 10 5 50
1 2 3 4 5
2 3 8 9 10
8 1
45 7
69 9
85 6
51 8
40 2
85 4
67 7
65 3
28 7
98 7
94 3
47 5
50 3
44 3
76 8
50 9
48 7
81 9
16 4
70 5
22 3
80 3
22 6
33 3
57 2
4 5
6 5
18 9
74 5
11 5
14 2
3 4
3 1
68 4
37 5
93 7
42 8
78 6
71 2
27 7
57 7
96 6
69 1
30 2
9 6
39 8
54 8
2 3
78 4

output:

463426103

result:

ok 1 number(s): "463426103"

Test #21:

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

input:

100 10 6 50
3 4 5 6 8 9
5 6 7 8 9 10
56 1
39 8
84 6
4 4
66 6
88 8
95 8
24 9
78 2
54 5
85 1
3 4
81 5
36 6
69 9
47 1
60 2
26 9
68 9
8 3
13 2
31 3
25 2
72 3
88 3
81 9
97 1
67 1
90 4
86 6
74 8
56 7
50 6
94 5
67 5
49 3
42 7
42 5
53 7
87 1
80 3
12 6
96 6
58 7
15 9
46 7
89 3
17 6
71 6
6 5

output:

123434985

result:

ok 1 number(s): "123434985"

Test #22:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

10 100 3 50
14 20 52
44 57 68
1 24
8 43
2 26
6 57
5 56
3 85
2 3
10 80
4 18
9 30
6 6
5 3
4 91
5 50
9 37
4 66
10 10
9 7
7 15
7 46
4 15
2 68
9 50
8 39
5 5
8 64
9 4
5 79
8 59
9 19
10 23
7 19
8 6
5 38
8 92
6 93
5 94
1 21
6 85
5 71
4 60
9 23
3 61
2 76
4 21
8 82
6 99
9 55
3 96
9 64

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

10 100 5 50
12 14 45 50 54
20 24 68 80 88
5 37
10 43
5 86
1 18
6 40
2 83
8 64
6 97
4 31
2 59
3 63
6 17
1 57
5 92
4 9
3 96
9 88
6 71
8 93
10 32
2 32
2 3
6 60
5 57
8 86
4 23
4 40
7 84
10 51
8 83
5 10
8 75
5 44
7 43
1 65
10 20
1 15
3 71
1 30
2 98
8 14
1 92
5 69
10 53
8 48
4 43
3 92
6 74
5 41
3 67

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

10 100 7 50
11 13 21 32 35 67 89
41 56 70 75 90 91 92
3 49
8 39
5 39
1 66
7 15
5 73
8 22
6 24
7 40
1 87
6 28
6 30
3 14
9 40
2 77
5 24
1 63
7 29
6 73
4 19
8 63
10 88
6 56
7 70
7 79
4 56
3 96
2 79
5 85
3 39
7 35
3 35
6 87
1 48
10 38
1 42
3 53
4 60
1 12
9 94
9 4
8 50
9 62
10 60
4 50
7 23
3 81
4 98
2 57...

output:

0

result:

ok 1 number(s): "0"

Test #25:

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

input:

100 100 10 50
4 11 20 24 33 37 38 57 60 71
42 47 48 62 68 80 84 87 91 95
28 22
49 40
89 44
72 33
66 29
99 80
38 92
18 80
36 73
63 26
65 31
48 52
84 6
34 95
37 80
3 94
23 40
37 84
42 75
33 49
97 13
37 19
57 92
78 5
92 89
82 49
23 36
95 85
64 23
86 88
97 51
50 55
51 53
66 67
100 95
54 39
50 34
23 32
9...

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: 0
Accepted
time: 66ms
memory: 3600kb

input:

100 100 20 50
1 2 9 11 12 15 17 18 20 22 25 34 45 52 56 59 67 71 78 83
23 25 29 35 37 38 53 61 67 68 69 77 80 81 82 85 87 91 95 96
100 15
13 38
42 54
11 31
28 31
14 56
17 5
51 46
59 40
5 72
24 41
100 77
42 70
81 96
3 27
60 9
21 36
40 90
99 51
59 57
51 63
96 29
6 17
23 41
3 45
5 4
84 22
21 63
19 6
59...

output:

0

result:

ok 1 number(s): "0"

Test #27:

score: 0
Accepted
time: 98ms
memory: 3584kb

input:

100 100 30 50
6 9 10 11 14 16 17 18 19 20 21 22 24 25 26 28 30 31 32 39 48 51 58 63 64 65 67 73 78 82
33 34 38 40 42 50 52 53 54 56 60 62 64 68 70 71 74 80 81 84 86 87 88 89 90 95 97 98 99 100
77 7
74 44
83 60
58 21
91 40
30 37
97 9
84 19
78 11
46 23
90 54
40 94
3 46
24 93
65 73
16 34
24 36
40 88
57...

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 131ms
memory: 3636kb

input:

100 100 40 50
1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 22 26 27 30 33 34 37 38 39 44 45 50 53 54 56 57 62 63 65 66 67 71 77 78
16 19 20 32 33 35 39 41 47 48 52 53 56 61 62 64 65 66 69 70 72 74 75 76 77 78 81 82 83 84 86 87 88 89 90 96 97 98 99 100
57 4
43 42
36 70
93 11
49 46
41 17
76 14
4 92
92 88
7...

output:

696316238

result:

ok 1 number(s): "696316238"

Test #29:

score: 0
Accepted
time: 161ms
memory: 3676kb

input:

100 100 50 50
4 5 6 7 9 10 11 12 13 14 15 16 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 35 39 40 41 44 45 46 49 50 51 52 53 57 60 64 66 73 77 78 80 82 92 98
23 26 29 33 35 36 39 41 42 47 48 49 54 55 56 57 58 59 60 61 62 63 64 66 68 70 71 72 73 74 76 77 79 81 82 83 84 88 89 90 91 92 93 94 95 96 97 ...

output:

0

result:

ok 1 number(s): "0"

Test #30:

score: 0
Accepted
time: 166ms
memory: 3632kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 17 18 19 20 21 22 25 26 28 29 31 32 33 36 37 38 39 40 41 42 43 44 45 46 47 50 57 59 62 63 64 65 70 71 77 78
4 6 10 13 29 32 37 41 43 44 46 47 52 53 55 58 62 63 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

55822359

result:

ok 1 number(s): "55822359"

Test #31:

score: 0
Accepted
time: 166ms
memory: 3704kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 31 32 34 35 36 37 38 39 40 41 47 48 49 50 51 52 53 55 60 65 67 68
20 24 28 31 33 35 40 45 46 54 55 56 57 58 59 61 62 63 66 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

268820259

result:

ok 1 number(s): "268820259"

Test #32:

score: 0
Accepted
time: 166ms
memory: 3640kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 20 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 41 42 43 46 51 52 55 56 57 58 59 60 63 66 69 80 91
7 18 23 25 26 36 37 38 40 44 47 48 51 54 55 60 63 64 65 66 67 69 70 71 72 73 75 77 78 79 80 81 82 83 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

252789512

result:

ok 1 number(s): "252789512"

Test #33:

score: 0
Accepted
time: 166ms
memory: 3648kb

input:

100 100 50 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 20 21 22 23 25 26 27 28 29 30 31 32 35 39 40 41 42 44 46 47 51 52 53 57 58 59 64 66 69 78 79 85 86
18 23 28 30 31 32 33 34 35 38 42 43 47 49 53 55 58 61 63 64 65 66 68 70 71 74 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

604525399

result:

ok 1 number(s): "604525399"