submission_id
stringlengths
5
9
problem_id
stringlengths
3
6
date
int64
-1
-1
language
stringclasses
11 values
verdict
stringclasses
1 value
cpu_time
int64
-1
15k
memory
int64
-1
1.07B
code
stringlengths
16
11k
source
stringclasses
1 value
testcount
int64
0
604
lenght
int64
16
11k
s681968706
p04051
1,569,214,767
cpp
Accepted
206
64,640
// 23;23 #include <algorithm> #include <iostream> #include <cstdio> #define rint register int #define N 200005 #define M 2003 using namespace std; const int Mod = 1e9 + 7; const int eps = 2001; int n, a[N], b[N], f[M << 1][M << 1]; int fac[M << 2], inv[M << 2], ifac[M << 2]; inline void prework() { fac[0] = inv[1] = ifac[0] = 1; for (rint i = 1; i <= eps << 2; ++i) fac[i] = 1ll * fac[i - 1] * i % Mod; for (rint i = 2; i <= eps << 2; ++i) inv[i] = 1ll * inv[Mod % i] * (Mod - Mod / i) % Mod; for (rint i = 1; i <= eps << 2; ++i) ifac[i] = 1ll * ifac[i - 1] * inv[i] % Mod; } inline int C(int x, int y) { return 1ll * fac[x + y] * ifac[x] % Mod * ifac[y] % Mod; } int main() { #ifdef whyqx freopen("work.in", "r", stdin); freopen("work.out", "w", stdout); #endif prework(); cin >> n; for (rint i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i), ++f[eps - a[i]][eps - b[i]]; for (rint i = 1; i <= eps << 1; ++i) for (rint j = 1; j <= eps << 1; ++j) (f[i][j] += (f[i - 1][j] + f[i][j - 1]) % Mod) %= Mod; long long ans = 0; for (rint i = 1; i <= n; ++i) (ans += f[eps + a[i]][eps + b[i]]) %= Mod; for (rint i = 1; i <= n; ++i) (ans -= C(a[i] << 1, b[i] << 1)) %= Mod; cout << 1ll * (ans % Mod + Mod) % Mod * ((Mod + 1) >> 1) % Mod; return 0; }
codenet
-1
1,382
s681968706
p04051
1,569,214,767
cpp
Accepted
206
64,640
// 23;23 #include <algorithm> #include <iostream> #include <cstdio> #define rint register int #define N 200005 #define M 2003 using namespace std; const int Mod = 1e9 + 7; const int eps = 2001; int n, a[N], b[N], f[M << 1][M << 1]; int fac[M << 2], inv[M << 2], ifac[M << 2]; inline void prework() { fac[0] = inv[1] = ifac[0] = 1; for (rint i = 1; i <= eps << 2; ++i) fac[i] = 1ll * fac[i - 1] * i % Mod; for (rint i = 2; i <= eps << 2; ++i) inv[i] = 1ll * inv[Mod % i] * (Mod - Mod / i) % Mod; for (rint i = 1; i <= eps << 2; ++i) ifac[i] = 1ll * ifac[i - 1] * inv[i] % Mod; } inline int C(int x, int y) { return 1ll * fac[x + y] * ifac[x] % Mod * ifac[y] % Mod; } int main() { #ifdef whyqx freopen("work.in", "r", stdin); freopen("work.out", "w", stdout); #endif prework(); cin >> n; for (rint i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i), ++f[eps - a[i]][eps - b[i]]; for (rint i = 1; i <= eps << 1; ++i) for (rint j = 1; j <= eps << 1; ++j) (f[i][j] += (f[i - 1][j] + f[i][j - 1]) % Mod) %= Mod; long long ans = 0; for (rint i = 1; i <= n; ++i) (ans += f[eps + a[i]][eps + b[i]]) %= Mod; for (rint i = 1; i <= n; ++i) (ans -= C(a[i] << 1, b[i] << 1)) %= Mod; cout << 1ll * (ans % Mod + Mod) % Mod * ((Mod + 1) >> 1) % Mod; return 0; }
codenet
-1
1,382
s181439014
p04051
1,473,242,925
cpp
Accepted
987
172,800
#include <iostream> using namespace std; const int KMAX = 200000 + 5; const int N = 2000 + 5; const int MOD = 1000000000 + 7; const int INV2 = 500000000 + 4; int comb[4 * N][2 * N]; void precalc_comb() { for (int i = 0; i < 4 * N; ++ i) { comb[i][0] = 1; for (int j = 1; j <= i && j < 2 * N; ++ j) { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; if (comb[i][j] >= MOD) comb[i][j] -= MOD; } } } int K; int A[KMAX]; int B[KMAX]; int dp[2 * N][2 * N]; int main() { ios_base :: sync_with_stdio(false); cin >> K; for (int i = 1; i <= K; ++ i) cin >> A[i] >> B[i]; for (int i = 1; i <= K; ++ i) ++ dp[N - A[i]][N - B[i]]; for (int i = 1; i < 2 * N; ++ i) for (int j = 1; j < 2 * N; ++ j) { dp[i][j] += dp[i][j - 1]; if (dp[i][j] >= MOD) dp[i][j] -= MOD; dp[i][j] += dp[i - 1][j]; if (dp[i][j] >= MOD) dp[i][j] -= MOD; } precalc_comb(); int ans = 0; for (int i = 1; i <= K; ++ i) { ans += dp[N + A[i]][N + B[i]]; if (ans >= MOD) ans -= MOD; ans -= comb[A[i] + B[i] + A[i] + B[i]][A[i] + A[i]]; if (ans < 0) ans += MOD; } ans = (1LL * ans * INV2) % MOD; cout << ans << '\n'; return 0; }
codenet
-1
1,385
s346264439
p04051
1,501,812,665
cpp
Accepted
174
126,976
//such a genius problem! #include <bits/stdc++.h> #define FI(i,a,b) for(int i=(a);i<=(b);i++) #define FD(i,a,b) for(int i=(a);i>=(b);i--) #define LL long long #define Ldouble long double #define PI 3.14159265358979323846264338327950288419 #define PII pair<int,int> #define PLL pair<LL,LL> #define mp make_pair #define fi first #define se second using namespace std; #define mod 1000000007 #define C 2001 int n, a[200005], b[200005]; int grid[4005][4005], dp[4005][4005], ans; int po(int A, int B){ int c = 1, d = A; while(B){ if(B & 1) c = 1LL * c * d % mod; d = 1LL * d * d % mod; B >>= 1; } return c; } int fact[8004], inv[8004]; int ncr(int N, int R){ return (1LL * fact[N] * inv[R]) % mod * inv[N - R] % mod; } int main(){ fact[0] = inv[0] = 1; FI(i, 1, 8000){ fact[i] = 1LL * fact[i - 1] * i % mod; inv[i] = po(fact[i], mod - 2); } scanf("%d", &n); FI(i, 1, n){ scanf("%d %d", &a[i], &b[i]); grid[C - a[i]][C - b[i]]--; grid[C + a[i]][C + b[i]]++; } FI(i, 1, 4002) FI(j, 1, 4002){ dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; if(grid[i][j] < 0){ dp[i][j] = (dp[i][j] - grid[i][j]) % mod; } if(grid[i][j] > 0){ ans = (ans + 1LL * grid[i][j] * dp[i][j]) % mod; } } FI(i, 1, n) ans = (ans - ncr(2 * (a[i] + b[i]), 2 * b[i])) % mod; ans = 1LL * ans * po(2, mod - 2) % mod; printf("%d\n", (ans + mod) % mod); return 0; }
codenet
-1
1,386
s917345681
p04051
1,590,089,111
cpp
Accepted
107
64,512
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i) #define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i) #define mp(x,y) make_pair((x),(y)) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef pair<int,int> pii; inline int read(){ register int x=0,f=1;register char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();} while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();} return f?x:-x; } const int mod=1000000007; int n,a[200005],b[200005],f[4005][4005],fac[8005],ifc[8005]; #define f(x,y) f[x+2000][y+2000] inline void inc(int& x,int y){x=x+y<mod?x+y:x+y-mod;} inline void dec(int& x,int y){x=x-y>=0?x-y:x-y+mod;} inline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;} inline int C(int n,int m){return (n<0||m<0||n<m)?0:1ll*fac[n]*ifc[m]%mod*ifc[n-m]%mod;} int main(){ // freopen("in.in","r",stdin); REP(i,fac[0]=1,8001)fac[i]=1ll*fac[i-1]*i%mod; ifc[8001]=power(fac[8001],mod-2); DREP(i,8001,1)ifc[i-1]=1ll*ifc[i]*i%mod; n=read(); REP(i,1,n){ a[i]=read(),b[i]=read(); ++f(-a[i],-b[i]); } REP(i,-2000,2000)REP(j,-2000,2000) inc(f(i+1,j),f(i,j)),inc(f(i,j+1),f(i,j)); int ans=0; REP(i,1,n)inc(ans,f(a[i],b[i])); REP(i,1,n)dec(ans,C(a[i]*2+b[i]*2,a[i]*2)); ans=1ll*ans*(mod+1)/2%mod; printf("%d\n",ans); return 0; }
codenet
-1
1,387
s129621965
p04051
1,541,014,873
cpp
Accepted
127
64,512
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<iostream> #include<cstdio> #include<cstring> #define ll long long #define p 1000000007 using namespace std; inline int get(){ int n=0;char c;while((c=getchar())||23333){ if(c>='0'&&c<='9')break;if(c=='-')goto s; }n=c-'0';while((c=getchar())||23333){ if(c>='0'&&c<='9')n=n*10+c-'0';else return(n); }s:while((c=getchar())||23333){ if(c>='0'&&c<='9')n=n*10-c+'0';else return(n); } } int dp[4001][4001];ll jc[8001],jcny[8001]; inline ll mi(int a,int b){ ll ans=1,tmp=a;while(b){ if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1; }return(ans); }int xs[200001],ys[200001]; inline ll cnm(int n,int m){ ll cjr=jc[n]*jcny[m];cjr%=p;cjr*=jcny[n-m];cjr%=p;return(cjr); } int main(){ int n=get();for(register int i=1;i<=n;i++){ xs[i]=get();ys[i]=get();dp[2000-xs[i]][2000-ys[i]]++; }jc[0]=1;for(register int i=1;i<=8000;i++)jc[i]=(jc[i-1]*i)%p; jcny[8000]=mi(jc[8000],p-2);for(register int i=7999;i>=0;i--)jcny[i]=(jcny[i+1]*(i+1))%p; for(register int i=0;i<=4000;i++){ for(register int j=0;j<=4000;j++){ if(i-1>=0)dp[i][j]+=dp[i-1][j]; if(j-1>=0)dp[i][j]+=dp[i][j-1];dp[i][j]%=p; } }ll ans=0;for(register int i=1;i<=n;i++){ ans+=dp[2000+xs[i]][2000+ys[i]]; ans-=cnm(xs[i]+xs[i]+ys[i]+ys[i],xs[i]+xs[i]);ans%=p;ans+=p;ans%=p; }ans*=mi(2,p-2);ans%=p;cout<<ans<<endl; return(0); }
codenet
-1
1,387
s282504647
p04051
1,493,200,483
cpp
Accepted
230
65,792
#include <bits/stdc++.h> using namespace std; const int EXP = 2e3 + 3; const int DIM = 4e3 + 5; const int MOD = 1e9 + 7; pair<int, int> arr[DIM * DIM]; int fct[DIM * 2], inv[DIM * 2], dp[DIM][DIM]; inline int lgput( int x, int n ) { if( n == 0 ) return 1; int y = lgput( x, n / 2 ); y = ( 1LL * y * y ) % MOD; if( n % 2 == 1 ) y = ( 1LL * y * x ) % MOD; return y; } inline int comb( int n, int k ) { return ( ( ( 1LL * fct[n] * inv[k] ) % MOD ) * inv[n - k] ) % MOD; } int main( void ) { fct[0] = inv[0] = 1; for( int i = 1; i < DIM * 2; i ++ ) { fct[i] = ( 1LL * fct[i - 1] * i ) % MOD; inv[i] = lgput( fct[i], MOD - 2 ); } int n; cin >> n; for( int i = 1; i <= n; i ++ ) { cin >> arr[i].first >> arr[i].second; dp[EXP - arr[i].first][EXP - arr[i].second] ++; } for( int i = 1; i < DIM; i ++ ) for( int j = 1; j < DIM; j ++ ) dp[i][j] = ( dp[i][j] + dp[i - 1][j] + dp[i][j - 1] ) % MOD; int ans = 0; for( int i = 1; i <= n; i ++ ) { ans = ( ans + dp[EXP + arr[i].first][EXP + arr[i].second] ) % MOD; ans = ( ans - comb( ( arr[i].first + arr[i].second ) * 2, arr[i].first * 2 ) + MOD ) % MOD; } ans = ( 1LL * ans * lgput( 2, MOD - 2 ) ) % MOD; cout << ans << endl; return 0; }
codenet
-1
1,387
s918685324
p04051
1,537,199,240
cpp
Accepted
122
67,712
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define gc getchar() #define lint long long #define mod 1000000007 #define debug(x) cerr<<#x<<"="<<x #define sp <<" " #define ln <<endl #define f(x,y) dp[(x)+BAS+5][(y)+BAS+5] #define N 200010 #define BAS 2010 #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; inline int inn() { int x,ch;while((ch=gc)<'0'||ch>'9');x=ch^'0';while((ch=gc)>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0');return x; } int a[N],b[N],dp[BAS*2+100][BAS*2+100],fac[N],facinv[N]; inline int fast_pow(int x,int k,int ans=1) { for(;k;k>>=1,x=(lint)x*x%mod) (k&1)?ans=(lint)ans*x%mod:0;return ans; } inline int S(int n) { rep(i,1,n) f(-a[i],-b[i])++;int ans=0; rep(i,-BAS,BAS) rep(j,-BAS,BAS) if(f(i,j)) f(i+1,j)+=f(i,j),f(i,j+1)+=f(i,j),(f(i+1,j)>=mod?f(i+1,j)-=mod:0),(f(i,j+1)>=mod?f(i,j+1)-=mod:0); rep(i,1,n) ans+=f(a[i],b[i]),(ans>=mod?ans-=mod:0);return ans; } inline int prelude(int n) { rep(i,fac[0]=1,n) fac[i]=(lint)fac[i-1]*i%mod;facinv[n]=fast_pow(fac[n],mod-2); for(int i=n-1;i>=0;i--) facinv[i]=(i+1ll)*facinv[i+1]%mod;return 0; } inline int C(int n,int m) { return (lint)fac[n]*facinv[n-m]%mod*facinv[m]%mod; } int main() { int n=inn();rep(i,1,n) a[i]=inn(),b[i]=inn();int ans=S(n);prelude(10000); rep(i,1,n) ans-=C(2*a[i]+2*b[i],2*a[i]),(ans<0?ans+=mod:0); return !printf("%lld\n",(lint)fast_pow(2,mod-2)*ans%mod); }
codenet
-1
1,390
s959588547
p04051
1,538,193,147
cpp
Accepted
180
101,376
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int offset = 2005; const int mod = 1000000007; void add(int &x,int y) { x += y; if (x >= mod) x -= mod; } int mul(int x,int y) { return (long long) x * y % mod; } int pw(int x,int y) { int ret = 1; while (y) { if (y & 1) ret = mul(ret, x); x = mul(x, x); y >>= 1; } return ret; } int n; int a[N], b[N]; vector<int> _get[offset + offset]; int f[offset + offset][offset + offset], upd[offset + offset][offset + offset]; int fac[N], ifac[N]; int calc(int x,int y) { return mul(fac[x + y], mul(ifac[x], ifac[y])); } int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; upd[-a[i] + offset][-b[i] + offset]++; _get[a[i] + offset].push_back(b[i] + offset); } int res = 0; for (int x = 0; x < offset + offset; ++x) { for (int y = 0; y < offset + offset; ++y) { add(f[x][y], upd[x][y]); if (x > 0) add(f[x][y], f[x - 1][y]); if (y > 0) add(f[x][y], f[x][y - 1]); } for (int y : _get[x]) add(res, f[x][y]); } fac[0] = 1; for (int i = 1; i < N; ++i) fac[i] = mul(fac[i - 1], i); ifac[N - 1] = pw(fac[N - 1], mod - 2); for (int i = N - 2; i >= 0; --i) ifac[i] = mul(ifac[i + 1], i + 1); for (int i = 1; i <= n; ++i) add(res, mod - calc(a[i] + a[i], b[i] + b[i])); res = mul(res, pw(2, mod - 2)); cout << res << '\n'; }
codenet
-1
1,393
s641303225
p04051
1,486,533,826
cpp
Accepted
230
64,512
#include<bits/stdc++.h> using namespace std; int ans, N, M, mod = 1e9 + 7, a[200009], b[200009], fac[8009], inv[8009], dp[4009][4009]; int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;} int substract (int x, int y) {if (x >= y) return x - y; return x - y + mod;} int mul (int x, int y) {return 1LL * x * y % mod;} int pow (int a, int b) { int p = 1; for (int i=0; (1<<i) <= b; i++) { if (b & (1 << i)) p = mul (p, a); a = mul (a, a); } return p; } void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i); inv[lim] = pow (fac[lim], mod - 2);for (int i=lim - 1; i>=1; i--)inv[i] = mul (inv[i + 1], i + 1);} int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;} int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d", &N), Prec (8000), M = 2000, ans = 0; for (int i=1; i<=N; i++) { scanf ("%d %d", &a[i], &b[i]), dp[M + 1 - a[i]][M + 1 - b[i]] ++; ans = substract (ans, comb (2 * a[i] + 2 * b[i], 2 * a[i])); } for (int i=1; i<=2 * M + 1; i++) for (int j=1; j<=2 * M + 1; j++) dp[i][j] = add (dp[i][j], add (dp[i - 1][j], dp[i][j - 1])); for (int i=1; i<=N; i++) ans = add (ans, dp[M + 1 + a[i]][M + 1 + b[i]]); ans = mul (ans, pow (2, mod - 2)); printf ("%d\n", ans); return 0; }
codenet
-1
1,396
s062170479
p04051
1,578,599,859
cpp
Accepted
202
101,504
//IOI 2021 #include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second typedef pair<int, int> pii; const int MAXN = 200 * 1000 + 1, MAXS = 2 * 1000 + 17, mod = 1e9 + 7; int sum(int a, int b) { a += b; if (a >= mod) a -= mod; else if (a < 0) a += mod; return a; } int mul(int a, int b) { return (1LL * a * b) % mod; } int pw(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(a, res); a = mul(a, a); b >>= 1; } return res; } int n, dp[MAXS << 1][MAXS << 1], x[MAXN], y[MAXN], p[MAXS << 1][MAXS << 1], ans, fac[MAXN], ifac[MAXN]; vector<pii> all; void prep() { fac[0] = 1; for (int i = 1; i < MAXN; i++) fac[i] = mul(fac[i - 1], i); for (int i = 1; i < MAXN; i++) ifac[i] = pw(fac[i], mod - 2); } int C(int a, int b) { return mul(fac[a], mul(ifac[b], ifac[a - b])); } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); prep(); cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i], p[MAXS - x[i]][MAXS - y[i]]++; for (int i = 1; i < MAXS << 1; i++) for (int j = 1; j < MAXS << 1; j++) dp[i][j] = sum(sum(dp[i - 1][j], dp[i][j - 1]), p[i][j]); for (int i = 1; i <= n; i++) ans = sum(ans, dp[x[i] + MAXS][y[i] + MAXS]); for (int i = 1; i <= n; i++) ans = sum(ans, -C(2 * x[i] + 2 * y[i], 2 * x[i])); ans = mul(ans, pw(2, mod - 2)); cout << ans << endl; return 0; }
codenet
-1
1,397
s344691045
p04051
1,509,057,302
cpp
Accepted
197
95,360
#include <bits/stdc++.h> #define SZ(x) ((int(x.size()))) typedef long long ll; typedef long double ld; using namespace std; const int mod = 1000000007, maxn = 4*1000+10, O = 2005; ll ans, kam, fac[2 * maxn], caf[2 * maxn]; int n, a, b, dp[maxn][maxn], mark[maxn][maxn]; ll power (ll a, ll b, int m) { if (b == 0) return 1; ll kmk = power (a, b / 2, m); if (b & 1) return (((kmk * kmk) % m) * a) % m; return (kmk * kmk) % m; } void make_fac () { fac[0] = 1; for (int i = 1; i < 2 * maxn; i++) fac[i] = (fac[i - 1] * i) % mod; } void make_caf () { for (int i = 0; i < 2 * maxn; i++) caf[i] = power (fac[i], mod - 2, mod); } ll C (int R, int N) { return (((fac[N] * caf[R]) % mod) * caf[N - R]) % mod; } int main() { ios::sync_with_stdio(0); cin.tie(0); make_fac (); make_caf (); cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; kam = (kam + C (2 * a, 2 * (a + b))) % mod; dp[O - a][O - b]++; mark[O + a][O + b]++; } for (int i = 1; i < maxn; i++) { for (int j = 1; j < maxn; j++) { dp[i][j] = (((dp[i][j] + dp[i - 1][j]) % mod) + dp[i][j - 1]) % mod; ans = (ans + (((ll)dp[i][j] * mark[i][j]) % mod)) % mod; } } cout << (((ans + mod - kam) % mod) * power (2, mod - 2, mod)) % mod; return 0; }
codenet
-1
1,398
s321234320
p04051
1,590,700,625
cpp
Accepted
209
97,792
/*input 3 1 1 1 1 2 1 */ #include <bits/stdc++.h> using namespace std; int read() { int x = 0, c = getchar(); for(; !(c > 47 && c < 58); c = getchar()); for(; (c > 47 && c < 58); c = getchar()) x = x * 10 + c - 48; return x; } const int maxm = 2005; const int maxn = 200005; const int mod = 1e9 + 7; void add(int &a, int b) { a = (a + b) % mod; } pair<int, int> p[maxn]; int n; int f[maxm << 1][maxm << 1]; int mark[maxm << 1][maxm << 1]; int mul[maxn], inv[maxn]; int C(int k, int n) { if(k > n) return 0; return 1ll * mul[n] * inv[n - k] % mod * inv[k] % mod; } int main(){ mul[0] = inv[0] = inv[1] = 1; for(int i = 1; i < maxn; ++ i) mul[i] = 1ll * i * mul[i - 1] % mod; for(int i = 2; i < maxn; ++ i) inv[i] = -1ll * (mod / i) * inv[mod % i] % mod + mod; for(int i = 2; i < maxn; ++ i) inv[i] = 1ll * inv[i] * inv[i - 1] % mod; n = read(); for(int i = 1; i <= n; ++ i) { int x = read(), y = read(); mark[x + maxm][y + maxm] ++; p[i] = make_pair(x, y); } for(int i = (maxm << 1) - 1; i; -- i) for(int j = (maxm << 1) - 1; j; -- j) { add(f[i][j], mark[i][j]); add(f[i - 1][j], f[i][j]); add(f[i][j - 1], f[i][j]); } int Ans = 0; for(int i = 1; i <= n; ++ i) { int x = p[i].first, y = p[i].second; int cur = (0ll + f[maxm - x][maxm - y] + mod - C(x + x, (x + y) << 1)) % mod; add(Ans, 1ll * cur * (mod + 1) / 2 % mod); } printf("%d\n", Ans); }
codenet
-1
1,399
s710756394
p04051
1,595,589,907
cpp
Accepted
289
93,516
#include <bits/stdc++.h> using namespace std; const int N = 4069; const int M = 200010; const int SHIFT = 2005; const int MOD = 1e9 + 7; int n, a[M], b[M], dp[N][N], fac[N << 1], inv[N << 1], dest[N][N]; int call (int x, int y) { if (x == N or y == N) return 0; if (~dp[x][y]) return dp[x][y]; dp[x][y] = call(x + 1, y) + call(x, y + 1); if (dp[x][y] >= MOD) dp[x][y] -= MOD; dp[x][y] += dest[x][y]; if (dp[x][y] >= MOD) dp[x][y] -= MOD; return dp[x][y]; } int bigMod (int a, int e) { if (e == -1) e = MOD - 2; int ret = 1; while (e) { if (e & 1) ret = (long long) ret * a % MOD; a = (long long) a * a % MOD, e >>= 1; } return ret; } inline int comb (int x, int y) { return (long long) inv[x] * inv[y] % MOD * fac[x + y] % MOD; } int main() { fac[0] = 1; for (int i = 1; i < N << 1; ++i) { fac[i] = (long long) i * fac[i - 1] % MOD; inv[i] = bigMod(fac[i], -1); } cin >> n; for (int i = 1; i <= n; ++i) { scanf("%d %d", a + i, b + i); ++dest[SHIFT + a[i]][SHIFT + b[i]]; } memset(dp, -1, sizeof dp); int ans = 0; for (int i = 1; i <= n; ++i) { ans += call(SHIFT - a[i], SHIFT - b[i]); if (ans >= MOD) ans -= MOD; } for (int i = 1; i <= n; ++i) { int cur = comb(a[i] << 1, b[i] << 1); ans -= cur; if (ans < 0) ans += MOD; } if (ans & 1) ans += MOD; ans >>= 1; cout << ans % MOD << '\n'; return 0; }
codenet
-1
1,402
s016451953
p04051
1,595,287,914
cpp
Accepted
201
130,592
#include<bits/stdc++.h> #define ll long long using namespace std; template<typename T> void read(T &x) { x=0;char c=getchar();bool p=0; for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1; for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48); if(p)x=-x; } const ll MOD=1000000000+7; ll ksm(ll basic,ll mi) { ll tmp=1; while(mi) { if(mi&1)tmp=tmp*basic%MOD; mi>>=1; basic=basic*basic%MOD; } return tmp; } ll f[4005][4005]; int a[200005],b[200005],n; ll fac[8005],inv[8005]; ll C(ll x,ll y) { return fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int main() { fac[0]=inv[0]=1; for(ll i=1;i<=8000;++i)fac[i]=fac[i-1]*i%MOD; inv[8000]=ksm(fac[8000],MOD-2); for(ll i=7999;i;--i)inv[i]=inv[i+1]*(i+1)%MOD; read(n); for(int i=1;i<=n;++i) { read(a[i]),read(b[i]); ++f[-a[i]+2000][-b[i]+2000]; } for(int i=0;i<=4000;++i) { for(int j=0;j<=4000;++j) { if(i)f[i][j]=(f[i][j]+f[i-1][j])%MOD; if(j)f[i][j]=(f[i][j]+f[i][j-1])%MOD; } } ll ans=0; for(int i=1;i<=n;++i) { ans=(ans+f[a[i]+2000][b[i]+2000])%MOD; } for(int i=1;i<=n;++i) { ans=(ans-C(2*a[i]+2*b[i],2*a[i])+MOD)%MOD; } ans=ans*ksm(2,MOD-2)%MOD; printf("%lld\n",ans); return 0; } /* C(a[i]+b[i]+a[j]+b[j],a[i]+a[j]):从(-a[i],-b[i])走到(a[j],b[j]) */
codenet
-1
1,402
s971887031
p04051
1,514,497,350
cpp
Accepted
324
127,488
#include<bits/stdc++.h> using namespace std; typedef long long ll; int N; int A[200010],B[200010] = {0}; ll mod = 1000000007; ll dp[4010][4010] = {0}; ll ans = 0; ll F[8010],R[8010]; ll pow_mod(ll a,ll b) { if(b == 0)return 1; ll res = pow_mod(a * a % mod,b / 2); if(b & 1)res = res * a % mod; return res; } ll con(ll a,ll b) { return F[a] * R[b] % mod * R[a - b] % mod; } int main() { scanf("%d",&N); for(int i = 0; i < N; i++)scanf("%d%d",A + i,B + i); for(int i = 0; i < N; i++) { dp[2001 - A[i]][2001 - B[i]]++; } for(int i = 1; i <= 4001; i++) { for(int j = 1; j <= 4001; j++) { dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % mod; } } for(int i = 0; i < N; i++) { ans += dp[A[i] + 2001][B[i] + 2001]; ans %= mod; } /* for(int i = 0; i < 8010; i++) { for(int j = 0; j <= i; j++) { if(j == 0)con[i][j] = 1; else con[i][j] = (con[i - 1][j] + con[i - 1][j - 1]) % mod; } } */ F[0] = 1; for(int i = 1; i < 8010; i++)F[i] = F[i - 1] * i % mod; for(int i = 0; i < 8010; i++)R[i] = pow_mod(F[i],mod - 2); for(int i = 0; i < N; i++) { ans -= con(A[i] * 2 + B[i] * 2,A[i] * 2); ans = (ans + mod) % mod; } printf("%lld\n",ans * 500000004 % mod); return 0; }
codenet
-1
1,408
s420516464
p04051
1,494,731,853
cpp
Accepted
146
95,232
#include<cstdio> #include<cstring> #include<algorithm> #define N 2005 using namespace std; const int mod = 1e9+7; inline int read(){ int sum = 0, t = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') t = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ sum = sum * 10 + ch - '0'; ch = getchar(); } return sum * t; } int n; int f[N<<1][N<<1]; int a[N<<1][N<<1]; int fac[N<<2], inv[N<<2]; void upd(int &x, int y){ x += y; if(x >= mod) x -= mod; } int quick_mod(int x, int y){ int res = 1; x %= mod; for(; y ; y >>= 1, x = 1LL * x * x % mod) if(y & 1) res = 1LL * res * x % mod; return res; } int C(int x, int y){ return x < y ? 0 : 1LL * fac[x] * inv[y] % mod * inv[x - y] % mod; } int main(){ int ans = 0; fac[0] = 1; for(int i = 1; i < (N << 2); i++) fac[i] = 1LL * fac[i - 1] * i % mod; inv[(N << 2) - 1] = quick_mod(fac[(N << 2) - 1], mod - 2); for(int i = (N << 2) - 1; i ; i--) inv[i - 1] = 1LL * inv[i] * i % mod; n = read(); for(int i = 1; i <= n; i++){ int A = read(), B = read(); upd(a[A + N][B + N], 1); upd(f[N - A][N - B], 1); upd(ans, mod - C(A + A + B + B, A + A)); } for(int i = 0; i < (N << 1); i++) for(int j = 0; j < (N << 1); j++){ upd(ans, 1LL * a[i][j] * f[i][j] % mod); if(i + 1 < (N << 1)) upd(f[i + 1][j], f[i][j]); if(j + 1 < (N << 1)) upd(f[i][j + 1], f[i][j]); } ans = 1LL * ans * 500000004 % mod; printf("%d\n", ans); }
codenet
-1
1,414
s044546675
p04051
1,581,671,086
cpp
Accepted
185
65,920
#include <bits/stdc++.h> using namespace std; #define Pii pair<int, int> #define ll long long #define mod 1000000007 #define N 10001 #define S 2000 ll Qpow(ll x, ll n) { ll s = 1; while (n) { if (n & 1) s = s * x % mod; x = x * x % mod; n >>= 1; } return s; } ll inv(ll x) { return Qpow(x, mod - 2); } ll fac[N], ifac[N]; ll C(int x, int y) { return fac[x] * ifac[x - y] % mod * ifac[y] % mod; } void Prepare() { fac[0] = 1; for (ll i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod; ifac[N - 1] = inv(fac[N - 1]); for (ll i = N - 1; i; i--) ifac[i - 1] = ifac[i] * i % mod; } Pii P[S * S]; int d[S << 1 | 1][S << 1 | 1], n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &P[i].first, &P[i].second); Prepare(); for (int i = 1; i <= n; i++) d[S - P[i].first][S - P[i].second]++; for (int dis = 1; dis <= S << 2; dis++) for (int i = max(0, dis - (S << 1)); i <= min(S << 1, dis); i++) { int j = dis - i; if (i) d[i][j] = (d[i][j] + d[i - 1][j]) % mod; if (j) d[i][j] = (d[i][j] + d[i][j - 1]) % mod; } ll ans = 0; for (int i = 1; i <= n; i++) { int x = P[i].first, y = P[i].second; ans = (ans + d[x + S][y + S]) % mod; ans = (ans - C(2 * x + 2 * y, 2 * x) + mod) % mod; } printf("%lld\n", ans * inv(2) % mod); return 0; }
codenet
-1
1,416
s625880692
p04051
1,597,695,146
cpp
Accepted
158
67,828
#include<bits/stdc++.h> #define ll long long #define ld long double #define db double #define pint pair<int,ll> #define mk make_pair #define pb push_back #define eb emplace_back #define ins insert #define fi first #define se second #define Rep(x,y,z) for(int x=y;x<=z;x++) #define Red(x,y,z) for(int x=y;x>=z;x--) using namespace std; const int MAXN=2e5+5,MAXM=4005,Mod=1e9+7,Inv=Mod+1>>1; char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny; inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;} //inline char gc(){return getchar();} inline int read(){ int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc; for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny; } int n,O,f[MAXM][MAXM],a[MAXN],b[MAXN],Fac[MAXN],iFac[MAXN]; inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;} int main(){ // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); n=read(),O=2000; Fac[0]=iFac[0]=1;Rep(i,1,8000)Fac[i]=1ll*Fac[i-1]*i%Mod,iFac[i]=Fp(Fac[i],Mod-2); Rep(i,1,n)a[i]=read(),b[i]=read(),f[O-a[i]][O-b[i]]++; Rep(i,0,4000)Rep(j,0,4000)f[i][j]=(0ll+(i?f[i-1][j]:0)+(j?f[i][j-1]:0)+f[i][j])%Mod; int ans=0;Rep(i,1,n)ans=(ans+f[O+a[i]][O+b[i]])%Mod,ans=(ans-1ll*Fac[a[i]+b[i]<<1]*iFac[a[i]<<1]%Mod*iFac[b[i]<<1]%Mod+Mod)%Mod; cout<<1ll*ans*Inv%Mod<<'\n'; return 0; }
codenet
-1
1,417
s722615422
p04051
1,576,682,640
cpp
Accepted
191
65,280
//Created Time:2019年12月18日 星期三 08时37分26秒 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define N 200005 #define M 4004 #define mod 1000000007 using namespace std; int n; int ifac[N], fac[N], f[M][M], cnt[M][M], x[N], y[N]; int read(); void init(); int quick_pow(int); int C(int ,int); int main(){ n = read(); int m = 2001; init(); for(int i = 1; i <= n; ++i){ x[i] = read(), y[i] = read(); f[m - x[i]][m - y[i]]++; } for(int i = 1; i <= m * 2; ++i) for(int j = 1; j <= m * 2; ++j) (f[i][j] += (f[i - 1][j] + f[i][j - 1]) % mod) %= mod; int ans = 0; for(int i = 1; i <= n; ++i){ (ans += f[x[i] + m][y[i] + m]) %= mod; (ans += mod - C(x[i] * 2 + y[i] * 2, x[i] * 2)) %= mod; } cout << 1ll * ans * quick_pow(2) % mod << endl;; return 0; } int read(){ int x = 0; char ch = getchar(); for(; !isdigit(ch); ch = getchar()); for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); return x; } void init(){ int m = 10000; fac[0] = ifac[0] = 1; for(int i = 1; i <= m; ++i) fac[i] = 1ll * fac[i - 1] * i % mod; ifac[m] = quick_pow(fac[m]); for(int i = m; i; --i) ifac[i - 1] = 1ll * ifac[i] * i % mod; return ; } int quick_pow(int x){ int sum = 1, y = mod - 2; for(; y; y >>= 1, x = 1ll * x * x % mod) if(y & 1) sum = 1ll * sum * x % mod; return sum; } int C(int x, int y){ return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod; }
codenet
-1
1,417
s601812761
p04051
1,574,141,451
cpp
Accepted
174
96,384
#include<bits/stdc++.h> #define MAXN 200005 #define MAXM 4005 #define INF 1000000000 #define MOD 1000000007 #define INV 500000004 #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int> P; const int offset=2000; int n,a[MAXN],b[MAXN],fact[2*MAXM],invf[2*MAXM]; int dp[MAXM][MAXM],coef[MAXM][MAXM]; void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;} void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;} int pow_mod(int a,int i) { int s=1; while(i) { if(i&1) s=1LL*s*a%MOD; a=1LL*a*a%MOD; i>>=1; } return s; } int comb(int n,int k) { if(n<k) return 0; return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD; } int main() { fact[0]=invf[0]=1; for(int i=1;i<=8000;i++) fact[i]=1LL*fact[i-1]*i%MOD; invf[8000]=pow_mod(fact[8000],MOD-2); for(int i=7999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i],&b[i]); add(dp[offset-a[i]][offset-b[i]],1); add(coef[offset+a[i]][offset+b[i]],1); } int ans=0; for(int i=0;i<=4000;i++) for(int j=0;j<=4000;j++) { add(ans,1LL*coef[i][j]*dp[i][j]%MOD); add(dp[i+1][j],dp[i][j]); add(dp[i][j+1],dp[i][j]); } for(int i=1;i<=n;i++) dec(ans,comb(2*a[i]+2*b[i],2*a[i])); ans=1LL*ans*INV%MOD; printf("%d\n",ans); return 0; }
codenet
-1
1,419
s601812761
p04051
1,574,141,451
cpp
Accepted
174
96,384
#include<bits/stdc++.h> #define MAXN 200005 #define MAXM 4005 #define INF 1000000000 #define MOD 1000000007 #define INV 500000004 #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int> P; const int offset=2000; int n,a[MAXN],b[MAXN],fact[2*MAXM],invf[2*MAXM]; int dp[MAXM][MAXM],coef[MAXM][MAXM]; void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;} void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;} int pow_mod(int a,int i) { int s=1; while(i) { if(i&1) s=1LL*s*a%MOD; a=1LL*a*a%MOD; i>>=1; } return s; } int comb(int n,int k) { if(n<k) return 0; return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD; } int main() { fact[0]=invf[0]=1; for(int i=1;i<=8000;i++) fact[i]=1LL*fact[i-1]*i%MOD; invf[8000]=pow_mod(fact[8000],MOD-2); for(int i=7999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i],&b[i]); add(dp[offset-a[i]][offset-b[i]],1); add(coef[offset+a[i]][offset+b[i]],1); } int ans=0; for(int i=0;i<=4000;i++) for(int j=0;j<=4000;j++) { add(ans,1LL*coef[i][j]*dp[i][j]%MOD); add(dp[i+1][j],dp[i][j]); add(dp[i][j+1],dp[i][j]); } for(int i=1;i<=n;i++) dec(ans,comb(2*a[i]+2*b[i],2*a[i])); ans=1LL*ans*INV%MOD; printf("%d\n",ans); return 0; }
codenet
-1
1,419
s462801030
p04051
1,595,529,846
cpp
Accepted
212
146,456
#include <iostream> #include <cstring> #include <cstdio> #define LL long long #define Maxn 200010 #define Maxk 8010 using namespace std; const LL INF = 1e9, D = 2001, MOD = 1e9 + 7; inline int read() { int x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while('0' <= c && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } int n, a[Maxn], b[Maxn]; LL f[Maxk][Maxk], fac[Maxk], facinv[Maxk], ans; LL Pow(LL a, LL b) { LL ans = 1, base = a; while(b) { if(b & 1) ans = ans * base % MOD; base = base * base % MOD; b >>= 1; } return ans; } void pre() { fac[0] = facinv[0] = 1; for(int i = 1; i < Maxk; ++i) fac[i] = fac[i - 1] * i % MOD; facinv[Maxk - 1] = Pow(fac[Maxk - 1], MOD - 2); for(int i = Maxk - 2; i; --i) facinv[i] = facinv[i + 1] * (i + 1) % MOD; } LL C(LL a, LL b) { return fac[a] * facinv[b] % MOD * facinv[a - b] % MOD; } int main() { n = read(); pre(); for(int i = 1; i <= n; ++i) { a[i] = read(); b[i] = read(); ++f[D - a[i]][D - b[i]]; } for(int i = 1; i <= 4003; ++i) for(int j = 1; j <= 4003; ++j) f[i][j] += f[i - 1][j] + f[i][j - 1], f[i][j] %= MOD; for(int i = 1; i <= n; ++i) ans = (ans + f[a[i] + D][b[i] + D]) % MOD; for(int i = 1; i <= n; ++i) ans -= C(a[i] * 2 + b[i] * 2, a[i] * 2), ans %= MOD; ans *= Pow(2, MOD - 2); cout << (ans % MOD + MOD) % MOD << endl; return 0; }
codenet
-1
1,422
s601670334
p04051
1,539,727,786
cpp
Accepted
195
196,736
#include <iostream> #include <cstring> #include <cstdio> #include <cctype> #define int long long const int mod = 1e9 + 7; inline void read(int & x) { x = 0; int k = 1; char c = getchar(); while (!isdigit(c)) if (c == '-') c = getchar(), k = -1; else c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); x *= k; } inline int min(int a, int b) { return a > b ? b : a; } int n, ans = 0, O = 2001; int a[201010], b[201010]; int d[4050][4050]; int dp[4050][4050]; int fac[40005]; int inv[40005]; inline int ksm(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; b >>= 1, a = (a * a) % mod; } return ans; } void DP_it(void) { for (int i = 1; i <= 4030; ++i) for (int j = 1; j <= 4030; ++j) dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + d[i][j]) % mod; } inline int C(int a, int b) { return ((fac[a] * inv[b]) % mod * inv[a - b]) % mod; } signed main() { fac[0] = 1; inv[0] = 1; for (int i = 1; i <= 40000; ++i) fac[i] = (1LL * fac[i - 1] * i) % mod; inv[40000] = ksm(fac[40000], mod - 2); for (int i = 39999; i >= 1; --i) inv[i] = (inv[i + 1] * (i + 1)) % mod; read(n); for (int i = 1; i <= n; ++i) read(a[i]), read(b[i]), ++d[O - a[i]][O - b[i]]; DP_it(); for (int i = 1; i <= n; ++i) ans =((ans + dp[O + a[i]][O + b[i]] - C((a[i] + b[i]) << 1, a[i] + a[i])) % mod + mod) % mod; std::cout << (ans * ksm(2, mod - 2)) % mod; }
codenet
-1
1,422
s315911951
p04051
1,566,975,656
cpp
Accepted
227
129,024
#include <iostream> #define llint long long #define mod 1000000007 using namespace std; llint n; llint a[200005], b[200005]; llint dp[4009][4009]; const int Zero = 2004; const int FACT_MAX = 10005; llint fact[FACT_MAX], fact_inv[FACT_MAX]; llint modpow(llint a, llint n) { if(n == 0) return 1; if(n % 2){ return ((a%mod) * (modpow(a, n-1)%mod)) % mod; } else{ return modpow((a*a)%mod, n/2) % mod; } } void make_fact() { llint val = 1; fact[0] = 1; for(int i = 1; i < FACT_MAX; i++){ val *= i; val %= mod; fact[i] = val; } fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2); for(int i = FACT_MAX-2; i >= 0; i--){ fact_inv[i] = fact_inv[i+1] * (i+1) % mod; } } llint comb(llint n, llint k) { llint ret = 1; ret *= fact[n]; ret *= fact_inv[k], ret %= mod; ret *= fact_inv[n-k], ret %= mod; return ret; } int main(void) { make_fact(); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for(int i = 1; i <= n; i++) dp[Zero+a[i]][Zero+b[i]]++; for(int i = Zero+2000; i >= Zero-2000; i--){ for(int j = Zero+2000; j >= Zero-2000; j--){ dp[i][j] += dp[i+1][j] + dp[i][j+1]; dp[i][j] %= mod; } } llint ans = 0; for(int i = 1; i <= n; i++){ ans += dp[Zero-a[i]][Zero-b[i]]; ans %= mod; } for(int i = 1; i <= n; i++){ ans += mod - comb(2*(a[i]+b[i]), 2*a[i]); ans %= mod; } ans *= modpow(2, mod-2), ans %= mod; cout << ans << endl; return 0; }
codenet
-1
1,423
s361697414
p04051
1,476,341,379
cpp
Accepted
384
139,888
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long double ld; using namespace std; const ll MOD = 1e9 + 7; ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD; --b; } return ans; } ll fc[10000]; ll bfc[10000]; void init() { fc[0] = 1; for (int i = 1; i < 10000; ++i) fc[i] = (fc[i - 1] * i) % MOD; for (int i = 0; i < 10000; ++i) bfc[i] = pw(fc[i], MOD - 2); } ll cnk(int n, int k) { return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD; } const int MX = 2100; int n; ll arr[MX * 2][MX * 2]; int main() { init(); scanf("%d", &n); ll ans = 0; vector<pair<int, int> > vv; for (int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); ++arr[MX - a][MX - b]; vv.push_back(make_pair(a, b)); ans = (ans + MOD - cnk(2 * a + 2 * b, 2 * b)) % MOD; } for (int i = 1; i < MX * 2; ++i) for (int j = 1; j < MX * 2; ++j) arr[i][j] = (arr[i][j] + arr[i - 1][j] + arr[i][j - 1]) % MOD; for (int i = 0; i < (int)vv.size(); ++i) { ans = (ans + arr[vv[i].first + MX][vv[i].second + MX]) % MOD; } ans = (ans * pw(2, MOD - 2)) % MOD; cout << ans << "\n"; return 0; }
codenet
-1
1,423
s488647272
p04051
1,573,418,074
cpp
Accepted
189
130,944
#pragma GCC optimize("Ofast,inline", 3) #include<bits/stdc++.h> #define il inline #define rg register #define gi read<int> #define int long long using namespace std; const int O = 2e5 + 10, lim = 2010, mod = 1e9 + 7, Lim = 2020; template<class TT> il TT read() { TT o = 0, fl = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') fl = -1, ch = getchar(); while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar(); return fl * o; } int n, a[O], b[O], dp[Lim << 1][Lim << 1], fac[Lim << 2], inv[Lim << 2], ans; //il void pls(int & x, int y) {x += y; if (x >= mod) x -= mod;} il int C(int x, int y) {return 1ll * fac[y] * inv[x] % mod * inv[y - x] % mod;} signed main() { fac[0] = inv[1] = 1; for (int i = 1; i <= lim << 2; ++i) fac[i] = 1ll * fac[i - 1] * i % mod; for (int i = 2; i <= lim << 2; ++i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i <= lim << 2; ++i) inv[i] = 1ll * inv[i] * inv[i - 1] % mod; n = gi(); for (int i = 1; i <= n; ++i) { a[i] = gi(), b[i] = gi(); ++dp[lim - a[i]][lim - b[i]]; } for (int i = 1; i <= lim + 1 << 1; ++i) for (int j = 1; j <= lim + 1 << 1; ++j) dp[i][j] = ((dp[i][j] + dp[i][j - 1]) % mod + dp[i - 1][j]) % mod; for (int i = 1; i <= n; ++i) { (ans += dp[lim + a[i]][lim + b[i]]) %= mod; (ans += mod - C(a[i] << 1, a[i] + b[i] << 1)) %= mod; } printf("%lld", 1ll * ans * inv[2] % mod); return 0; }
codenet
-1
1,424
s772632850
p04051
1,515,032,111
cpp
Accepted
128
64,384
#include<cstdio> inline int read() { int x;char c; while((c=getchar())<'0'||c>'9'); for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0'; return x; } const int MOD=1e9+7; struct mint{int x;mint(int x=0):x(x){}}; inline mint operator+ (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;} inline mint operator- (mint a){return MOD-a.x;} inline mint operator- (mint a,mint b){return a+-b;} inline mint operator* (mint a,mint b){return 1LL*a.x*b.x%MOD;} inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;} inline mint operator~ (mint x){return x<<MOD-2;} inline mint operator/ (mint a,mint b){return a*~b;} inline mint&operator+= (mint&a,mint b){return a=a+b;} inline mint&operator-= (mint&a,mint b){return a=a-b;} inline mint&operator*= (mint&a,mint b){return a=a*b;} inline mint&operator<<=(mint&x,int y){return x=x<<y;} inline mint&operator/= (mint&a,mint b){return a=a/b;} #define MN 200000 #define MX 2001 mint f[MX*2][MX*2],F[MX*4+5],R[MX*4+5],ans; int a[MN+5],b[MN+5]; inline mint C(int n,int m){return F[n]*R[m]*R[n-m];} int main() { int n=read(),i,j; for(i=1;i<=n;++i)a[i]=read(),b[i]=read(),f[MX-a[i]][MX-b[i]]+=1; for(i=1;i<MX*2;++i)for(j=1;j<MX*2;++j)f[i][j]+=f[i-1][j]+f[i][j-1]; for(F[0]=i=1;i<=MX*4;++i)F[i]=F[i-1]*i; for(R[i=MX*4]=~F[MX*4];i--;)R[i]=R[i+1]*(i+1); for(i=1;i<=n;++i)ans+=f[MX+a[i]][MX+b[i]]-C(a[i]+b[i]<<1,a[i]<<1); printf("%d",ans/2); }
codenet
-1
1,424
s062055886
p04051
1,489,332,286
cpp
Accepted
153
65,664
#include<set> #include<map> #include<cmath> #include<queue> #include<bitset> #include<string> #include<cstdio> #include<cctype> #include<cassert> #include<cstdlib> #include<cstring> #include<sstream> #include<iostream> #include<algorithm> #define For(i,x,y) for (int i=x;i<y;i++) #define pb push_back #define mp make_pair #define fi first #define se second #define dprintf(...) fprintf(stderr,__VA_ARGS__) using namespace std; typedef long long ll; typedef double db; typedef pair<int,int> pii; typedef vector<int> Vi; int IN(){ int c,f,x; while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0'); while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x; } const int N=200000+19; const int M=2000+19; const int S=2001; const int p=1e9+7; int A[N],B[N]; int f[2*M][2*M],fac[4*M],inv[4*M]; int n,res; int Pow(int a,int b){ int res=1; for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p; return res; } int C(int n,int m){ return 1ll*fac[n]*inv[m]%p*inv[n-m]%p; } int main(){ fac[0]=1; For(i,1,4*M) fac[i]=1ll*fac[i-1]*i%p; inv[4*M-1]=Pow(fac[4*M-1],p-2); for (int i=4*M-1;i;i--) inv[i-1]=1ll*inv[i]*i%p; n=IN(); For(i,1,n+1){ A[i]=IN(),B[i]=IN(); f[-A[i]+S][-B[i]+S]++; } For(i,1,2*M) For(j,1,2*M){ f[i][j]=(0ll+f[i][j]+f[i][j-1]+f[i-1][j])%p; } For(i,1,n+1){ res=(res+f[A[i]+S][B[i]+S])%p; res=(res-C(2*A[i]+2*B[i],2*A[i])+p)%p; } printf("%d\n",1ll*res*Pow(2,p-2)%p); }
codenet
-1
1,426
s905452247
p04051
1,468,722,152
cpp
Accepted
336
67,072
#include<stdio.h> #include<algorithm> using namespace std; long long mod=1000000007; int p[210000]; int q[210000]; long long inv[11000]; long long fact[11000]; long long factinv[11000]; int M=10000; inline long long C(int a,int b){ return fact[a]*factinv[b]%mod*factinv[a-b]%mod; } //int T[2100][2100]; //int Y[2100][2100]; long long d2=500000004; int dp[4100][4100]; int main(){ int a;scanf("%d",&a); for(int i=0;i<a;i++){ scanf("%d%d",p+i,q+i); } long long ret=0; inv[1]=fact[0]=factinv[0]=1; for(int i=1;i<M;i++)fact[i]=fact[i-1]*i%mod; for(int i=2;i<M;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod; for(int i=1;i<M;i++)factinv[i]=factinv[i-1]*inv[i]%mod; /* for(int i=0;i<a;i++){ T[p[i]][0]++; T[p[i]][q[i]]--; Y[q[i]][0]++; Y[q[i]][p[i]]--; } for(int i=0;i<2100;i++){ for(int j=1;j<2100;j++){ T[i][j]+=T[i][j-1]; Y[i][j]+=Y[i][j-1]; } }*/ int D=2050; for(int i=0;i<a;i++){ dp[D+p[i]][D+q[i]]++; } for(int i=D+2010;i>=0;i--){ for(int j=D+2010;j>=0;j--){ if(dp[i][j]>=mod)dp[i][j]-=mod; if(i)dp[i-1][j]+=dp[i][j]; if(j)dp[i][j-1]+=dp[i][j]; } } for(int i=0;i<a;i++){ //printf("%d: %lld\n",i,dp[D-p[i]][D-q[i]]); ret=(ret+dp[D-p[i]][D-q[i]])%mod; } //printf("%lld\n",ret); for(int i=0;i<a;i++){ // printf("%d: %lld\n",i,C(p[i]*2+q[i]*2,p[i]*2)); ret=(ret+mod-C(p[i]*2+q[i]*2,p[i]*2))%mod; } //printf("%lld\n",ret); ret=ret*d2%mod; printf("%lld\n",ret); }
codenet
-1
1,427
s847409223
p04051
1,569,628,294
cpp
Accepted
101
128,768
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; bool chkmax(int &x,int y){return x<y?x=y,true:false;} bool chkmin(int &x,int y){return x>y?x=y,true:false;} int readint(){ int 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; } const int cys=1000000007; int n,maxa; ll a[200005],b[200005],fac[8005],inv[8005],d[4005][4005]; ll mod(ll x){return x>=cys?x-cys:x;} ll qpow(ll x,ll p){ ll ret=1; for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys; return ret; } int main(){ n=readint(); for(int i=1;i<=n;i++) a[i]=readint(),b[i]=readint(),chkmax(maxa,max(a[i],b[i])); fac[0]=inv[0]=1; for(int i=1;i<=4*maxa;i++) fac[i]=fac[i-1]*i%cys; inv[4*maxa]=qpow(fac[4*maxa],cys-2); for(int i=4*maxa-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys; for(int i=1;i<=n;i++) d[-a[i]+maxa][-b[i]+maxa]++; for(int i=0;i<=2*maxa;i++){ for(int j=0;j<=2*maxa;j++){ if(i) d[i][j]=mod(d[i][j]+d[i-1][j]); if(j) d[i][j]=mod(d[i][j]+d[i][j-1]); } } ll ans=0; for(int i=1;i<=n;i++) ans=mod(ans+d[a[i]+maxa][b[i]+maxa]); for(int i=1;i<=n;i++) ans=mod(ans+cys-fac[2*a[i]+2*b[i]]*inv[2*a[i]]%cys*inv[2*b[i]]%cys); printf("%lld\n",ans*((cys+1)/2)%cys); return 0; }
codenet
-1
1,430
s844869351
p04051
1,590,811,211
cpp
Accepted
258
196,352
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second #define endl '\n' #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=4e3+10,mod=1e9+7,M=2e5+100; ll dp[N][N]; ll val[N][N]; ll a[M],b[M]; ll power(ll n,ll k){ if (k==0) return 1; if (k%2==1){ ll x=power(n,k/2); return x*x%mod*n%mod; } ll x=power(n,k/2); return x*x%mod; } ll fac[M],fm[M]; ll ent(ll k,ll n){ if (k==0 || k==n) return 1; if (k<0 || k>n) return 0; return (fac[n]*fm[k]%mod)*fm[n-k]%mod; } int32_t main(){ fac[0]=1; for (int i=1;i<M;i++){ fac[i]=fac[i-1]*i%mod; fm[i]=power(fac[i],mod-2); } ll n; cin >> n; for (int i=1;i<=n;i++) cin >> a[i] >> b[i]; for (int i=1;i<=n;i++){ val[-a[i]+N/2][-b[i]+N/2]++; } ll ans=0; for (int i=1;i<N;i++){ for (int j=1;j<N;j++){ dp[i][j]+=dp[i][j-1]+dp[i-1][j]+val[i][j]; dp[i][j]%=mod; } } for (int i=1;i<=n;i++){ ans+=dp[a[i]+N/2][b[i]+N/2]; ans-=ent(2*a[i],2*a[i]+2*b[i]); ans+=mod; ans%=mod; } cout << ans*power(2,mod-2)%mod << endl; }
codenet
-1
1,431
s850648336
p04051
1,503,250,838
cpp
Accepted
557
127,600
#include <cstdio> #include <cassert> #include <vector> using namespace std; long long tbl[4010][4010]; long long fact[8010]; long long iFact[8010]; long long mod=1000000007; long long poww(long long x,long long y) { long long res = 1; while(y) { if(y & 1) res = (res * x) % mod; x = x * x % mod; y = y >> 1; } return res; //if (x==0) return 1; //if (x==1) return b; //long long tmp = poww(b,x/2); //tmp=(tmp*tmp)%mod; //if (x%2) { //return (tmp*b)%mod; //} else { //return tmp; //} } int main() { int n; scanf("%d",&n); fact[0]=1; for (int i=1;i<8010;i++) { fact[i]=fact[i-1]*i; fact[i]%=mod; iFact[i]=poww(fact[i],mod-2); //printf("%lld\n",fact[i]); } //printf("%lld\n",iFact[2]); int a,b; long long ans=0; //int c,d; //scanf("%d%d%d%d",&a,&b,&c,&d); //printf("%d %d %lld %lld %lld\n",a+c,b+d,fact[a+b+c+d],iFact[a+c],iFact[b+d]); vector<pair<int,int>> ttt; for (int i=0;i<n;i++) { scanf("%d%d",&a,&b); ans-=(((fact[2*a+2*b]*iFact[2*a])%mod)*iFact[2*b])%mod; ans%=mod; //printf("%lld\n",(((fact[2*a+2*b]*iFact[2*a])%mod)*iFact[2*b])%mod); tbl[2001-a][2001-b]++; ttt.push_back({2001+a,2001+b}); } for (int i=1;i<4010;i++) { for (int j=1;j<4010;j++) { tbl[i][j]+=(tbl[i-1][j]+tbl[i][j-1])%mod; tbl[i][j]%=mod; } } for (int i=0;i<n;i++) { ans+=tbl[ttt[i].first][ttt[i].second]; ans%=mod; } ans*=iFact[2]; ans%=mod; printf("%lld\n",ans); return 0; }
codenet
-1
1,432
s093460944
p04051
1,469,990,805
cpp
Accepted
1,434
252,288
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef long double ld; #define fi first #define se second #define pb push_back #define mp make_pair const int MOD = 1e9 + 7; const int N = 2001; int a[200001]; int b[200001]; int dp[8001][8001]; int choose(int a, int b) { if(a < b) return 0; if(dp[a][b] != -1) return dp[a][b]; if(b == 0) return 1; if(b == 1) return a; dp[a][b] = (ll(choose(a - 1, b)) + ll(choose(a - 1, b - 1)))%MOD; return dp[a][b]; } ll modpow(ll a, ll b) { ll r = 1; while(b) { if(b&1) r = (r*a)%MOD; a = (a*a)%MOD; b>>=1; } return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } for(int i = 0; i < n; i++) { dp[-a[i]+N][-b[i]+N]++; //dp2[a[i]+N][b[i]+N]++; } for(int i = 1; i <= 4010; i++) { for(int j = 1; j <= 4010; j++) { dp[i][j] = (ll(dp[i][j]) + ll(dp[i - 1][j]) + ll(dp[i][j - 1]))%MOD; } } ll ans = 0; ll ans2 = 0; for(int i = 0; i < n; i++) { ans += dp[a[i]+N][b[i]+N]; ans %= MOD; } memset(dp, -1, sizeof(dp)); for(int i = 0; i < n; i++) { ans2 += choose(2*(a[i]+b[i]), 2*b[i]); ans2 %= MOD; } //cout << ans << ' ' << ans2 << endl; ans = (ans - ans2)%MOD; if(ans < 0) ans += MOD; ans = (ans*modpow(2, MOD - 2))%MOD; if(ans < 0) ans += MOD; cout << ans; return 0; }
codenet
-1
1,436
s534737613
p04051
1,523,222,233
cpp
Accepted
78
75,008
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int mod=1e9+7; inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);} inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);} inline int mul(int x,int y) {return (LL)x*y%mod;} inline int power(int a,int b,int rs=1) { for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs; } const int N=2e5+50, M=8e3+50; int n,A[N],B[N],fac[M],ifac[M],f[4500][4500]; inline int& F(int a,int b) {return f[a+2003][b+2003];} inline int C(int a,int b) {return mul(fac[a], mul(ifac[b], ifac[a-b]));} int main() { fac[0]=1; for(int i=1;i<M;i++) fac[i]=mul(fac[i-1],i); ifac[M-1]=power(fac[M-1],mod-2); for(int i=M-2;~i;i--) ifac[i]=mul(ifac[i+1],i+1); n=rd(); for(int i=1;i<=n;i++) A[i]=rd(), B[i]=rd(), F(-A[i],-B[i])++;//, cerr<<A[i]<<" "<<B[i]<<endl; for(int i=-2000;i<=2000;++i) for(int j=-2000;j<=2000;++j) { F(i,j)=add(F(i,j),F(i-1,j)); F(i,j)=add(F(i,j),F(i,j-1)); } int ans=0; for(int i=1;i<=n;i++) ans=add(ans,F(A[i],B[i])), ans=dec(ans,C(2*A[i]+2*B[i],2*B[i])); cout<<mul(ans,(mod+1)/2); }
codenet
-1
1,438
s098662004
p04051
1,586,099,610
cpp
Accepted
221
128,640
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; inline ll read(){ ll f=1,res=0;char c=getchar(); while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){res=res*10+c-'0',c=getchar();} return f*res; } const ll mod=1e9+7; const int maxn=2e5+5; const int maxm=8005; ll fac[maxm]; //阶乘 ll inv[maxm]; //逆元 ll a[maxn],b[maxn],n,ans; ll f[maxm/2][maxm/2],base=maxm/4; const ll inv2=500000004; ll quickMod(ll a,ll b){ ll ans=1; while(b){ if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } void getFac(){ fac[0]=inv[0]=1; for(int i=1;i<=maxm;i++){ fac[i]=fac[i-1]*i%mod; inv[i]=quickMod(fac[i],mod-2); //表示i的阶乘的逆元 } } ll getC(ll n,ll m){ return fac[n]*inv[n-m]%mod*inv[m]%mod;//C(n,m) = n!/((n-m)!*m!) % (1e9+7) } int main(){ // freopen("math.in","r",stdin); // freopen("math.out","w",stdout); getFac(); n=read(); for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),f[base-a[i]][base-b[i]]++; for(int i=1;i<=maxm/2-1;i++){ for(int j=1;j<=maxm/2-1;j++){ f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod; // printf("%d %d %lld\n",i,j,f[i][j]); }//cout<<"orz"<<" "<<i; } ans=0; for(int i=1;i<=n;i++){ ans=(ans+f[base+a[i]][base+b[i]])%mod; ans=(ans-getC(2*a[i]+2*b[i],2*a[i]))%mod; } ans=(ans+mod)%mod; ans=ans*inv2%mod; printf("%lld",ans); return 0; }
codenet
-1
1,440
s089984773
p04051
1,543,618,754
cpp
Accepted
242
222,976
#include <cstdio> #include <algorithm> int read() { int x=0,f=1; char ch=getchar(); while((ch<'0')||(ch>'9')) { if(ch=='-') { f=-f; } ch=getchar(); } while((ch>='0')&&(ch<='9')) { x=x*10+ch-'0'; ch=getchar(); } return x*f; } const int maxn=200000; const int maxm=2001; const int maxk=maxm<<1; const int mod=1000000007; int n,x[maxn+10],y[maxn+10],mp[maxk+10][maxk+10],f[maxk+10][maxk+10],C[maxk*2+10][maxk+10]; int main() { n=read(); for(int i=1; i<=n; ++i) { int a=read(),b=read(); ++mp[maxm-a][maxm-b]; x[i]=a; y[i]=b; } C[0][0]=1; for(int i=1; i<=maxk*2; ++i) { C[i][0]=C[i-1][0]; for(int j=1; (j<=i)&&(j<=maxk); ++j) { C[i][j]=C[i-1][j]+C[i-1][j-1]; if(C[i][j]>=mod) { C[i][j]-=mod; } } } for(int i=1; i<=maxk; ++i) { for(int j=1; j<=maxk; ++j) { f[i][j]=mp[i][j]+f[i-1][j]+f[i][j-1]; if(f[i][j]>=mod) { f[i][j]-=mod; } } } int ans=0; for(int i=1; i<=n; ++i) { ans+=f[x[i]+maxm][y[i]+maxm]; if(ans>=mod) { ans-=mod; } ans-=C[(x[i]+y[i])<<1][x[i]<<1]; if(ans<0) { ans+=mod; } } ans=1ll*ans*((mod+1)/2)%mod; printf("%d\n",ans); return 0; }
codenet
-1
1,440
s527028927
p04051
1,514,690,547
cpp
Accepted
260
189,440
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; } int N; int A[200000], B[200000]; int nCr[8001][4001]; int T[4002][4002]; signed main() { ios::sync_with_stdio(false); cin.tie(0); nCr[0][0] = 1; for (int i=1; i<=8000; i++) { nCr[i][0] = 1; for (int j=1; j<=min(i, 4000); j++) { nCr[i][j] = nCr[i-1][j-1] + nCr[i-1][j]; if (nCr[i][j] >= MOD) nCr[i][j] -= MOD; } } cin >> N; rep(i, N) { cin >> A[i] >> B[i]; T[2000-A[i]][2000-B[i]]++; } for (int i=0; i<=4000; i++) { for (int j=0; j<=4000; j++) { add(T[i+1][j], T[i][j]); add(T[i][j+1], T[i][j]); } } int s = 0; rep(i, N) { int X = A[i], Y = B[i]; add(s, T[2000+A[i]][2000+B[i]]); } rep(i, N) { add(s, MOD-nCr[2*A[i]+2*B[i]][2*A[i]]); } s = (500000004LL*s)%MOD; cout << s << "\n"; return 0; }
codenet
-1
1,440
s490076294
p04051
1,507,943,041
cpp
Accepted
127
64,256
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 200000, mod = 1e9 + 7, maxx = 4001, offset = 2000; inline int Add(int a) { if (a >= mod) a -= mod; return a; } inline int Sub(int a) { if (a < 0) a += mod; return a; } inline int Mul(int a, int b) { return (long long)a * b % mod; } int Pow(int a, int b) { int c = 1; for (; b; b >>= 1) { if (b & 1) c = Mul(a, c); a = Mul(a, a); } return c; } int n, a[maxn], b[maxn]; int dp[maxx][maxx]; int fact[8001], ifact[8001]; inline int Choose(int n, int m) { return Mul(fact[n], Mul(ifact[m], ifact[n - m])); } int main(void) { fact[0] = 1; for (int i = 1; i <= 8000; ++i) { fact[i] = Mul(fact[i - 1], i); } ifact[8000] = Pow(fact[8000], mod - 2); for (int i = 8000; i >= 1; --i) { ifact[i - 1] = Mul(ifact[i], i); } scanf("%d", &n); int ans = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", a + i, b + i); ++dp[offset - a[i]][offset - b[i]]; ans = Sub(ans - Choose(a[i] + b[i] << 1, a[i] << 1)); } for (int i = 0; i < maxx; ++i) { for (int j = 0; j < maxx; ++j) { if (i) { dp[i][j] = Add(dp[i][j] + dp[i - 1][j]); } if (j) { dp[i][j] = Add(dp[i][j] + dp[i][j - 1]); } } } for (int i = 0; i < n; ++i) { ans = Add(ans + dp[offset + a[i]][offset + b[i]]); } printf("%d\n", Mul(ans, Pow(2, mod - 2))); return 0; }
codenet
-1
1,441
s466753575
p04051
1,540,417,386
cpp
Accepted
105
64,640
#include <cstdio> #define rg register using namespace std; typedef long long ll; const int maxn=200010,mod=1e9+7,inv2=500000004; template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;} template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;} template <typename Tp> inline void read(Tp &x) { x=0;int f=0;char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') f=1,ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); if(f) x=-x; } int n,ans,a[maxn],b[maxn],fac[8010],inv[8010],f[4010][4010]; inline int pls(int x,int y){return x+y>=mod?x+y-mod:x+y;} inline int dec(int x,int y){return x-y<0?x-y+mod:x-y;} int power(int x,int y) { int res=1; for(;y;y>>=1,x=(ll)x*x%mod) if(y&1) res=(ll)res*x%mod; return res; } inline int c(int n,int m){return m>n?0:(ll)fac[n]*inv[m]%mod*inv[n-m]%mod;} int main() { read(n);fac[0]=1; for(rg int i=1;i<=n;i++) { read(a[i]),read(b[i]); ++f[2000-a[i]][2000-b[i]]; } for(rg int i=1;i<=8000;i++) fac[i]=(ll)fac[i-1]*i%mod; inv[8000]=power(fac[8000],mod-2); for(rg int i=7999;~i;i--) inv[i]=(ll)inv[i+1]*(i+1)%mod; for(rg int i=0;i<=4000;i++) for(rg int j=0;j<=4000;j++) f[i][j]=pls(f[i][j],pls(i?f[i-1][j]:0,j?f[i][j-1]:0)); for(rg int i=1;i<=n;i++) { ans=pls(ans,f[2000+a[i]][2000+b[i]]); ans=dec(ans,c((a[i]+b[i])<<1,a[i]<<1)); } ans=(ll)ans*inv2%mod; printf("%d\n",ans); return 0; }
codenet
-1
1,443
s144375941
p04051
1,562,857,118
cpp
Accepted
130
64,640
//by OIerC //Forca Barcelona! #include<cstdio> using namespace std; const int P = 1e9 + 7; void add(int &a, int b){a += b; a >= P ? a -= P : 0;} void sub(int &a, int b){a -= b; a < 0 ? a += P : 0;} inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } const int M = 2e3 + 5, N = 2e5 + 5; int a[N], b[N], dp[M * 2][M * 2]; int fac[M * 4 + 5], ifac[M * 4 + 5]; int ans; int Pow(int x, int t) { int res = 1; for (; t; t >>= 1, x = 1LL * x * x % P) if (t & 1) res = 1LL * res * x % P; return res; } int C(int n, int m) { if (n < m) return 0; return 1LL * fac[n] * ifac[n - m] % P * ifac[m] % P; } int main() { int n = read(); for (int i = 1; i <= n; ++i) a[i] = read(), b[i] = read(); for (int i = 1; i <= n; ++i) ++dp[M - a[i]][M - b[i]]; for (int i = 1; i < 2 * M; ++i) for (int j = 1; j < 2 * M; ++j) add(dp[i][j], (dp[i][j - 1] + dp[i - 1][j]) % P); for (int i = 1; i <= n; ++i) add(ans, dp[a[i] + M][b[i] + M]); fac[0] = 1; for (int i = 1; i <= 4 * M; ++i) fac[i] = 1LL * fac[i - 1] * i % P; ifac[4 * M] = Pow(fac[4 * M], P - 2); for (int i = 4 * M; i; --i) ifac[i - 1] = 1LL * ifac[i] * i % P; for (int i = 1; i <= n; ++i) sub(ans, C(2 * a[i] + 2 * b[i], 2 * a[i])); printf("%d\n", 1LL * ans * ifac[2] % P); return 0; }
codenet
-1
1,445
s038121802
p04051
1,538,543,967
cpp
Accepted
209
64,512
#include<bits/stdc++.h> #define ED(x) ((int)x.size()-1) #define _for(i,a,b) for(int i=(a);i<=(b);++i) #define _rep(i,a,b) for(int i=(a);i>=(b);--i) #define changxv ios::sync_with_stdio(0);cin.tie(0); using namespace std; typedef long long ll; template<typename T>void dbg(const char*s,T h){cerr<<s<<'='<<h<<'\n';} template<typename T,typename...A>void dbg(const char*s,T h,A...t){ while(*s!=',')cerr<<*s++;cerr<<'='<<h<<", ";dbg(s+1,t...); } #define put(...) dbg(#__VA_ARGS__, __VA_ARGS__) const int maxn=2003; const int INF=0x3f3f3f3f; const int P=2001; const int mod=1e9+7; struct node{ int x,y; }p[200003]; int f[maxn<<1][maxn<<1]; int fac[maxn<<2],invfac[maxn<<2]; int Qpow(int x,int k){ int tmp=1; for(;k;k>>=1,x=(ll)x*x%mod)if(k&1)tmp=(ll)tmp*x%mod; return tmp; } void Pre(){ const int lim=8002; fac[0]=invfac[0]=1; _for(i,1,lim)fac[i]=(ll)fac[i-1]*i%mod; invfac[lim]=Qpow(fac[lim],mod-2); _rep(i,lim-1,1)invfac[i]=(ll)invfac[i+1]*(i+1)%mod; } int C(int n,int m){ if(n<m)return 0; return (ll)fac[n]*invfac[m]%mod*invfac[n-m]%mod; } int main(){changxv Pre(); int n;cin>>n; _for(i,1,n){ int x,y;cin>>x>>y; p[i]=(node){x,y}; ++f[-x+P][-y+P]; } _for(i,1,2000+P){ _for(j,1,2000+P){ (f[i][j]+=(f[i-1][j]+f[i][j-1])%mod)%=mod; } } int ans=0; _for(i,1,n){ (ans+=f[P+p[i].x][P+p[i].y])%=mod; (ans-=C(p[i].x+p[i].y<<1,p[i].x<<1)-mod)%=mod; } ans=(ll)ans*Qpow(2,mod-2)%mod; cout<<ans<<'\n'; return 0; }
codenet
-1
1,446
s025261894
p04051
1,519,165,184
cpp
Accepted
125
1,920
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define MOD 1000000007 #define f(i,j) f[(i)&1][(j)+4000] #define rint register int #define gc() getchar() inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc()) { for(; ch < '0' || ch > '9'; sgn = ch, ch = gc()); for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc()); return sgn-'-'?ans:-ans; } typedef pair<int,int> pii; pii p[200005]; int f[2][8005], fac[8005], efac[8005], n, X, Y, K, Ans; inline int exp(int s, int n=MOD-2){int a=1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;} inline int C(int n, int k){return 1ll*fac[n]*efac[k]%MOD*efac[n-k]%MOD;} int main() { n = read(); for(rint i = 1; i <= n; X = max(X,p[i].first=read()), Y = max(Y,p[i].second=read()), i++); K = (X+Y)<<1, sort(p+1,p+n+1); for(rint i = -X, j, q = n, t = 1; i <= X; i++) { for(j = -Y; j <= Y; j++) for(f(i,j) = f(i-1,j)+f(i,j-1), f(i,j)<MOD?:f(i,j)-=MOD; q && p[q]==pii(-i,-j); ++f(i,j)==MOD?f(i,j)=0:0, q--); for(; t <= n && p[t].first==i; Ans += f(i,p[t].second), Ans<MOD?:Ans-=MOD, t++); } fac[0] = 1; for(rint i = 1; i <= K; fac[i] = 1ll*i*fac[i-1]%MOD, i++); efac[K] = exp(fac[K]); for(rint i = K; i; efac[i-1] = 1ll*i*efac[i]%MOD, i--); for(rint i = 1; i <= n; Ans -= C((p[i].first<<1)+(p[i].second<<1),p[i].first<<1), Ans<0?Ans+=MOD:0, i++); printf("%lld\n",500000004ll*Ans%MOD); return 0; }
codenet
-1
1,446
s918112264
p04051
1,552,866,830
cpp
Accepted
142
64,640
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int bas = 2e3 + 1, mod = 1e9 + 7; const int Maxn = 2e5 + 5, N = bas * 2 + 5; int n, ans, a[Maxn], b[Maxn], f[N][N]; int fac[N * 2], inv[N * 2]; inline int add(int &x, int y) { x += y; if(x >= mod) x -= mod; } inline void sub(int &x, int y) { x -= y; if(x < 0) x += mod; } inline int mul(int x, int y) { return (LL) x * y % mod; } inline int Pow(int a, int b = mod - 2) { int res = 1; for(; b; b >>= 1, a = mul(a, a)) if(b & 1) res = mul(res, a); return res; } inline int C(int n, int m) { if(n < m || n < 0 || m < 0) return 0; return mul(fac[n], mul(inv[m], inv[n - m])); } void init(int n = 8e3) { inv[0] = fac[0] = 1; for(int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i); inv[n] = Pow(fac[n]); for(int i = n - 1; i; --i) inv[i] = mul(inv[i + 1], i + 1); } int main() { init(); scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d%d", a + i, b + i); ++ f[bas - a[i]][bas - b[i]]; } for(register int i = 1; i <= bas * 2; ++i) for(register int j = 1; j <= bas * 2; ++j) { add(f[i][j], f[i - 1][j]); add(f[i][j], f[i][j - 1]); } for(int i = 1; i <= n; ++i) { add(ans, f[bas + a[i]][bas + b[i]]); sub(ans, C(2 * (a[i] + b[i]), 2 * a[i])); } printf("%d\n", mul(ans, Pow(2))); return 0; }
codenet
-1
1,447
s494440773
p04051
1,509,628,464
cpp
Accepted
175
126,976
#include <cmath> #include <cstdio> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> //Constant const int N=200000; const int A=2000; const int D=A*2; const int F=A*4; const int MOD=1000000007; //Quick Read int Read(){ int x=0; bool neg=false; char c=getchar(); while(isdigit(c)==false)neg^=c=='-',c=getchar(); while(isdigit(c)==true)x=x*10+c-'0',c=getchar(); return neg==true?-x:x; } inline void Read(int &x){x=Read();} //Math long long fac[F+1],facinv[F+1]; int Power(long long x,int y){ long long ans=1; for(int i=y;i>=1;i>>=1){ if(i&1)ans=ans*x%MOD; x=x*x%MOD; } return ans; } inline long long Comb(int n,int m){return (long long)fac[n]*facinv[n-m]%MOD*facinv[m]%MOD;} //Main int a[N+1],b[N+1]; long long f[D+1][D+1]; int main(){ // freopen("AGC001E.in","r",stdin); // freopen("AGC001E.out","w",stdout); int n=Read(); for(int i=1;i<=n;++i)Read(a[i]),Read(b[i]),++f[A-a[i]][A-b[i]]; for(int i=0;i<=D;++i) for(int j=0;j<=D;++j){ if(i!=0)f[i][j]=(f[i][j]+f[i-1][j])%MOD; if(j!=0)f[i][j]=(f[i][j]+f[i][j-1])%MOD; } long long ans=0; for(int i=1;i<=n;++i)ans+=f[A+a[i]][A+b[i]]; fac[0]=1; for(int i=1;i<=F;++i)fac[i]=(fac[i-1]*i)%MOD; facinv[F]=Power(fac[F],MOD-2); for(int i=F-1;i>=0;--i)facinv[i]=facinv[i+1]*(i+1)%MOD; for(int i=1;i<=n;++i)ans=(ans-Comb((a[i]+b[i])*2,b[i]*2))%MOD; ans=ans*facinv[2]%MOD; if(ans<0)ans+=MOD; printf("%lld\n",ans); return 0; }
codenet
-1
1,447
s158319730
p04051
1,540,506,099
cpp
Accepted
189
64,640
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; #define inv2 500000004 const int N=200010;const int M=8000; /*inline int ask(int x) { int ans=0; for(;x;x-=x&-x) ans+=c[x]; return ans; }*/ inline int read() { int x=0,o=1;char ch=getchar(); while(!isdigit(ch)&&ch!='-') ch=getchar(); if(ch=='-') o=-1,ch=getchar(); while(isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*o; } int fac[M+10],ifac[M+10],m,f[M/2+10][M/2+10],base=M/4+2,n,A[N],B[N]; inline int Pow(int a,int b) { int ans=1; for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod; return ans; } inline int C(int n,int m) { return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; } int main() { n=read(); fac[0]=1; for(register int i=1;i<=M;i++) fac[i]=1ll*fac[i-1]*i%mod; ifac[M]=Pow(fac[M],mod-2); for(register int i=M-1;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod; for(register int i=1;i<=n;i++) { A[i]=read(); B[i]=read(); f[base-A[i]][base-B[i]]++; } for(register int i=1;i<=M/2+2;i++) for(register int j=1;j<=M/2+2;j++) f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod; long long ans=0; for(register int i=1;i<=n;i++) { ans=(ans+f[A[i]+base][B[i]+base])%mod; ans=(ans-C(2*A[i]+2*B[i],2*A[i]))%mod; } ans=(ans+mod)%mod; ans=1ll*inv2*ans%mod; printf("%lld\n",ans); return 0; }
codenet
-1
1,450
s737890673
p04051
1,533,322,670
cpp
Accepted
284
129,152
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair <ll , int> pll; typedef vector <ll> vll; typedef pair <pll,ll> p3l; #define pb push_back #define X first #define Y second #define mkp make_pair #define smax(a,b) a=max(a,b) #define ER(x) cout<<#x<<" "<<x<<"\n"; #define smin(a,b) a=min(a,b) #define SZ(s) (ll)((s).size()) #define For(i,a,b) for (int i=a;i<b;i++) #define Ford(i,a,b) for (int i=a;i>=b;i--) #define RET(x) {cout<<x<<'\n';} //return 0;} #define RETD(x) {cout << fixed << setprecision(15) << x <<'\n';} #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) const ll maxn=2e5+10,M=4e3+10,SQ=360,bghs=1e9+7,inf=1e18+15,LG=22,I=2e3+5; ll n,dp[M][M],fac[4*M]; pll ab[maxn]; ll pw(ll x,ll n=bghs-2) { if (n==0) return 1; ll res=pw(x,n/2); res*=res; res%=bghs; if (n%2) res*=x,res%=bghs; return res; } ll C(ll i,ll j) { return (((fac[i]*pw(fac[j]))%bghs)*pw(fac[i-j]))%bghs; } int main() { IOS; cin>>n; For(i,0,n) {cin>>ab[i].X>>ab[i].Y;dp[I-ab[i].X][I-ab[i].Y]++;} For(i,1,M) For(j,1,M) dp[i][j]+=(dp[i-1][j]+dp[i][j-1]),dp[i][j]%=bghs; ll ans=0; fac[0]=1; For(i,1,4*M) fac[i]=(i*fac[i-1])%bghs; For(i,0,n) { ans=(ans+dp[I+ab[i].X][I+ab[i].Y])%bghs; //ER(dp[I-ab[i].X][I-ab[i].Y]); ans=(ans-C(2*(ab[i].X+ab[i].Y),2*ab[i].X))%bghs; } cout<<(((ans+bghs)%bghs)*(ll)(5e8 + 4))%bghs<<'\n'; }
codenet
-1
1,451
s400009682
p04051
1,565,225,906
cpp
Accepted
142
84,736
//quming #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i) #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v) template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;} template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;} using namespace std; const int P=1e9+7; inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;} inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;} inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;} inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;} int ksm(R int x,R int y){ R int res=1; for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0; return res; } const int N=2e5+5,M=5005,S=2005; int a[N],b[N],fac[N],ifac[N],f[M][M],xmx,ymx,n,res; inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;} void init(int n){ fac[0]=ifac[0]=1; fp(i,1,n)fac[i]=mul(fac[i-1],i); ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1); } int main(){ // freopen("testdata.in","r",stdin); scanf("%d",&n); fp(i,1,n)scanf("%d%d",&a[i],&b[i]),cmax(xmx,a[i]),cmax(ymx,b[i]); init((xmx+ymx)<<1); fp(i,1,n)++f[S-a[i]][S-b[i]]; fp(i,S-xmx,S+xmx)fp(j,S-ymx,S+ymx)if(f[i][j])upd(f[i+1][j],f[i][j]),upd(f[i][j+1],f[i][j]); fp(i,1,n)upd(res,f[S+a[i]][S+b[i]]); fp(i,1,n)res=dec(res,C((a[i]+b[i])<<1,a[i]<<1)); printf("%d\n",mul(res,(P+1)>>1)); return 0; }
codenet
-1
1,452
s646111277
p04051
1,528,141,568
cpp
Accepted
209
189,952
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define sqr(x) ((x)*(x)) #define mp make_pair #define uint unsigned #define PI pair<int,int> inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline int read(){ int x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(int a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(int a){ if(a<0){ a=-a; putchar('-'); } write(a); puts(""); } inline int rnd(int x){ return rand()%x; } inline ull rnd(){ return ((ull)rand()<<30^rand())<<4|rand()%4; } const int N=2005,M=200005,mod=1000000007; int n,dp[N<<1][N<<1],c[N<<2][N<<1],a[M],b[M],ans; int main(){ n=read(); for(int i=1;i<=n;i++){ a[i]=read(); b[i]=read(); dp[-a[i]+N][-b[i]+N]++; } for(int i=1;i<2*N;i++){ for(int j=1;j<2*N;j++){ dp[i][j]=(dp[i-1][j]+dp[i][j-1]+dp[i][j])%mod; } } for(int i=0;i<4*N;i++){ c[i][0]=1; for(int j=1;j<2*N&&j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; } for(int i=1;i<=n;i++){ans=(ans+dp[a[i]+N][b[i]+N])%mod; ans=(ans-c[a[i]*2+b[i]*2][a[i]*2])%mod;} cout<<((ll)ans*(mod+1)/2%mod+mod)%mod<<endl; } /* 10*3*4 */
codenet
-1
1,454
s819603694
p04051
1,518,980,932
cpp
Accepted
229
96,256
#include<cstdio> #include<cstring> #include<iostream> #include<stdlib.h> #include<ctime> #include<string> #include<cmath> #include<algorithm> #include<vector> #include<set> #include<map> #include<queue> #define pb push_back #define mp make_pair #define fi first #define se second #define LL long long #define FOR(i,a,b) for (int i=a;i<=b;i++) #define FORD(i,a,b) for (int i=a;i>=b;i--) using namespace std; typedef pair<int,int> pa; void getint(int &v){ char ch,fu=0; for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar()); if(ch=='-') fu=1, ch=getchar(); for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0'; if(fu) v=-v; } const int MO=1e9+7; LL ans,fac[8010],inv[8010]; int n,v[4010][4010],tag[4010][4010],a[200010],b[200010]; LL pw(LL x,LL y){ LL t=1; for (;y;y>>=1){ if (y&1) t=t*x%MO; x=x*x%MO; } return t; } LL C(int x,int y){ return fac[x]*inv[y]%MO*inv[x-y]%MO; } int main(){ scanf("%d",&n); FOR(i,1,n){ scanf("%d%d",&a[i],&b[i]); v[2000-a[i]][2000-b[i]]++; tag[2000+a[i]][2000+b[i]]++; } FOR(i,0,4000) FOR(j,0,4000){ (v[i+1][j]+=v[i][j])%=MO; (v[i][j+1]+=v[i][j])%=MO; } FOR(i,0,4000) FOR(j,0,4000) (ans+=1ll*v[i][j]*tag[i][j])%=MO; fac[0]=1; FOR(i,1,8000) fac[i]=fac[i-1]*i%MO; inv[8000]=pw(fac[8000],MO-2); FORD(i,7999,0) inv[i]=inv[i+1]*(i+1)%MO; FOR(i,1,n) (ans-=C(a[i]+a[i]+b[i]+b[i],a[i]+a[i]))%=MO; ans=ans*pw(2,MO-2)%MO; ans=(ans%MO+MO)%MO; cout<<ans<<endl; return 0; }
codenet
-1
1,454
s822443266
p04051
1,552,888,091
cpp
Accepted
191
91,904
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<map> #include<bitset> #include<vector> using namespace std; #define i32 int #define i64 long long #define db double #define rep(i,s,n) for(i32 i=s;i<=n;i++) #define rep_(i,n,s) for(i32 i=n;i>=s;i--) i32 RI(){ char ch=getchar();i32 sum=0,f=1; while(!isdigit(ch)){ if(ch=='-')f=-1; ch=getchar(); } while(isdigit(ch))sum=sum*10+ch-'0',ch=getchar(); return f*sum; } i64 RL(){ char ch=getchar();i64 sum=0; while(!isdigit(ch))ch=getchar(); while(isdigit(ch))sum=sum*10+ch-'0',ch=getchar(); return sum; } const i32 N=5005; const i32 mod=1e9+7; i32 n,ans; i32 F[N][N],A[300000],B[300000],jc[N<<2]; i32 ksm(i32 x,i32 y){ i32 s=1; while(y){ if(y&1)s=1LL*s*x%mod; y>>=1; x=1LL*x*x%mod; } return s; } i32 C(i32 x,i32 y){return 1LL*jc[x]*ksm(1LL*jc[x-y]*jc[y]%mod,mod-2)%mod;} i32 get(i32 x,i32 y){return C(x+y,x);} i32 main(){ n=RI(); rep(i,1,n){A[i]=RI();B[i]=RI();F[-A[i]+2001][-B[i]+2001]++;} jc[0]=1;rep(i,1,10000)jc[i]=1LL*jc[i-1]*i%mod; rep(i,1,4500){ rep(j,1,4500){ F[i][j]=(F[i][j]+F[i-1][j]+F[i][j-1])%mod; } } rep(i,1,n){ ans=(ans+F[A[i]+2001][B[i]+2001])%mod; ans=(ans-get(A[i]<<1,B[i]<<1)+mod)%mod; } ans=1LL*ans*ksm(2,mod-2)%mod; printf("%d",ans); }
codenet
-1
1,456
s251566453
p04051
1,567,484,270
cpp
Accepted
190
64,640
#include <iostream> #include <cstdio> #include <cstring> #define MOD 1000000007 using namespace std; typedef long long LL; const int MAXN = 2e05 + 10; const int MAXM = 4000 + 10; const int q = 2002; LL fact[MAXM << 1]= {0}, invfact[MAXM << 1]= {0}; inline LL C (int n, int m) { return fact[n] * invfact[m] % MOD * invfact[n - m] % MOD; } int f[MAXM][MAXM]= {0}; int N; int x[MAXN], y[MAXN]; int getnum () { int num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; } int main () { N = getnum (); for (int i = 1; i <= N; i ++) { x[i] = getnum (), y[i] = getnum (); f[- x[i] + q][- y[i] + q] ++; } for (int i = 1; i <= (q << 1); i ++) for (int j = 1; j <= (q << 1); j ++) f[i][j] = (f[i][j] + (f[i - 1][j] + f[i][j - 1]) % MOD) % MOD; LL ans = 0; for (int i = 1; i <= N; i ++) ans = (ans + f[x[i] + q][y[i] + q]) % MOD; fact[0] = invfact[0] = invfact[1] = 1; for (int i = 1; i <= (q << 2); i ++) { fact[i] = fact[i - 1] * i % MOD; if (i > 1) invfact[i] = (MOD - MOD / i) * invfact[MOD % i] % MOD; } for (int i = 1; i <= (q << 2); i ++) invfact[i] = invfact[i] * invfact[i - 1] % MOD; for (int i = 1; i <= N; i ++) ans = (ans - C ((x[i] + y[i]) << 1, x[i] << 1) + MOD) % MOD; ans = ans * invfact[2] % MOD; cout << ans << endl; return 0; } /* 3 1 1 1 1 2 1 */ /* 3 1999 1999 1999 1999 2000 1999 */
codenet
-1
1,460
s864300628
p04051
1,485,315,221
cpp
Accepted
467
128,896
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define pb push_back #define fi first #define se second template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} const int mod=1000000007; int dp[4010][4010]; int N; int A[222222],B[222222]; inline void add(int &a,int b){a+=b;if(a>=mod)a-=mod;} int mpow(int n,int m){ int ret=1; while(m){ if(m&1)ret=ret*n%mod; n=n*n%mod; m>>=1; } return ret; } int fact[8888],inv[8888]; signed main(){ cin>>N; rep(i,N)cin>>A[i]>>B[i]; rep(i,N)dp[2000-A[i]][2000-B[i]]++; for(int i=0;i<=4000;i++){ for(int j=0;j<=4000;j++){ add(dp[i+1][j],dp[i][j]); add(dp[i][j+1],dp[i][j]); } } fact[0]=1; for(int i=1;i<=8000;i++)fact[i]=fact[i-1]*i%mod; inv[8000]=mpow(fact[8000],mod-2); for(int i=7999;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod; int ans=0; rep(i,N)add(ans,dp[2000+A[i]][2000+B[i]]); rep(i,N)ans=(ans-fact[(A[i]+B[i])*2]*inv[A[i]*2]%mod*inv[B[i]*2]%mod+mod)%mod; cout<<ans*inv[2]%mod<<endl; return 0; }
codenet
-1
1,460
s091920638
p04051
1,562,969,522
cpp
Accepted
199
82,816
/* * Author : YangDavid * Created Time : 2019年07月12日 星期五 16时59分54秒 */ #include<bits/stdc++.h> #define rep(i, n) for(int i = 1; i <= n; ++i) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 222222, MOD = 1000000007, inv2 = (MOD + 1) / 2, D = 2003; int muln(int x, int y) { return 1LL * x * y % MOD; } int mo(int x) { if(x >= MOD) x -= MOD; if(x < 0) x += MOD; return x; } int qpow(int x, int y) { int ret = 1; for(; y; y >>= 1, x = muln(x, x)) if(y & 1) ret = muln(ret, x); return ret; } int inv(int x) { return qpow(x, MOD - 2); } int n, a[maxn], b[maxn], dp[4030][4030], fac[maxn], ifac[maxn], p[2010][2010], ans; int f(int x, int y) { return muln(fac[x + y], muln(ifac[x], ifac[y])); } int main() { scanf("%d", &n); rep(i, n) { scanf("%d%d", &a[i], &b[i]); dp[-a[i] + D][-b[i] + D]++; p[a[i]][b[i]]++; } fac[0] = ifac[0] = 1; for(int i = 1; i <= 200000; ++i) { fac[i] = muln(fac[i - 1], i); ifac[i] = inv(fac[i]); } for(int i = -2000; i <= 2000; ++i) { for(int j = -2000; j <= 2000; ++j) { dp[i+D][j+D] = mo(dp[i+D][j+D] + dp[i - 1+D][j+D] + dp[i+D][j - 1+D]); if(i >= 0 && j >= 0) ans = mo(ans + muln(dp[i+D][j+D], p[i][j])); } } for(int i = 1; i <= n ;++i) ans = mo(ans - f(2 * a[i], 2 * b[i])); ans = muln(ans, inv2); printf("%d\n", ans); return 0; }
codenet
-1
1,464
s091920638
p04051
1,562,969,522
cpp
Accepted
199
82,816
/* * Author : YangDavid * Created Time : 2019年07月12日 星期五 16时59分54秒 */ #include<bits/stdc++.h> #define rep(i, n) for(int i = 1; i <= n; ++i) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 222222, MOD = 1000000007, inv2 = (MOD + 1) / 2, D = 2003; int muln(int x, int y) { return 1LL * x * y % MOD; } int mo(int x) { if(x >= MOD) x -= MOD; if(x < 0) x += MOD; return x; } int qpow(int x, int y) { int ret = 1; for(; y; y >>= 1, x = muln(x, x)) if(y & 1) ret = muln(ret, x); return ret; } int inv(int x) { return qpow(x, MOD - 2); } int n, a[maxn], b[maxn], dp[4030][4030], fac[maxn], ifac[maxn], p[2010][2010], ans; int f(int x, int y) { return muln(fac[x + y], muln(ifac[x], ifac[y])); } int main() { scanf("%d", &n); rep(i, n) { scanf("%d%d", &a[i], &b[i]); dp[-a[i] + D][-b[i] + D]++; p[a[i]][b[i]]++; } fac[0] = ifac[0] = 1; for(int i = 1; i <= 200000; ++i) { fac[i] = muln(fac[i - 1], i); ifac[i] = inv(fac[i]); } for(int i = -2000; i <= 2000; ++i) { for(int j = -2000; j <= 2000; ++j) { dp[i+D][j+D] = mo(dp[i+D][j+D] + dp[i - 1+D][j+D] + dp[i+D][j - 1+D]); if(i >= 0 && j >= 0) ans = mo(ans + muln(dp[i+D][j+D], p[i][j])); } } for(int i = 1; i <= n ;++i) ans = mo(ans - f(2 * a[i], 2 * b[i])); ans = muln(ans, inv2); printf("%d\n", ans); return 0; }
codenet
-1
1,464
s050960439
p04051
1,505,271,294
cpp
Accepted
104
98,304
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<bitset> #include<map> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long LL; typedef double db; int get(){ char ch; while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-'); if (ch=='-'){ int s=0; while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0'; return -s; } int s=ch-'0'; while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0'; return s; } const int mo = 1e+9+7; const int N = 2e+3; int f[N*2+3][N*2+3]; LL ny[N*4+3],js[N*4+3]; int n; LL ans; int ad[N*2+3][N*2+3]; struct point{ int x,y; }a[200003]; LL quickmi(LL x,LL tim){ LL ans=1; x%=mo; for(;tim;tim/=2,x=x*x%mo)if (tim&1)ans=ans*x%mo; return ans; } inline int add(int x,int y){ return x+y>=mo?x+y-mo:x+y; } LL calc(int x,int y){ return js[x*2+y*2]*ny[x*2]%mo*ny[y*2]%mo; } int main(){ n=get(); fo(i,1,n){ int x=get(),y=get(); a[i].x=x;a[i].y=y; ad[N-a[i].x][N-a[i].y]++; } js[0]=1; fo(i,1,8000)js[i]=js[i-1]*i%mo; ny[8000]=quickmi(js[8000],mo-2); fd(i,7999,0)ny[i]=ny[i+1]*(i+1)%mo; fo(i,0,4000) fo(j,0,4000){ if (i>0)f[i][j]=add(f[i][j],f[i-1][j]); if (j>0)f[i][j]=add(f[i][j],f[i][j-1]); f[i][j]=add(f[i][j],ad[i][j]); } ans=0; fo(i,1,n)ans=add(ans,f[a[i].x+N][a[i].y+N]); fo(i,1,n)ans=(ans+mo-calc(a[i].x,a[i].y))%mo; ans=ans*((mo+1)/2)%mo; printf("%lld\n",ans); return 0; }
codenet
-1
1,464
s063498182
p04051
1,507,665,194
cpp
Accepted
107
78,848
#include<bits/stdc++.h> using namespace std; #define pb push_back #define SZ(x) ((x).size()) #define All(x) (x).begin(),(x).end() #define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--) #define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) template<class T>void read(T&num){ num=0;T f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar(); num*=f; } const int maxn=2e3+5,mod=1e9+7; int n,ans; int fac[maxn<<2],ifac[maxn<<2]; int cnt[maxn][maxn],f[maxn<<1][maxn<<1]; int add(int x,int y){return x+y>=mod?x+y-mod:x+y;} int sub(int x,int y){return x-y<0?x-y+mod:x-y;} int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;} void upd(int &x,int y){x=add(x,y);} int C(int x,int y){ return 1ll*fac[x]*ifac[y]%mod*ifac[x-y]%mod; } int main(){ fac[0]=1;rep(i,1,8e3)fac[i]=1ll*fac[i-1]*i%mod; rep(i,0,8e3)ifac[i]=power(fac[i],mod-2,mod); read(n); rep(i,1,n){ int x,y;read(x);read(y); ans=sub(ans,C(x+x+y+y,x+x)); cnt[x][y]++; } rep(i,-2000,2000)rep(j,-2000,2000){ if(i<0&&j<0)upd(f[i+2001][j+2001],cnt[-i][-j]); upd(f[i+2001][j+2001],f[i-1+2001][j+2001]); upd(f[i+2001][j+2001],f[i+2001][j-1+2001]); if(i>0&&j>0)upd(ans,1ll*f[i+2001][j+2001]*cnt[i][j]%mod); } ans=1ll*ans*power(2,mod-2,mod)%mod; printf("%d\n",ans); return 0; }
codenet
-1
1,465
s277528942
p04051
1,545,070,880
cpp
Accepted
147
127,872
#include <cstdio> typedef long long LL; const int MX = 2e3 + 5, N = 2e5 + 5, MOD = 1e9 + 7; int a[N], b[N], n; LL f[(MX<<1) + 5][(MX<<1) + 5]; LL jc[(MX<<2) + 5], inv[(MX<<2) + 5], invjc[(MX<<2) + 5]; LL ans; inline int read() { int 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; } inline void add(LL &a, LL b) { a += b; if (a >= MOD)a -= MOD; } inline LL calc(int a, int b) { return (LL)jc[a] * invjc[b] % MOD * invjc[a - b] % MOD; } int main() { n = read(); for (int i = 1; i <= n; ++i) { a[i] = read(); b[i] = read(); f[MX - a[i]][MX - b[i]]++; } for (int i = 1; i <= (MX << 1); ++i) { for (int j = 1; j <= (MX << 1); ++j) { add(f[i][j], f[i - 1][j]); add(f[i][j], f[i][j - 1]); } } invjc[0] = invjc[1] = inv[0] = inv [1] = jc [0] = jc [1] = 1; for (int i = 2; i <= (MX << 2); ++i)jc[i] = (LL)jc[i - 1] * i % MOD; for (int i = 2; i <= (MX << 2); ++i)inv[i] = (LL)(MOD - MOD / i) * inv[MOD % i] % MOD; for (int i = 2; i <= (MX << 2); ++i)invjc[i] = (LL)invjc[i - 1] * inv[i] % MOD; for (int i = 1; i <= n; ++i)add(ans, f[a[i] + MX][b[i] + MX]); for (int i = 1; i <= n; ++i)add(ans, MOD - calc(2 * (a[i] + b[i]), 2 * a[i])); printf("%lld\n", ans * inv[2] % MOD); return 0; }
codenet
-1
1,466
s676649719
p04051
1,533,614,626
cpp
Accepted
170
127,232
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; typedef pair<ll,ll> pll; void read(int& x){ scanf("%d",&x); } void read(ll& x){ scanf("%lld",&x); } void read(pp& x){ scanf("%d%d",&x.first, &x.second); } void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); } template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); } #define all(x) (x).begin(),(x).end() #define pb push_back #define eb emplace_back #define x first #define y second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define sz(x) (int)(x).size() int n; const ll mod = int(1e9) + 7; ll dp[4010][4010]; pp d[200010]; ll fact[8010]; ll frev[8010]; ll ppow(ll b, ll e){ ll ret = 1; while(e){ if(e&1) (ret*=b)%=mod; (b*=b)%=mod; e>>=1; } return ret; } int main() { read(n); rrep(i, n) read(d[i]), ++dp[2000-d[i].x][2000-d[i].y]; rep(i, 4001) rep(j, 4001){ if(i) (dp[i][j] += dp[i-1][j]) %= mod; if(j) (dp[i][j] += dp[i][j-1]) %= mod; } fact[0]=1; rrep(i, 8000) fact[i]=fact[i-1]*i%mod; frev[8000]=ppow(fact[8000], mod-2); for(int i=7999; 0<=i; --i) frev[i]=frev[i+1]*(i+1)%mod; ll ans = 0; rrep(i, n){ int x, y; tie(x, y) = d[i]; (ans += dp[x+2000][y+2000]) %= mod; } rrep(i, n){ int x, y; tie(x, y) = d[i]; (ans += mod - fact[x+y<<1]*frev[x<<1]%mod*frev[y<<1]%mod) %= mod; } (ans *= (mod+1)/2) %= mod; printf("%lld\n", ans); return 0; }
codenet
-1
1,466
s154455618
p04051
1,578,882,672
cpp
Accepted
135
73,856
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> const int mod = 1000000007; const int N = 4005; const int M = 8000; using namespace std; int f[N + 505][N + 505], a[200005], b[200005], fac[M << 1], inv[M << 1], base, ans, n; template < typename T > inline T read() { T x = 0, w = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); } while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * w; } int fpow(int x, int y) { int res = 1; while(y) { if(y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod; y >>= 1; } return res; } int C(int n, int m) { return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod; } int main() { n = read <int> (), base = 2002; for(int i = (fac[0] = 1); i <= M; i++) fac[i] = 1ll * fac[i - 1] * i % mod; inv[M] = fpow(fac[M], mod - 2); for(int i = M - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod; for(int i = 1; i <= n; i++) { a[i] = read <int> (), b[i] = read <int> (); f[base - a[i]][base - b[i]]++; } for(int i = 1; i <= base + 2000; i++) for(int j = 1; j <= base + 2000; j++) f[i][j] = (1ll * f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod; for(int i = 1; i <= n; i++) { ans = (1ll * ans + f[base + a[i]][base + b[i]]) % mod; ans = (1ll * ans - C(2 * a[i] + 2 * b[i], 2 * a[i])) % mod; } ans = (ans + mod) % mod; ans = 1ll * ans * 500000004 % mod; printf("%d\n", ans); return 0; }
codenet
-1
1,468
s610861816
p04051
1,535,840,165
cpp
Accepted
185
66,176
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e3 + 5; const int mod = 1e9 + 7; int n, a[N], b[N], fact[N], inv_fact[N], dp[M * 2][M * 2], ans = 0; int binPow (int x, int y) { int ans = 1; while (y > 0) { if (y & 1) ans = (1LL * ans * x) % mod; x = (1LL * x * x) % mod; y >>= 1; } return ans; } void prep(){ fact[0] = inv_fact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = (1LL * i * fact[i - 1]) % mod; inv_fact[i] = binPow(fact[i], mod - 2); } } void add (int &x, int y) { x = (x + y) % mod; } int C (int n, int k) { int res = 1; res = 1LL * res * fact[n] % mod; res = 1LL * res * inv_fact[k] % mod; res = 1LL * res * inv_fact[n - k] % mod; return res; } int main(){ scanf("%d", &n); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i], &b[i]); dp[-a[i] + M - 5][-b[i] + M - 5]++; } prep(); for (int i = 0; i < M * 2; i++) { for (int j = 0; j < M * 2; j++) { if (i) add(dp[i][j], dp[i - 1][j]); if (j) add(dp[i][j], dp[i][j - 1]); } } for (int i = 1; i <= n; i++) add(ans, dp[a[i] + M - 5][b[i] + M - 5]); for (int i = 1; i <= n; i++) ans = (ans - C(a[i] * 2 + b[i] * 2, a[i] * 2)) % mod; ans = (1LL * ans * binPow(2, mod - 2)) % mod; if (ans < 0) ans += mod; printf("%d", ans); return 0; }
codenet
-1
1,468
s213938211
p04051
1,468,728,008
cpp
Accepted
582
67,712
#include <iostream> #include <cstdio> #include <cstring> #include <cassert> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; /* f(x, y) = C(x + y, y) (0, 0) -> (x, y) = f(x - 0, y - 0) (a, b) -> (c, d) = f(c - a, d - b) (a <= c && b <= d) f(A[i] + A[j], B[i] + B[j]) がほしい (-A[j], -B[j]) -> (A[i], B[i]) = f(A[i] + A[j], B[i] + B[j]) */ ll f[9000], finv[9000]; ll C(int n, int k){ ll res = f[n]; res = (res * finv[k]) % MOD; res = (res * finv[n - k]) % MOD; return res; } int ways[4100][4100]; void add(int &x, int y){ x = (x + y) % MOD; } ll mod_pow(ll x, ll e){ ll v = 1; for(;e;e>>=1){ if(e & 1)v = (v * x) % MOD; x = (x * x) % MOD; } return v; } int main(){ f[0] = 1; for(int i=1;i<9000;i++)f[i] = f[i-1] * i % MOD; finv[8999] = mod_pow(f[8999], MOD - 2); for(int i=8998;i>=0;i--)finv[i] = finv[i + 1] * (i + 1) % MOD; int N; cin >> N; vector<int> A(N), B(N); for(int i=0;i<N;i++){ cin >> A[i] >> B[i]; } for(int i=0;i<N;i++){ ways[2000 - A[i]][2000 - B[i]] += 1; } for(int i=0;i<4100;i++)for(int j=0;j<4100;j++){ if(i > 0) add(ways[i][j], ways[i-1][j]); if(j > 0) add(ways[i][j], ways[i][j-1]); } ll res = 0; for(int i=0;i<N;i++){ res += ways[2000 + A[i]][2000 + B[i]]; res += MOD - C(2 * A[i] + 2 * B[i], 2 * A[i]); res %= MOD; } res = (res * mod_pow(2, MOD - 2)) % MOD; cout << res << endl; return 0; }
codenet
-1
1,475
s275878531
p04051
1,490,027,677
cpp
Accepted
233
128,768
//satyaki3794 #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define MOD (1000000007LL) #define LEFT(n) (2*(n)) #define RIGHT(n) (2*(n)+1) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; ll pwr(ll base, ll p, ll mod = MOD){ ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans; } ll gcd(ll a, ll b){ if(b == 0) return a; return gcd(b, a%b); } const int BASE = 2001; int n; ll DP[2*BASE+5][2*BASE+5], A[200005], B[200005], fac[8002]; ll C(int n, int r){ ll ans = fac[n]; ans = (ans * pwr(fac[r], MOD-2)) % MOD; ans = (ans * pwr(fac[n-r], MOD-2)) % MOD; return ans; } int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); fac[0] = 1; for(int i=1;i<=8000;i++) fac[i] = (i * fac[i-1]) % MOD; scanf("%d", &n); for(int i=1;i<=n;i++){ scanf("%lld%lld", &A[i], &B[i]); DP[BASE-A[i]][BASE-B[i]]++; } for(int i=-2000;i<=2000;i++) for(int j=-2000;j<=2000;j++){ DP[BASE+i][BASE+j] = (DP[BASE+i][BASE+j] + DP[BASE+i-1][BASE+j] + DP[BASE+i][BASE+j-1]) % MOD; } ll ans = 0; for(int i=1;i<=n;i++){ ans = (ans + DP[BASE+A[i]][BASE+B[i]]) % MOD; ans = (ans - C(2*A[i]+2*B[i], 2*A[i])) % MOD; } ans = (ans * pwr(2, MOD-2)) % MOD; ans += MOD; ans %= MOD; printf("%lld\n", ans); return 0; }
codenet
-1
1,476
s275878531
p04051
1,490,027,677
cpp
Accepted
233
128,768
//satyaki3794 #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define MOD (1000000007LL) #define LEFT(n) (2*(n)) #define RIGHT(n) (2*(n)+1) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; ll pwr(ll base, ll p, ll mod = MOD){ ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans; } ll gcd(ll a, ll b){ if(b == 0) return a; return gcd(b, a%b); } const int BASE = 2001; int n; ll DP[2*BASE+5][2*BASE+5], A[200005], B[200005], fac[8002]; ll C(int n, int r){ ll ans = fac[n]; ans = (ans * pwr(fac[r], MOD-2)) % MOD; ans = (ans * pwr(fac[n-r], MOD-2)) % MOD; return ans; } int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); fac[0] = 1; for(int i=1;i<=8000;i++) fac[i] = (i * fac[i-1]) % MOD; scanf("%d", &n); for(int i=1;i<=n;i++){ scanf("%lld%lld", &A[i], &B[i]); DP[BASE-A[i]][BASE-B[i]]++; } for(int i=-2000;i<=2000;i++) for(int j=-2000;j<=2000;j++){ DP[BASE+i][BASE+j] = (DP[BASE+i][BASE+j] + DP[BASE+i-1][BASE+j] + DP[BASE+i][BASE+j-1]) % MOD; } ll ans = 0; for(int i=1;i<=n;i++){ ans = (ans + DP[BASE+A[i]][BASE+B[i]]) % MOD; ans = (ans - C(2*A[i]+2*B[i], 2*A[i])) % MOD; } ans = (ans * pwr(2, MOD-2)) % MOD; ans += MOD; ans %= MOD; printf("%lld\n", ans); return 0; }
codenet
-1
1,476
s178393511
p04051
1,495,724,313
cpp
Accepted
158
63,104
#include <cstring> #include <algorithm> #include <cstdio> using namespace std; typedef long long ll; const int MAXN = 4010; const int ZERO = 2005; const int MOD = 1e9+7; int a[MAXN][MAXN] = {0}; int fpow( int a, int b ) { if( !b ) return 1; int rtn = fpow(a,b/2); rtn = int((ll)rtn * rtn % MOD); if( b & 1 ) rtn = int((ll)rtn * a % MOD); return rtn; } int inv( int a ) { return fpow(a,MOD-2); } int fac[8010], ifac[8010]; void prelude() { fac[0] = 1; for( int i = 1; i < 8010; ++i ) fac[i] = int((ll)fac[i-1] * i % MOD); ifac[8009] = inv(fac[8009]); for( int i = 8008; i >= 0; --i ) ifac[i] = int((ll)ifac[i+1] * (i+1) % MOD); } int C( int a, int b ) { return int((ll)fac[a] * ifac[a-b] % MOD * ifac[b] % MOD); } int main() { prelude(); int n; scanf( "%d", &n ); int ans = 0; for( int i = 0; i < n; ++i ) { int x, y; scanf( "%d%d", &x, &y ); --a[ZERO+x][ZERO+y]; ++a[ZERO-x][ZERO-y]; // printf( "C(%d, %d) = %d\n", x+x+y+y, x+x, C(x+x+y+y, x+x) ); ans = (ans - C(x+x+y+y, x+x) + MOD) % MOD; } for( int i = 0; i < MAXN; ++i ) for( int j = 0; j < MAXN; ++j ) { int end = -a[i][j]; a[i][j] = max(a[i][j], 0); if( i ) a[i][j] = (a[i][j] + a[i-1][j]) % MOD; if( j ) a[i][j] = (a[i][j] + a[i][j-1]) % MOD; if( end > 0 ) ans = int((ans + (ll)a[i][j] * end) % MOD); // if( a[i][j] && i < ZERO+3 && j < ZERO+3 ) printf( "a[%d][%d] = %d\n", i, j, a[i][j] ); } ans = int((ll)ans * inv(2) % MOD); printf( "%d\n", ans ); return 0; }
codenet
-1
1,478
s369093714
p04051
1,570,802,161
cpp
Accepted
155
127,360
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #define MOD 1000000007 using namespace std; typedef long long ll; const ll inv2 = 500000004; template <typename T> inline void getint(T &num){ register int ch, neg = 0; while(!isdigit(ch = getchar())) if(ch == '-') neg = 1; num = ch & 15; while(isdigit(ch = getchar())) num = num * 10 + (ch & 15); if(neg) num = -num; } inline ll fastpow(ll bas, ll ex){ register ll res = 1; bas %= MOD; for(; ex; ex >>= 1, bas = bas * bas % MOD) if(ex & 1) res = res * bas % MOD; return res; } int N, A[200005], B[200005]; ll f[4005][4005], fac[16005] = {1}, ifac[16005], ans = 0; inline void Init(){ for(register int i = 1; i <= 16000; i++) fac[i] = fac[i - 1] * i % MOD; ifac[16000] = fastpow(fac[16000], MOD - 2); for(register int i = 16000; i >= 1; i--) ifac[i - 1] = ifac[i] * i % MOD; } inline ll C(int n, int m) {return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;} int main(){ getint(N), Init(); for(register int i = 1; i <= N; i++){ getint(A[i]), getint(B[i]); f[2001 - A[i]][2001 - B[i]]++; } for(register int i = 1; i <= 4001; i++) for(register int j = 1; j <= 4001; j++) (f[i][j] += f[i - 1][j] + f[i][j - 1]) %= MOD; for(register int i = 1; i <= N; i++) (ans += f[2001 + A[i]][2001 + B[i]]) %= MOD; for(register int i = 1; i <= N; i++) (ans += MOD - C(A[i] + B[i] << 1, A[i] << 1)) %= MOD; return printf("%lld\n", ans * inv2 % MOD), 0; }
codenet
-1
1,480
s995950795
p04051
1,560,115,014
cpp
Accepted
182
64,640
#include <bits/stdc++.h> using namespace std; const int maxn = 4010, mod = 1e9 + 7; int n, f[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; vector<int> a(n); vector<int> b(n); for ( int i = 0; i < n; ++ i) { cin >> a[i] >> b[i]; f[2000 - a[i]][2000 - b[i]] ++; } for ( int i = 1; i <= 4000; ++ i) { f[0][i] = (f[0][i] + f[0][i-1]) % mod; } for ( int i = 1; i <= 4000; ++ i) { f[i][0] = (f[i][0] + f[i-1][0]) % mod; for ( int k = 1; k <= 4000; ++ k) { f[i][k] = (f[i][k] + (f[i - 1][k] + f[i][k - 1]) % mod) % mod; } } int ret = 0; for ( int i = 0; i < n; ++ i) { ret = (ret + f[a[i]+2000][b[i]+2000]) % mod; } function<int(int, int)> _pow = [&](int x, int n) { int ret = 1; for ( ; n; n >>= 1, x = 1LL * x * x % mod) { if( n & 1) { ret = 1LL * ret * x % mod; } } return ret; }; vector<int> fac(maxn << 1); vector<int> ifac(maxn << 1); for ( int i = fac[0] = 1; i <= 8000; ++ i) { fac[i] = 1LL * fac[i - 1] * i % mod; } ifac[8000] = _pow(fac[8000], mod - 2); for ( int i = 8000; i; -- i) { ifac[i - 1] = 1LL * ifac[i] * i % mod; } function<int(int, int)> C = [&](int n, int m) { return 1LL * fac[n] * ifac[m] % mod * ifac[n-m] % mod; }; for ( int i = 0; i < n; ++ i) { ret = (ret - C(a[i]+b[i] << 1, a[i] << 1) + mod) % mod; } cout << (1LL * ret * (mod + 1 >> 1) % mod) << "\n"; return 0; }
codenet
-1
1,481
s805041158
p04051
1,569,908,948
cpp
Accepted
194
68,096
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define mp make_pair #define ff first #define ss second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(v) v.begin(),v.end() const int maxn = 2e5 + 100, maxval = 2010; const ll inf = 2e18, mod = 1e9 + 7; int n, a[maxn], b[maxn], dp[maxval * 2][maxval * 2]; ll fact[maxn], invfact[maxn]; ll powmod(ll a, ll b) { if (!b) return 1LL; ll tmp = powmod(a, b / 2); tmp = tmp * tmp % mod; if (b & 1) tmp = tmp * a % mod; return tmp; } void addmod(int& a, int b) { a += b; if (a > mod) a -= mod; } ll comb(int n, int r) { return fact[n] * (invfact[r] * invfact[n - r] % mod) % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); fact[0] = 1; invfact[0] = powmod(fact[0], mod - 2); for (int i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i % mod, invfact[i] = powmod(fact[i], mod - 2); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; dp[maxval - a[i]][maxval - b[i]]++; } for (int i = 0; i < maxval * 2 - 2; i++) for (int j = 0; j < maxval * 2 - 2; j++) addmod(dp[i + 1][j], dp[i][j]), addmod(dp[i][j + 1], dp[i][j]); ll ans = 0; for (int i = 0; i < n; i++) ans = (ans + dp[maxval + a[i]][maxval + b[i]]) % mod; for (int i = 0; i < n; i++) ans = (ans - comb(2 * a[i] + 2 * b[i], 2 * a[i]) + mod) % mod; ans = ans * powmod(2, mod - 2) % mod; cout << ans << endl; }
codenet
-1
1,482
s840682183
p04051
1,573,532,076
cpp
Accepted
193
64,512
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> using namespace std; inline int gi() { register int data = 0, w = 1; register char ch = 0; while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); return w * data; } const int Mod = 1e9 + 7; const int T = 2001; int N, f[4005][4005], A[200005], B[200005]; int fpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % Mod; x = 1ll * x * x % Mod; y >>= 1; } return res; } int fac[8005], ifc[8005]; int C(int n, int m) { if (n < m) return 0; else return 1ll * fac[n] * ifc[n - m] % Mod * ifc[m] % Mod; } int main () { N = gi(); for (int i = 1; i <= N; i++) A[i] = gi(), B[i] = gi(), f[T - A[i]][T - B[i]]++; for (int i = 1; i <= 4001; i++) for (int j = 1; j <= 4001; j++) f[i][j] = (f[i][j] + (f[i - 1][j] + f[i][j - 1]) % Mod) % Mod; fac[0] = 1; for (int i = 1; i <= 8000; i++) fac[i] = 1ll * fac[i - 1] * i % Mod; ifc[8000] = fpow(fac[8000], Mod - 2); for (int i = 7999; ~i; i--) ifc[i] = 1ll * ifc[i + 1] * (i + 1) % Mod; int ans = 0; for (int i = 1; i <= N; i++) { ans = (ans + f[A[i] + T][B[i] + T]) % Mod; ans = (ans - C((A[i] + B[i]) << 1, A[i] << 1) + Mod) % Mod; } ans = 1ll * ans * fpow(2, Mod - 2) % Mod; printf("%d\n", ans); return 0; }
codenet
-1
1,483
s549323976
p04051
1,573,770,997
cpp
Accepted
140
64,768
#include<bits/stdc++.h> #define LL long long #define RG register using namespace std; template<class T> T gi() { T x = 0; bool f = 0; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = 1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f ? -x : x; } const int N = 200010, Mod = 1e9 + 7; int A[N], B[N], n, fac[8010], ifac[8010]; int C(int n, int m) { if (n < m) return 0; return 1ll * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod; } int fpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = 1ll * a * a % Mod) if (b & 1) res = 1ll * res * a % Mod; return res; } int f[4010][4010]; int main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); n = gi<int>(); for (int i = 1; i <= n; i++) { A[i] = gi<int>(), B[i] = gi<int>(); f[2000 - A[i]][2000 - B[i]]++; } fac[0] = 1; for (int i = 1; i <= 8000; i++) fac[i] = 1ll * fac[i - 1] * i % Mod; ifac[8000] = fpow(fac[8000], Mod - 2); for (int i = 8000; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % Mod; for (int i = 0; i <= 4000; i++) for (int j = 0; j <= 4000; j++) { if (i) f[i][j] = (f[i][j] + f[i - 1][j]) % Mod; if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % Mod; } int ans = 0; for (int i = 1; i <= n; i++) { ans = (ans + f[A[i] + 2000][B[i] + 2000]) % Mod; ans = (ans - C(A[i] + A[i] + B[i] + B[i], A[i] + A[i]) + Mod) % Mod; } printf("%d\n", 1ll * ans * fpow(2, Mod - 2) % Mod); return 0; }
codenet
-1
1,485
s218837826
p04051
1,506,612,668
cpp
Accepted
212
65,280
#include <bits/stdc++.h> using namespace std; #define fo(i,s,t) for(int i = s; i <= t; ++ i) #define fd(i,s,t) for(int i = s; i >= t; -- i) #define bf(i,s) for(int i = head[s]; i; i = e[i].next) #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define pb push_back #define VI vector<int> #define sf scanf #define pf printf #define fp freopen #define SZ(x) ((int)(x).size()) #define IF_DEBUG 0 typedef long long ll; typedef double db; typedef unsigned long long ull; const int inf = 1<<30; const ll INF = 1ll<<60; const db Inf = 1e20; const db eps = 1e-9; void gmax(int &a,int b){a = (a > b ? a : b);} void gmin(int &a,int b){a = (a < b ? a : b);} const int maxn = 200050; const int maxm = 2005; const int P = 1e9+7; int f[maxm<<1][maxm<<1]; int N, A[maxn], B[maxn], Fac[maxn], Ans; int inv(int a) { int ans = 1, b = P-2; while(b) { if(b&1) ans = (1ll*ans*a)%P; b >>= 1; a = (1ll*a*a)%P; } return ans; } int C(int n,int m) { return (((1ll*Fac[n]*inv(Fac[m]))%P)*inv(Fac[n-m]))%P; } int main() { sf("%d",&N); fo(i,1,N) sf("%d%d",&A[i],&B[i]); fo(i,1,N) f[-A[i]+maxm][-B[i]+maxm] ++; fo(i,-2000,2000) fo(j,-2000,2000) f[i+maxm][j+maxm] = (1ll*f[i+maxm][j+maxm]+f[i-1+maxm][j+maxm]+f[i+maxm][j-1+maxm])%P; fo(i,1,N) Ans = (1ll*Ans + f[A[i]+maxm][B[i]+maxm])%P; Fac[0] = 1; fo(i,1,maxn-1) Fac[i] = (1ll*Fac[i-1]*i)%P; fo(i,1,N) Ans = ((1ll*Ans - C(A[i]*2+B[i]*2,A[i]*2))%P+P)%P; Ans = 1ll*Ans*inv(2)%P; pf("%d\n",Ans); return 0; }
codenet
-1
1,486
s944375841
p04051
1,506,086,123
cpp
Accepted
209
189,824
#include<cstdio> #include<iostream> #include<algorithm> #include<ctime> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<cstring> #include<map> #include<vector> #include<set> #define rep(i,j,k) for(register int i = j; i <= k; i++) #define dow(i,j,k) for(register int i = j; i >= k; i--) #define fi first #define se second //#define P pair<ll,ll> #define mp(a,b) make_pair(a,b) #define ll long long #define ull unsigned long long using namespace std; inline int read() { int s = 0, t = 1; char c = getchar(); while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); } while( isdigit(c) ) s = s * 10 + c - 48, c = getchar(); return s * t; } const int N = 4008, M = 2001, p = 1e9+7; inline void _(ll &x) { if( x >= p ) x -= p; } ll ans = 0, f[N][N], g[N][N], fac[N<<1] = {1}, ni[N<<1] = {1,1}; inline ll C(int n,int m) { return fac[n] * ni[m] % p * ni[n-m] % p; } int main() { int n = read(), x, y, mx = 0, my = 0; rep(i,1,8000) fac[i] = fac[i-1] * i % p; rep(i,2,8000) ni[i] = (p - p / i) * ni[p % i] % p; rep(i,2,8000) ni[i] = ni[i] * ni[i-1] % p; rep(i,1,n) { mx = max(mx,x = read()), my = max(my,y = read()); f[M-x][M-y]++; g[M+x][M+y]++; (ans -= C((x+y)<<1,x<<1)) %= p; } rep(i,M-mx,M+mx) { rep(j,M-my,M+my) { _(f[i][j]+=f[i-1][j]); _(f[i][j]+=f[i][j-1]); } } rep(i,1+M,mx+M) { rep(j,1+M,my+M) { (ans += (ll)g[i][j] * f[i][j]) %= p; } } cout<<(ans + p) % p * ((p + 1) / 2) % p<<endl; return 0; }
codenet
-1
1,487
s773800224
p04051
1,575,526,324
cpp
Accepted
233
128,256
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 4e3 + 5; const int _C = 2000; const int P = 1e9 + 7; typedef long long LL; #define f(x, y) F[(x) + _C + 1][(y) + _C + 1] #define m(x, y) wap[(x) + _C + 1][(y) + _C + 1] #define C(x, y) ((x >= y && y >= 0) ? (frac[x] * inv_frac[(x) - (y)] % P * inv_frac[y] % P) : 0) int wap[M][M], n; int F[M][M], ans; LL frac[N], inv_frac[N]; inline LL ksm(LL base, LL x) { LL res = 1; while(x) { if(x & 1) res *= base, res %= P; x >>= 1, base *= base, base %= P; } return res; } void init() { int a, b; scanf("%d", &n); frac[0] = 1; for(int i = 1; i < N; i++) frac[i] = frac[i - 1] * i % P; inv_frac[N - 1] = ksm(frac[N - 1], P - 2); for(int i = N - 2; i >= 0; i--) inv_frac[i] = inv_frac[i + 1] * (i + 1) % P; for(int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); ans += P - C(a + a + b + b, a + a); ans %= P; m(-a, -b) ++; f(-a, -b) ++; m(a, b) --; } for(int i = -_C; i <= _C; i++) { for(int j = -_C; j <= _C; j++) { f(i, j) += (f(i - 1, j) + f(i, j - 1)) % P; f(i, j) %= P; //if(f(i, j)) printf("f(%d, %d) = %lld\n", i, j, f(i, j)); if(m(i, j) < 0) ans += (LL)-m(i, j) * f(i, j) % P, ans %= P; } } if(ans % 2 == 0) ans /= 2; else ans += P, ans /= 2; cout << ans << endl; } int main() { init(); return 0; }
codenet
-1
1,488
s975430492
p04051
1,485,402,244
cpp
Accepted
228
64,640
#include <bits/stdc++.h> #define LL long long #define INF 0x3f3f3f3f // -Wall using namespace std; template<class T> inline void read(T& x) { int f = 1; x = 0; 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();} x *= f; } /*============ Header Template ============*/ const int N = 200000 + 5; const int mo = 1000000007; const int M = 2000; int n; int a[N], b[N]; int c[(M << 1) + 5][(M << 1) + 5]; LL f[N], inv[N]; void exgcd(LL a, LL b, LL &x, LL &y) { if (b == 0) {x = 1, y = 0; return;} exgcd(b, a % b, y, x); y -= x * (a / b); } LL C(int n, int m) {return m > n ? 0 : f[n] * inv[m] % mo * inv[n - m] % mo;} void pre() { f[0] = 1; for (int i = 1; i <= 8000; i++) f[i] = f[i - 1] * i % mo; LL y; exgcd(f[8000], mo, inv[8000], y); for (int i = 7999; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mo; } int main() { read(n); pre(); for (int i = 1; i <= n; i++) read(a[i]), read(b[i]); for (int i = 1; i <= n; i++) c[-b[i] + M][-a[i] + M]++; for (int i = 0; i <= M * 2; i++) for (int j = 0; j <= M * 2; j++) { (c[i][j + 1] += c[i][j]) %= mo; (c[i + 1][j] += c[i][j]) %= mo; } LL ans = 0; for (int i = 1; i <= n; i++) (ans += c[b[i] + M][a[i] + M]) %= mo; for (int i = 1; i <= n; i++) { LL tmp = C(a[i] + b[i] + a[i] + b[i], a[i] + a[i]); (ans -= tmp) %= mo; } ans = ans * inv[2] % mo; printf("%lld\n", (ans + mo) % mo); return 0; }
codenet
-1
1,488
s109992288
p04051
1,567,886,202
cpp
Accepted
152
132,096
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 10; const int mod = 1e9 + 7; int n; int inv[N], fac[N], f[4010][4010], a[N], b[N]; template<class T>inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x = f ? -x : x; return; } int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod, b >>= 1; } return ans; } void init() { fac[0] = 1; for (int i = 1; i <= N - 10; ++i) fac[i] = fac[i - 1] * i % mod; inv[N - 10] = qpow(fac[N - 10], mod - 2); for (int i = N - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod; } int C(int x, int y) { return fac[x] * inv[y] % mod * inv[x - y] % mod; } signed main() { init(); read(n); for (int i = 1; i <= n; ++i) { read(a[i]), read(b[i]); f[2001 - a[i]][2001 - b[i]]++; } for (int i = 1; i <= 4001; ++i) for (int j = 1; j <= 4001; ++j) { f[i][j] = (f[i][j] + f[i - 1][j]) % mod; f[i][j] = (f[i][j] + f[i][j - 1]) % mod; } int ans = 0; for (int i = 1; i <= n; ++i) ans = (ans + f[2001 + a[i]][2001 + b[i]]) % mod; for (int i = 1; i <= n; ++i) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod; printf("%lld\n", ans * qpow(2, mod - 2) % mod); return 0; }
codenet
-1
1,493
s109992288
p04051
1,567,886,202
cpp
Accepted
152
132,096
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 10; const int mod = 1e9 + 7; int n; int inv[N], fac[N], f[4010][4010], a[N], b[N]; template<class T>inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x = f ? -x : x; return; } int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod, b >>= 1; } return ans; } void init() { fac[0] = 1; for (int i = 1; i <= N - 10; ++i) fac[i] = fac[i - 1] * i % mod; inv[N - 10] = qpow(fac[N - 10], mod - 2); for (int i = N - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod; } int C(int x, int y) { return fac[x] * inv[y] % mod * inv[x - y] % mod; } signed main() { init(); read(n); for (int i = 1; i <= n; ++i) { read(a[i]), read(b[i]); f[2001 - a[i]][2001 - b[i]]++; } for (int i = 1; i <= 4001; ++i) for (int j = 1; j <= 4001; ++j) { f[i][j] = (f[i][j] + f[i - 1][j]) % mod; f[i][j] = (f[i][j] + f[i][j - 1]) % mod; } int ans = 0; for (int i = 1; i <= n; ++i) ans = (ans + f[2001 + a[i]][2001 + b[i]]) % mod; for (int i = 1; i <= n; ++i) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod; printf("%lld\n", ans * qpow(2, mod - 2) % mod); return 0; }
codenet
-1
1,493
s625951607
p04051
1,577,778,891
cpp
Accepted
147
64,752
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)x.size() //#define int ll const int MOD = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= MOD) { a -= MOD; } } void sub(int &a, int b) { a -= b; if (a < 0) { a += MOD; } } int mult(int a, int b) { return (a * 1ll * b) % MOD; } int b_pow(int a, int b) { if (!b) { return 1; } if (b & 1) { return mult(a, b_pow(a, b - 1)); } return b_pow(mult(a, a), b >> 1); } const int N = 4010; int dp[N][N], f[2 * N], rf[2 * N]; int C(int n, int k) { if (n < 0 || k < 0 || n < k) { return 0; } return mult(f[n], mult(rf[k], rf[n - k])); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); f[0] = 1; for (int i = 1; i <= 8000; i++) { f[i] = mult(f[i - 1], i); } for (int i = 0; i <= 8000; i++) { rf[i] = b_pow(f[i], MOD - 2); } int n; cin >> n; vector<pair<int, int>> pr; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; pr.pb({a, b}); dp[2000 - a][2000 - b]++; } for (int i = 0; i <= 4000; i++) { for (int j = 0; j <= 4000; j++) { add(dp[i + 1][j], dp[i][j]); add(dp[i][j + 1], dp[i][j]); } } int ans = 0; for (auto it : pr) { add(ans, dp[it.F + 2000][it.S + 2000]); } for (auto it : pr) { sub(ans, C(2 * it.F + 2 * it.S, 2 * it.S)); } ans = mult(ans, b_pow(2, MOD - 2)); cout << ans << '\n'; }
codenet
-1
1,496
s248916063
p04051
1,595,292,401
cpp
Accepted
156
68,096
#include <iostream> #include <cstdio> #include <algorithm> template <typename Tp> inline void read(Tp &x) { x = 0; bool f = true; char ch = getchar(); for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-'; for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48); x = f ? x : -x; } const int N = 2e5 + 7, M = 4e3 + 7, P = 1e9 + 7; int A[N], B[N], F[M][M], Fac[M * 2], iFac[M * 2]; inline int Power(int a, int x) { int res = 1; while (x) { if (x & 1) res = 1LL * res * a % P; a = 1LL * a * a % P; x >>= 1; } return res; } inline int Inv(int x) { return Power(x, P - 2); } inline int C(int n, int m) { if (m < 0 || m > n) return 0; return 1LL * Fac[n] * iFac[n - m] % P * iFac[m] % P; } int main() { Fac[0] = 1; for (int i = 1; i < M * 2; ++i) Fac[i] = 1LL * Fac[i - 1] * i % P; iFac[2 * M - 1] = Inv(Fac[2 * M - 1]); for (int i = 2 * M - 2; i >= 0; --i) iFac[i] = 1LL * iFac[i + 1] * (i + 1) % P; int n; read(n); for (int i = 1; i <= n; ++i) read(A[i]), read(B[i]), ++F[-A[i] + M / 2][-B[i] + M / 2]; for (int i = 1; i < M; ++i) for (int j = 1; j < M; ++j) F[i][j] = (1LL * F[i][j] + F[i - 1][j] + F[i][j - 1]) % P; int Ans = 0; for (int i = 1; i <= n; ++i) { Ans = (Ans + F[A[i] + M / 2][B[i] + M / 2]) % P; Ans = (Ans + P - C(2 * (A[i] + B[i]), 2 * A[i])) % P; } printf("%lld\n", 1LL * Ans * Inv(2) % P); return 0; }
codenet
-1
1,497
s331848841
p04051
1,508,963,040
cpp
Accepted
133
65,792
#include <bits/stdc++.h> using namespace std; const int N = 202020; const int M = 4040; const int MOD = 1000000007; const int s = 2020; typedef long long ll; inline char get(void) { static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (S == T) return EOF; } return *S++; } template<typename T> inline void read(T &x) { static char c; x = 0; int sgn = 0; for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1; for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0'; if (sgn) x = -x; } int a[N], b[N]; int f[M][M]; int fac[N], inv[N]; int n, m, ans; inline void Add(int &x, int a) { x += a; while (x >= MOD) x -= MOD; } inline int C(int n, int m) { return (ll)fac[n + m] * inv[n] % MOD * inv[m] % MOD; } int main(void) { read(n); for (int i = 1; i <= n; i++) { read(a[i]); read(b[i]); ++f[s - a[i]][s - b[i]]; } for (int i = 1; i < M; i++) for (int j = 1; j < M; j++) { Add(f[i][j], f[i - 1][j]); Add(f[i][j], f[i][j - 1]); } inv[1] = 1; for (int i = 2; i <= 10000; i++) inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD; fac[0] = inv[0] = 1; for (int i = 1; i <= 10000; i++) { fac[i] = (ll)i * fac[i - 1] % MOD; inv[i] = (ll)inv[i] * inv[i - 1] % MOD; } for (int i = 1; i <= n; i++) { Add(ans, f[s + a[i]][s + b[i]]); Add(ans, MOD - C(a[i] << 1, b[i] << 1)); } ans = (ll)ans * (MOD + 1) / 2 % MOD; cout << ans << endl; return 0; }
codenet
-1
1,498
s004039560
p04051
1,591,661,976
cpp
Accepted
123
66,048
#include<bits/stdc++.h> using namespace std; #define N 200000 + 5 #define M 4000 + 5 #define Mod 1000000007 #define rep(i, l, r) for(int i = l; i <= r; ++i) int n, del, ans, a[N], b[N], f[N], inv[N], dp[M][M]; int read(){ char c; int x = 0, f = 1; c = getchar(); while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int c(int x){ return x + del;} int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;} int Dec(int a, int b){ return (a -= b) < 0 ? a + Mod : a;} int Mul(int a, int b){ return 1ll * a * b % Mod;} int Qpow(int a, int b){ int ans = 1; while(b){ if(b & 1) ans = Mul(ans, a); a = Mul(a, a), b >>= 1; } return ans; } int C(int n, int m){ if(m > n) return 0; return Mul(f[n], Mul(inv[m], inv[n - m])); } int main(){ f[0] = inv[0] = 1; rep(i, 1, N - 5) f[i] = Mul(f[i - 1], i), inv[i] = Qpow(f[i], Mod - 2); n = read(), del = 2000; rep(i, 1, n) a[i] = read(), b[i] = read(), dp[c(-a[i])][c(-b[i])] += 1; rep(i, -del, del) rep(j, -del, del){ if(i > -del) dp[c(i)][c(j)] = Inc(dp[c(i)][c(j)], dp[c(i - 1)][c(j)]); if(j > -del) dp[c(i)][c(j)] = Inc(dp[c(i)][c(j)], dp[c(i)][c(j - 1)]); } rep(i, 1, n) ans = Inc(ans, dp[c(a[i])][c(b[i])]); rep(i, 1, n) ans = Dec(ans, C(a[i] + a[i] + b[i] + b[i], a[i] + a[i])); ans = Mul(ans, Qpow(2, Mod - 2)); printf("%d", ans); return 0; }
codenet
-1
1,499
s326400701
p04051
1,554,926,246
cpp
Accepted
102
64,512
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<set> #define ll long long #define mod 1000000007 #define Mod1(x) (x>=mod?x-mod:x) #define Mod2(x) (x<0?x+mod:x) #define maxn 200010 inline ll read() { ll x=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; return x*f; } inline void write(ll x) { static int buf[20],len; len=0; if(x<0)x=-x,putchar('-'); for(;x;x/=10)buf[len++]=x%10; if(!len)putchar('0'); else while(len)putchar(buf[--len]+'0'); } inline void writeln(ll x){write(x); putchar('\n');} inline void writesp(ll x){write(x); putchar(' ');} const int size=4010,inv2=(mod+1)>>1; int fac[2*size],inv[2*size]; int dp[size][size]; int a[maxn],b[maxn]; int n,tot; inline ll power(ll a,ll b) { ll ans=1; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=ans*a%mod; return ans; } inline ll C(ll n,ll m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;} int main() { n=read(); for(int i=1;i<=n;i++){ a[i]=read(); b[i]=read(); ++dp[2000-a[i]][2000-b[i]]; } for(int i=0;i<=4000;i++) for(int j=0;j<=4000;j++){ if(i)dp[i][j]=Mod1(dp[i][j]+dp[i-1][j]); if(j)dp[i][j]=Mod1(dp[i][j]+dp[i][j-1]); } int ans=0; for(int i=1;i<=n;i++) ans=Mod1(ans+dp[2000+a[i]][2000+b[i]]); fac[0]=inv[0]=1; for(int i=1;i<=8000;i++) fac[i]=(ll)fac[i-1]*i%mod,inv[i]=power(fac[i],mod-2); for(int i=1;i<=n;i++) ans=Mod2(ans-C(2*a[i]+2*b[i],2*a[i])); writeln((ll)ans*inv2%mod); return 0; }
codenet
-1
1,499
s344129827
p04051
1,523,083,392
cpp
Accepted
252
99,072
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MX = 4010; const int offset = 2000; int exp(int x, int n) { int ret = 1; while(n) { if(n & 1) ret = 1LL * ret * x % mod; x = 1LL * x * x % mod; n >>= 1; } return ret; } int inv(int x) { return exp(x, mod - 2); } int fact[10010], invf[10010]; int comb(int n, int k) { return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod; } int N; int A[200010], B[200010]; int chk[4010][4010]; int cc[4010][4010]; int dp(int x, int y) { if(x >= MX || y >= MX) return 0; int &ret = cc[x][y]; if(ret != -1) return ret; ret = 0; ret += chk[x][y]; ret %= mod; ret += dp(x + 1, y); ret %= mod; ret += dp(x, y + 1); ret %= mod; return ret; } int main() { fact[0] = 1; for(int i = 1; i < 10010; i++) { fact[i] = 1LL * fact[i - 1] * i % mod; } for(int i = 0; i < 10010; i++) { invf[i] = inv(fact[i]); } scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d %d", &A[i], &B[i]); chk[ A[i] + offset ][ B[i] + offset ]++; } memset(cc, -1, sizeof(cc)); int ans = 0; for(int i = 0; i < N; i++) { ans += dp(-A[i] + offset, -B[i] + offset); ans %= mod; } for(int i = 0; i < N; i++) { ans += mod - comb(2 * A[i] + 2 * B[i], 2 * A[i]); ans %= mod; } ans = 1LL * ans * inv(2) % mod; ans %= mod; printf("%d", ans); }
codenet
-1
1,499
s299467498
p04051
1,586,136,744
cpp
Accepted
151
195,328
#include<bits/stdc++.h> #define mod 1000000007 #define int long long #define BASE 3000 using namespace std; inline int read(){ int res=0; char c; bool zf=0; while(((c=getchar())<'0'||c>'9')&&c!= '-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } struct op{ int a,b; }data[200005]; int dp[6005][6005]; int frac[10005],inv[10005]; inline int C(int a,int b){ return frac[a]*inv[a-b]%mod*inv[b]%mod; } inline int solve(int x,int y=mod-2,int MOD=mod){ int res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1; } return res; } signed main(){ int n=read(); for(register int i=1;i<=n;i++)data[i].a=read(),data[i].b=read(); for(register int i=1;i<=n;i++)dp[BASE-data[i].a][BASE-data[i].b]++; int Maxx=-2e9,Maxy=-2e9; for(register int i=1;i<=n;i++)Maxx=max(Maxx,data[i].a),Maxy=max(Maxy,data[i].b); for(register int i=-Maxx;i<=Maxx;i++)for(register int j=-Maxy;j<=Maxy;j++)dp[BASE+i][BASE+j]=(dp[BASE+i][BASE+j]+dp[BASE+i-1][BASE+j]+dp[BASE+i][BASE+j-1])%mod; int ans=0; for(register int i=1;i<=n;i++)ans=(ans+dp[BASE+data[i].a][BASE+data[i].b])%mod; int temp=(Maxx+Maxy)<<1; frac[1]=1;for(register int i=2;i<=temp;i++)frac[i]=frac[i-1]*i%mod; inv[temp]=solve(frac[temp]);for(register int i=temp-1;i>=1;i--)inv[i]=inv[i+1]*(i+1)%mod; for(register int i=1;i<=n;i++) ans=(ans-C((data[i].a+data[i].b)<<1,data[i].a<<1)+mod)%mod; cout<<ans*solve(2)%mod; return 0; }
codenet
-1
1,500
s338393840
p04051
1,573,418,653
cpp
Accepted
143
129,152
// =================================== // author: M_sea // website: http://m-sea-blog.com/ // =================================== #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #define re register using namespace std; inline int read() { int X=0,w=1; char c=getchar(); while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); } while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar(); return X*w; } const int mod=1e9+7; inline int qpow(int a,int b) { int c=1; for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod; return c; } const int N=200000+10,SIZE=2001,L=(SIZE<<2)+10; int fac[L],ifac[L]; inline void init(int n) { fac[0]=1; for (re int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod; ifac[n]=qpow(fac[n],mod-2); for (re int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod; } inline int C(int n,int m) { return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; } int n,a[N],b[N],dp[L][L]; int main() { init(SIZE<<2); n=read(); for (re int i=1;i<=n;++i) { a[i]=read(),b[i]=read(); ++dp[SIZE-a[i]][SIZE-b[i]]; } for (re int i=1;i<=SIZE<<1;++i) for (re int j=1;j<=SIZE<<1;++j) dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod; int ans=0; for (re int i=1;i<=n;++i) { ans=(ans+dp[SIZE+a[i]][SIZE+b[i]])%mod; ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod)%mod; } printf("%lld\n",1ll*ans*qpow(2,mod-2)%mod); return 0; }
codenet
-1
1,502
s092671508
p04051
1,468,729,420
cpp
Accepted
673
147,840
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long modpow(long long a, long long b) { if (b == 0) return 1; return modpow(a * a % mod, b / 2) * (b & 1 ? a : 1) % mod; } long long modinv(long long a) { return modpow(a, mod - 2); } vector<long long> fact, inv_fact; void init_fact(int n) { fact.resize(n); fact[0] = 1; for (int i = 1; i < n; i++) { fact[i] = i * fact[i - 1] % mod; } inv_fact.resize(n); inv_fact[n - 1] = modinv(fact[n - 1]); for (int i = n - 2; i >= 0; i--) { inv_fact[i] = (i + 1) * inv_fact[i + 1] % mod; } } long long nPr(int n, int r) { if (n < r || n < 0 || r < 0) return 0; return fact[n] * inv_fact[n - r] % mod; } long long nCr(int n, int r) { if (n < r || n < 0 || r < 0) return 0; return fact[n] * inv_fact[r] % mod * inv_fact[n - r] % mod; } long long nHr(int n, int r) { if (n == 0 && r == 0) return 1; return nCr(n + r - 1, r); } int main() { init_fact(101010); int n; cin >> n; vector<int> a(n), b(n); static long long dp[4400][4400]; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i], &b[i]); dp[2010 - a[i]][2010 - b[i]]++; } for (int i = 0; i < 4200; i++) { for (int j = 0; j < 4200; j++) { (dp[i + 1][j] += dp[i][j]) %= mod; (dp[i][j + 1] += dp[i][j]) %= mod; } } long long ans = 0; for (int i = 0; i < n; i++) { (ans += dp[2010 + a[i]][2010 + b[i]]) %= mod; (ans += mod - nCr(a[i] * 2 + b[i] * 2, a[i] * 2)) %= mod; } ans = ans * modinv(2) % mod; cout << ans << endl; }
codenet
-1
1,507
s916167839
p04051
1,578,600,208
cpp
Accepted
212
65,024
#include<bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 20, mod = 1e9 + 7, X = 4000 + 20; int x[N], y[N], dp[X][X], fact[N], factRev[N], n, ans; int sum(int a, int b) { return ((1LL * a + b) % mod + mod) % mod; } int mul(int a, int b) { return ((1LL * a * b) % mod + mod) % mod; } int pw(int a, int b) { int res = 1, tmp = a; while (b) { if (b & 1) res = mul(res, tmp); tmp = mul(tmp, tmp); b >>= 1; } return res; } int c(int a, int b) { return mul(fact[a], mul(factRev[b], factRev[a - b])); } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; fact[0] = 1; for (int i = 1; i <= 8000; i++) fact[i] = mul(fact[i - 1], i); factRev[8000] = pw(fact[8000], mod - 2); for (int i = 8000 - 1; ~i; i--) factRev[i] = mul(factRev[i + 1], i + 1); for (int i = 0; i < n; i++) dp[2000 - x[i]][2000 - y[i]]++; for (int i = 0; i <= 4000; i++) for (int j = 0; j <= 4000; j++) { if (i) dp[i][j] = sum(dp[i][j], dp[i - 1][j]); if (j) dp[i][j] = sum(dp[i][j], dp[i][j - 1]); } for (int i = 0; i < n; i++) ans = sum(ans, dp[x[i] + 2000][y[i] + 2000]); for (int i = 0; i < n; i++) ans = sum(ans, -c((x[i] + y[i]) * 2, x[i] * 2)); ans = mul(ans, pw(2, mod - 2)); return cout << ans << "\n", 0; }
codenet
-1
1,510
s796623598
p04051
1,507,653,141
cpp
Accepted
169
96,640
#include<bits/stdc++.h> using namespace std; #define MAXN 200005 #define MAXM 4005 #define DELTA 2000 #define LIMIT 4000 #define P 1000000007 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int a[MAXN], b[MAXN]; int cnt[MAXM][MAXM]; int key[MAXM][MAXM]; long long fac[MAXM * 2], inv[MAXM * 2]; long long power(long long x, long long y) { if (y == 0) return 1; long long tmp = power(x, y / 2); if (y % 2 == 0) return tmp * tmp % P; else return tmp * tmp % P * x % P; } long long getc(int x, int y) { return fac[x] * inv[y] % P * inv[x - y] % P; } int main() { int N = MAXM * 2 - 1; fac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % P; inv[N] = power(fac[N], P - 2); for (int i = N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % P; int n; read(n); for (int i = 1; i <= n; i++) { read(a[i]), read(b[i]); key[a[i] + DELTA][b[i] + DELTA]++; cnt[DELTA - a[i]][DELTA - b[i]]++; } long long ans = 0; for (int i = 0; i <= LIMIT; i++) for (int j = 0; j <= LIMIT; j++) { ans = (ans + (long long) key[i][j] * cnt[i][j]) % P; cnt[i][j + 1] = (cnt[i][j + 1] + cnt[i][j]) % P; cnt[i + 1][j] = (cnt[i + 1][j] + cnt[i][j]) % P; } for (int i = 1; i <= n; i++) ans = (ans - getc(a[i] + a[i] + b[i] + b[i], a[i] + a[i])) % P; ans = (ans + P) % P; ans = ans * power(2, P - 2) % P; cout << ans << endl; return 0; }
codenet
-1
1,510
s796623598
p04051
1,507,653,141
cpp
Accepted
169
96,640
#include<bits/stdc++.h> using namespace std; #define MAXN 200005 #define MAXM 4005 #define DELTA 2000 #define LIMIT 4000 #define P 1000000007 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int a[MAXN], b[MAXN]; int cnt[MAXM][MAXM]; int key[MAXM][MAXM]; long long fac[MAXM * 2], inv[MAXM * 2]; long long power(long long x, long long y) { if (y == 0) return 1; long long tmp = power(x, y / 2); if (y % 2 == 0) return tmp * tmp % P; else return tmp * tmp % P * x % P; } long long getc(int x, int y) { return fac[x] * inv[y] % P * inv[x - y] % P; } int main() { int N = MAXM * 2 - 1; fac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % P; inv[N] = power(fac[N], P - 2); for (int i = N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % P; int n; read(n); for (int i = 1; i <= n; i++) { read(a[i]), read(b[i]); key[a[i] + DELTA][b[i] + DELTA]++; cnt[DELTA - a[i]][DELTA - b[i]]++; } long long ans = 0; for (int i = 0; i <= LIMIT; i++) for (int j = 0; j <= LIMIT; j++) { ans = (ans + (long long) key[i][j] * cnt[i][j]) % P; cnt[i][j + 1] = (cnt[i][j + 1] + cnt[i][j]) % P; cnt[i + 1][j] = (cnt[i + 1][j] + cnt[i][j]) % P; } for (int i = 1; i <= n; i++) ans = (ans - getc(a[i] + a[i] + b[i] + b[i], a[i] + a[i])) % P; ans = (ans + P) % P; ans = ans * power(2, P - 2) % P; cout << ans << endl; return 0; }
codenet
-1
1,510
s744796889
p04051
1,590,024,141
cpp
Accepted
128
67,072
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P; template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; } template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; } const int MAXM = 4005, MAXN = 200005, MOD = 1e9 + 7; void add(int &a, int b) { a += b - MOD, a += a >> 31 & MOD; } void sub(int &a, int b) { a -= b, a += a >> 31 & MOD; } int hav[MAXM][MAXM]; int aa[MAXN], bb[MAXN], f[MAXM], n; LL fac[MAXN], inv[MAXN]; LL modpow(LL a, int b) { LL res = 1; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } void init() { int n = 2e5; for (int i = fac[0] = 1; i <= n; i++) fac[i] = fac[i - 1] * i % MOD; inv[n] = modpow(fac[n], MOD - 2); for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % MOD; } LL binom(int a, int b) { return fac[a] * inv[b] % MOD * inv[a - b] % MOD; } int main() { scanf("%d", &n); const int M = 2000; for (int i = 1; i <= n; i++) { scanf("%d%d", aa + i, bb + i); ++hav[M + aa[i]][M + bb[i]]; ++hav[M - aa[i]][M - bb[i]]; } init(); int ans = 0; for (int i = 0; i <= 4000; i++) { f[0] += hav[i][0]; for (int j = 1; j <= 4000; j++) { add(f[j], f[j - 1]); if (hav[i][j]) { if (i <= M) f[j] += hav[i][j]; else ans = (ans + (LL)f[j] * hav[i][j]) % MOD; } } } for (int i = 1; i <= n; i++) sub(ans, binom(aa[i] + bb[i] + aa[i] + bb[i], aa[i] + aa[i])); printf("%lld\n", (LL)ans * (MOD + 1) / 2 % MOD); return 0; }
codenet
-1
1,512
s025549738
p04051
1,503,208,591
cpp
Accepted
245
160,640
#include <iostream> #include <fstream> #include <vector> #include <string> #include <algorithm> #include <set> #include <map> #include <cmath> #include <cstring> #include <ctime> #include <unordered_map> #include <iomanip> using namespace std; #define fi first #define se second #define pb push_back #define all(v) (v).begin(),(v).end() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int,int> pii; ll fpow(ll x, ll p, ll mod){ ll res=1; for (;p;p>>=1){ if (p&1) res=(res*x)%mod; x=(x*x)%mod;} return res;} ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b); } const int maxc=2000,mod=1000000007; ll N,a[200100],b[200100],dp[2*maxc+10][2*maxc+10],cnt[maxc+10][maxc+10],f[4*maxc+10]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> N; int i,j; for (i=1; i<=N; i++){ cin >> a[i] >> b[i]; cnt[a[i]][b[i]]++; } for (i=maxc; i>=-maxc; i--) for (j=maxc; j>=-maxc; j--){ dp[i+maxc][j+maxc]=(dp[i+maxc+1][j+maxc]+dp[i+maxc][j+maxc+1])%mod; if (i>0 && j>0) dp[i+maxc][j+maxc]=(dp[i+maxc][j+maxc]+cnt[i][j])%mod; } f[0]=1; for (i=1; i<=4*maxc; i++) f[i]=(i*f[i-1])%mod; ll res=0; for (i=1; i<=N; i++){ res=(res+dp[-a[i]+maxc][-b[i]+maxc])%mod; ll val=f[2*(a[i]+b[i])]*fpow(f[2*a[i]],mod-2,mod)%mod*fpow(f[2*b[i]],mod-2,mod)%mod; res=(res-val+mod)%mod; } res=res*fpow(2,mod-2,mod)%mod; cout << res << "\n"; return 0; }
codenet
-1
1,516
s216288998
p04051
1,570,149,203
cpp
Accepted
145
68,992
#include <cstdio> #include <cstring> #include <cstdlib> #include <cstring> #include <algorithm> #include <numeric> #include <functional> #define LOG(FMT...) fprintf(stderr, FMT) using namespace std; typedef long long ll; const int N = 200010, P = 1000000007, A = 2010; int n; int a[N], b[N], fac[N * 4], ifac[N * 4]; int f[A * 2][A * 2]; void add(int& x, int y) { if ((x += y) >= P) x -= P; } void sub(int& x, int y) { if ((x -= y) < 0) x += P; } int main() { // freopen("test.in", "r", stdin); // freopen("test.out", "w", stdout); scanf("%d", &n); int ma = 0, mb = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", &a[i], &b[i]); ma = max(ma, a[i]); mb = max(mb, b[i]); } for (int i = 0; i < n; ++i) ++f[ma - a[i]][mb - b[i]]; for (int i = 0; i <= ma * 2; ++i) for (int j = 0; j <= mb * 2; ++j) { if (i) add(f[i][j], f[i - 1][j]); if (j) add(f[i][j], f[i][j - 1]); } int ans = 0; for (int i = 0; i < n; ++i) add(ans, f[ma + a[i]][mb + b[i]]); fac[0] = 1; int K = (ma + mb) * 2; for (int i = 1; i <= K; ++i) fac[i] = fac[i - 1] * (ll)i % P; ifac[1] = 1; for (int i = 2; i <= K; ++i) ifac[i] = -(P / i) * (ll)ifac[P % i] % P + P; ifac[0] = 1; for (int i = 1; i <= K; ++i) ifac[i] = ifac[i - 1] * (ll)ifac[i] % P; for (int i = 0; i < n; ++i) ans = (ans + (P - fac[(a[i] + b[i]) * 2]) * (ll)ifac[a[i] * 2] % P * ifac[b[i] * 2]) % P; if (ans & 1) ans += P; ans >>= 1; printf("%d\n", ans); return 0; }
codenet
-1
1,518
s167694052
p04051
1,519,863,453
cpp
Accepted
226
135,424
#include <bits/stdc++.h> #define endl '\n' using namespace std; template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; } template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; } const int MAXN = (1 << 20); const int OFFSET = (1 << 11); const int MAXM = (1 << 12); const int mod = (int)1e9 + 7; const int inv2 = (mod + 1) / 2; int n; int a[MAXN], b[MAXN]; void read() { cin >> n; for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; } int dp[MAXM][MAXM]; int C[MAXM][MAXM]; void solve() { C[0][0] = 1; for(int i = 0; i < MAXM; i++) for(int j = 0; j < MAXM; j++) { if(i) C[i][j] += C[i - 1][j]; if(C[i][j] >= mod) C[i][j] -= mod; if(j) C[i][j] += C[i][j - 1]; if(C[i][j] >= mod) C[i][j] -= mod; } int answer = 0; for(int i = 0; i < n; i++) { answer = answer + mod - C[2 * b[i]][2 * a[i]]; if(answer >= mod) answer -= mod; if(answer < 0) answer += mod; } for(int i = 0; i < n; i++) dp[OFFSET - b[i]][OFFSET - a[i]]++; for(int i = 0; i < MAXM; i++) for(int j = 0; j < MAXM; j++) { if(i) dp[i][j] += dp[i - 1][j]; if(dp[i][j] >= mod) dp[i][j] -= mod; if(j) dp[i][j] += dp[i][j - 1]; if(dp[i][j] >= mod) dp[i][j] -= mod; } for(int i = 0; i < n; i++) { answer += dp[OFFSET + b[i]][OFFSET + a[i]]; if(answer >= mod) answer -= mod; } answer = (answer * 1ll * inv2) % mod; cout << answer << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); read(); solve(); return 0; }
codenet
-1
1,520
s977715021
p04051
1,522,354,702
cpp
Accepted
109
81,152
#include <bits/stdc++.h> #define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i) #define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i) #define Set(a, v) memset(a, v, sizeof(a)) #define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout) using namespace std; bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;} bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;} inline int read() { int x = 0, fh = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1; for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0'); return x * fh; } int n; int a[200005],b[200005]; int dp[5005][5005]; int f[100005],inv[100005]; const int mod=1e9+7; long long qpow(long long x,long long y){ long long res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1; } return res; } int main () { n=read(); F(i,1,n){ a[i]=read(),b[i]=read(); dp[2000-a[i]][2000-b[i]]++; } F(i,0,4000){ F(j,0,4000){ dp[i][j]=((j==0?0:dp[i][j-1])+(i==0?0:dp[i-1][j])+dp[i][j])%mod; } } int ans=0; F(i,1,n){ ans=(ans+dp[a[i]+2000][b[i]+2000])%mod; } f[0]=1; F(i,1,30000)f[i]=f[i-1]*1ll*i%mod; inv[30000]=qpow(f[30000],mod-2); f(i,30000-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod; // F(i,1,30000)cout<<f[i]<<" "<<inv[i]<<endl; F(i,1,n){ ans=(ans-f[a[i]+a[i]+b[i]+b[i]]*1ll*inv[b[i]+b[i]]%mod*inv[a[i]+a[i]]%mod+mod)%mod; } ans=(1ll*ans*qpow(2,mod-2))%mod; printf("%d\n",ans); return 0; }
codenet
-1
1,524
s879336480
p04051
1,486,703,107
cpp
Accepted
243
86,272
#include <bits/stdc++.h> using namespace std; const int maxV = 2000; const int dim = maxV * 2 + 10; const int mod = 1e9 + 7; int n, ans; int fact[2*dim], ifact[2*dim]; int dp[dim][dim], cnt[dim][dim]; int sum(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int diff(int a, int b) { a -= b; if (a < 0) a += mod; return a; } int mul(int a, int b) { return (1LL * a * b) % mod; } int lgpow(int a, int b) { int res = 1; for (int i = 0; (1 << i) <= b; ++i) { if (b & (1 << i)) res = mul(res, a); a = mul(a, a); } return res; } int f(int x, int y) { int res = fact[x+y]; res = mul(res, ifact[x]); res = mul(res, ifact[y]); return res; } int main() { // freopen("input","r",stdin); // freopen("output","w",stdout); fact[0] = ifact[0] = 1; for (int i = 1; i <= maxV * 4; ++i) fact[i] = mul(fact[i-1], i), ifact[i] = mul(ifact[i-1], lgpow(i, mod - 2)); scanf("%d", &n); for (int i = 1; i <= n; ++i) { int a, b; scanf("%d %d", &a, &b); ans = diff(ans, f(a + a, b + b)); dp[maxV-a][maxV-b]++; cnt[maxV+a][maxV+b]++; } for (int i = 0; i <= maxV * 2; ++i) for (int j = 0; j <= maxV * 2; ++j) { if (i) dp[i][j] = sum(dp[i][j], dp[i-1][j]); if (j) dp[i][j] = sum(dp[i][j], dp[i][j-1]); if (cnt[i][j]) ans = sum(ans, mul(cnt[i][j], dp[i][j])); } printf("%d\n", mul(ans, lgpow(2, mod - 2))); return 0; }
codenet
-1
1,524
s609870016
p04051
1,573,420,729
cpp
Accepted
329
150,400
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; typedef int ll; typedef long long int li; const ll MAXN=2e5+51,MOD=1e9+7; ll cnt,offset=3000,res; ll x[MAXN],y[MAXN],fact[MAXN>>4],finv[MAXN>>4],dp[MAXN>>5][MAXN>>5]; inline ll read() { register ll num=0,neg=1; register char ch=getchar(); while(!isdigit(ch)&&ch!='-') { ch=getchar(); } if(ch=='-') { neg=-1; ch=getchar(); } while(isdigit(ch)) { num=(num<<3)+(num<<1)+(ch-'0'); ch=getchar(); } return num*neg; } inline ll qpow(ll base,ll exponent) { ll res=1; while(exponent) { if(exponent&1) { res=(li)res*base%MOD; } base=(li)base*base%MOD,exponent>>=1; } return res; } inline void setup(ll cnt) { fact[0]=fact[1]=finv[0]=1; for(register int i=2;i<=cnt;i++) { fact[i]=(li)fact[i-1]*i%MOD; } finv[cnt]=qpow(fact[cnt],MOD-2); for(register int i=cnt-1;i;i--) { finv[i]=(li)finv[i+1]*(i+1)%MOD; } } inline ll calc(ll p) { return (li)fact[(x[p]+y[p])<<1]*finv[x[p]<<1]%MOD*finv[y[p]<<1]%MOD; } int main() { setup(8000),cnt=read(); for(register int i=0;i<cnt;i++) { dp[offset-(x[i]=read())][offset-(y[i]=read())]++; } for(register int i=1;i<=(offset<<1);i++) { for(register int j=1;j<=(offset<<1);j++) { dp[i][j]=(dp[i][j]+(dp[i-1][j]+dp[i][j-1])%MOD)%MOD; } } for(register int i=0;i<cnt;i++) { res=(res+dp[offset+x[i]][offset+y[i]])%MOD; res=(res-calc(i)+MOD)%MOD; } printf("%d\n",res&1?(res+MOD)>>1:res>>1); }
codenet
-1
1,525
s273377816
p04051
1,468,777,549
cpp
Accepted
1,455
189,824
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; int INF = INT_MAX / 2; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int N; cin >> N; vector<int> a(N), b(N); vector<vector<int> > dp(4002, vector<int>(4002)); for (int i = 0; i < N; i++) { scanf("%d%d", &a[i], &b[i]); dp[2000 - a[i]][2000 - b[i]]++; } for (int y = 0; y <= 4000; y++) for (int x = 0; x <= 4000; x++) { dp[y + 1][x] = (dp[y + 1][x] + dp[y][x]) % MOD; dp[y][x + 1] = (dp[y][x + 1] + dp[y][x]) % MOD; } int ans = 0; for (int i = 0; i < N; i++) ans = (ans + dp[2000 + a[i]][2000 + b[i]]) % MOD; vector<vector<int> > C(8001, vector<int>(4001)); for (int i = 0; i <= 8000; i++) { C[i][0] = 1; for (int j = 1; j <= min(i, 4000); j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; } for (int i = 0; i < N; i++) { int x = C[(a[i] + b[i]) * 2][a[i] * 2]; ans = (ans - x) % MOD; } ans = (ll)ans * (MOD/2+1) % MOD; cout << (ans + MOD) % MOD << endl; }
codenet
-1
1,528
s273377816
p04051
1,468,777,549
cpp
Accepted
1,455
189,824
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; int INF = INT_MAX / 2; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int N; cin >> N; vector<int> a(N), b(N); vector<vector<int> > dp(4002, vector<int>(4002)); for (int i = 0; i < N; i++) { scanf("%d%d", &a[i], &b[i]); dp[2000 - a[i]][2000 - b[i]]++; } for (int y = 0; y <= 4000; y++) for (int x = 0; x <= 4000; x++) { dp[y + 1][x] = (dp[y + 1][x] + dp[y][x]) % MOD; dp[y][x + 1] = (dp[y][x + 1] + dp[y][x]) % MOD; } int ans = 0; for (int i = 0; i < N; i++) ans = (ans + dp[2000 + a[i]][2000 + b[i]]) % MOD; vector<vector<int> > C(8001, vector<int>(4001)); for (int i = 0; i <= 8000; i++) { C[i][0] = 1; for (int j = 1; j <= min(i, 4000); j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; } for (int i = 0; i < N; i++) { int x = C[(a[i] + b[i]) * 2][a[i] * 2]; ans = (ans - x) % MOD; } ans = (ll)ans * (MOD/2+1) % MOD; cout << (ans + MOD) % MOD << endl; }
codenet
-1
1,528
s949692535
p04051
1,576,062,196
cpp
Accepted
114
64,512
//#include<bits/stdc++.h> #include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <set> #include <queue> #include <deque> #include <map> #include <stack> #include<bitset> #include<list> #include<cassert> #include<numeric> using namespace std; const int N = 200005; const int mod = 1000000007; int n,F[4005][4005],fac[8005],inv[8005],A[N],B[N],ans; int read() { int ret = 0; int f = 1; char ch = getchar(); while(ch < '0'||ch > '9') { if (ch == '-') { f =- f; ch = getchar(); } } while (ch >= '0'&&ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return ret * f; } inline int QP(int a,int b) { int ret = 1; int w = a; while(b) { if(b & 1) ret = (long long)ret * w % mod; w = (long long)w * w % mod; b >>= 1; } return ret; } int C(int n,int m) { return (long long)fac[n] * inv[m] % mod * inv[n - m] % mod; } int main() { n = read(); fac[0]=1; for(int i=1; i<=8000;i++) { fac[i] = (long long)fac[i - 1] * i % mod; inv[i] = QP(fac[i], mod - 2); } for(int i = 1; i <= n; i++) { A[i] = read(); B[i] = read(); F[2000 - A[i]][2000 - B[i]]++; } for (int i = 0;i <= 4000; i++) { for (int j = 0;j <= 4000; j++) { F[i][j] = ((long long)F[i][j] + (j ? F[i][j - 1] : 0) + (i ? F[i - 1][j] : 0)) % mod; } } for (int i = 1; i <= n;i++) { ans = (ans + F[2000 + A[i]][2000 + B[i]]) % mod; ans = (ans - C(A[i] + B[i] + A[i] + B[i], A[i] + A[i]) + mod)%mod; } ans = (long long)ans * QP(2,mod - 2) % mod; cout << ans << endl; }
codenet
-1
1,529
s552985544
p04051
1,586,214,925
cpp
Accepted
268
180,736
#include<iostream> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; Int fact[1100000]; Int revfact[1100000]; Int rev[1100000]; void init(){ Int m = MOD; fact[0] = 1; revfact[0] = 1; rev[0] = 0; rev[1] = 1; for(int i = 1;i < 1100000;i++){ fact[i] = fact[i-1] * i % m; if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD; revfact[i] = revfact[i-1] * rev[i] % MOD; } } Int nCk(Int n, Int k){ if(n < k)return 0; return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD; } Int n, a[220000], b[220000]; Int dp_[4400][4400]; Int &dp(int x, int y){ return dp_[x+2200][y+2200]; } int main(){ init(); cin >> n; for(int i = 0;i < n;i++){ cin >> a[i] >> b[i]; dp(-a[i], -b[i])++; } for(int i = 0;i < 4400;i++){ for(int j = 0;j < 4400;j++){ if(i)dp_[i][j] += dp_[i-1][j]; if(j)dp_[i][j] += dp_[i][j-1]; dp_[i][j] %= MOD; } } Int ans = 0; for(int i = 0;i < n;i++){ ans += dp(a[i], b[i]); ans -= nCk(2*(a[i] + b[i]), 2*a[i]); ans %= MOD; } if(ans < 0)ans += MOD; if(ans % 2 == 1)ans += MOD; ans /= 2; cout << ans << endl; return 0; }
codenet
-1
1,532
s552985544
p04051
1,586,214,925
cpp
Accepted
268
180,736
#include<iostream> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; Int fact[1100000]; Int revfact[1100000]; Int rev[1100000]; void init(){ Int m = MOD; fact[0] = 1; revfact[0] = 1; rev[0] = 0; rev[1] = 1; for(int i = 1;i < 1100000;i++){ fact[i] = fact[i-1] * i % m; if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD; revfact[i] = revfact[i-1] * rev[i] % MOD; } } Int nCk(Int n, Int k){ if(n < k)return 0; return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD; } Int n, a[220000], b[220000]; Int dp_[4400][4400]; Int &dp(int x, int y){ return dp_[x+2200][y+2200]; } int main(){ init(); cin >> n; for(int i = 0;i < n;i++){ cin >> a[i] >> b[i]; dp(-a[i], -b[i])++; } for(int i = 0;i < 4400;i++){ for(int j = 0;j < 4400;j++){ if(i)dp_[i][j] += dp_[i-1][j]; if(j)dp_[i][j] += dp_[i][j-1]; dp_[i][j] %= MOD; } } Int ans = 0; for(int i = 0;i < n;i++){ ans += dp(a[i], b[i]); ans -= nCk(2*(a[i] + b[i]), 2*a[i]); ans %= MOD; } if(ans < 0)ans += MOD; if(ans % 2 == 1)ans += MOD; ans /= 2; cout << ans << endl; return 0; }
codenet
-1
1,532