QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614080#9441. Many Common Segment Problemsucup-team087#AC ✓1832ms202984kbC++2351.4kb2024-10-05 15:33:352024-10-05 15:33:36

Judging History

This is the latest submission verdict.

  • [2024-10-05 15:33:36]
  • Judged
  • Verdict: AC
  • Time: 1832ms
  • Memory: 202984kb
  • [2024-10-05 15:33:35]
  • 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;
	}
};

#define USE_GOOD_MOD

//size of input must be a power of 2
//output of forward fmt is bit-reversed
//output elements are in the range [0,mod*4)
//input of inverse fmt should be bit-reversed
template<class mint>
void inplace_fmt(const int n,mint*const f,bool inv){
	static constexpr uint mod=mint::mod;
	static constexpr uint mod2=mod*2;
	static constexpr int L=30;
	static mint g[L],ig[L],p2[L];
	if(g[0].v==0){
		rep(i,L){
			mint w=-mint::root().pow(((mod-1)>>(i+2))*3);
			g[i]=w;
			ig[i]=w.inv();
			p2[i]=mint(1<<i).inv();
		}
	}
	if(!inv){
		int b=n;
		if(b>>=1){//input:[0,mod)
			rep(i,b){
				uint x=f[i+b].v;
				f[i+b].v=f[i].v+mod-x;
				f[i].v+=x;
			}
		}
		if(b>>=1){//input:[0,mod*2)
			mint p=1;
			for(int i=0,k=0;i<n;i+=b*2){
				rng(j,i,i+b){
					uint x=(f[j+b]*p).v;
					f[j+b].v=f[j].v+mod-x;
					f[j].v+=x;
				}
				p*=g[__builtin_ctz(++k)];
			}
		}
		while(b){
			if(b>>=1){//input:[0,mod*3)
				mint p=1;
				for(int i=0,k=0;i<n;i+=b*2){
					rng(j,i,i+b){
						uint x=(f[j+b]*p).v;
						f[j+b].v=f[j].v+mod-x;
						f[j].v+=x;
					}
					p*=g[__builtin_ctz(++k)];
				}
			}
			if(b>>=1){//input:[0,mod*4)
				mint p=1;
				for(int i=0,k=0;i<n;i+=b*2){
					rng(j,i,i+b){
						uint x=(f[j+b]*p).v;
						f[j].v=(f[j].v<mod2?f[j].v:f[j].v-mod2);
						f[j+b].v=f[j].v+mod-x;
						f[j].v+=x;
					}
					p*=g[__builtin_ctz(++k)];
				}
			}
		}
	}else{
		int b=1;
		if(b<n/2){//input:[0,mod)
			mint p=1;
			for(int i=0,k=0;i<n;i+=b*2){
				rng(j,i,i+b){
					ull x=f[j].v+mod-f[j+b].v;
					f[j].v+=f[j+b].v;
					f[j+b].v=x*p.v%mod;
				}
				p*=ig[__builtin_ctz(++k)];
			}
			b<<=1;
		}
		for(;b<n/2;b<<=1){
			mint p=1;
			for(int i=0,k=0;i<n;i+=b*2){
				rng(j,i,i+b/2){//input:[0,mod*2)
					ull x=f[j].v+mod2-f[j+b].v;
					f[j].v+=f[j+b].v;
					f[j].v=(f[j].v)<mod2?f[j].v:f[j].v-mod2;
					f[j+b].v=x*p.v%mod;
				}
				rng(j,i+b/2,i+b){//input:[0,mod)
					ull x=f[j].v+mod-f[j+b].v;
					f[j].v+=f[j+b].v;
					f[j+b].v=x*p.v%mod;
				}
				p*=ig[__builtin_ctz(++k)];
			}
		}
		if(b<n){//input:[0,mod*2)
			rep(i,b){
				uint x=f[i+b].v;
				f[i+b].v=f[i].v+mod2-x;
				f[i].v+=x;
			}
		}
		mint z=p2[__lg(n)];
		rep(i,n)f[i]*=z;
	}
}

template<class mint>
void inplace_fmt(vector<mint>&f,bool inv){
	inplace_fmt(si(f),f.data(),inv);
}

//size of input must be a power of 2
//output elements are in the range [0,mod*4)
template<class mint>
void half_fmt(const int n,mint*const f){
	static constexpr uint mod=mint::mod;
	static constexpr uint mod2=mod*2;
	static const int L=30;
	static mint g[L],h[L];
	if(g[0].v==0){
		rep(i,L){
			g[i]=-mint::root().pow(((mod-1)>>(i+2))*3);
			h[i]=mint::root().pow((mod-1)>>(i+2));
		}
	}
	int b=n;
	int lv=0;
	if(b>>=1){//input:[0,mod)
		mint p=h[lv++];
		for(int i=0,k=0;i<n;i+=b*2){
			rng(j,i,i+b){
				uint x=(f[j+b]*p).v;
				f[j+b].v=f[j].v+mod-x;
				f[j].v+=x;
			}
			p*=g[__builtin_ctz(++k)];
		}
	}
	if(b>>=1){//input:[0,mod*2)
		mint p=h[lv++];
		for(int i=0,k=0;i<n;i+=b*2){
			rng(j,i,i+b){
				uint x=(f[j+b]*p).v;
				f[j+b].v=f[j].v+mod-x;
				f[j].v+=x;
			}
			p*=g[__builtin_ctz(++k)];
		}
	}
	while(b){
		if(b>>=1){//input:[0,mod*3)
			mint p=h[lv++];
			for(int i=0,k=0;i<n;i+=b*2){
				rng(j,i,i+b){
					uint x=(f[j+b]*p).v;
					f[j+b].v=f[j].v+mod-x;
					f[j].v+=x;
				}
				p*=g[__builtin_ctz(++k)];
			}
		}
		if(b>>=1){//input:[0,mod*4)
			mint p=h[lv++];
			for(int i=0,k=0;i<n;i+=b*2){
				rng(j,i,i+b){
					uint x=(f[j+b]*p).v;
					f[j].v=(f[j].v<mod2?f[j].v:f[j].v-mod2);
					f[j+b].v=f[j].v+mod-x;
					f[j].v+=x;
				}
				p*=g[__builtin_ctz(++k)];
			}
		}
	}
}

template<class mint>
void half_fmt(vector<mint>&f){
	half_fmt(si(f),f.data());
}

#ifdef USE_GOOD_MOD

template<class mint>
vc<mint> multiply(vc<mint> x,const vc<mint>&y,bool same=false){
	if(x.empty()||y.empty())return {};
	int n=si(x)+si(y)-1;
	int s=1;
	while(s<n)s*=2;
	x.resize(s);inplace_fmt(x,false);
	if(!same){
		static vc<mint> z;
		z.clear();z.resize(s);
		rep(i,si(y))z[i]=y[i];
		inplace_fmt(z,false);
		rep(i,s)x[i]*=z[i];
	}else{
		rep(i,s)x[i]*=x[i];
	}
	inplace_fmt(x,true);x.resize(n);
	return x;
}
template<class mint>
vc<mint> multiply_givenlength(vc<mint> x,const vc<mint>&y,bool same=false){
	int s=si(x);
	assert(ispow2(s));
	assert(si(y));
	x.resize(s);inplace_fmt(x,false);
	if(!same){
		static vc<mint> z;
		z.clear();z.resize(s);
		rep(i,si(y))z[i]=y[i];
		inplace_fmt(z,false);
		rep(i,s)x[i]*=z[i];
	}else{
		rep(i,s)x[i]*=x[i];
	}
	inplace_fmt(x,true);
	return x;
}

#else

//59501818244292734739283969-1=5.95*10^25 までの値を正しく計算
//最終的な列の大きさが 2^24 までなら動く
//最終的な列の大きさが 2^20 以下のときは,下の 3 つの素数を使ったほうが速い(は?)
//VERIFY: yosupo
//Yukicoder No980 (same=true)
namespace arbitrary_convolution{
	constexpr modinfo base0{167772161,3};//2^25 * 5 + 1
	constexpr modinfo base1{469762049,3};//2^26 * 7 + 1
	constexpr modinfo base2{754974721,11};//2^24 * 45 + 1
	//extern constexpr modinfo base0{1045430273,3};//2^20 * 997 + 1
	//extern constexpr modinfo base1{1051721729,6};//2^20 * 1003 + 1
	//extern constexpr modinfo base2{1053818881,7};//2^20 * 1005 + 1
	using mint0=modular<base0>;
	using mint1=modular<base1>;
	using mint2=modular<base2>;
	template<class t,class mint>
	vc<t> sub(const vc<mint>&x,const vc<mint>&y,bool same=false){
		int n=si(x)+si(y)-1;
		int s=1;
		while(s<n)s*=2;
		vc<t> z(s);rep(i,si(x))z[i]=x[i].v;
		inplace_fmt(z,false);
		if(!same){
			vc<t> w(s);rep(i,si(y))w[i]=y[i].v;
			inplace_fmt(w,false);
			rep(i,s)z[i]*=w[i];
		}else{
			rep(i,s)z[i]*=z[i];
		}
		inplace_fmt(z,true);z.resize(n);
		return z;
	}
	template<class mint>
	vc<mint> multiply(const vc<mint>&x,const vc<mint>&y,bool same=false){
		auto d0=sub<mint0>(x,y,same);
		auto d1=sub<mint1>(x,y,same);
		auto d2=sub<mint2>(x,y,same);
		int n=si(d0);
		vc<mint> res(n);
		static const mint1 r01=mint1(mint0::mod).inv();
		static const mint2 r02=mint2(mint0::mod).inv();
		static const mint2 r12=mint2(mint1::mod).inv();
		static const mint2 r02r12=r02*r12;
		static const mint w1=mint(mint0::mod);
		static const mint w2=w1*mint(mint1::mod);
		rep(i,n){
			ull a=d0[i].v;
			ull b=(d1[i].v+mint1::mod-a)*r01.v%mint1::mod;
			ull c=((d2[i].v+mint2::mod-a)*r02r12.v+(mint2::mod-b)*r12.v)%mint2::mod;
			res[i].v=(a+b*w1.v+c*w2.v)%mint::mod;
		}
		return res;
	}
	template<class t,class mint>
	vc<t>&sub_givenlength(const vc<mint>&x,const vc<mint>&y,bool same=false){
		int s=si(x);
		assert(ispow2(s));
		assert(si(y)==s);
		static vc<t> z;
		z.clear();z.resize(s);
		rep(i,si(x))z[i]=x[i].v;
		inplace_fmt(z,false);
		if(!same){
			static vc<t> w;
			w.clear();w.resize(s);
			rep(i,si(y))w[i]=y[i].v;
			inplace_fmt(w,false);
			rep(i,s)z[i]*=w[i];
		}else{
			rep(i,s)z[i]*=z[i];
		}
		inplace_fmt(z,true);
		return z;
	}
	template<class mint>
	vc<mint> multiply_givenlength(vc<mint> x,const vc<mint>&y,bool same=false){
		auto&d0=sub_givenlength<mint0>(x,y,same);
		auto&d1=sub_givenlength<mint1>(x,y,same);
		auto&d2=sub_givenlength<mint2>(x,y,same);
		int n=si(d0);
		x.resize(n);
		static const mint1 r01=mint1(mint0::mod).inv();
		static const mint2 r02=mint2(mint0::mod).inv();
		static const mint2 r12=mint2(mint1::mod).inv();
		static const mint2 r02r12=r02*r12;
		static const mint w1=mint(mint0::mod);
		static const mint w2=w1*mint(mint1::mod);
		rep(i,n){
			ull a=d0[i].v;
			ull b=(d1[i].v+mint1::mod-a)*r01.v%mint1::mod;
			ull c=((d2[i].v+mint2::mod-a)*r02r12.v+(mint2::mod-b)*r12.v)%mint2::mod;
			x[i].v=(a+b*w1.v+c*w2.v)%mint::mod;
		}
		return x;
	}
}
using arbitrary_convolution::multiply;
using arbitrary_convolution::multiply_givenlength;

#endif

//UTPC2021 C
namespace integer_convolution{
	extern constexpr modinfo base0{1045430273,3};//2^20 * 997 + 1
	extern constexpr modinfo base1{1051721729,6};//2^20 * 1003 + 1
	//extern constexpr modinfo base0{469762049,3};//2^26 * 7 + 1
	//extern constexpr modinfo base1{754974721,11};//2^24 * 45 + 1
	using mint0=modular<base0>;
	using mint1=modular<base1>;
	template<class t>
	vc<t> sub(const vi&x,const vi&y,bool same=false){
		int n=si(x)+si(y)-1;
		int s=1;
		while(s<n)s*=2;
		vc<t> z(s);rep(i,si(x))z[i]=x[i];
		inplace_fmt(z,false);
		if(!same){
			vc<t> w(s);rep(i,si(y))w[i]=y[i];
			inplace_fmt(w,false);
			rep(i,s)z[i]*=w[i];
		}else{
			rep(i,s)z[i]*=z[i];
		}
		inplace_fmt(z,true);z.resize(n);
		return z;
	}
	vi multiply(const vi&x,const vi&y,bool same=false){
		auto d0=sub<mint0>(x,y,same);
		auto d1=sub<mint1>(x,y,same);
		const mint1 r=mint1(mint0::mod).inv();
		const ll v=ll(mint0::mod)*mint1::mod;
		int n=si(d0);
		vi res(n);
		rep(i,n){
			res[i]=d0[i].v+(r*(d1[i]-d0[i].v)).v*(ull)mint0::mod;
			if(res[i]>v/2)res[i]-=v;
		}
		return res;
	}
}

//最大で 1<<mx のサイズの fft が登場!
template<class mint>
vc<mint> large_convolution(const vc<mint>&a,const vc<mint>&b,int mx){
	int n=si(a),m=si(b);
	vc<mint> c(n+m-1);
	int len=1<<(mx-1);
	for(int i=0;i<n;i+=len){
		for(int j=0;j<n;j+=len){
			int x=min(len,n-i),y=min(len,m-j);
			auto d=multiply(vc<mint>(a.bg+i,a.bg+i+x),vc<mint>(b.bg+j,b.bg+j+y));
			rep(k,si(d))
				c[i+j+k]+=d[k];
		}
	}
	return c;
}

//input A: N 次,B ?,M
//output D: M 次多項式
//C を M 次多項式として
//[x^N] A*B*C = [x^M] D*C
//となるような D を返す
//CF796F
template<class mint>
vc<mint> transpose_advance(const vc<mint>&a,const vc<mint>&b,int m){
	int n=si(a)-1;
	auto d=multiply(a,b);
	vc<mint> res(m+1);
	if(n>=m){
		rep(i,m+1)res[i]=d[i+n-m];
	}else{
		rng(i,m-n,m+1)res[i]=d[i+n-m];
	}
	return res;
}

//Yukicoder 2166
template<class mint>
void chmult(vc<mint>&x,const vc<mint>&y,int s){
	x=multiply(move(x),y);
	x.resize(s);
}

//Poly というのは常にサイズ 1 以上であることにしよう
//low のあたりをかならずサイズ s のものを返すようにいじった
//その影響で何かが起きているかも知れないし,起きていないかも知れない
template<class mint>
struct Poly:public vc<mint>{
	/*Poly(){}
	//Poly(const vc<mint>&val):vc<mint>(val){}
	//Poly(vc<mint>&&val):vc<mint>(val){}
	explicit Poly(int n):vc<mint>(n){}
	explicit Poly(int n,mint v):vc<mint>(n,v){}
	//Poly(initializer_list<mint>init):vc<mint>(all(init)){}
	template<class...Args>
	Poly(Args&&...args):vc<mint>(forward<Args>(args)...){}*/
	Poly(const vc<mint>&val):vc<mint>(val){}
	Poly(vc<mint>&&val):vc<mint>(val){}
	using vc<mint>::vector;
	using vc<mint>::operator=;
	//Poly(const Poly<mint>&rhs):vc<mint>((vc<mint>)rhs){}
	//Poly(Poly<mint>&&rhs):vc<mint>(forward<vc<mint>>(rhs)){}
	int size()const{
		return vc<mint>::size();
	}
	void ups(int s){
		if(size()<s)this->resize(s,0);
	}
	Poly low(int s)const{
		assert(s);
		Poly res(s);
		rep(i,min(s,size()))res[i]=(*this)[i];
		return res;
	}
	Poly rev()const{
		auto r=*this;
		reverse(all(r));
		return r;
	}
	Poly operator>>(int x)const{
		assert(x<size());
		Poly res(size()-x);
		rep(i,size()-x)res[i]=(*this)[i+x];
		return res;
	}
	Poly operator<<(int x)const{
		Poly res(size()+x);
		rep(i,size())res[i+x]=(*this)[i];
		return res;
	}
	mint freq(int i)const{
		return i<size()?(*this)[i]:0;
	}
	Poly operator-()const{
		Poly res=*this;
		for(auto&v:res)v=-v;
		return res;
	}
	Poly& operator+=(const Poly&r){
		ups(r.size());
		rep(i,r.size())
			(*this)[i]+=r[i];
		return *this;
	}
	template<class T>
	Poly& operator+=(T t){
		(*this)[0]+=t;
		return *this;
	}
	Poly& operator-=(const Poly&r){
		ups(r.size());
		rep(i,r.size())
			(*this)[i]-=r[i];
		return *this;
	}
	template<class T>
	Poly& operator-=(T t){
		(*this)[0]-=t;
		return *this;
	}
	template<class T>
	Poly& operator*=(T t){
		for(auto&v:*this)
			v*=t;
		return *this;
	}
	Poly& operator*=(const Poly&r){
		*this=multiply(*this,r);;
		return *this;
	}
	Poly square()const{
		return multiply(*this,*this,true);
	}
	#ifndef USE_GOOD_MOD
	Poly inv(int s)const{
		Poly r{mint(1)/(*this)[0]};
		for(int n=1;n<s;n*=2)
			r=r*2-(r.square()*low(2*n)).low(2*n);
		r.resize(s);
		return r;
	}
	#else
	//source: Section 4 of "Removing redundancy from high-precision Newton iteration"
	// 5/3
	Poly inv(int s)const{
		Poly r(s);
		r[0]=mint(1)/(*this)[0];
		for(int n=1;n<s;n*=2){
			vc<mint> f=low(2*n);
			f.resize(2*n);
			inplace_fmt(f,false);
			vc<mint> g=r.low(2*n);
			g.resize(2*n);
			inplace_fmt(g,false);
			rep(i,2*n)f[i]*=g[i];
			inplace_fmt(f,true);
			rep(i,n)f[i]=0;
			inplace_fmt(f,false);
			rep(i,2*n)f[i]*=g[i];
			inplace_fmt(f,true);
			rng(i,n,min(2*n,s))r[i]=-f[i];
		}
		return r;
	}
	#endif
	template<class T>
	Poly& operator/=(T t){
		return *this*=mint(1)/mint(t);
	}
	Poly quotient(const Poly&r,const Poly&rri)const{
		int m=r.size();
		assert(r[m-1].v);
		int n=size();
		int s=n-m+1;
		if(s<=0) return {0};
		return (rev().low(s)*rri.low(s)).low(s).rev();
	}
	Poly& operator/=(const Poly&r){
		return *this=quotient(r,r.rev().inv(max(size()-r.size(),int(0))+1));
	}
	Poly& operator%=(const Poly&r){
		*this-=*this/r*r;
		return *this=low(r.size()-1);
	}
	Poly operator+(const Poly&r)const{return Poly(*this)+=r;}
	template<class T>
	Poly operator+(T t)const{return Poly(*this)+=t;}
	template<class T>
	friend Poly operator+(T t,Poly r){
		r[0]+=t;
		return r;
	}
	Poly operator-(const Poly&r)const{return Poly(*this)-=r;}
	template<class T>
	Poly operator-(T t)const{return Poly(*this)-=t;}
	template<class T>
	friend Poly operator-(T t,Poly r){
		for(auto&v:r)v=-v;
		r[0]+=t;
		return r;
	}
	template<class T>
	Poly operator*(T t)const{return Poly(*this)*=t;}
	Poly operator*(const Poly&r)const{return Poly(*this)*=r;}
	template<class T>
	Poly operator/(T t)const{return Poly(*this)/=t;}
	Poly operator/(const Poly&r)const{return Poly(*this)/=r;}
	Poly operator%(const Poly&r)const{return Poly(*this)%=r;}
	Poly dif()const{
		assert(size());
		if(size()==1){
			return {0};
		}else{
			Poly r(size()-1);
			rep(i,r.size())
				r[i]=(*this)[i+1]*(i+1);
			return r;
		}
	}
	Poly inte(const mint invs[])const{
		Poly r(size()+1,0);
		rep(i,size())
			r[i+1]=(*this)[i]*invs[i+1];
		return r;
	}
	//VERIFY: yosupo
	//opencupXIII GP of Peterhof H
	Poly log(int s,const mint invs[])const{
		assert((*this)[0]==1);
		if(s==1)return {0};
		return (low(s).dif()*inv(s-1)).low(s-1).inte(invs);
	}
	//Petrozavodsk 2019w mintay1 G
	//yosupo judge
	//UOJ Round23 C
	Poly exp(int s,const mint invs[])const{
		assert((*this)[0]==mint(0));
		Poly f{1},g{1};
		for(int n=1;;n*=2){
			if(n>=s)break;
			g=g*2-(g.square()*f).low(n);
			//if(n>=s)break;
			Poly q=low(n).dif();
			q=q+g*(f.dif()-f*q).low(2*n-1);
			f=f+(f*(low(2*n)-q.inte(invs))).low(2*n);
		}
		return f.low(s);
	}
	//exp(x),exp(-x) のペアを返す
	//UOJ Round23 C
	pair<Poly,Poly> exp2(int s,const mint invs[])const{
		assert((*this)[0]==mint(0));
		Poly f{1},g{1};
		for(int n=1;;n*=2){
			//if(n>=s)break;
			g=g*2-(g.square()*f).low(n);
			if(n>=s)break;
			Poly q=low(n).dif();
			q=q+g*(f.dif()-f*q).low(2*n-1);
			f=f+(f*(low(2*n)-q.inte(invs))).low(2*n);
		}
		return make_pair(f.low(s),g.low(s));
	}
	#ifndef USE_GOOD_MOD
	//CF250 E
	Poly sqrt(int s)const{
		assert((*this)[0]==1);
		static const mint half=mint(1)/mint(2);
		Poly r{1};
		for(int n=1;n<s;n*=2)
			r=(r+(r.inv(n*2)*low(n*2)).low(n*2))*half;
		return r.low(s);
	}
	#else
	//11/6
	//VERIFY: yosupo
	Poly sqrt(int s)const{
		assert((*this)[0]==1);
		static const mint half=mint(1)/mint(2);
		vc<mint> f{1},g{1},z{1};
		for(int n=1;n<s;n*=2){
			rep(i,n)z[i]*=z[i];
			inplace_fmt(z,true);
			
			vc<mint> delta(2*n);
			rep(i,n)delta[n+i]=z[i]-freq(i)-freq(n+i);
			inplace_fmt(delta,false);
			
			vc<mint> gbuf(2*n);
			rep(i,n)gbuf[i]=g[i];
			inplace_fmt(gbuf,false);
			
			rep(i,2*n)delta[i]*=gbuf[i];
			inplace_fmt(delta,true);
			f.resize(2*n);
			rng(i,n,2*n)f[i]=-half*delta[i];
			
			if(2*n>=s)break;
			
			z=f;
			inplace_fmt(z,false);
			
			vc<mint> eps=gbuf;
			rep(i,2*n)eps[i]*=z[i];
			inplace_fmt(eps,true);
			
			rep(i,n)eps[i]=0;
			inplace_fmt(eps,false);
			
			rep(i,2*n)eps[i]*=gbuf[i];
			inplace_fmt(eps,true);
			g.resize(2*n);
			rng(i,n,2*n)g[i]=-eps[i];
		}
		f.resize(s);
		return f;
	}
	#endif
	pair<Poly,Poly> divide(const Poly&r,const Poly&rri)const{
		Poly a=quotient(r,rri);
		Poly b=*this-a*r;
		return make_pair(a,b.low(r.size()-1));
	}
	//Yukicoder No.215
	Poly pow_mod(int n,const Poly&r)const{
		Poly rri=r.rev().inv(r.size());
		Poly cur{1},x=*this%r;
		while(n){
			if(n%2)
				cur=(cur*x).divide(r,rri).b;
			x=(x*x).divide(r,rri).b;
			n/=2;
		}
		return cur;
	}
	int lowzero()const{
		rep(i,size())if((*this)[i]!=0)return i;
		return size();
	}
	//VERIFY: yosupo
	//UOJ Round23 C (z=0,p<0)
	//Multiuni2023-4-B
	Poly pow(int s,int p,const mint invs[])const{
		assert(s>0);
		if(p==0){
			Poly res(s,0);
			res[0]=1;
			return res;
		}
		int n=size(),z=0;
		for(;z<n&&(*this)[z]==0;z++);
		assert(z==0||p>0);
		if(z*p>=s)return Poly(s,0);
		mint c=(*this)[z],cinv=c.inv();
		mint d=c.pow(p);
		int t=s-z*p;
		Poly x(t);
		rng(i,z,min(z+t,n))x[i-z]=(*this)[i]*cinv;
		x=x.log(t,invs);
		rep(i,t)x[i]*=p;
		x=x.exp(t,invs);
		rep(i,t)x[i]*=d;
		Poly y(s);
		rep(i,t)y[z*p+i]=x[i];
		return y;
	}
	//verified in compositional inverse
	Poly pow_const1(mint p,const mint invs[])const{
		assert((*this)[0]==1);
		Poly x=log(size(),invs);
		rep(i,size())x[i]*=p;
		return x.exp(size(),invs);
	}
	mint eval(mint x)const{
		mint r=0,w=1;
		for(auto v:*this){
			r+=w*v;
			w*=x;
		}
		return r;
	}
};
template<class T>
void print_single(const Poly<T>&v,int suc=1){
	rep(i,v.size())
		print_single(v[i],i==int(v.size())-1?3:2);
	if(suc==1){
		if(dbg)cout<<endl;
		else cout<<"\n";
	}
	if(suc==2)
		cout<<" ";
}

//CF641 F2
//f*x^(-a)
template<class mint>
struct Laurent{
	Poly<mint> f;
	int a;
	Laurent(const Poly<mint>&num,const Poly<mint>&den,int s){
		a=den.lowzero();
		assert(a<si(den));
		f=(num*(den>>a).inv(s)).low(s);
	}
	Laurent(const Poly<mint>&ff,int aa):f(ff),a(aa){}
	Laurent dif()const{
		return Laurent(f*(-a)+(f.dif()<<1),a+1);
	}
	mint&operator[](int i){
		assert(inc(0,i+a,si(f)-1));
		return f[i+a];
	}
};

template<class mint>
ll m2l(mint a){
	return a.v<mint::mod/2?a.v:ll(a.v)-ll(mint::mod);
}

template<class mint>
void showpoly(const Poly<mint>&a){
	vi tmp(si(a));
	rep(i,si(a)){
		tmp[i]=m2l(a[i]);
	}
	cerr<<tmp<<endl;
}

//source: Tellegen’s Principle into Practice

//Yukicoder No.1145
//top には,(x-a[i]) の積が入っている(a がサイズ s に拡張されていることに注意)
//なので例えば (1-a[i]x) の積が欲しい場合は,
//	Poly<mint> f=s.top;
//	Poly<mint> g(n+1);
//	rep(i,n+1)g[i]=f[si(f)-1-i];
template<class mint>
struct subproduct_tree{
	using poly=Poly<mint>;
	int raws,s,h;
	mint*buf;
	vc<mint*>f;
	vi len;
	poly top;
	void inner_product(const int n,const mint*a,const mint*b,mint*c){
		rep(i,n)c[i]=a[i]*b[i];
	}
	//first n elements are fft-ed
	//last n elements are raw data mod x^n-1
	//the coefficient of x^n is v
	//convert the whole array into size-2n fft-ed array
	void doubling_fmt(const int n,mint*a,const mint v){
		a[n]-=v*2;
		half_fmt(n,a+n);
	}
	subproduct_tree(const vc<mint>&a){
		raws=si(a);
		s=1;while(s<si(a))s*=2;
		h=__lg(s)+1;
		buf=new mint[s*h*2];
		f.resize(s*2);
		len.resize(s*2);
		{
			mint*head=buf;
			rng(i,1,s*2){
				len[i]=s>>__lg(i);
				f[i]=head;
				head+=len[i]*2;
			}
		}
		rep(i,s){
			mint w=i<si(a)?a[i]:0;
			f[s+i][0]=-w+1;
			f[s+i][1]=-w-1;
		}
		if(s==1)f[1][1]=f[1][0];
		gnr(i,1,s){
			inner_product(len[i],f[i*2],f[i*2+1],f[i]);
			copy(f[i],f[i]+len[i],f[i]+len[i]);
			inplace_fmt(len[i],f[i]+len[i],true);
			if(i>1)doubling_fmt(len[i],f[i],1);
		}
		top.resize(s+1);
		rep(i,s)top[i]=f[1][s+i];
		top[0]-=1;
		top[s]=1;
	}
	~subproduct_tree(){
		delete[] buf;
	}
	//VERIFY: yosupo
	vc<mint> multieval(const poly&b){
		mint*buf2=new mint[s*2];
		vc<mint*> c(s*2);
		{
			mint*head=buf2;
			rng(i,1,s*2){
				if((i&(i-1))==0&&__lg(i)%2==0)head=buf2;
				c[i]=head;
				head+=len[i];
			}
		}
		{
			poly tmp=top.rev().inv(si(b)).rev()*b;
			rep(i,s)c[1][i]=i<si(b)?tmp[si(b)-1+i]:0;
		}
		vc<mint> tmp(s);
		rng(i,1,s){
			inplace_fmt(len[i],c[i],false);
			rep(k,2){
				tmp.resize(len[i]);
				rep(j,len[i])tmp[j]=f[i*2+(k^1)][j]*c[i][j];
				inplace_fmt(tmp,true);
				rep(j,len[i]/2)c[i*2+k][j]=tmp[len[i]/2+j];
			}
		}
		vc<mint> ans(raws);
		rep(i,raws)ans[i]=c[s+i][0];
		delete[] buf2;
		return ans;
	}
	poly interpolate(const vc<mint>&val){
		mint*buf2=new mint[s*2*2];
		vc<mint*> c(s*2);
		{
			mint*head=buf2;
			rng(i,1,s*2){
				if((i&(i-1))==0&&__lg(i)%2==0)head=buf2;
				c[i]=head;
				head+=len[i]*2;
			}
		}
		{
			vc<mint> z=multieval(poly(top.bg+(s-si(val)),top.ed).dif());
			rep(i,s){
				mint w=i<si(val)?val[i]/z[i]:0;
				c[s+i][0]=c[s+i][1]=w;
			}
		}
		gnr(i,1,s){
			rep(j,len[i])
				c[i][j]=c[i*2][j]*f[i*2+1][j]+c[i*2+1][j]*f[i*2][j];
			copy(c[i],c[i]+len[i],c[i]+len[i]);
			inplace_fmt(len[i],c[i]+len[i],true);
			if(i>1)doubling_fmt(len[i],c[i],0);
		}
		poly res(c[1]+s+(s-si(val)),c[1]+s*2);
		delete[] buf2;
		return res;
	}
	//res[i]=prod_{j!=i} (a[i]-a[j])
	//Yukicoder 2556
	vc<mint> product_of_difference(){
		return multieval(poly(top.bg+(s-raws),top.ed).dif());
	}
};

template<class mint>
vc<mint> multieval(const Poly<mint>&f,const vc<mint>&x){
	return subproduct_tree<mint>(x).multieval(f);
}

template<class mint>
Poly<mint> interpolate(const vc<mint>&x,const vc<mint>&y){
	assert(si(x)==si(y));
	if(si(x)==1)return {y[0]};
	subproduct_tree<mint> tree(x);
	return tree.interpolate(y);
}

//a==-1 だけ verify されてる
//LOJ 6703
//product of ax+b
//ARC155F
template<class mint>
Poly<mint> product_linear(const vc<pair<mint,mint>>&rw){
	mint w=1;
	vc<mint> buf;
	for(auto ab:rw){
		if(ab.a==0){
			w*=ab.b;
		}else{
			w*=ab.a;
			buf.pb(-ab.b/ab.a);
		}
	}
	subproduct_tree<mint> tree(buf);
	const auto&f=tree.top;
	int n=si(buf)+1;
	vc<mint> res(n);
	rep(i,n)res[i]=f[si(f)-n+i]*w;
	res.resize(si(rw)+1);
	return res;
}

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

//FFT の結果をキャッシュして持っておく
//rw に生データ,buf に fft 後のデータ
//どちらかが空でもよい
//si(buf) は 0 or si(rw) 以上の 2 冪
//Codechef 2021 January Lunchtime EXPGROUP
//yosupo product of polynomial sequence
//Yukicoder 2166
//メモリ食いまくり
//ABC278H
//Osijek Day6 A
//Yukicoder 2575 (a<b<c の畳込みがほしいときはここへ)
struct F{
	int n;
	vc<mint> rw,buf;
	F():n(0){}
	F(const vc<mint>&given):rw(given){
		n=si(rw);
		assert(n>0);
	}
	F(initializer_list<mint> init):rw(all(init)){
		n=si(rw);
		assert(n>0);
	}
	int size()const{return n;}
	bool empty()const{return n==0;}
	void assume_have(){
		if(rw.empty()){
			int s=minp2(n);
			assert(si(buf)>=s);
			rw.resize(s);
			rep(i,s)rw[i]=buf[i].v;
			inplace_fmt(rw,true);
			rw.resize(n);
		}
		assert(si(rw)==n);
	}
	vc<mint> getrw(){
		if(n==0)return {};
		assume_have();
		return rw;
	}
	void prepare(int len){
		if(si(buf)<len)assume_have();
		if(buf.empty()){
			int s=minp2(n);
			buf.resize(s);
			rep(i,n)buf[i]=rw[i];
			inplace_fmt(buf,false);
		}
		while(si(buf)<len){
			int s=si(buf);
			buf.resize(s*2);
			rep(i,n)buf[s+i]=rw[i];
			half_fmt(s,buf.data()+s);
		}
	}
	void copy_from(F&a){
		n=a.n;
		rw=a.rw;
		if(si(a.buf)){
			int s=minp2(n);
			buf.resize(s);
			rep(i,s)buf[i]=a.buf[i];
		}else buf.clear();
	}
	void init_from_sum(F&a,F&b){
		if(a.empty())return copy_from(b);
		if(b.empty())return copy_from(a);
		n=max(a.n,b.n);
		if(si(a.rw)&&si(b.rw)){
			rw.resize(n);
			rep(i,n){
				rw[i]=0;
				if(i<a.n)rw[i]+=a.rw[i];
				if(i<b.n)rw[i]+=b.rw[i];
			}
		}else rw.clear();
		int s=minp2(n);
		if(si(a.buf)>=s&&si(b.buf)>=s){
			buf.resize(s);
			rep(i,s)buf[i]=mint(a.buf[i].v)+mint(b.buf[i].v);
		}else buf.clear();
		if(rw.empty()&&buf.empty()){
			/*
			a.prepare(n);
			b.prepare(n);
			buf.resize(s);
			rep(i,s)buf[i]=mint(a.buf[i].v)+mint(b.buf[i].v);
			*/
			//こっちのほうが微小にメモリが少なくなる?
			a.assume_have();
			b.assume_have();
			rw.assign(n,0);
			rep(i,a.n)rw[i]+=a.rw[i];
			rep(i,b.n)rw[i]+=b.rw[i];
		}
	}
	//Osijek Day6 A (n=0,middle=true)
	void init_from_product(F&a,F&b,bool middle=false){
		if(a.n==0||b.n==0){
			n=0;
			rw.clear();
			buf.clear();
			return;
		}
		assert(a.n>0);
		assert(b.n>0);
		if(middle){
			assert(a.n>=b.n);
			n=a.n;
		}else{
			n=a.n+b.n-1;
		}
		rw.clear();
		int s=minp2(n);
		a.prepare(n);
		b.prepare(n);
		buf.resize(s);
		rep(i,s)buf[i]=a.buf[i]*b.buf[i];
	}
	F operator*(F&b){
		F res;
		res.init_from_product(*this,b);
		return res;
	}
	F operator*(F&&b){
		F res;
		res.init_from_product(*this,b);
		return res;
	}
	F operator+(F&b){
		F res;
		res.init_from_sum(*this,b);
		return res;
	}
	F operator+(F&&b){
		F res;
		res.init_from_sum(*this,b);
		return res;
	}
	F& operator*=(F&b){
		return *this=(*this)*b;
	}
	F& operator+=(F&b){
		return *this=(*this)+b;
	}
	F& operator+=(F&&b){
		return *this=(*this)+b;
	}
	void freememory(){
		n=0;
		vc<mint>().swap(rw);
		vc<mint>().swap(buf);
	}
	//middle product の情報をつくる
	//a,b,c が x の関数だとする
	//ans+=[x^deg(a)] abc だとしよう
	//ab の係数上位 deg(c)+1 項を d とおけば
	//ans+=[x^deg(d)] dc とできるので,この d を求めよう
	//単にサイズを広げない prod をするだけ
	//deg(a)>=deg(b)+deg(c) でないと破綻する
	F middle(F&b){
		F res;
		res.init_from_product(*this,b,true);
		return res;
	}
	//middle product の情報が buf に入っているとする
	//サイズ s に縮める
	//[n-s,n) が重要で,それ以外のパートにはゴミが入っているかもしれない
	//Osijek Day6 A
	void middle_shrink(int s){
		if(empty())return;
		assert(s<=n);
		if(s<n){
			assume_have();
			rep(i,s)rw[i]=rw[n-s+i];
			rw.resize(n=s);
			buf.clear();
		}
	}
	//転置原理+分割統治と組み合わせるといい感じ
	//ありがちなパターン
	//for i=0,1,...: ans[i]=[x^(n-1)]v; v=m_i*v
	//m_i が(高々)一次なら,dfs(l,r) では v[k].middle_shrink(r-l)
	//m_i の要素の次数はバラバラでも大丈夫
	//空の prod で空が返るようにしてあるので m_i に空を入れてもいい
	//行列とかで戻していくとき,middle 側は空or全部同じ次数という形にしておく
};



struct Query{
	int kind;
	mint a,b;
};
//kind 0: ax+b
//kind 1: eval at a
vc<mint> prefix_multieval(vc<Query> qs){
	/*vc<mint> res;
	rep(i,si(qs)){
		if(qs[i].kind==1){
			mint v=1;
			rep(j,i){
				if(qs[j].kind==0){
					v*=qs[j].a*qs[i].a+qs[j].b;
				}
			}
			res.pb(v);
		}
	}
	return res;*/
	
	int s=si(qs);
	int d=0;
	for(auto [kind,a,b]:qs)if(kind==0)d++;
	assert(d<s);
	
	using P=pair<F,F>;
	vc<P> buf(2*s);
	auto getid=[&](int l,int r){
		if(r-l==1)return l+r;
		else return (l+r)/2*2;
	};
	{
		auto dfs=[&](auto self,int l,int r)->void{
			auto&[a,b]=buf[getid(l,r)];
			if(r-l==1){
				if(qs[l].kind==1){
					a={1,-qs[l].a};
					b={1,-qs[l].a};
				}else{
					a={qs[l].a,qs[l].b};
					b={0,1};
				}
			}else{
				int m=(l+r)/2;
				self(self,l,m);
				self(self,m,r);
				auto&[al,bl]=buf[getid(l,m)];
				auto&[ar,br]=buf[getid(m,r)];
				a=al*ar;
				b=bl*br;
				
				ar.freememory();
				bl.freememory();
			}
		};
		dfs(dfs,0,s);
	}
	F ini;
	{
		vc<pair<mint,mint>> dens;
		for(auto [kind,a,b]:qs)if(kind==1)dens.eb(-a,1);
		Poly<mint> den=product_linear(dens);
		den=den.inv(d+1);
		assert(d+1<=s);
		den.resize(s);
		rotate(den.bg,den.bg+d+1,den.ed);
		ini=den;
	}
	vc<mint> ans;
	{
		auto dfs=[&](auto self,int l,int r,F&z)->void{
			z.middle_shrink(r-l);
			{
				auto&[a,b]=buf[getid(l,r)];
				a.freememory();
				b.freememory();
			}
			if(r-l==1){
				mint val=z.getrw()[0];
				if(qs[l].kind==1)ans.pb(val);
				z.freememory();
			}else{
				int m=(l+r)/2;
				auto&[al,bl]=buf[getid(l,m)];
				auto&[ar,br]=buf[getid(m,r)];
				
				F zl=z.middle(br),zr=z.middle(al);
				z.freememory();
				self(self,l,m,zl);
				self(self,m,r,zr);
			}
		};
		dfs(dfs,0,s,ini);
	}
	return ans;
}

mint sub(int n,vc<pi> lr,int sh){
	if(n==0)return 0;
	vi fix(n+1);
	for(auto [l,r]:lr){
		if(l!=-1&&r!=-1){
			fix[l]++;
			fix[r]--;
		}
	}
	rep(i,n)fix[i+1]+=fix[i];
	int bothfree=0;
	for(auto [l,r]:lr){
		if(l==-1&&r==-1){
			bothfree++;
		}
	}
	
	vc<mint> rcnt(n+1,1),lcnt(n+1,1);
	for(auto [l,r]:lr){
		if(l==-1&&r!=-1){
			rcnt[r]*=(r+sh);
		}
		if(l!=-1&&r==-1){
			lcnt[l]*=(n-l+sh);
		}
	}
	rep(i,n)rcnt[i+1]*=rcnt[i];
	per(i,n)lcnt[i]*=lcnt[i+1];
	
	vc<mint> res(n);
	rep(i,n){
		res[i]=mint(2).pow(fix[i])*mint((n+sh+1)*(n+sh)/2+(i+1)*(n-i)).pow(bothfree);
		res[i]*=rcnt[i];
		res[i]*=lcnt[i+1];
	}
	
	{//about left
		vvc<pair<mint,mint>> buf(n+1);
		for(auto [l,r]:lr){
			if(l!=-1&&r==-1){
				buf[l].eb(-1,n+sh-l+n);
			}
		}
		vc<Query> qs;
		rep(i,n){
			for(auto [a,b]:buf[i]){
				qs.pb({0,a,b});
			}
			qs.pb({1,i,0});
		}
		auto z=prefix_multieval(qs);
		
		rep(i,n)res[i]*=z[i];
	}

	{//about right
		vvc<pair<mint,mint>> buf(n+1);
		for(auto [l,r]:lr){
			if(l==-1&&r!=-1){
				buf[r].eb(1,r+sh+1);
			}
		}
		vc<Query> qs;
		per(i,n){
			for(auto [a,b]:buf[i+1]){
				qs.pb({0,a,b});
			}
			qs.pb({1,i,0});
		}
		auto z=prefix_multieval(qs);
		rein(z);
		rep(i,n)res[i]*=z[i];
	}
	
	return SUM(res);
}

void slv(){
	INT(n,m);
	VPI(lr,n);
	mint tot=1;
	for(auto [l,r]:lr){
		if(l==-1){
			if(r==-1){
				tot*=m*(m+1)/2;
			}else{
				tot*=r;
			}
		}else{
			if(r==-1){
				tot*=m+1-l;
			}else{
				tot*=1;
			}
		}
	}
	
	for(auto&[l,r]:lr){
		if(l!=-1)l--;
	}
	mint ans=sub(m,lr,0);
	m--;
	for(auto&[l,r]:lr){
		if(r!=-1)r--;
	}
	ans-=sub(m,lr,1);
	
	ans-=tot;
	
	print(ans);
}

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: 14ms
memory: 44608kb

input:

3 3
1 -1
2 2
2 3

output:

18

result:

ok "18"

Test #2:

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

input:

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

output:

15

result:

ok "15"

Test #3:

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

input:

10 13
4 -1
-1 -1
7 11
-1 -1
-1 -1
-1 -1
11 -1
3 8
-1 9
-1 -1

output:

841024210

result:

ok "841024210"

Test #4:

score: 0
Accepted
time: 213ms
memory: 65444kb

input:

46508 20888
9935 17879
803 14990
5348 5434
2630 15632
6302 16990
4875 20297
15220 17881
10385 16908
7395 13312
4794 5956
1867 13086
5261 14262
506 19423
18148 20403
1083 6648
13858 18123
4036 14289
7743 11040
15055 20527
1576 8846
10614 12995
2111 16084
6669 14966
1704 16041
8030 16085
6939 9047
281...

output:

622373905

result:

ok "622373905"

Test #5:

score: 0
Accepted
time: 109ms
memory: 55164kb

input:

71468 8417
1491 3032
3940 4632
4208 6407
419 5971
3498 5578
1905 3096
1962 3199
1291 2756
694 8294
2090 4946
7008 7851
2751 2882
2706 6889
108 5225
136 7934
2980 7661
4680 4716
1442 6931
610 2433
2029 7632
7493 8090
3186 5781
381 884
3605 6949
2658 4522
3990 5039
581 1842
2834 7073
969 7024
2753 637...

output:

624258105

result:

ok "624258105"

Test #6:

score: 0
Accepted
time: 911ms
memory: 123708kb

input:

33867 68520
14011 22082
27837 41559
2144 15734
12979 31839
886 12147
24281 49957
9826 65576
1722 19415
14491 47918
50636 58028
17563 41887
16942 39177
24530 40332
1552 34825
14639 29619
3990 12925
47753 51870
40028 53008
2544 30228
8858 41307
21578 60354
50609 60612
20338 21716
40758 41397
26456 648...

output:

222682065

result:

ok "222682065"

Test #7:

score: 0
Accepted
time: 457ms
memory: 86484kb

input:

75153 39190
26291 36182
5293 32997
7346 9934
2591 35269
19354 29051
22682 33232
2834 11921
15097 26586
21097 22576
16043 37502
6017 38992
13072 36070
31124 38395
11041 29593
3057 25268
20445 29246
32902 33740
22225 23893
21068 35059
13229 23256
33091 34091
28800 38407
21094 23905
6683 32400
3521 341...

output:

644912633

result:

ok "644912633"

Test #8:

score: 0
Accepted
time: 486ms
memory: 90376kb

input:

38983 51827
23950 48250
8451 21390
34709 41670
8577 19224
28009 38802
8116 46250
33417 41876
6012 27827
20506 28824
32508 36718
9519 42347
16217 47490
27201 43904
28345 36254
18056 51005
32416 48961
3944 44653
35051 46634
7354 28377
184 18868
5637 41072
17151 32335
46925 51578
38617 43416
28959 4596...

output:

66873446

result:

ok "66873446"

Test #9:

score: 0
Accepted
time: 447ms
memory: 86576kb

input:

7679 44174
248 9943
15956 26442
2725 33239
10294 16406
1756 43460
17823 36584
4116 8280
1378 8294
2284 6085
14532 29528
131 29456
8000 15758
7967 36529
18153 22142
24272 42715
5906 43341
15538 30632
30706 39656
578 37881
4671 42928
12276 35991
11872 39136
27705 33517
21108 27545
2303 27196
38175 400...

output:

346752121

result:

ok "346752121"

Test #10:

score: 0
Accepted
time: 928ms
memory: 126740kb

input:

64986 73724
3612 17490
57957 71291
9395 47466
16850 17666
34093 69220
9241 43326
3408 50034
25 43682
15457 38280
11293 12231
23016 60834
15987 24580
7089 70748
46238 49344
56579 71985
19218 59431
56899 64041
15137 38936
9921 34761
11644 28437
22451 55339
33303 61478
4834 11432
9944 49814
20282 35353...

output:

773636281

result:

ok "773636281"

Test #11:

score: 0
Accepted
time: 1016ms
memory: 137980kb

input:

100000 100000
31015 42574
31826 52090
83087 85955
23220 37841
56013 70940
34751 70547
62376 76457
31649 91712
18505 47662
85040 98454
13121 30466
1256 3470
3980 85011
57880 71144
32147 38601
31379 50646
72392 87906
48476 76451
40774 58685
64093 68937
32329 80656
8177 25150
15432 60258
22018 69969
48...

output:

941648147

result:

ok "941648147"

Test #12:

score: 0
Accepted
time: 1025ms
memory: 137936kb

input:

100000 100000
21014 66363
7456 75478
5229 68612
15284 54049
29655 88817
65818 66444
33870 76176
29544 90569
62304 90461
83356 99748
24455 94172
57249 66657
44630 50799
65039 67617
4906 38962
7679 51541
59316 74310
28441 76551
19291 98970
7367 65494
62031 78933
21758 59135
46144 98556
21049 55166
573...

output:

526465770

result:

ok "526465770"

Test #13:

score: 0
Accepted
time: 1006ms
memory: 138080kb

input:

100000 100000
28862 53149
9949 69392
28285 43896
10353 80816
34142 87078
63124 67907
41674 71792
48558 72019
7933 14947
74512 93023
31561 85833
15508 33590
49247 51145
14356 99398
22644 66661
7140 85438
66105 67726
5276 71801
42804 71017
79393 96156
1822 11277
23399 70023
93290 99802
28361 43488
245...

output:

491623414

result:

ok "491623414"

Test #14:

score: 0
Accepted
time: 1000ms
memory: 137916kb

input:

100000 100000
14799 99589
42148 79991
40478 73277
20849 87949
45939 72422
41866 46646
4066 26608
33598 57285
17116 42252
32284 66953
77926 88983
5776 86665
28968 39697
18131 25212
27377 42980
29537 93995
18671 55017
7758 76277
17700 62026
24191 54409
41589 55516
72711 73804
31813 37554
24757 72146
1...

output:

394684748

result:

ok "394684748"

Test #15:

score: 0
Accepted
time: 994ms
memory: 137984kb

input:

100000 100000
55015 73375
3596 29679
19231 76062
82350 90597
19070 96441
66671 80639
47379 62902
38990 66802
37706 64205
4989 34650
20110 59898
6647 99705
41498 42886
7404 33540
36363 42005
37631 75016
68188 82917
21072 43390
36562 68641
21837 95043
65523 85407
21441 41841
4913 98767
29560 94781
196...

output:

962695745

result:

ok "962695745"

Test #16:

score: 0
Accepted
time: 1018ms
memory: 137952kb

input:

100000 100000
48836 52965
22215 37796
26537 29092
90657 98341
2131 7342
17641 64091
46683 79182
1165 35743
10331 23332
2889 41333
56769 75505
63440 94599
40276 80762
14501 68386
3239 8420
3295 69001
42668 83714
43199 90350
39921 65865
16402 19637
48565 85097
44750 83786
59138 84536
61461 96164
65218...

output:

269046725

result:

ok "269046725"

Test #17:

score: 0
Accepted
time: 1024ms
memory: 137948kb

input:

100000 100000
1089 99857
8077 43835
37678 60147
2950 63548
84341 95606
4257 36034
15407 30716
27902 71808
18112 93015
608 75716
53770 66511
54636 89625
41858 47390
45083 76588
1172 53992
19357 42200
37722 52861
61126 92664
48696 88494
48676 89136
33660 90563
9778 25918
53528 97743
7510 96964
5597 33...

output:

86816533

result:

ok "86816533"

Test #18:

score: 0
Accepted
time: 1008ms
memory: 138144kb

input:

100000 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 100000
1 10000...

output:

538261387

result:

ok "538261387"

Test #19:

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

input:

1744 831
2 -1
430 692
-1 661
-1 145
282 330
-1 -1
27 -1
-1 579
232 538
-1 -1
318 508
315 -1
-1 -1
715 -1
524 -1
-1 555
-1 172
445 -1
-1 -1
-1 -1
79 -1
-1 -1
-1 -1
-1 231
-1 695
-1 654
63 -1
206 -1
-1 44
352 787
7 351
591 686
781 -1
313 -1
-1 154
576 -1
185 239
555 611
-1 721
-1 550
102 204
19 -1
436...

output:

603361949

result:

ok "603361949"

Test #20:

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

input:

645 233
-1 -1
33 227
-1 137
57 -1
51 -1
21 -1
44 108
41 123
-1 140
72 -1
-1 88
6 -1
21 56
-1 182
-1 160
-1 168
102 127
134 -1
-1 -1
-1 -1
181 -1
17 165
54 190
-1 97
187 -1
-1 147
78 -1
10 52
-1 169
75 -1
63 157
-1 100
21 155
-1 -1
-1 208
155 -1
38 196
-1 161
-1 231
-1 109
-1 206
-1 -1
-1 104
-1 -1
9...

output:

167490773

result:

ok "167490773"

Test #21:

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

input:

282 279
-1 131
-1 -1
113 115
35 256
9 268
-1 105
261 -1
-1 -1
89 -1
18 -1
65 182
-1 -1
-1 -1
167 191
-1 194
-1 -1
-1 -1
-1 -1
-1 105
32 51
-1 211
111 133
-1 -1
-1 -1
29 276
-1 35
29 276
-1 -1
54 -1
79 -1
-1 -1
142 164
82 -1
51 -1
-1 -1
262 -1
6 119
-1 -1
209 -1
-1 184
-1 -1
-1 -1
-1 -1
67 124
-1 124...

output:

269738573

result:

ok "269738573"

Test #22:

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

input:

2000 2000
904 -1
119 -1
-1 -1
175 722
-1 1469
692 1062
49 425
-1 783
1825 -1
-1 1133
733 1325
1946 -1
127 1559
694 1287
-1 -1
583 -1
-1 -1
1423 1626
12 -1
-1 -1
613 1547
-1 1057
368 1509
574 1515
1405 -1
971 -1
560 1370
430 1802
-1 1934
-1 795
-1 117
-1 -1
1367 1878
-1 1468
1118 1723
-1 -1
-1 647
-1...

output:

417815992

result:

ok "417815992"

Test #23:

score: 0
Accepted
time: 26ms
memory: 46604kb

input:

2000 2000
-1 -1
32 -1
327 -1
1220 1869
-1 1444
200 1066
1522 -1
1049 -1
1541 -1
1630 -1
-1 267
-1 482
-1 -1
-1 -1
1005 1847
131 303
24 1933
568 1176
772 -1
-1 -1
-1 -1
1920 -1
1676 -1
1697 1847
-1 -1
-1 -1
-1 973
1357 -1
886 1735
974 -1
-1 1943
-1 456
912 1531
916 -1
820 964
-1 -1
-1 96
404 1575
-1 ...

output:

946305065

result:

ok "946305065"

Test #24:

score: 0
Accepted
time: 26ms
memory: 46608kb

input:

2000 2000
842 1676
820 1103
155 -1
691 -1
763 1757
540 1818
-1 -1
-1 -1
-1 -1
813 -1
942 -1
-1 -1
939 -1
1600 -1
67 1656
-1 1365
691 -1
1245 -1
330 866
399 1774
1761 -1
831 1310
-1 1639
48 1572
-1 -1
-1 395
-1 47
-1 520
680 993
-1 -1
885 1449
117 757
924 -1
-1 -1
-1 1053
1752 1893
-1 907
-1 882
940 ...

output:

504771084

result:

ok "504771084"

Test #25:

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

input:

2000 2000
1846 -1
-1 354
363 1151
678 -1
-1 -1
606 1154
154 1931
633 857
1557 -1
124 1798
934 -1
-1 -1
-1 -1
1334 -1
-1 -1
-1 633
571 -1
834 944
1107 1545
390 1566
296 561
160 1589
745 -1
611 1142
287 779
-1 1546
1766 1807
-1 -1
-1 -1
541 -1
-1 -1
-1 562
1705 -1
1496 -1
-1 291
143 1934
-1 -1
342 -1
...

output:

164655804

result:

ok "164655804"

Test #26:

score: 0
Accepted
time: 22ms
memory: 46680kb

input:

2000 2000
1304 -1
1697 -1
-1 116
-1 -1
432 467
-1 225
-1 1135
-1 -1
56 -1
1949 -1
174 -1
-1 1742
-1 -1
1730 1947
-1 1008
-1 1404
1092 1267
-1 -1
-1 -1
-1 883
1602 -1
-1 -1
1124 1810
502 -1
-1 1557
396 -1
400 729
-1 -1
-1 -1
-1 1705
286 1719
277 -1
-1 -1
421 -1
-1 -1
574 1285
1265 1668
-1 794
-1 -1
5...

output:

433544803

result:

ok "433544803"

Test #27:

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

input:

2000 2000
651 1106
707 924
638 968
1080 1581
97 1257
261 1531
1160 1733
26 1571
743 1741
86 1283
1245 1536
393 511
793 1051
881 1755
1437 1613
15 795
337 1343
1723 1823
1059 1875
476 1927
524 1109
1870 1983
916 1750
363 1115
18 779
306 371
47 115
216 951
128 407
229 1986
1253 1683
397 1909
1785 1891...

output:

275736124

result:

ok "275736124"

Test #28:

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

input:

2000 2000
488 525
1086 1118
1812 1888
86 1836
459 491
782 1449
238 436
125 598
403 941
341 1296
358 1985
57 568
423 652
874 1862
324 1597
985 1746
22 753
251 642
172 378
487 1486
810 1564
874 1789
380 1097
215 1625
744 1532
1589 1952
9 1764
4 330
559 562
940 1836
364 386
91 1562
1191 1806
484 1823
5...

output:

647106319

result:

ok "647106319"

Test #29:

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

input:

2000 2000
-1 -1
-1 -1
-1 107
-1 -1
-1 -1
618 -1
-1 1936
42 -1
-1 456
-1 443
31 -1
-1 -1
750 -1
-1 -1
-1 141
-1 47
-1 515
-1 606
-1 -1
-1 -1
-1 40
581 -1
-1 482
-1 -1
790 -1
-1 -1
-1 557
-1 -1
-1 1308
1238 -1
-1 53
-1 -1
-1 -1
1956 -1
217 -1
-1 1972
-1 -1
1070 -1
-1 -1
-1 82
706 -1
-1 16
-1 -1
12 -1
...

output:

178213118

result:

ok "178213118"

Test #30:

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

input:

2000 2000
-1 -1
844 -1
-1 1719
-1 1682
1041 -1
1549 -1
-1 -1
-1 459
1404 -1
1862 -1
-1 1275
344 -1
1003 -1
-1 -1
-1 -1
1738 -1
804 -1
1481 -1
-1 1096
-1 -1
-1 -1
191 -1
-1 432
-1 -1
-1 -1
1538 -1
1525 -1
-1 -1
-1 946
-1 -1
-1 1292
1973 -1
1343 -1
-1 769
1129 -1
1722 -1
-1 -1
-1 -1
1295 -1
-1 741
-1 ...

output:

326294367

result:

ok "326294367"

Test #31:

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

input:

2000 2000
1019 -1
707 -1
551 -1
1755 -1
1231 -1
513 -1
1042 -1
-1 460
1557 -1
-1 899
-1 1083
-1 1262
-1 444
1811 -1
1831 -1
671 -1
105 -1
-1 1299
-1 1559
1491 -1
980 -1
1054 -1
-1 300
-1 934
1660 -1
-1 186
355 -1
1463 -1
-1 653
-1 678
-1 1569
1342 -1
-1 884
-1 126
1777 -1
-1 971
-1 13
-1 569
1072 -1...

output:

751548938

result:

ok "751548938"

Test #32:

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

input:

2000 2000
1539 -1
1305 -1
1660 -1
1742 -1
-1 1535
184 -1
211 -1
1908 -1
531 -1
1548 -1
1676 -1
1346 -1
-1 893
156 -1
1790 -1
170 -1
283 -1
1573 -1
-1 35
-1 838
1741 -1
1289 -1
-1 1650
-1 1410
1163 -1
1189 -1
1592 -1
-1 180
1829 -1
-1 574
1000 -1
-1 342
1928 -1
1498 -1
1572 -1
1138 -1
-1 1970
-1 1856...

output:

186475814

result:

ok "186475814"

Test #33:

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

input:

2000 2000
-1 1009
-1 1594
-1 1522
-1 311
-1 1679
-1 679
-1 103
-1 78
-1 797
-1 1530
-1 829
-1 1813
-1 383
-1 930
-1 712
-1 988
-1 1023
-1 1257
-1 1162
-1 17
-1 966
-1 1815
-1 680
-1 1315
-1 1348
-1 171
-1 200
-1 779
-1 1320
-1 1506
-1 937
-1 779
-1 161
-1 1640
-1 1999
-1 761
-1 871
-1 1934
-1 1228
-...

output:

63681103

result:

ok "63681103"

Test #34:

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

input:

2000 2000
-1 1505
-1 857
-1 54
-1 194
-1 368
-1 1154
-1 629
-1 175
-1 1287
-1 770
-1 1243
-1 1451
-1 507
-1 1328
-1 102
-1 75
-1 1357
-1 415
-1 499
-1 1736
-1 1214
-1 1702
-1 1521
-1 717
-1 863
-1 1534
-1 1349
-1 606
-1 1466
-1 1314
-1 1526
-1 1024
-1 579
-1 1788
-1 155
-1 615
-1 517
-1 569
-1 744
-...

output:

630266191

result:

ok "630266191"

Test #35:

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

input:

2000 2000
1047 -1
384 -1
1758 -1
1389 -1
740 -1
816 -1
203 -1
489 -1
569 -1
1276 -1
1531 -1
154 -1
1999 -1
379 -1
329 -1
203 -1
1452 -1
161 -1
1384 -1
559 -1
79 -1
208 -1
92 -1
1125 -1
1616 -1
384 -1
1082 -1
204 -1
1811 -1
1105 -1
58 -1
613 -1
1619 -1
1243 -1
1392 -1
1631 -1
653 -1
1373 -1
632 -1
15...

output:

114835083

result:

ok "114835083"

Test #36:

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

input:

2000 2000
1513 -1
3 -1
640 -1
1744 -1
1998 -1
960 -1
1676 -1
608 -1
56 -1
1794 -1
334 -1
999 -1
1739 -1
106 -1
711 -1
1579 -1
641 -1
1257 -1
544 -1
797 -1
479 -1
374 -1
1358 -1
1643 -1
1278 -1
714 -1
302 -1
1520 -1
1916 -1
67 -1
1581 -1
898 -1
778 -1
767 -1
1651 -1
76 -1
1235 -1
742 -1
1523 -1
370 -...

output:

429309272

result:

ok "429309272"

Test #37:

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

input:

2000 2000
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1...

output:

708459481

result:

ok "708459481"

Test #38:

score: 0
Accepted
time: 971ms
memory: 129044kb

input:

39371 73505
-1 67150
-1 57770
42317 -1
-1 -1
65127 -1
48039 57936
16817 -1
46051 52105
-1 44100
33469 43807
-1 66673
-1 -1
83 68755
-1 65324
11453 31180
-1 2443
35823 -1
-1 -1
-1 -1
8433 24104
37008 55794
21490 -1
-1 23813
59037 -1
-1 43665
-1 -1
25001 42758
18631 -1
29828 -1
-1 -1
-1 -1
43963 -1
37...

output:

417807573

result:

ok "417807573"

Test #39:

score: 0
Accepted
time: 900ms
memory: 123292kb

input:

516 68842
17469 -1
23357 -1
8760 46430
7432 -1
-1 48636
19607 -1
41983 -1
-1 17512
47499 -1
11213 38541
21538 -1
32032 68432
-1 35755
-1 54811
37739 63152
-1 21436
585 5674
-1 -1
-1 -1
-1 -1
51261 51348
-1 28993
3606 22514
-1 64998
20340 48659
35722 65937
-1 -1
-1 64396
-1 -1
-1 -1
1482 50269
28310 ...

output:

944392637

result:

ok "944392637"

Test #40:

score: 0
Accepted
time: 490ms
memory: 90708kb

input:

11928 51104
7727 -1
12632 13001
-1 -1
-1 -1
6272 50896
23549 -1
-1 -1
-1 43881
27531 48840
-1 45956
-1 41853
27809 33690
-1 16089
27024 39291
-1 -1
5238 -1
36436 -1
-1 22559
40105 -1
20976 37615
-1 -1
-1 6246
17537 47844
8564 9869
-1 2246
24489 -1
-1 -1
10003 17239
-1 -1
-1 -1
3415 25065
3283 25074
...

output:

760980906

result:

ok "760980906"

Test #41:

score: 0
Accepted
time: 875ms
memory: 115736kb

input:

87869 56606
24516 39428
26004 -1
-1 48577
-1 17564
-1 -1
33985 -1
55338 -1
-1 51915
20824 -1
-1 17939
7402 45187
31118 -1
8297 20482
32329 36079
10683 36084
-1 5542
30020 -1
12935 13532
-1 25603
15811 -1
-1 6534
38966 -1
-1 -1
13907 -1
23761 45077
-1 14130
35441 51955
-1 -1
-1 -1
21280 -1
7405 32321...

output:

876373628

result:

ok "876373628"

Test #42:

score: 0
Accepted
time: 414ms
memory: 77904kb

input:

40641 26318
7109 13581
25097 -1
23267 -1
1102 13576
12052 -1
12801 18315
-1 9329
-1 -1
4332 -1
10112 20954
666 -1
14616 -1
-1 25123
-1 14856
-1 -1
-1 4259
4865 -1
-1 -1
253 -1
9566 -1
7063 -1
-1 -1
5486 -1
1559 -1
9327 22486
9521 13718
862 13292
4843 7815
14881 16553
25182 -1
-1 -1
-1 -1
10534 -1
11...

output:

603095629

result:

ok "603095629"

Test #43:

score: 0
Accepted
time: 1130ms
memory: 149972kb

input:

100000 100000
80910 85031
-1 46621
61333 99990
89041 -1
-1 46204
48529 79326
-1 -1
2747 55365
-1 -1
-1 5862
3891 54076
-1 90774
50016 -1
-1 13462
41283 -1
7290 8385
961 78037
61802 -1
-1 20292
72341 -1
-1 -1
98901 -1
32950 -1
61160 -1
-1 -1
84609 -1
60542 -1
54713 -1
35383 88820
58869 -1
14739 -1
49...

output:

875564287

result:

ok "875564287"

Test #44:

score: 0
Accepted
time: 1145ms
memory: 149864kb

input:

100000 100000
-1 -1
-1 -1
58262 66732
58914 61320
67630 69377
11169 40789
52235 76000
-1 38693
-1 -1
-1 51837
-1 -1
-1 -1
-1 20873
-1 86015
61867 -1
-1 79893
-1 43481
32490 -1
-1 -1
-1 -1
-1 34584
15429 52880
-1 96933
5109 -1
373 -1
-1 -1
73425 -1
31557 -1
-1 24025
75347 -1
-1 -1
-1 -1
14028 -1
3929...

output:

711299685

result:

ok "711299685"

Test #45:

score: 0
Accepted
time: 1120ms
memory: 149896kb

input:

100000 100000
75183 78136
35617 -1
-1 18706
57048 -1
-1 -1
-1 27906
31253 -1
86063 -1
-1 53125
20587 -1
-1 -1
88024 -1
-1 92960
16945 83958
-1 47260
48746 -1
-1 -1
30210 -1
54460 75100
8786 -1
-1 -1
-1 -1
68101 -1
12156 93667
-1 -1
44107 73979
54642 70186
-1 -1
-1 95729
-1 20306
42929 -1
28087 -1
-1...

output:

51364591

result:

ok "51364591"

Test #46:

score: 0
Accepted
time: 1158ms
memory: 149808kb

input:

100000 100000
-1 29231
27579 -1
-1 -1
-1 56749
-1 -1
-1 -1
-1 -1
42070 -1
-1 15181
-1 5211
72963 -1
-1 -1
72323 -1
-1 50903
-1 97727
-1 -1
-1 -1
-1 17913
-1 83302
-1 27183
-1 -1
-1 88000
19902 -1
78405 -1
61740 -1
36441 37528
24828 95216
-1 -1
-1 99257
82763 -1
85843 -1
7610 26057
-1 -1
54130 -1
532...

output:

749999568

result:

ok "749999568"

Test #47:

score: 0
Accepted
time: 1162ms
memory: 150308kb

input:

100000 100000
-1 -1
-1 -1
71455 87994
-1 -1
-1 70805
-1 6368
39972 68521
-1 46049
21208 91408
68 39582
-1 36681
63072 -1
76257 -1
-1 -1
-1 -1
-1 -1
-1 9393
-1 63750
-1 99364
-1 1479
-1 13423
-1 3420
10066 -1
-1 -1
-1 -1
-1 -1
-1 -1
58639 -1
-1 18319
-1 80225
25804 -1
-1 -1
68756 -1
-1 -1
16180 -1
40...

output:

930185694

result:

ok "930185694"

Test #48:

score: 0
Accepted
time: 1017ms
memory: 138080kb

input:

100000 100000
56199 91291
40437 82521
19552 81440
12739 83409
53402 77939
42064 63128
4342 65251
38574 74433
4013 13097
3550 70914
52773 56209
32166 76985
95408 97749
57359 84113
66381 70787
39433 68501
12977 13199
8762 22385
1055 18446
36373 92518
925 39093
23947 59419
44418 92857
22872 80638
47058...

output:

49931541

result:

ok "49931541"

Test #49:

score: 0
Accepted
time: 1022ms
memory: 138168kb

input:

100000 100000
50106 86783
60571 70716
47204 54138
55639 62784
36078 84941
6279 21915
4868 83374
28166 58000
1682 67802
9121 23778
59200 84282
28024 78232
38001 46997
24442 72617
18579 29514
46860 80122
26555 91391
80518 97471
7833 38804
72763 96909
7043 60172
35749 96351
68580 75643
18826 83843
1136...

output:

658828321

result:

ok "658828321"

Test #50:

score: 0
Accepted
time: 1757ms
memory: 179724kb

input:

100000 100000
52142 -1
-1 -1
-1 -1
-1 30266
-1 -1
35323 -1
79660 -1
13258 -1
34358 -1
36621 -1
26780 -1
-1 -1
50361 -1
-1 -1
65478 -1
-1 -1
-1 -1
11658 -1
-1 -1
-1 -1
-1 76128
-1 19735
4957 -1
-1 -1
-1 -1
-1 313
34883 -1
79739 -1
40675 -1
-1 -1
-1 86093
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -...

output:

208320674

result:

ok "208320674"

Test #51:

score: 0
Accepted
time: 1755ms
memory: 179804kb

input:

100000 100000
53906 -1
-1 -1
-1 90057
-1 -1
-1 67689
-1 -1
-1 80045
-1 -1
-1 -1
1418 -1
65159 -1
-1 32307
-1 -1
-1 23951
-1 -1
-1 -1
-1 -1
-1 64225
-1 19711
80412 -1
-1 -1
-1 -1
-1 -1
-1 60840
-1 71629
-1 93515
35923 -1
-1 -1
51987 -1
-1 -1
65197 -1
12027 -1
-1 -1
-1 -1
-1 75962
83550 -1
-1 -1
-1 12...

output:

383054357

result:

ok "383054357"

Test #52:

score: 0
Accepted
time: 1832ms
memory: 185472kb

input:

100000 100000
63575 -1
-1 7400
79813 -1
98399 -1
13873 -1
14572 -1
19061 -1
70999 -1
77559 -1
65265 -1
4346 -1
-1 74813
-1 7985
-1 35710
35861 -1
79524 -1
30778 -1
67501 -1
-1 22305
-1 44157
-1 62332
-1 5628
-1 18973
27455 -1
-1 48414
66056 -1
24981 -1
68294 -1
21015 -1
-1 46011
-1 5575
4417 -1
6624...

output:

503409689

result:

ok "503409689"

Test #53:

score: 0
Accepted
time: 1822ms
memory: 185396kb

input:

100000 100000
-1 33901
-1 66021
62619 -1
84968 -1
5973 -1
221 -1
74746 -1
-1 8218
66325 -1
81801 -1
-1 19236
93697 -1
10390 -1
-1 37512
-1 28713
57237 -1
84838 -1
18557 -1
57091 -1
74599 -1
46617 -1
-1 64742
-1 3585
23920 -1
96818 -1
91194 -1
-1 34039
-1 76341
63222 -1
-1 4070
52549 -1
52320 -1
2529...

output:

542286132

result:

ok "542286132"

Test #54:

score: 0
Accepted
time: 1810ms
memory: 185612kb

input:

100000 100000
-1 74707
-1 79497
80831 -1
-1 13660
-1 2355
-1 3193
93434 -1
46852 -1
-1 71434
56165 -1
72138 -1
-1 60877
53744 -1
-1 29414
-1 79316
-1 34371
-1 83159
70157 -1
-1 10459
44011 -1
-1 89285
2721 -1
-1 81322
64654 -1
-1 55226
-1 88643
55364 -1
-1 29667
-1 88510
-1 68812
-1 95576
-1 36116
-...

output:

915309845

result:

ok "915309845"

Test #55:

score: 0
Accepted
time: 1788ms
memory: 185416kb

input:

100000 100000
-1 30060
20079 -1
-1 23063
21687 -1
-1 69283
-1 60835
42463 -1
69629 -1
-1 74776
36689 -1
89922 -1
-1 8379
214 -1
3715 -1
77111 -1
28023 -1
-1 12596
98730 -1
-1 1776
52953 -1
50069 -1
-1 51070
-1 83557
-1 4535
-1 50618
16148 -1
70826 -1
50838 -1
-1 59590
-1 88742
24648 -1
55639 -1
2375...

output:

923853144

result:

ok "923853144"

Test #56:

score: 0
Accepted
time: 1817ms
memory: 184712kb

input:

100000 100000
-1 99984
-1 99213
145 -1
-1 99053
318 -1
-1 99009
-1 99565
-1 99220
-1 99334
-1 99870
-1 99547
342 -1
621 -1
568 -1
526 -1
26 -1
916 -1
565 -1
526 -1
-1 99107
-1 99362
462 -1
-1 99471
-1 99151
-1 99022
487 -1
-1 99020
458 -1
907 -1
676 -1
927 -1
-1 99216
253 -1
589 -1
-1 99880
-1 99874...

output:

128192368

result:

ok "128192368"

Test #57:

score: 0
Accepted
time: 1512ms
memory: 202920kb

input:

100000 100000
-1 32146
-1 6895
-1 43504
-1 94964
-1 5082
-1 69541
-1 58879
-1 9425
-1 9722
-1 19108
-1 77933
-1 30806
-1 10667
-1 90570
-1 77965
-1 65368
-1 82544
-1 78636
-1 91380
-1 50002
-1 66292
-1 23842
-1 38060
-1 90192
-1 4081
-1 94755
-1 57313
-1 55556
-1 20864
-1 51424
-1 17220
-1 51489
-1 ...

output:

461531218

result:

ok "461531218"

Test #58:

score: 0
Accepted
time: 1485ms
memory: 202984kb

input:

100000 100000
-1 24112
-1 29415
-1 59008
-1 59525
-1 72057
-1 32796
-1 53056
-1 39914
-1 60183
-1 29066
-1 30319
-1 22292
-1 75168
-1 30075
-1 730
-1 57883
-1 71736
-1 22823
-1 33880
-1 27859
-1 42291
-1 80947
-1 25413
-1 38888
-1 50895
-1 51239
-1 40782
-1 48036
-1 20833
-1 6017
-1 11031
-1 13706
-...

output:

685855997

result:

ok "685855997"

Test #59:

score: 0
Accepted
time: 1480ms
memory: 201776kb

input:

100000 100000
-1 99946
-1 99374
-1 99695
-1 99908
-1 99425
-1 99298
-1 99444
-1 99478
-1 99074
-1 99338
-1 99540
-1 99466
-1 99773
-1 99256
-1 99117
-1 99903
-1 99889
-1 99727
-1 99067
-1 99458
-1 99391
-1 99324
-1 99169
-1 99185
-1 99213
-1 99811
-1 99974
-1 99273
-1 99299
-1 99296
-1 99418
-1 9934...

output:

741344412

result:

ok "741344412"

Test #60:

score: 0
Accepted
time: 1494ms
memory: 202844kb

input:

100000 100000
88122 -1
22419 -1
72915 -1
16790 -1
82911 -1
68163 -1
97964 -1
99368 -1
62160 -1
81235 -1
27503 -1
57865 -1
5780 -1
32671 -1
91062 -1
96378 -1
36135 -1
88493 -1
26161 -1
50422 -1
20914 -1
84193 -1
33641 -1
73209 -1
65369 -1
87331 -1
31318 -1
62567 -1
68644 -1
31605 -1
82937 -1
22518 -1...

output:

274568803

result:

ok "274568803"

Test #61:

score: 0
Accepted
time: 1491ms
memory: 202940kb

input:

100000 100000
65732 -1
11100 -1
71587 -1
75320 -1
9952 -1
47148 -1
20555 -1
64361 -1
43541 -1
4169 -1
95423 -1
83066 -1
71053 -1
68728 -1
14445 -1
34486 -1
67223 -1
94492 -1
15553 -1
22406 -1
35564 -1
40226 -1
72709 -1
93475 -1
38314 -1
18136 -1
47848 -1
6843 -1
14004 -1
68815 -1
81926 -1
88686 -1
4...

output:

110203772

result:

ok "110203772"

Test #62:

score: 0
Accepted
time: 1498ms
memory: 201748kb

input:

100000 100000
138 -1
533 -1
344 -1
58 -1
284 -1
760 -1
235 -1
908 -1
285 -1
402 -1
516 -1
780 -1
412 -1
128 -1
869 -1
95 -1
375 -1
577 -1
444 -1
474 -1
714 -1
538 -1
196 -1
58 -1
628 -1
764 -1
389 -1
209 -1
673 -1
352 -1
921 -1
725 -1
781 -1
108 -1
560 -1
158 -1
7 -1
310 -1
433 -1
214 -1
824 -1
103 ...

output:

399221708

result:

ok "399221708"

Test #63:

score: 0
Accepted
time: 1007ms
memory: 138080kb

input:

100000 100000
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -...

output:

682834676

result:

ok "682834676"

Test #64:

score: 0
Accepted
time: 1231ms
memory: 201804kb

input:

100000 100000
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-1 1
-...

output:

538261387

result:

ok "538261387"

Test #65:

score: 0
Accepted
time: 1469ms
memory: 201892kb

input:

100000 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100000
-1 100...

output:

168783817

result:

ok "168783817"

Test #66:

score: 0
Accepted
time: 1493ms
memory: 201864kb

input:

100000 100000
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 99999
-1 9999...

output:

911213386

result:

ok "911213386"

Test #67:

score: 0
Accepted
time: 1491ms
memory: 201852kb

input:

100000 100000
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 65536
-1 6553...

output:

958020328

result:

ok "958020328"

Test #68:

score: 0
Accepted
time: 1482ms
memory: 201876kb

input:

100000 100000
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 65535
-1 6553...

output:

376123473

result:

ok "376123473"

Test #69:

score: 0
Accepted
time: 1453ms
memory: 201832kb

input:

100000 100000
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 65537
-1 6553...

output:

558998334

result:

ok "558998334"

Test #70:

score: 0
Accepted
time: 1472ms
memory: 199280kb

input:

100000 100000
53486 -1
39997 88519
84325 -1
37606 -1
66183 79560
-1 10303
-1 53157
8761 -1
12793 67803
33675 -1
12761 47448
-1 93895
49265 67228
7378 -1
-1 57452
67968 76339
47096 -1
49571 62188
31863 91277
35138 -1
73437 94561
46238 60564
-1 62721
15721 38820
39037 43534
85549 -1
76266 -1
70417 892...

output:

234032781

result:

ok "234032781"

Test #71:

score: 0
Accepted
time: 1463ms
memory: 201884kb

input:

100000 100000
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1 -1
1...

output:

168783817

result:

ok "168783817"

Test #72:

score: 0
Accepted
time: 1461ms
memory: 201744kb

input:

100000 100000
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2 -1
2...

output:

911213386

result:

ok "911213386"

Test #73:

score: 0
Accepted
time: 1199ms
memory: 201548kb

input:

100000 100000
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000 -1
100000...

output:

538261387

result:

ok "538261387"

Test #74:

score: 0
Accepted
time: 1479ms
memory: 201824kb

input:

100000 100000
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -1
34465 -...

output:

958020328

result:

ok "958020328"

Test #75:

score: 0
Accepted
time: 1454ms
memory: 201752kb

input:

100000 100000
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -1
34466 -...

output:

376123473

result:

ok "376123473"

Test #76:

score: 0
Accepted
time: 1480ms
memory: 201788kb

input:

100000 100000
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -1
34464 -...

output:

558998334

result:

ok "558998334"

Test #77:

score: 0
Accepted
time: 1443ms
memory: 199320kb

input:

100000 100000
-1 67653
29813 -1
8485 85934
12402 23734
-1 84172
7904 30261
71842 -1
-1 58480
7175 84465
65363 95224
20337 81386
-1 91396
741 51360
-1 52196
3940 86117
1982 9289
18819 65495
4767 -1
24735 99523
34668 60575
6755 83029
80722 87776
55520 79079
32800 39607
45123 50000
33895 38990
31019 -1...

output:

367637584

result:

ok "367637584"

Extra Test:

score: 0
Extra Test Passed