// Problem: No.2615 ペアの作り方 // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2615 // Memory Limit: 512 MB // Time Limit: 2000 ms #include #define debug(x) cerr<<(#x)<<" "<<(x)< #define rep(i,a,b) for(ll i=(a);i<=(b);++i) #define per(i,a,b) for(ll i=(a);i>=(b);--i) using namespace std; bool Mbe; ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } void write(ll x){ if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+'0'); } const ll N=1e6+9,Mod=998244353; ll n,a[N],b[N],ans=1,c1,c2; bool Med; int main(){ cerr<>1; if(a[i]<=b[mid])pos=mid,r=mid-1; else l=mid+1; } ll cnt=n-pos+1; if(c1==i)ans=ans*cnt%Mod; else ans=ans*max(0ll,cnt-(c1-i))%Mod; } rep(i,1,c2){ ll l=c1+1,r=n,pos=n+1; while(l<=r){ ll mid=(l+r)>>1; if(b[i]<=a[mid])pos=mid,r=mid-1; else l=mid+1; } ll cnt=n-pos+1; if(c2==i)ans=ans*cnt%Mod; else ans=ans*max(0ll,cnt-(c2-i))%Mod; } write(ans); return 0; }