#include #include using namespace std; using namespace atcoder; #define ll long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define repl(i,a,b) for(ll i=(a);i<(b);i++) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() template bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;} template bool chmax(T &a,T b){if(a fac,inv,finv; void COMinit(int k){ fac.resize(k),inv.resize(k),finv.resize(k); fac[0]=fac[1]=1; inv[1]=1; finv[0]=finv[1]=1; rep(i,2,k){ fac[i]=fac[i-1]*i; inv[i]=-(mod/i)*inv[mod%i]; finv[i]=finv[i-1]*inv[i]; } return; } mint COM(ll n,ll k){ if(n> q; vector qr(q); rep(i,0,q){ int n,m; cin >> n >> m; qr[i]={n,m,i}; } int w=max(1,(int)sqrt(q)); sort(all(qr),[&](auto a,auto b){ if(a.n/w == b.n/w) return a.m ans(q); { rep(j,1,m+1) now+=COM(2*j-2,n-1); ans[id]=now; } mint inv2=mint(2).inv(); rep(i,1,q){ auto [N,M,ID]=qr[i]; while(nN){ now=COM(2*m,n)-2*now; n--; } while(mM){ now-=COM(2*m-2,n-1); m--; } n=N,m=M,id=ID; ans[id]=now; } rep(i,0,q){ cout << ans[i].val() << "\n"; } return; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; // cin >> T; rep(_,0,T){ solve(); } }