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
|
---|---|---|---|---|---|---|---|---|---|---|
s453264350 | p04051 | 1,562,702,174 | cpp | Accepted | 163 | 130,432 | #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int p=1000000007;
const int N=2000;
long long f[N*2+10][N*2+10],x,y,ans,step[200005],finv[8005];
long long n,a[200005],b[200005],amax=2002,bmax=2002,d[8005];
void cou(int num)
{
step[num]=d[a[num]+b[num]];
step[num]=(step[num]*finv[a[num]])%p;
step[num]=(step[num]*finv[b[num]])%p;
}
long long cheng(long long a,long long b)
{
long long now=a,ans=1;
while(b)
{
if(b&1)
ans=(now*ans)%p;
b>>=1;
now=(now*now)%p;
}
return ans;
}
void chuli()
{
d[1]=1;
for(int i=2;i<=8000;i++)
d[i]=(d[i-1]*i)%p;
finv[8000]=cheng(d[8000],p-2);
for(int i=7999;i>=1;i--)
finv[i]=(finv[i+1]*(i+1))%p;
}
int main()
{
scanf("%lld",&n);
chuli();
for(int i=1;i<=n;i++)
{
scanf("%lld %lld",&a[i],&b[i]);
a[i]*=2;b[i]*=2;
cou(i);
a[i]/=2;b[i]/=2;
}
for(int i=1;i<=n;i++)
{
f[amax-a[i]][bmax-b[i]]++;
a[i]=amax+a[i];
b[i]=bmax+b[i];
}
x=2*amax;y=2*bmax;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
f[i][j]+=f[i-1][j]+f[i][j-1];
f[i][j]%=p;
}
}
for(int i=1;i<=n;i++)
{
ans+=f[a[i]][b[i]]-step[i];
ans%=p;
}
ans=(ans+p)%p;
x=cheng(2,p-2);
// printf("x=%d\n",x);
ans=(ans*x)%p;
printf("%lld\n",ans);
return 0;
} | codenet | -1 | 1,242 |
s972633044 | p04051 | 1,546,189,929 | cpp | Accepted | 149 | 129,152 | #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define P pair<int,int>
const LL inf = 0x3f3f3f3f;
const LL mod = 1e9+7;
const LL N = 4e3+10;
template <typename tp> inline void read(tp &x)
{
x=0;char c=getchar();int f=0;
for(;c>'9'||c<'0';f|=(c=='-'),c=getchar());
for(;c<='9'&&c>='0';x=(x<<3)+(x<<1)+c-'0',c=getchar());
if(f) x=-x;
}
LL n,a[200010],b[200010],ans;
LL fac[N*2],fav[N*2],inv[N*2];
void init()
{
fac[0]=fav[0]=1;
inv[1] = fac[1] = fav[1] = 1;
for (int i = 2; i < N * 2; ++i)
{
inv[i] = -mod / i * inv[mod % i] % mod + mod;
fac[i] = fac[i - 1] * i % mod;
fav[i] = fav[i - 1] * inv[i] % mod;
}
}
inline LL C(int x, int y)
{
if (x < 0 || x < y) return 0;
return fac[x] * fav[y] % mod * fav[x - y] % mod;
}
LL cost[N][N];
signed main()
{
read(n);init();
for(int i=1;i<=n;i++) read(a[i]),read(b[i]);
for(int i=1;i<=n;i++) cost[-a[i]+2001][-b[i]+2001]++;
for(int i=1;i<=4001;i++)
for(int j=1;j<=4001;j++)
(cost[i][j]+=(cost[i-1][j]+cost[i][j-1]))%=mod;
//cout<<ans<<endl;
for(int i=1;i<=n;i++)
ans=(ans+cost[a[i]+2001][b[i]+2001])%mod;
//cout<<ans<<endl;
for(int i=1;i<=n;i++)
ans=(ans-C(a[i]*2+b[i]*2,a[i]*2)+mod)%mod;
printf("%lld\n",(ans*(mod+1)/2%mod+mod)%mod);
return 0;
} | codenet | -1 | 1,242 |
s729023063 | p04051 | 1,578,804,395 | cpp | Accepted | 95 | 65,024 | #include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double
using namespace std;
const int N=2000+10,M=2e5+10,mod=1e9+7;
int rd()
{
int x=0,w=1;char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,LL b,int mod){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}
int ginv(int a,int mod){return fpow(a,mod-2,mod);}
int n,ans,z[M][2],f[N<<1][N<<1],fac[N<<2],iac[N<<2];
int C(int a,int b){return 1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}
int main()
{
fac[0]=1;
for(int i=1;i<=8000;++i) fac[i]=1ll*fac[i-1]*i%mod;
iac[8000]=ginv(fac[8000],mod);
for(int i=8000;i;--i) iac[i-1]=1ll*iac[i]*i%mod;
n=rd();
for(int i=1;i<=n;++i)
{
z[i][0]=rd(),z[i][1]=rd();
ad(ans,mod-C(z[i][0]+z[i][0]+z[i][1]+z[i][1],z[i][0]+z[i][0]));
ad(f[2000-z[i][0]][2000-z[i][1]],1);
}
for(int i=0;i<=4000;++i)
for(int j=0;j<=4000;++j)
{
if(i) ad(f[i][j],f[i-1][j]);
if(j) ad(f[i][j],f[i][j-1]);
}
for(int i=1;i<=n;++i)
ad(ans,f[2000+z[i][0]][2000+z[i][1]]);
ans=1ll*ans*ginv(2,mod)%mod;
printf("%d\n",ans);
return 0;
}
| codenet | -1 | 1,243 |
s798619519 | p04051 | 1,552,577,590 | cpp | Accepted | 216 | 225,024 | #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int N=2010;
const int V=4020;
const int mo=1e9+7;
int c[V*2+10][V+10];
int Sum(int x,int y) {
x+=y;
return (x>=mo)?x-mo:x;
}
int Sub(int x,int y) {
x-=y;
return (x<0)?x+mo:x;
}
int Mul(int x,int y) {
return (long long)x*y%mo;
}
int n;
int vis[V+10][V+10],f[V+10][V+10];
void Calcvalue(int x,int y) {
int nx=x+N,ny=y+N;
f[nx][ny]=Sum((nx==0?0:f[nx-1][ny]),((ny==0)?0:f[nx][ny-1]));
if (x<=0&&y<=0) f[nx][ny]=Sum(f[nx][ny],vis[-x][-y]);
}
void Prework() {
c[0][0]=1;
for (int i=1;i<=V*2;i++) {
c[i][0]=1;
for (int j=1;j<=min(i,V);j++)
c[i][j]=Sum(c[i-1][j],c[i-1][j-1]);
}
}
int main() {
Prework();
int ans=0;
scanf("%d",&n);
for (int i=1;i<=n;i++) {
int x,y;
scanf("%d%d",&x,&y);
vis[x][y]++;
ans=Sub(ans,c[(x+y)*2][x*2]);
}
for (int i=-N;i<=N;i++)
for (int j=-N;j<=N;j++)
Calcvalue(i,j);
for (int i=0;i<=N;i++)
for (int j=0;j<=N;j++)
ans=Sum(ans,Mul(vis[i][j],f[i+N][j+N]));
printf("%d\n",Mul(ans,(mo+1)/2));
return 0;
}
| codenet | -1 | 1,246 |
s515292186 | p04051 | 1,548,046,543 | cpp | Accepted | 170 | 128,128 | #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10, M = 2010;
const LL mod = 1e9 + 7;
LL power(LL a, LL b)
{
LL c = 1;
for (; b; a = a * a % mod, b >>= 1)
if (b & 1) c = c * a % mod;
return c;
}
LL fac[M << 2], inv[M << 2];
void init(int n)
{
fac[0] = 1;
for (int i = 1; i <= n; ++ i)
fac[i] = fac[i - 1] * i % mod;
inv[n] = power(fac[n], mod - 2);
for (int i = n - 1; i >= 0; -- i)
inv[i] = inv[i + 1] * (i + 1) % mod;
}
LL C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
int n;
int a[N], b[N], maxa, maxb;
LL f[M << 1][M << 1];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++ i)
{
scanf("%d %d", &a[i], &b[i]);
maxa = max(maxa, a[i]);
maxb = max(maxb, b[i]);
}
++ maxa, ++ maxb;
init(maxa + maxb << 1);
for (int i = 1; i <= n; ++ i)
++ f[maxa - a[i]][maxb - b[i]];
for (int i = 1; i <= maxa << 1; ++ i)
for (int j = 1; j <= maxb << 1; ++ j)
(f[i][j] += f[i - 1][j] + f[i][j - 1]) %= mod;
LL ans = 0;
for (int i = 1; i <= n; ++ i)
(ans += f[maxa + a[i]][maxb + b[i]]) %= mod;
for (int i = 1; i <= n; ++ i)
(ans += mod - C(a[i] + b[i] << 1, a[i] << 1)) %= mod;
printf("%lld\n", ans * power(2, mod - 2) % mod);
} | codenet | -1 | 1,246 |
s343749135 | p04051 | 1,507,903,301 | cpp | Accepted | 243 | 125,568 | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int o = 2000, N = (o << 1) + 5, mo = 1000000007 ;
using namespace std ;
int n, a[N][N], b[N][N], fac[N << 2], inv[N << 2] ;
int mul(int a, int b) {
int ans = 1, w = a % mo ;
for ( ; b; b /= 2) {
if (b & 1) ans = (ll) ans * w % mo ;
w = (ll) w * w % mo ;
}
return ans ;
}
int main() {
scanf("%d", &n) ;
int ans = 0, x, y ;
fac[0] = inv[0] = 1 ;
rep(i, 1, o * 4) {
fac[i] = (ll) fac[i - 1] * i % mo ;
}
inv[o * 4] = mul(fac[o * 4], mo - 2) ;
for (int i = o * 4 - 1 ; i; -- i) {
inv[i] = (ll) inv[i + 1] * (i + 1) % mo ;
}
memset(a, 0, sizeof(a)) ;
memset(b, 0, sizeof(b)) ;
rep(i, 1, n) {
scanf("%d%d", &x, &y) ;
++ a[o - x][o - y] ;
++ b[o + x][o + y] ;
ans = (ans - (ll) fac[x + y + x + y] * inv[x << 1] % mo * inv[x + y + x + y - (x << 1)] % mo) % mo ;
}
rep(i, 0, 2 * o) rep(j, 0, 2 * o) {
if (i) a[i][j] = (a[i][j] + a[i - 1][j]) % mo ;
if (j) a[i][j] = (a[i][j] + a[i][j - 1]) % mo ;
ans = (ans + (ll) a[i][j] * b[i][j] % mo) % mo ;
}
ans = (ll) ans * inv[2] % mo ;
printf("%d\n", (ans + mo) % mo) ;
return 0 ;
} | codenet | -1 | 1,247 |
s107401436 | p04051 | 1,493,265,103 | cpp | Accepted | 132 | 64,384 | #include <cstdio>
#define MOD 1000000007
#define MAXN 200000
#define D 2001
const int q=D+D+1;
int d[q][q];
int fact[2*q], invFact[2*q];
int a[MAXN+1], b[MAXN+1];
inline int lgput(int a, int n){
int r=1;
while(n){
if(n%2) r=1LL*a*r%MOD;
n/=2;
a=1LL*a*a%MOD;
}
return r;
}
inline int comb(int n, int k){
return 1LL*fact[n]*invFact[n-k]%MOD*invFact[k]%MOD;
}
int main(){
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%d%d", &a[i], &b[i]);
for(int i=1; i<=n; i++)
d[D-a[i]][D-b[i]]++;
for(int i=1; i<q; i++){
for(int j=1; j<q; j++){
d[i][j]+=d[i-1][j]+d[i][j-1];
if(d[i][j]>=MOD) d[i][j]-=MOD;
}
}
int ans=0;
for(int i=1; i<=n; i++){
ans+=d[D+a[i]][D+b[i]];
if(ans>=MOD) ans-=MOD;
}
fact[0]=1;
for(int i=1; i<2*q; i++)
fact[i]=1LL*fact[i-1]*i%MOD;
invFact[2*q-1]=lgput(fact[2*q-1], MOD-2);
for(int i=2*q-2; i>=0; i--)
invFact[i]=1LL*invFact[i+1]*(i+1)%MOD;
for(int i=1; i<=n; i++){
ans-=comb(2*a[i]+2*b[i], 2*a[i]);
if(ans<0) ans+=MOD;
}
ans=1LL*ans*lgput(2, MOD-2)%MOD;
printf("%d\n", ans);
return 0;
}
| codenet | -1 | 1,247 |
s367995368 | p04051 | 1,522,770,711 | cpp | Accepted | 202 | 190,080 | #include <iostream>
#include <cstdio>
#include <cstdlib>
#define MOD 1000000007
#define ll long long
using namespace std;
int n;
ll dp[4010][4010], num[4010][4010];
ll fac[8010], invfac[8010];
ll exp(ll a, ll b)
{
if (!b) return 1;
ll k = exp(a, b / 2);
if (b & 1)
return k * k % MOD * a % MOD;
return k * k % MOD;
}
void init()
{
fac[0] = invfac[0] = 1;
for (int i = 1; i <= 8000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
invfac[i] = exp(fac[i], MOD - 2);
// cout << fac[i] * invfac[i] % MOD << ' ';
}
}
ll C(int n, int m)
{
return fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}
int main()
{
ios::sync_with_stdio(false);
init();
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++)
{
int a, b;
cin >> a >> b;
dp[2000 - a][2000 - b]++;
num[2000 + a][2000 + b]++;
ans = (ans - C(2 * a + 2 * b, 2 * a) + MOD) % MOD;
}
for (int i = 0; i <= 4000; i++)
for (int j = 0; j <= 4000; j++)
{
if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
}
for (int i = 2000; i <= 4000; i++)
for (int j = 2000; j <= 4000; j++)
ans = (ans + dp[i][j] * num[i][j] % MOD) % MOD;
ll inv2 = exp(2, MOD - 2);
ans = (ans * inv2) % MOD;
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,250 |
s367995368 | p04051 | 1,522,770,711 | cpp | Accepted | 202 | 190,080 | #include <iostream>
#include <cstdio>
#include <cstdlib>
#define MOD 1000000007
#define ll long long
using namespace std;
int n;
ll dp[4010][4010], num[4010][4010];
ll fac[8010], invfac[8010];
ll exp(ll a, ll b)
{
if (!b) return 1;
ll k = exp(a, b / 2);
if (b & 1)
return k * k % MOD * a % MOD;
return k * k % MOD;
}
void init()
{
fac[0] = invfac[0] = 1;
for (int i = 1; i <= 8000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
invfac[i] = exp(fac[i], MOD - 2);
// cout << fac[i] * invfac[i] % MOD << ' ';
}
}
ll C(int n, int m)
{
return fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}
int main()
{
ios::sync_with_stdio(false);
init();
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++)
{
int a, b;
cin >> a >> b;
dp[2000 - a][2000 - b]++;
num[2000 + a][2000 + b]++;
ans = (ans - C(2 * a + 2 * b, 2 * a) + MOD) % MOD;
}
for (int i = 0; i <= 4000; i++)
for (int j = 0; j <= 4000; j++)
{
if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
}
for (int i = 2000; i <= 4000; i++)
for (int j = 2000; j <= 4000; j++)
ans = (ans + dp[i][j] * num[i][j] % MOD) % MOD;
ll inv2 = exp(2, MOD - 2);
ans = (ans * inv2) % MOD;
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,250 |
s604145728 | p04051 | 1,551,753,023 | cpp | Accepted | 147 | 66,172 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = 2e3 + 10, mod = 1e9 + 7;
namespace {
inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
}
int n, f[M << 1 | 1][M << 1 | 1], a[N], b[N], fac[N], ifac[N], inv[N];
int binom(int x, int y) {
if(x < y) {
return 0;
}
return mul(fac[x], mul(ifac[y], ifac[x - y]));
}
int main(void) {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
f[M - a[i]][M - b[i]]++;
}
for(int i = 1; i < M << 1; i++) {
for(int j = 1; j < M << 1; j++) {
f[i][j] = add(f[i][j], add(f[i - 1][j], f[i][j - 1]));
}
}
fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
for(int i = 2; i < M << 4; i++) {
fac[i] = mul(fac[i - 1], i);
inv[i] = mul(mod - mod / i, inv[mod % i]);
ifac[i] = mul(ifac[i - 1], inv[i]);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans = sub(ans, binom(2 * (a[i] + b[i]), 2 * a[i]));
}
for(int i = 1; i <= n; i++) {
ans = add(ans, f[M + a[i]][M + b[i]]);
}
ans = mul(ans, mod + 1 >> 1);
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,252 |
s573743628 | p04051 | 1,490,457,779 | cpp | Accepted | 136 | 94,976 | #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
int sum=0;char c=getchar( );bool f=0;
while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
if(f) return -sum;
return sum;
}
const int N=10005;
const int mod=1000000007;
int n;LL jc[N],ny[N];
inline LL quick(LL a,int b)
{
LL r=1,base=a;
while(b)
{
if(b&1) r=r*base%mod;
base=base*base%mod;
b>>=1;
}
return r;
}
int f[4005][4005],g[4005][4005],ans;
inline void up(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
int main( )
{
int i,j,x,y,x2,y2;
n=read( );
jc[0]=1;
for(i=1;i<N;i++) jc[i]=jc[i-1]*i%mod;
ny[0]=1;ny[N-1]=quick(jc[N-1],mod-2);
for(i=N-1;i>=2;i--) ny[i-1]=ny[i]*i%mod;
for(i=1;i<=n;i++)
{
x=read( );y=read( );
f[-x+2000][-y+2000]++;g[x+2000][y+2000]++;
x2=x<<1,y2=y<<1;
up(ans,mod-jc[x2+y2]*ny[x2]%mod*ny[y2]%mod);
}
for(i=0;i<=4000;i++)
for(j=0;j<=4000;j++)
{
if(g[i][j]) up(ans,(LL)f[i][j]*g[i][j]%mod);
up(f[i+1][j],f[i][j]);
up(f[i][j+1],f[i][j]);
}
printf("%lld",(LL)ans*quick(2,mod-2)%mod);
return 0;
}
| codenet | -1 | 1,252 |
s881402085 | p04051 | 1,507,254,922 | cpp | Accepted | 161 | 64,512 | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
using namespace std;
const int N = 4010, M = 200010;
const int Mod = 1e9 + 7;
int Pow(int x, int e){
int ret = 1;
while(e){
if(e & 1) ret = 1ll * ret * x % Mod;
x = 1ll * x * x % Mod;
e >>= 1;
}
return ret;
}
int dp[N][N], fac[N << 1], rfac[N << 1];
int Px[M], Py[M], n;
void init(){
fac[0] = 1;
int m = 8005;
For(i, 1, m) fac[i] = 1ll * fac[i - 1] * i % Mod;
rfac[m] = Pow(fac[m], Mod - 2);
Forr(i, m - 1, 0) rfac[i] = 1ll * rfac[i + 1] * (i + 1) % Mod;
}
inline int C(int a, int b){
return 1ll * fac[a] * rfac[b] % Mod * rfac[a - b] % Mod;
}
int main(){
scanf("%d", &n);
init();
int ans = 0;
For(i, 1, n){
scanf("%d%d", &Px[i], &Py[i]);
ans = (ans - C((Px[i] + Py[i]) << 1, Px[i] << 1) + Mod) % Mod;
dp[2000 - Px[i]][2000 - Py[i]]++;
Px[i] += 2000, Py[i] += 2000;
}
For(i, 0, 4000) For(j, 0, 4000){
if(i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % Mod;
if(j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % Mod;
}
For(i, 1, n) ans = (ans + dp[Px[i]][Py[i]]) % Mod;
printf("%lld\n", 1ll * ans * rfac[2] % Mod);
return 0;
} | codenet | -1 | 1,253 |
s143971906 | p04051 | 1,554,926,060 | cpp | Accepted | 194 | 65,792 | #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=200005;
const int MOD=1e9+7;
const int Inv=500000004;
int add (int x,int y) {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y) {return (LL)x*y%MOD;}
int dec (int x,int y) {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
if (y==0) return 1;
if (y==1) return x;
int lalal=Pow(x,y>>1);
lalal=mul(lalal,lalal);
if (y&1) lalal=mul(lalal,x);
return lalal;
}
int JC[N],inv[N];
void Init (int n)
{
JC[0]=1;for (int u=1;u<=n;u++) JC[u]=mul(JC[u-1],u);
inv[n]=Pow(JC[n],MOD-2);
for (int u=n-1;u>=0;u--) inv[u]=mul(inv[u+1],u+1);
}
int C (int x,int y) {return mul(JC[x],mul(inv[y],inv[x-y]));}
int a[N],b[N];
int f[4005][4005];
int main()
{
Init(8000);
int n;
scanf("%d",&n);
for (int u=1;u<=n;u++)
{
scanf("%d%d",&a[u],&b[u]);
f[2001-a[u]][2001-b[u]]++;
}
for (int u=1;u<=4002;u++)
for (int i=1;i<=4002;i++)
f[u][i]=add(f[u][i],add(f[u-1][i],f[u][i-1]))%MOD;
int ans=0;
for (int u=1;u<=n;u++)
{
ans=add(ans,f[a[u]+2001][2001+b[u]]);
//printf("YES:%d\n",f[a[u]+2001][b[u]+2001]);
ans=dec(ans,C(a[u]*2+b[u]*2,a[u]*2));
}
ans=mul(ans,Inv);
printf("%d\n",ans);
return 0;
}
| codenet | -1 | 1,254 |
s085158038 | p04051 | 1,508,289,569 | cpp | Accepted | 244 | 100,480 | #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 5005;
const int mod = 1e9 + 7;
const int Base = N >> 1;
int f[N][N] , n , m , a[(int)2e5 + 5] , b[(int)2e5 + 5] , P[(int)2e5 + 5] , inv[(int)2e5 + 5];
int getinv(int x , int y) {
if(y == 1) return x % mod;
if(y == 0) return 1;
int it = getinv(x , y >> 1);
it = it * 1ll * it % mod;
if(y & 1) {
it = it * 1ll * x % mod;
}
return it;
}
int main(void) {
scanf("%d" , &n);
P[0] = 1;
for(int i = 1;i <= 100000;i ++) P[i] = P[i - 1] * 1ll * i % mod;
for(int i = 1;i <= 100000;i ++) inv[i] = getinv(P[i] , mod - 2) % mod;
for(int i = 1;i <= n;i ++) {
scanf("%d%d" , &a[i] , &b[i]);
f[Base - a[i]][Base - b[i]] ++;
}
for(int i = 0;i <= N - 4;i ++) {
for(int j = 0;j <= N - 4;j ++) {
f[i + 1][j] = (f[i + 1][j] + f[i][j]) % mod;
f[i][j + 1] = (f[i][j + 1] + f[i][j]) % mod;
}
}
int ans = 0;
for(int i = 1;i <= n;i ++) {
ans = ans - P[2 * a[i] + 2 * b[i]] * 1ll * inv[2 * a[i]] % mod * 1ll *inv[2 * b[i]] % mod;
ans %= mod;
}
if(ans < 0) ans += mod;
for(int i = 1;i <= n;i ++) {
ans += f[Base + a[i]][Base + b[i]];
ans %= mod;
}
cout << ans * 1ll * getinv(2 , mod - 2) % mod<< endl;
} | codenet | -1 | 1,254 |
s006447801 | p04051 | 1,601,073,636 | cpp | Accepted | 266 | 149,108 | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=1e9+7;
int fac[maxm],inv[maxm];
int a[maxm],b[maxm];
int d[4444][4444];
int n;
int ppow(int a,int b,int mod){
int ans=1%mod;a%=mod;
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<maxm;i++)fac[i]=fac[i-1]*i%mod;
inv[maxm-1]=ppow(fac[maxm-1],mod-2,mod);
for(int i=maxm-2;i>=0;i--)inv[i]=(i+1)*inv[i+1]%mod;
}
int C(int n,int m){
if(m<0||m>n)return 0;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
init();
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
const int base=2000;
for(int i=1;i<=n;i++){
d[-a[i]+base][-b[i]+base]++;
}
for(int i=0;i<=4010;i++){
for(int j=0;j<=4010;j++){
if(i-1>=0)d[i][j]+=d[i-1][j];
if(j-1>=0)d[i][j]+=d[i][j-1];
d[i][j]%=mod;
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans+=d[a[i]+base][b[i]+base];
ans%=mod;
}
for(int i=1;i<=n;i++){
ans-=C(2*(a[i]+b[i]),2*a[i]);
ans%=mod;
}
ans=(ans*ppow(2,mod-2,mod)%mod+mod)%mod;
cout<<ans<<endl;
return 0;
}
| codenet | -1 | 1,255 |
s693146286 | p04051 | 1,561,536,887 | cpp | Accepted | 246 | 249,088 | #include<cstdio>
#include<queue>
#define O 2002
#define MOD 1000000007
#define R 2000
int n;
int grid[4005][4005];
int dy[4005][4005];
int comb[8005][4005];
int my_pow(long long val, int exp) {
long long ex = val;
val = 1;
while (exp > 0) {
if (exp % 2 == 1) {
val *= ex;
val %= MOD;
}
ex = ex * ex%MOD;
exp /= 2;
}
return val;
}
int main() {
scanf("%d", &n);
int i,j;
comb[0][0] = 1;
for (i = 1; i <= 8000; i++) {
comb[i][0] = 1;
for (j = 1; j <= i && j<=4000; j++) {
comb[i][j] = comb[i-1][j - 1] + comb[i-1][j];
comb[i][j] %= MOD;
}
}
int ans = 0;
for (i = 1; i <= n; i++) {
int a, b;
scanf("%d%d", &a, &b);
grid[O + a][O + b]++;
grid[O - a][O - b]++;
if (a > b) {
int temp = a; a = b; b = temp;
}
ans -= comb[a * 2 + b * 2][a * 2];
if (ans < 0) ans += MOD;
}
for (i = O - R; i <= O + R; i++) {
for (j = O - R; j <= O + R; j++) {
if (i < O && j < O) {
dy[i][j] += grid[i][j];
}
dy[i][j] += dy[i - 1][j];
dy[i][j] %= MOD;
dy[i][j] += dy[i][j - 1];
dy[i][j] %= MOD;
if (i > O && j > O) {
ans += (long long)dy[i][j] * grid[i][j] % MOD;
ans %= MOD;
}
}
}
int divied = my_pow(2, MOD - 2);
ans = (long long)ans*divied % MOD;
printf("%d", ans);
return 0;
} | codenet | -1 | 1,256 |
s846674618 | p04051 | 1,582,519,518 | cpp | Accepted | 165 | 127,488 | #include<bits/stdc++.h>
#define Rg register
#define i60 long long
#define fp( i , x , y ) for(Rg int i=(x); i<=(y); ++i)
#define fq( i , x , y ) for(Rg int i=(y); i>=(x); --i)
#define Show fp( i , 1 , n ) cout << inv[i] << " " ;
const int hgs = 1e9+7 , P = 2005 , N = 200005 ;
using namespace std ;
i60 f[P<<1][P<<1] , inv[P<<2] , fac[P<<2] , Ans1 , Ans2 , Ans ;
int a[N] , b[N] , n ;
i60 power( i60 A , int B ) {
i60 tep = 1 ;
for( ; B ; B >>= 1 ) {
if( B&1 ) tep = tep * A % hgs ;
A = A * A % hgs ;
} return tep ; }
i60 C( int A , int B ) { return fac[B] * inv[A] % hgs * inv[B-A] % hgs ; }
signed main( ) {
ios::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
cin >> n ; fac[0] = 1 ;
fp( i , 1 , n ) cin >> a[i] >> b[i] , f[P-a[i]][P-b[i]] ++ ;
fp( i , 1 , 2*P-5 ) fp( j , 1 , 2*P-5 )
f[i][j] = ( f[i][j] + f[i-1][j] + f[i][j-1] ) % hgs ;
fp( i , 1 , n ) Ans1 = ( Ans1 + f[P+a[i]][P+b[i]] ) % hgs ;
fp( i , 1 , 4*P-10 ) fac[i] = fac[i-1] * i % hgs ;
fp( i , 1 , 4*P-10 ) inv[i] = power( fac[i] , hgs-2 ) ;
fp( i , 1 , n ) Ans2 = ( Ans2 + C( a[i]+a[i] , 2*(a[i]+b[i]) ) ) % hgs ;
Ans = ( Ans1 - Ans2 + hgs ) % hgs ;
cout << Ans * inv[2] % hgs << endl ;
return 0 ;
} | codenet | -1 | 1,257 |
s630108111 | p04051 | 1,548,809,517 | cpp | Accepted | 410 | 131,200 | #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
#define Mod 1000000007
ll modinv(ll a) {
ll m=Mod;
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main(){
ll n;
ll i,j;
cin>>n;
ll a[n];
ll b[n];
for(i=0;i<n;i++) cin>>a[i]>>b[i];
vector<vector<ll> > dp(4040,vector<ll>(4040,0));
ll h=2020;
for(i=0;i<n;i++){
dp[h-a[i]][h-b[i]]++;
}
for(i=1;i<4040;i++){
for(j=1;j<4040;j++){
dp[i][j]+=dp[i-1][j]+dp[i][j-1];
dp[i][j]%=Mod;
}
}
ll ans=0;
for(i=0;i<n;i++){
ans+=dp[h+a[i]][h+b[i]];
ans%=Mod;
}
ll kaijou[8080];
kaijou[0]=1;
for(i=1;i<8080;i++){
kaijou[i]=i*kaijou[i-1];
kaijou[i]%=Mod;
}
ll gen=0;
for(i=0;i<n;i++){
ll x=kaijou[2*(a[i]+b[i])]*modinv(kaijou[2*a[i]]);
x%=Mod;
x*=modinv(kaijou[2*b[i]]);
x%=Mod;
gen+=x;
gen%=Mod;
}
cout<<((ans-gen+Mod)%Mod*modinv(2))%Mod<<endl;
return 0;
} | codenet | -1 | 1,257 |
s692092151 | p04051 | 1,506,794,837 | cpp | Accepted | 163 | 3,456 | #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define G(n,m) ((LL)fac[(n)+(m)]*ifac[n]%mo*ifac[m]%mo)
const int maxn=8010;
const int base=2010;
const int mo=1e9+7;
int n,m,f[maxn],Ans,fac[maxn],ifac[maxn];
struct Point{
int x,y;
Point() {}
Point(int x,int y):x(x),y(y) {}
bool operator < (const Point &p) const {return x==p.x?y<p.y:x<p.x;}
}P[400010];
int power(int x,int k)
{
int res=1;
while (k)
{
if (k&1) res=(LL)res*x%mo;
x=(LL)x*x%mo;
k>>=1;
}
return res;
}
int main()
{
#ifdef h10
freopen("E.in","r",stdin);
freopen("E.out","w",stdout);
#endif
int i,j;
fac[0]=1;
for (i=1;i<=8000;i++)
fac[i]=(LL)fac[i-1]*i%mo;
ifac[8000]=power(fac[8000],mo-2);
for (i=8000;i>=1;i--)
ifac[i-1]=(LL)ifac[i]*i%mo;
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d%d",&P[i].x,&P[i].y);
for (i=1;i<=n;i++)
P[n+i]=Point(-P[i].x,-P[i].y);
sort(P+1,P+n+n+1);
int p=1;
for (i=-2000;i<=2000;i++)
{
if (i<0)
for (;P[p].x==i;p++)
(f[P[p].y+base]+=1)%=mo;
for (j=-2000;j<=2000;j++)
(f[j+base]+=f[j-1+base])%=mo;
if (i>0)
for (;P[p].x==i;p++)
(Ans+=f[P[p].y+base])%=mo;
}
for (i=1;i<=n+n;i++)
if (P[i].x>0) (Ans+=mo-G(2*P[i].x,2*P[i].y))%=mo;
Ans=(LL)Ans*power(2,mo-2)%mo;
printf("%d\n",Ans);
}
| codenet | -1 | 1,258 |
s548010125 | p04051 | 1,559,147,842 | cpp | Accepted | 240 | 66,176 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 2005;
const int mod = 1e9 + 7;
int a[N], b[N];
int dp[M << 1][M << 1], p[N], inv[N];
int mod_pow(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 C(int x, int y){
if (x < y) return 0;
return 1LL * p[x] * inv[y] % mod * inv[x - y] % mod;
}
int main(){
p[0] = 1; inv[0] = 1;
for (int i = 1; i < N; i++) p[i] = 1LL * p[i - 1] * i % mod;
for (int i = 1; i < N; i++) inv[i] = mod_pow(p[i], mod - 2);
int n, k, ans;
scanf("%d",&n);
for (int i = 1; i <= n; i++) scanf("%d %d",&a[i],&b[i]);
for (int i = 1; i <= n; i++) dp[M - a[i]][M - b[i]]++;
for (int i = 2; i <= M * 4 - 2; i++){
for (int j = 1; j < i; j++){
k = i - j;
if (max(j, k) > M * 2 - 1) continue;
if (j > 1){
dp[j][k] += dp[j - 1][k];
dp[j][k] %= mod;
}
if (k > 1){
dp[j][k] += dp[j][k - 1];
dp[j][k] %= mod;
}
}
}
ans = 0;
for (int i = 1; i <= n; i++){
ans += dp[M + a[i]][M + b[i]];
ans %= mod;
}
for (int i = 1; i <= n; i++) ans = (ans - C((a[i] + b[i]) * 2, a[i] * 2) + mod) % mod;
ans = 1LL * ans * mod_pow(2, mod - 2) % mod;
printf("%d\n", ans);
return 0;
}
| codenet | -1 | 1,259 |
s520486243 | p04051 | 1,537,314,398 | cpp | Accepted | 121 | 64,512 | #include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
#define MAXN 8004
#define bas 2002
#define mod 1000000007
#define inv2 500000004
using namespace std;
int read(){
int nm=0,fh=1; char cw=getchar();
for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
return nm*fh;
}
int add(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
int mus(int x,int y){return (x-y)<0?x-y+mod:x-y;}
int mul(int x,int y){return (LL)x*(LL)y%mod;}
void upd(int &x,int y){x=add(x,y);}
int qpow(int x,int sq){
int res=1; x%=mod;
while(sq){if(sq&1) res=mul(res,x);x=mul(x,x),sq>>=1;}
return res;
}
int n,m,fac[MAXN],ifac[MAXN],F[bas<<1][bas<<1],A[M],B[M],ans;
int C(int tot,int tk){return mul(mul(fac[tot],ifac[tk]),ifac[tot-tk]);}
int main(){
n=read(),fac[0]=1;
for(int i=1;i<MAXN;i++) fac[i]=mul(fac[i-1],i),ifac[i]=qpow(fac[i],mod-2);
for(int i=1;i<=n;i++) A[i]=read(),B[i]=read(),F[bas-A[i]][bas-B[i]]++;
for(int i=1;i<(bas<<1);i++){
for(int j=1;j<(bas<<1);j++) upd(F[i][j],add(F[i-1][j],F[i][j-1]));
}
for(int i=1;i<=n;i++){
upd(ans,F[bas+A[i]][bas+B[i]]);
upd(ans,mod-C((A[i]+B[i])<<1,A[i]<<1));
}
printf("%d\n",mul(ans,inv2)); return 0;
} | codenet | -1 | 1,259 |
s878998525 | p04051 | 1,572,270,133 | cpp | Accepted | 116 | 65,024 | #include<bits/stdc++.h>
using namespace std;
template<class T> T read(){
T x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*w;
}
template<class T> T read(T&x){
return x=read<T>();
}
#define CO const
#define IN inline
typedef long long LL;
CO int mod=1000000000+7;
IN int add(int a,int b){
return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
return (LL)a*b%mod;
}
IN int fpow(int a,int b){
int ans=1;
for(;b;b>>=1,a=mul(a,a))
if(b&1) ans=mul(ans,a);
return ans;
}
int a[200010],b[200010];
int f[4020][4020];
#define dp(i,j) f[i+2001][j+2001]
int fac[8010],ifac[8010];
int main(){
int n=read<int>();
for(int i=1;i<=n;++i) read(a[i]),read(b[i]);
for(int i=1;i<=n;++i) ++dp(-a[i],-b[i]);
for(int i=-2000;i<=2000;++i)
for(int j=-2000;j<=2000;++j) dp(i,j)=add(dp(i,j),add(dp(i-1,j),dp(i,j-1)));
int ans=0;
for(int i=1;i<=n;++i) ans=add(ans,dp(a[i],b[i]));
fac[0]=1;
for(int i=1;i<=8000;++i) fac[i]=mul(fac[i-1],i);
ifac[8000]=fpow(fac[8000],mod-2);
for(int i=7999;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
for(int i=1;i<=n;++i) ans=add(ans,mod-mul(fac[2*a[i]+2*b[i]],mul(ifac[2*a[i]],ifac[2*b[i]])));
ans=mul(ans,fpow(2,mod-2));
printf("%d\n",ans);
return 0;
}
| codenet | -1 | 1,260 |
s237617832 | p04051 | 1,562,540,635 | cpp | Accepted | 209 | 64,640 | #include <bits/stdc++.h>
using namespace std;
#define N 4000
#define BASE 2001
#define MOD 1000000007
int n, a[200005], b[200005], fac[2 * N + 5], facinv[2 * N + 5], f[2 * BASE + 5][2 * BASE + 5], ans;
int fpow(int x, int p) {
int ret = 1;
while (p) {
if (p & 1) ret = 1LL * ret * x % MOD;
x = 1LL * x * x % MOD;
p >>= 1;
}
return ret;
}
int C(int n, int m) {
return 1LL * fac[n] * facinv[m] % MOD * facinv[n - m] % MOD;
}
int main() {
scanf("%d", &n);
fac[0] = 1;
for (int i = 1; i <= 2 * N; ++i)
fac[i] = 1LL * fac[i - 1] * i % MOD;
facinv[2 * N] = fpow(fac[2 * N], MOD - 2);
for (int i = 2 * N; i >= 1; --i)
facinv[i - 1] = 1LL * facinv[i] * i % MOD;
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + MOD) % MOD;
f[BASE - a[i]][BASE - b[i]]++;
}
for (int i = 1; i <= 2 * BASE; ++i)
for (int j = 1; j <= 2 * BASE; ++j)
f[i][j] = (f[i][j] + (f[i - 1][j] + f[i][j - 1]) % MOD) % MOD;
for (int i = 1; i <= n; ++i)
ans = (ans + f[a[i] + BASE][b[i] + BASE]) % MOD;
ans = 1LL * ans * fpow(2, MOD - 2) % MOD;
printf("%d\n", ans);
return 0;
} | codenet | -1 | 1,260 |
s782637102 | p04051 | 1,570,738,273 | cpp | Accepted | 136 | 64,640 | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
x=0; char c=getchar(); int f=1;
while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10,M=4010,L=2001;
const int mod=1e9+7;
inline void add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
inline void dec(int &x,int y) { x-=y; if(x<0) x+=mod; }
int Pow(int x,int y) {
int res=1;
while(y) {
if(y&1) res=res*(ll)x%mod;
x=x*(ll)x%mod,y>>=1;
}
return res;
}
int fac[M<<1],inv[M<<1];
void predo(int n) {
fac[0]=1; for(int i=1;i<=n;++i) fac[i]=fac[i-1]*(ll)i%mod;
inv[n]=Pow(fac[n],mod-2); for(int i=n;i>=1;--i) inv[i-1]=inv[i]*(ll)i%mod;
}
int C(int n,int m) { return fac[n]*(ll)inv[m]%mod*inv[n-m]%mod; }
int f[M][M];
int A[N],B[N],n;
int main() {
rd(n);
for(int i=1;i<=n;++i) {
rd(A[i]),rd(B[i]);
f[L-A[i]][L-B[i]]++;
}
for(int i=0;i<=L*2;++i)
for(int j=0;j<=L*2;++j) {
if(i) add(f[i][j],f[i-1][j]);
if(j) add(f[i][j],f[i][j-1]);
}
predo(8000);
int ans=0;
for(int i=1;i<=n;++i) {
add(ans,f[L+A[i]][L+B[i]]);
dec(ans,C(2*(A[i]+B[i]),2*A[i]));
}
ans=ans*(ll)((mod+1)/2)%mod;
printf("%d",ans);
return 0;
} | codenet | -1 | 1,261 |
s240952074 | p04051 | 1,532,720,810 | cpp | Accepted | 216 | 64,640 | #include<cstdio>
int cnt,mo,n,m,dp[4011][4011],x[200001],y[200001],xi[501],yi[501],a,b,tot,ans,jie[20001],ni[20001];
int mi(int aa,int bb)
{
int s=1;
while(bb!=0)
{
if((bb%2)==1)s=(1ll*s*aa)%mo;
aa=(1ll*aa*aa)%mo;
bb=bb/2;
}
return(s);
}
int main()
{
scanf("%d",&n);
tot=0;
mo=1000000007;
jie[0]=1;
for(int i=1;i<=20000;i++)jie[i]=(1ll*jie[i-1]*i)%mo;
ni[20000]=mi(jie[20000],mo-2);
for(int i=20000;i>=1;i--) ni[i-1]=(1ll*ni[i]*i)%mo;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
if((a<=4000)&&(b<=4000))
{
tot++;
x[tot]=a;
y[tot]=b;
ans=(ans-1ll*((1ll*jie[a+b+a+b]*ni[2*a])%mo)*ni[2*b])%mo;
dp[a+2001][b+2001]++;
}
else
{
cnt++;
xi[cnt]=a;
yi[cnt]=b;
}
}
for(int i=4001;i>=1;i--)
for(int j=4001;j>=1;j--)
{
dp[i][j-1]=(dp[i][j-1]+dp[i][j])%mo;
dp[i-1][j]=(dp[i-1][j]+dp[i][j])%mo;
}
for(int i=1;i<=tot;i++)ans=(ans+dp[2001-x[i]][2001-y[i]])%mo;
ans=(1ll*ans*mi(2,mo-2))%mo;
for(int i=1;i<=cnt;i++)
for(int j=i+1;j<=cnt;j++)ans=(ans+1ll*((1ll*jie[xi[i]+yi[i]+xi[j]+yi[j]]*ni[xi[i]+xi[j]])%mo)*ni[yi[i]+yi[j]])%mo;
for(int i=1;i<=cnt;i++)
for(int j=1;j<=tot;j++)ans=(ans+1ll*((1ll*jie[xi[i]+yi[i]+x[j]+y[j]]*ni[xi[i]+x[j]])%mo)*ni[yi[i]+y[j]])%mo;
ans=(ans+mo)%mo;
printf("%d\n",ans);
} | codenet | -1 | 1,261 |
s997107203 | p04051 | 1,579,492,496 | cpp | Accepted | 191 | 65,024 | #include<bits/stdc++.h>
#define rg register
#define il inline
#define cn const
#define gc getchar()
#define fp(i,a,b) for(rg int i=(a),ed=(b);i<=ed;++i)
using namespace std;
typedef cn int cint;
typedef long long LL;
il int rd(){
rg int x(0),f(1); rg char c(gc);
while(c<'0'||'9'<c){ if(c=='-') f=-1; c=gc; }
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=gc;
return x*f;
}
template<typename T> il void ckmax(T &x,cn T &y){ if(x<y)x=y; }
cint maxn=200010,maxm=2010,bs=2000,mod=1000000007,inv2=500000004;
int n,maxa,maxb,a[maxn],b[maxn],f[maxm<<1][maxm<<1];
int fac[maxm<<2],inv[maxm<<2],ifac[maxm<<2];
LL ans;
il int c(cint &n,cint &m){
return 1ll*fac[n]*ifac[m]%mod *ifac[n-m]%mod;
}
int main(){
// freopen("sample.in","r",stdin);
n=rd();
fp(i,1,n){
a[i]=rd(),b[i]=rd(),++f[bs-a[i]][bs-b[i]];
ckmax(maxa,a[i]),ckmax(maxb,b[i]);
}
fp(i,bs-maxa,bs+maxa)fp(j,bs-maxb,bs+maxb){
f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod;
}
fac[0]=1; fp(i,1,maxa+maxb<<1)fac[i]=1ll*fac[i-1]*i%mod;
inv[1]=1; fp(i,2,maxa+maxb<<1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
ifac[0]=1; fp(i,1,maxa+maxb<<1)ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
fp(i,1,n)ans=(ans+f[bs+a[i]][bs+b[i]]-c(a[i]+b[i]<<1,a[i]<<1)+mod)%mod;
printf("%lld\n",ans*inv2%mod);
return 0;
} | codenet | -1 | 1,267 |
s464382945 | p04051 | 1,578,803,960 | cpp | Accepted | 187 | 128,000 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int _ = 2e5 + 10;
const int __ = 4000 + 10;
const int delta = 2000 + 1;
const ll mod = 1e9 + 7;
int N;
ll f[__][__], fac[__ << 1], facinv[_ << 1];
struct node {
int x, y;
} p[_];
ll ksm(ll a, ll b) {
ll ret = 1;
for ( ; b; b >>= 1) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
}
return ret;
}
inline void init(int lim = 8010) {
fac[0] = 1;
for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
facinv[0] = 1, facinv[lim] = ksm(fac[lim], mod - 2);
for (int i = lim - 1; i >= 1; --i) facinv[i] = 1ll * facinv[i + 1] * (i + 1) % mod;
}
ll C(ll n, ll m) { return fac[n] * facinv[m] % mod * facinv[n - m] % mod; }
signed main() {
init();
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
int x, y;
scanf("%d%d", &x, &y);
p[i] = {x, y};
f[-x + delta][-y + delta] += 1;
}
for (int i = 1; i <= delta * 2; ++i)
for (int j = 1; j <= delta * 2; ++j)
f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;
ll ans = 0;
for (int i = 1; i <= N; ++i) {
ans = (ans + f[p[i].x + delta][p[i].y + delta]) % mod;
ans = (ans - C(2 * p[i].x + 2 * p[i].y, 2 * p[i].x) + mod) % mod;
}
ans = ans * ksm(2, mod - 2) % mod;
printf("%lld\n", ans);
return 0;
}
| codenet | -1 | 1,268 |
s274419106 | p04051 | 1,562,782,522 | cpp | Accepted | 167 | 99,968 | #include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 4002, M = 2e5 + 7, MOD = 1e9 + 7;
int f[N][N], g[N][N], a[M], b[M], c[M], d[M];
LL fac[N * 2], inv[N * 2];
LL qpow(LL x, LL y){
LL z = 1;
while (y > 0){
if (y % 2) z = z * x % MOD;
x = x * x % MOD;
y /= 2;
}
return z;
}
void init(){
fac[0] = 1;
for (int i = 1; i < 2 * N; i++) fac[i] = fac[i - 1] * i % MOD;
inv[2 * N - 1] = qpow(fac[2 * N - 1], MOD - 2);
for (int i = 2 * N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
}
LL C(int n, int m){
return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main(){
init();
int n; LL ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
for (int i = 1; i <= n; i++) ans = (ans - C(2 * (a[i] + b[i]), 2 * a[i]) + MOD) % MOD;
for (int i = 1; i <= n; i++){
c[i] = -a[i] + 2000;
d[i] = -b[i] + 2000;
a[i] += 2000;
b[i] += 2000;
}
for (int i = 1; i <= n; i++) f[c[i]][d[i]] ++, g[a[i]][b[i]] ++;
for (int i = 0; i <= 4000; i++){
for (int j = 0; j <= 4000; j++){
if (i > 0) f[i][j] += f[i - 1][j];
if (j > 0) f[i][j] += f[i][j - 1];
f[i][j] %= MOD;
ans = (ans + 1LL * g[i][j] * f[i][j] % MOD) % MOD;
}
}
printf("%lld", ans * qpow(2, MOD - 2) % MOD);
return 0;
} | codenet | -1 | 1,271 |
s949144280 | p04051 | 1,474,151,455 | cpp | Accepted | 913 | 127,104 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
int N;
int dp [4001] [4001];
int memo [4001] [4001];
const int init_pos = 2000;
const int MOD = 1e9 + 7;
int comb(int x,int y)
{
if(x == 0 && y == 0) return 1;
if(memo [x] [y]) return memo [x] [y];
int res = 0;
if(x - 1 >= 0) res += comb(x - 1,y);
if(y - 1 >= 0) res += comb(x,y - 1);
res %= MOD;
return memo [x] [y] = res;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
vector< pair<int,int> > coor(N);
FOR(i,0,N){
cin >> coor [i].first >> coor [i].second;
dp [init_pos - coor [i].first] [init_pos - coor [i].second]++;
}
for(int i = 0;i <= 4000;i++){
for(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] %= MOD;
}
}
int ans = 0;
FOR(i,0,N){
(ans += dp [init_pos + coor [i].first] [init_pos + coor [i].second]) %= MOD;
}
FOR(i,0,coor.size()){
(ans -= comb(coor [i].first * 2,coor [i].second * 2)) %= MOD;
}
(ans += MOD) %= MOD;
if(ans & 1){
ans += MOD;
}
ans /= 2;
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,272 |
s560001353 | p04051 | 1,577,150,013 | cpp | Accepted | 423 | 213,248 | // AGC001E.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5e3 + 200, DOM = 2500, mod = 1e9 + 7;
int mp[MAX_N][MAX_N], n, xi[MAX_N * 100], yi[MAX_N * 100], fac[MAX_N * MAX_N];
int quick_pow(int bas, int tim)
{
int ret = 1;
while (tim)
{
if (tim & 1)
ret = 1LL * ret * bas % mod;
bas = 1LL * bas * bas % mod;
tim >>= 1;
}
return ret;
}
int main()
{
scanf("%d", &n);
for (int i = fac[0] = 1; i < MAX_N * MAX_N; i++)
fac[i] = 1LL * fac[i - 1] * i % mod;
for (int i = 1; i <= n; i++)
{
scanf("%d%d", &xi[i], &yi[i]);
mp[DOM - xi[i]][DOM - yi[i]]++;
}
for (int i = 1; i <= (DOM << 1); i++)
for (int j = 1; j <= (DOM << 1); j++)
mp[i][j] = (1LL * mp[i][j] + mp[i - 1][j] + mp[i][j - 1]) % mod;
int ans = 0;
for (int i = 1; i <= n; i++)
{
int pans = mp[xi[i] + DOM][yi[i] + DOM];
// get oneself outta here;
int myself = 1LL * fac[(xi[i] << 1) + (yi[i] << 1)] * quick_pow(fac[xi[i] << 1], mod - 2) % mod * quick_pow(fac[yi[i] << 1], mod - 2) % mod;
ans = (1LL * ans + (pans + mod - myself) % mod) % mod;
}
printf("%lld\n", 1LL * ans * quick_pow(2, mod - 2) % mod);
return 0;
} | codenet | -1 | 1,273 |
s845404380 | p04051 | 1,537,468,190 | cpp | Accepted | 430 | 106,496 | #include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = (int)2123, mod = (int)1e9 + 7;
int n;
int ans, dp[N+N][N+N], cnt[N+N][N+N], f[10*N];
void add(int &a,int b){
a+=b;
if(a >= mod)
a-=mod;
}
ll binpow(ll x,ll p){
ll res = 1;
while(p){
if(p&1)
res = res * x % mod;
x = x * x % mod;
p/=2;
}
return res;
}
ll inv(ll x){
x%=mod;
return binpow(x, mod - 2);
}
ll C(int k,int n){
return 1ll * f[n] * inv( 1ll * f[k] * f[n-k]) %mod;
}
int main(){
f[0] = 1;
for(int i = 1; i < 10*N; i++)
f[i] = 1ll * f[i - 1] * i % mod;
cin >> n;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
add(ans, C(a+a,a+a+b+b));
dp[N-a][N-b]++;
cnt[N+a][N+b]++;
}
ans = mod - ans;
ans%=mod;
for(int d = 0; d <= 4*N; d++)
for(int x = 0; x <= d; x++){
int y = d - x;
if(x >= N + N || y >= N + N)
continue;
ans = (ans + 1ll * cnt[x][y] * dp[x][y]) % mod;
if(x + 1 < N + N)
add(dp[x + 1][y], dp[x][y]);
if(y + 1 < N + N)
add(dp[x][y + 1], dp[x][y]);
}
cout << ans * inv(2) % mod;
return 0;
}
| codenet | -1 | 1,274 |
s423497708 | p04051 | 1,499,043,628 | cpp | Accepted | 304 | 97,280 | // ** ALLAH **
// who is Hussain? -> whoishussain.org
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int N = 2e5 + 100, M = 2002;
int n, a[N], b[N], dpdpdp[3*M][3*M], fact[4*M+1];
int powm(int x, int p){
int ret = 1;
while( p ){
if( p & 1 ) ret = 1ll * ret * x % mod;
x = 1ll * x * x % mod;
p>>=1;
}
return ret;
}
int &dp(int i, int j){
return dpdpdp[i+M][j+M];
}
int32_t main(){
cin >> n;
for(int i =0;i < n;i ++) cin >> a[i] >> b[i], dp(-a[i],-b[i]) += 1;
for(int i = -M+2; i < M; i++)
for(int j = -M+2; j < M; j++)
dp(i,j) = (dp(i,j) + dp(i-1,j) + dp(i,j-1)) % mod;
fact[0] = 1;
for(int i= 1;i < 4*M;i ++) fact[i] = 1ll*fact[i-1] * i % mod;
int ans = 0;
for(int i = 0;i < n;i ++){
ans = (ans + dp(a[i],b[i]))%mod;
ans = (ans - 1ll * fact[2*(a[i]+b[i])] * powm(fact[2*a[i]],mod-2) % mod * powm(fact[2*b[i]],mod-2) % mod +mod ) %mod;
}
ans = 1ll * ans * powm(2, mod-2) % mod;
cout << (ans+mod)%mod << endl;
}
| codenet | -1 | 1,275 |
s819851658 | p04051 | 1,537,558,997 | cpp | Accepted | 173 | 127,232 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN=2e5+10;
const int mod=1e9+7;
const int INF=1e9+10;
const double EPS=1e-3;
const LL invTwo=500000004;
int x[MAXN][2];
LL y[4005][4005],inv[8005],fra[8005];
LL power(LL a,LL b){
LL c=1;
while(b){
if (b%2==1) c=c*a%mod;
a=a*a%mod;
b/=2;
}
return c;
}
LL C(LL n,LL m){
if (n<0 || m<0 || n<m) return 0;
return fra[n]*inv[m]%mod*inv[n-m]%mod;
}
int n;
int main(){
fra[0]=1; for(int i=1;i<=8000;i++) fra[i]=fra[i-1]*i%mod;
inv[8000]=power(fra[8000],mod-2); for(int i=7999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
scanf("%d",&n);
memset(y,0,sizeof(y));
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i][0],&x[i][1]);
y[2000-x[i][0]][2000-x[i][1]]++;
}
for(int i=0;i<=4000;i++)
for(int j=0;j<=4000;j++){
if (i>0) y[i][j]+=y[i-1][j];
if (j>0) y[i][j]+=y[i][j-1];
y[i][j]%=mod;
}
LL ans=0;
for(int i=1;i<=n;i++){
ans+=y[2000+x[i][0]][2000+x[i][1]];
ans-=C(x[i][0]*2+x[i][1]*2,x[i][0]*2);
ans%=mod;
}
if (ans<0) ans+=mod;
printf("%lld\n",ans*power(2,mod-2)%mod);
return 0;
} | codenet | -1 | 1,276 |
s204641152 | p04051 | 1,542,317,796 | cpp | Accepted | 166 | 132,480 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 200010,mod = 1e9 + 7;
ll n,a[maxn],b[maxn],f[4010][4010],c[4010][4010];
ll ni[maxn],nijie[maxn],jie[maxn],ans;
ll qpow(ll a,ll b)
{
ll res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll C(ll n,ll m)
{
return jie[n] * nijie[m] % mod * nijie[n - m] % mod;
}
int main()
{
ni[0] = ni[1] = nijie[0] = nijie[1] = jie[0] = jie[1] = 1;
for (ll i = 2; i <= 8001; i++)
{
jie[i] = jie[i - 1] * i % mod;
ni[i] = (mod - mod / i) * ni[mod % i] % mod;
nijie[i] = nijie[i - 1] * ni[i] % mod;
}
scanf("%lld",&n);
for (ll i = 1; i <= n; i++)
{
scanf("%lld%lld",&a[i],&b[i]);
f[2001 - a[i]][2001 - b[i]]++;
}
for (ll i = 1; i <= 4001; i++)
for (ll j = 1; j <= 4001; j++)
f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;
for (ll i = 1; i <= n; i++)
ans = (ans + f[a[i] + 2001][b[i] + 2001]) % mod;
for (ll i = 1; i <= n; i++)
ans = (ans - C(a[i] + a[i] + b[i] + b[i],a[i] + a[i]) + mod) % mod;
ans = ans * qpow(2,mod - 2) % mod;
printf("%lld\n",ans);
return 0;
}
| codenet | -1 | 1,278 |
s493840527 | p04051 | 1,595,257,685 | cpp | Accepted | 154 | 68,036 | #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
const int maxn = int(4e4) + 7, P = int(1e9) + 7;
typedef long long ll;
ll fac[maxn], inv[maxn];
ll Pow(ll x,ll y){
x%=P;
ll ans=1;
while(y){
if (y&1) ans=ans*x%P;
x=x*x%P;
y>>=1;
}
return ans%P;
}
void init() {
fac[0] = 1;
for (int i = 1; i <= maxn - 10; ++i) fac[i] = fac[i - 1] * i % P;
inv[maxn - 10] = Pow(fac[maxn - 10], P - 2);
for (int i = maxn - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % P;
}
ll C(int x, int y) {
return fac[x] * inv[y] % P * inv[x - y] % P;
}
int n, a[2000007], b[2000007], dp[4007][4007];
int main() {
// freopen("in.txt", "r", stdin);
init();
scanf("%lld",&n);
for (ll i=1; i<=n; i++){
scanf("%lld%lld",&a[i],&b[i]);
dp[2001-a[i]][2001-b[i]]++;
}
for (ll i=1; i<=4001; i++)
for (ll j=1; j<=4001; j++){
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%P;
}
ll ans=0;
for (ll i=1; i<=n; i++)
ans=(ans+dp[2001+a[i]][2001+b[i]])%P;
for (ll i=1; i<=n; i++)
ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+P)%P;
printf("%lld\n",ans*inv[2]%P);
// printf("%lld\n", ans * Pow(2, P - 2) % P);
return 0;
} | codenet | -1 | 1,280 |
s950658039 | p04051 | 1,571,365,793 | cpp | Accepted | 131 | 64,512 | #include <bits/stdc++.h>
const int N = 200005, M = 4005, mod = 1000000007;
typedef long long LL;
int n, a[N], b[N], ans;
int dp[M][M], factor[M << 1], ifactor[M << 1];
int& t(int x, int y) { return dp[x + 2000][y + 2000]; }
void reduce(int &x) { x += x >> 31 & mod; }
void add(int &x, int y) { x += y - mod, x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
for (; y; y >>= 1, x = (LL) x * x % mod)
if (y & 1) ans = (LL) ans * x % mod;
return ans;
}
void init(int n) {
factor[0] = 1;
for (int i = 1; i <= n; ++i) factor[i] = (LL) factor[i - 1] * i % mod;
ifactor[n] = pow(factor[n], mod - 2);
for (int i = n; i; --i) ifactor[i - 1] = (LL) ifactor[i] * i % mod;
}
int C(int x, int y) { return (LL) factor[x] * ifactor[y] % mod * ifactor[x - y] % mod; }
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n, ans = 0, init(8000);
for (int i = 1; i <= n; ++i)
std::cin >> a[i] >> b[i], ++t(-a[i], -b[i]);
for (int i = -2000; i <= 2000; ++i)
for (int j = -2000; j <= 2000; ++j)
add(t(i + 1, j), t(i, j)), add(t(i, j + 1), t(i, j));
for (int i = 1; i <= n; ++i) add(ans, t(a[i], b[i]));
for (int i = 1; i <= n; ++i)
reduce(ans -= C(a[i] + b[i] << 1, a[i] << 1));
std::cout << (LL) ans * (mod + 1 >> 1) % mod << '\n';
return 0;
} | codenet | -1 | 1,281 |
s778780891 | p04051 | 1,490,471,309 | cpp | Accepted | 181 | 132,224 |
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 210000;
const int modi = 1000000007;
int a[maxn], b[maxn];
int f[4100][4100];
int g[4100][4100];
ll fact[9100], inv[9100];
ll quickpow(ll base, ll times)
{
ll ans = 1;
while (times)
{
if (times & 1) ans = (ans * base) % modi;
base = (base * base) % modi;
times >>= 1;
}
return ans;
}
ll C(int n, int m)
{
return fact[n] * inv[m] % modi * inv[n - m] % modi;
}
int main(int argc, char * argv[])
{
int n;
scanf("%d", &n);
fact[0] = inv[0] = 1;
for (int i = 1; i <= 8100; ++i)
{
fact[i] = fact[i - 1] * i % modi;
inv[i] = quickpow(fact[i], modi - 2);
}
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
scanf("%d%d", &a[i], &b[i]);
g[-a[i] + 2001][-b[i] + 2001]++;
g[a[i] + 2001][b[i] + 2001]++;
ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i])) % modi;
}
f[0][0] = 1;
for (int i = 1; i <= 4001; ++i)
{
for (int j = 1; j <= 4001; ++j)
{
f[i][j] = (f[i - 1][j] + f[i][j - 1]) % modi;
if (i <= 2001 && j <= 2001)
f[i][j] = (f[i][j] + g[i][j]) % modi;
if (i > 2001 && j > 2001 && g[i][j] != 0)
{
ans = (ans + (ll)g[i][j] * f[i][j]) % modi;
}
}
}
printf("%lld\n", (ans * quickpow(2,modi-2) % modi + modi) % modi);
return 0;
} | codenet | -1 | 1,281 |
s132555154 | p04051 | 1,539,890,453 | cpp | Accepted | 324 | 172,288 | #include <bits/stdc++.h>
using namespace std;
#define maxn 2500000
#define mod 1000000007
#define maxm 4020
#define int long long
int n, a[maxn], b[maxn], inv[maxn], fac[maxn];
int ans, m, S = 2005, f[maxm][maxm];
int read()
{
int x = 0, k = 1;
char c; c = getchar();
while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * k;
}
void Up(int &x, int y) { x = (x + y) % mod; }
int C(int n, int m)
{
if(n < m || m < 0 || n < 0) return 0;
return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void pre()
{
fac[0] = fac[1] = 1; inv[0] = inv[1] = 1;
for(int i = 2; i < maxn; i ++) fac[i] = fac[i - 1] * i % mod;
for(int i = 2; i < maxn; i ++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
for(int i = 2; i < maxn; i ++) inv[i] = inv[i] * inv[i - 1] % mod;
}
signed main()
{
pre(); n = read();
for(int i = 1; i <= n; i ++)
{
a[i] = read(), b[i] = read();
f[-a[i] + S][-b[i] + S] ++;
}
m = 2 * S;
for(int i = 1; i <= m; i ++)
for(int j = 1; j <= m; j ++)
Up(f[i][j], (f[i - 1][j] + f[i][j - 1]) % mod);
for(int i = 1; i <= n; i ++)
{
Up(ans, f[a[i] + S][b[i] + S]);
Up(ans, mod - C(2 * (a[i] + b[i]), 2 * a[i]));
}
printf("%lld\n", ans * inv[2] % mod);
return 0;
} | codenet | -1 | 1,284 |
s131617739 | p04051 | 1,554,061,849 | cpp | Accepted | 200 | 190,592 | /*input
3
1 1
1 1
2 1
*/
// with "help" from editorial
#include <iostream>
#include <cstdio>
using namespace std;
const int MOD = 1e9 + 7, MAX = 2007, MAXN = 200007;
int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; }
int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; }
int mul(int a, int b) { return (long long) a * b % MOD; }
int F[MAX << 1][MAX << 1], N, A[MAXN], B[MAXN];
long long G[MAX << 1][MAX << 1];
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
int read()
{
int ans = 0; register char ch = getchar();
for (; 48 > ch || ch > 57; ch = getchar());
for (; 47 < ch && ch < 58; ch = getchar()) ans = ans * 10 + ch - 48;
return ans;
}
int main()
{
N = read();
FOR(i, 0, N-1) A[i] = read(), B[i] = read();
FOR(i, 0, (MAX << 1) - 1) F[i][0] = F[0][i] = 1;
FOR(i, 1, (MAX << 1) - 1) FOR(j, 1, (MAX << 1) - 1) {
F[i][j] = add(F[i-1][j], F[i][j-1]);
}
FOR(i, 0, N-1) ++G[MAX - A[i]][MAX - B[i]];
FOR(i, 1, (MAX << 1) - 1) FOR(j, 1, (MAX << 1) - 1) G[i][j] = add(G[i][j], add(G[i-1][j], G[i][j-1]));
int ans = 0;
FOR(i, 0, N-1) {
ans = sub(ans, F[A[i] + A[i]][B[i] + B[i]]);
ans = add(ans, G[MAX + A[i]][MAX + B[i]]);
}
cout << mul(ans, (MOD + 1) >> 1) << endl;
}
| codenet | -1 | 1,285 |
s879490249 | p04051 | 1,495,081,350 | cpp | Accepted | 138 | 65,152 | #include<bits/stdc++.h>
using namespace std;
#define pc(x) putchar(x)
namespace ib {char b[100];}
inline void pi(int x){
if(x==0) {pc(48); return;}
if(x<0) {pc('-'); x=-x;}
char *s=ib::b;
while(x) *(++s)=x%10,x/=10;
while(s!=ib::b) pc((*(s--))+48);
}
inline void ri(int &x){
x=0; static char c; bool t(0);
while(c=getchar(),c<'0'||c>'9') if(c=='-') t=1; else t=0;
do x=(x<<1)+(x<<3)+c-'0'; while(c=getchar(),c>='0'&&c<='9');
if(t) x=-x;
}
const int N=4024,M=1e9+7,NS=200024;
int x[NS],y[NS],f[N][N];
int jc[2*N],njc[2*N];
int ksm(int n,int c){
int jc=1;
while(c){
if(c&1) jc=(long long)jc*n%M;
n=(long long)n*n%M;
c>>=1;
}
return jc;
}
void build(){
int i;
jc[0]=njc[0]=1;
for(i=1;i<=8005;++i) jc[i]=(long long)jc[i-1]*i%M;
njc[8005]=ksm(jc[8005],M-2);
for(i=8005;i;--i) njc[i-1]=(long long)njc[i]*i%M;
}
inline int c(int n,int m){
return (long long)jc[m]*njc[n]%M*njc[m-n]%M;
}
int main(){
int i,j,n,ans=0;
ri(n); build();
for(i=0;i<n;++i){
ri(x[i]); ri(y[i]);
++f[2001-x[i]][2001-y[i]];
}
for(i=1;i<=4005;++i)
for(j=1;j<=4005;++j)
f[i][j]=(f[i-1][j]+f[i][j-1]+f[i][j])%M;
for(i=0;i<n;++i) ans=(ans+f[x[i]+2001][y[i]+2001])%M;
for(i=0;i<n;++i) ans=(ans+M-c(x[i]+x[i],x[i]+y[i]+x[i]+y[i]))%M;
ans=(long long)ans*njc[2]%M;
cout<<ans;
return 0;
} | codenet | -1 | 1,286 |
s901574466 | p04051 | 1,516,569,729 | cpp | Accepted | 244 | 63,488 | #include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
const int mid=2002;
int f[4020][4020];
int n;
ll ans,jc[8500],jc_n[8500];
ll power(ll x,ll k)
{
ll sss=1;
while (k)
{
if (k%2) sss=sss*x%mod;
x=x*x%mod;
k/=2;
}
return sss;
}
ll ny(ll x)
{
return power(x,mod-2);
}
ll C(int x,int y)
{
// printf("%d %d\n",x,y);
if (y>x||y<=0) return 0;
ll sss=jc[x];
sss=sss*jc_n[x-y]%mod*jc_n[y]%mod;
// printf("%lld\n",sss);
return sss;
}
void sol()
{
for (int i=1;i<=4010;++i)
for (int j=1;j<=4010;++j)
{
int ch=0;
if (f[i][j]<0)
ch-=f[i][j],f[i][j]=0;
f[i][j]=( (f[i-1][j]+f[i][j-1])%mod +f[i][j])%mod;
// if (ch)
// for (int kkk=1;kkk<=ch;++kkk)
// printf("+%lld\n",(ll)f[i][j]);
ans=(ans+(ll)f[i][j]*ch%mod)%mod;
}
}
int main()
{
// freopen("E.in","r",stdin);
// freopen("E.out","w",stdout);
jc[0]=1;
for (int i=1;i<=8400;++i)
{
jc[i]=jc[i-1]*i%mod;
jc_n[i]=ny(jc[i]);
}
scanf("%d",&n);
int x,y;
for (int i=1;i<=n;++i)
{
scanf("%d%d",&x,&y);
ans=((ans-C(2*x+2*y,x+x))%mod +mod)%mod;
++f[mid-x][mid-y];
--f[mid+x][mid+y];
}
// printf("%lld\n",ans);
sol();
// printf("check:%d\n",f[mid+1][mid+1]);
// printf("%lld\n",ans);
ans=ans*ny(2)%mod;
printf("%lld\n",ans);
return 0;
}
| codenet | -1 | 1,288 |
s901574466 | p04051 | 1,516,569,729 | cpp | Accepted | 244 | 63,488 | #include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
const int mid=2002;
int f[4020][4020];
int n;
ll ans,jc[8500],jc_n[8500];
ll power(ll x,ll k)
{
ll sss=1;
while (k)
{
if (k%2) sss=sss*x%mod;
x=x*x%mod;
k/=2;
}
return sss;
}
ll ny(ll x)
{
return power(x,mod-2);
}
ll C(int x,int y)
{
// printf("%d %d\n",x,y);
if (y>x||y<=0) return 0;
ll sss=jc[x];
sss=sss*jc_n[x-y]%mod*jc_n[y]%mod;
// printf("%lld\n",sss);
return sss;
}
void sol()
{
for (int i=1;i<=4010;++i)
for (int j=1;j<=4010;++j)
{
int ch=0;
if (f[i][j]<0)
ch-=f[i][j],f[i][j]=0;
f[i][j]=( (f[i-1][j]+f[i][j-1])%mod +f[i][j])%mod;
// if (ch)
// for (int kkk=1;kkk<=ch;++kkk)
// printf("+%lld\n",(ll)f[i][j]);
ans=(ans+(ll)f[i][j]*ch%mod)%mod;
}
}
int main()
{
// freopen("E.in","r",stdin);
// freopen("E.out","w",stdout);
jc[0]=1;
for (int i=1;i<=8400;++i)
{
jc[i]=jc[i-1]*i%mod;
jc_n[i]=ny(jc[i]);
}
scanf("%d",&n);
int x,y;
for (int i=1;i<=n;++i)
{
scanf("%d%d",&x,&y);
ans=((ans-C(2*x+2*y,x+x))%mod +mod)%mod;
++f[mid-x][mid-y];
--f[mid+x][mid+y];
}
// printf("%lld\n",ans);
sol();
// printf("check:%d\n",f[mid+1][mid+1]);
// printf("%lld\n",ans);
ans=ans*ny(2)%mod;
printf("%lld\n",ans);
return 0;
}
| codenet | -1 | 1,288 |
s764958910 | p04051 | 1,543,073,647 | cpp | Accepted | 124 | 64,640 | #include <iostream>
#include <cstdio>
#include <cstring>
typedef long long lint;
const int N=2005;
const int mod=1e9+7;
int n,ans,fac[N<<2],inv[N<<2],dp[N<<1][N<<1];
struct pnt{
int x,y;
}pt[(int)2e5+2];
template <class T> inline void twk(T &x){
if(x>=mod) x-=mod;
}
inline int nxi(){
int x=0;
char c;
while((c=getchar())>'9'||c<'0');
while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
return x;
}
inline int C(const int x,const int y){
if(x<y) return 0;
return (lint)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
inline int qpow(int x,int t){
int ans=1;
for(;t;t>>=1,x=(lint)x*x%mod){
if(t&1) ans=(lint)ans*x%mod;
}
return ans;
}
inline void init_C(){
fac[0]=1;
for(int i=1;i<N<<2;++i){
fac[i]=(lint)fac[i-1]*i%mod;
}
inv[(N<<2)-1]=qpow(fac[(N<<2)-1],mod-2);
for(int i=(N<<2)-1;i;--i){
inv[i-1]=(lint)inv[i]*i%mod;
}
}
int main(){
#ifndef ONLINE_JUDGE
// freopen("e.in","r",stdin);
#endif
init_C();
n=nxi();
for(int i=1;i<=n;++i){
const int x=nxi(),y=nxi();
twk(ans+=mod-C((x+y)<<1,x<<1));
pt[i]=(pnt){x,y};
++dp[N-x][N-y];
}
for(int i=1;i<N<<1;++i){
for(int j=1;j<N<<1;++j){
twk(dp[i][j]+=dp[i-1][j]);
twk(dp[i][j]+=dp[i][j-1]);
}
}
for(int i=1;i<=n;++i){
twk(ans+=dp[pt[i].x+N][pt[i].y+N]);
}
printf("%lld\n",(lint)ans*inv[2]%mod);
return 0;
} | codenet | -1 | 1,291 |
s184238566 | p04051 | 1,495,418,961 | cpp | Accepted | 190 | 126,848 | #include <cstdio>
const int N = 200100;
const int MOD = 1000000007;
int a[N], b[N];
int dp[4010][4010];
int val[4010][4010];
int val2[4010][4010];
long long fat[8010], inv[8010];
long long fpow(long long a, long long b){
long long c = 1;
for(;b;b>>=1, a=(a*a)%MOD)if(b&1)c=(c*1ll*a)%MOD;
return c;
}
void calcfat(int qtd){
fat[0]=1;
for(int i = 1; i <= qtd; i++){
fat[i]=(fat[i-1]*1ll*i)%MOD;
}
}
void calcinv(int qtd){
inv[0]=1;
for(int i = 1; i <= qtd; i++){
inv[i]=fpow(fat[i],MOD-2);
}
}
long long comb(int a, int b){
return (((fat[2*a+2*b]*inv[2*a])%MOD)*inv[2*b])%MOD;
}
int main(){
int n;
scanf("%d", &n);
calcfat(8001);
calcinv(8001);
long long ans = 0;
for(int i = 0; i <= 8001; i++){
//printf("%lld ",fat[i]);
}
//puts("");
for(int i = 0; i < n; i++){
int a, b;
scanf("%d %d",&a,&b);
ans = (ans - comb(a,b) + MOD) % MOD;
//printf("%lld\n",ans);
val2[2001+a][2001+b]++;
val[2001-a][2001-b]++;
}
//printf("%lld\n",ans);
for(int i = 1; i <= 4001; i++){
for(int j = 1; j <= 4001; j++){
dp[i][j]=((dp[i-1][j]+dp[i][j-1]) % MOD + val[i][j])%MOD;
if(i>2001 && j>2001 && val2[i][j]>0){
ans+=(val2[i][j]*1ll*dp[i][j])%MOD;
ans%=MOD;
}
dp[i][j]%=MOD;
}
}
ans = (ans *1ll* fpow(2,MOD-2))%MOD;
printf("%lld\n",ans);
} | codenet | -1 | 1,291 |
s138894204 | p04051 | 1,558,623,570 | cpp | Accepted | 108 | 64,640 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 4007;
const int maxm = 2e5 + 7;
const int base = 2000;
const int mod = 1e9 + 7;
const int inv2 = mod + 1 >> 1;
int n;
int f[maxn][maxn];
int a[maxm];
int b[maxm];
int fac[maxn << 1];
int inv[maxn << 1];
int Add(int x,int y){return (x += y) >= mod ? x - mod : x;}
int Sub(int x,int y){return (x -= y) < 0 ? x + mod : x;}
int Mul(int x,int y){return 1LL * x * y % mod;}
int Pow(int x,int k,int re = 1){
for(; k; k >>= 1,x = Mul(x,x))
if(k & 1)re = Mul(re,x);
return re;
}
int C(int n,int m){
return Mul(fac[n],Mul(inv[m],inv[n - m]));
}
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; ++i){
scanf("%d%d",&a[i],&b[i]);
++f[base - a[i]][base - b[i]];
}
for(int i = 0; i < maxn; ++i){
for(int j = 0; j < maxn; ++j){
if(i)f[i][j] = Add(f[i][j],f[i - 1][j]);
if(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] + base][b[i] + base]);
fac[0] = inv[0] = 1;
for(int i = 1; i <= 8000; ++i)fac[i] = Mul(fac[i - 1],i);
inv[8000] = Pow(fac[8000],mod - 2);
for(int i = 7999; i; --i)inv[i] = Mul(inv[i + 1],i + 1);
for(int i = 1; i <= n; ++i)
ans = Sub(ans,C((a[i] << 1) + (b[i] << 1),(a[i] << 1)));
printf("%d\n",Mul(ans,inv2));
return 0;
}
| codenet | -1 | 1,292 |
s695153675 | p04051 | 1,468,808,461 | cpp | Accepted | 380 | 64,896 | # include <cstdio>
# define REP(i, n) for (int i = 1; i <= n; ++ i)
# define REP_D(i, n) for (int i = n; i >= 1; -- i)
# define NR 201000
const int M = 2002, M2 = 4010, M4 = 8050;
const int mod = 1000000007;
int n, x[NR], y[NR];
int a[M2 + 10][M2 + 10];
int fac[M4 + 10], fac_inv[M4 + 10];
int pr (int a, int z) { int s = 1; do { if (z & 1) s = 1ll * s * a % mod; a = 1ll * a * a % mod; } while (z >>= 1); return s; }
int binom (int n, int k) { return n < k ? 0 : 1ll * fac[n] * fac_inv[k] % mod * fac_inv[n - k] % mod; }
void inc (int &x, int y) { x = (x + y) % mod; }
void dec (int &x, int y) { x = (x + mod - y) % mod; }
int main () {
scanf ("%d", &n);
fac[0] = fac_inv[0] = 1;
REP (i, M4) fac[i] = 1ll * fac[i - 1] * i % mod;
fac_inv[M4] = pr (fac[M4], mod - 2);
REP_D (i, M4 - 1) fac_inv[i] = 1ll * fac_inv[i + 1] * (i + 1) % mod;
REP (i, n) scanf ("%d%d", &x[i], &y[i]), ++ a[M - x[i]][M - y[i]];
REP (i, M2) REP (j, M2) inc (a[i][j], a[i][j - 1] + a[i - 1][j]);
int ans = 0;
REP (i, n) inc (ans, a[M + x[i]][M + y[i]]);
//printf ("!%d\n", ans);
REP (i, n) dec (ans, binom (2 * x[i] + 2 * y[i], 2 * x[i]));//, printf ("!%d %d\n", i, binom (2 * x[i] + 2 * y[i], 2 * x[i]));
//printf ("!%d\n", ans);
printf ("%lld\n", 1ll * ans * ((mod + 1) / 2) % mod);
return 0;
}
| codenet | -1 | 1,293 |
s341586090 | p04051 | 1,590,530,746 | cpp | Accepted | 180 | 129,408 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll mod = 1000000007;
const int mxN = 2005;
const int mxM = 200005;
ll dp[mxN*2][mxN*2], a[mxM], b[mxM];
ll fac[mxN*8], ifac[mxN*8], inv[mxN*8];
void pre(){
fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
for(int n = 2; n < mxN*8; n++){
fac[n] = n*fac[n - 1]%mod;
inv[n] = (mod - mod/n)*inv[mod%n]%mod;
ifac[n] = ifac[n - 1]*inv[n]%mod;
}
}
inline ll ncr(int n, int r){
if(r < 0 || r > n)return 0;
return fac[n]*(ifac[r]*ifac[n - r]%mod)%mod;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout<<setprecision(32);
pre();
memset(dp, 0, sizeof(dp));
int n;
cin>>n;
for(int i = 0; i < n; i++){
cin>>a[i]>>b[i];
dp[mxN - a[i]][mxN - b[i]]++;
}
for(int i = 0; i + 1 < (mxN<<1); i++){
for(int j = 0; j + 1 < (mxN<<1); 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;
}
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
ans += dp[mxN + a[i]][mxN + b[i]];
ans += mod - ncr(2*a[i] + 2*b[i], 2*b[i]);
}
ans %= mod;
ans *= (mod + 1)/2;
ans %= mod;
cout<<ans<<endl;
return 0;
} | codenet | -1 | 1,294 |
s985324877 | p04051 | 1,554,756,265 | cpp | Accepted | 157 | 65,792 | #include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int MaxA(4003);
const int MaxN(200003);
const int Mod(1e9 + 7);
const int inv2(500000004);
inline int add(int x, int y)
{
return (x += y) >= Mod ? x -= Mod : x;
}
inline int inc(int x, int y)
{
return (x -= y) < 0 ? x += Mod : x;
}
int fac[MaxN], rfac[MaxN];
int a[MaxN], b[MaxN];
int F[MaxA][MaxA];
inline int C(int n, int m)
{
return n < m ? 0 : (ull) fac[n] * rfac[m] % Mod * rfac[n - m] % Mod;
}
int fexp(int x, int k)
{
int res = 1;
for(; k; k >>= 1, x = (ull) x * x % Mod)
if(k & 1) res = (ull) res * x % Mod;
return res;
}
int main()
{
int n;
scanf("%d", &n);
for(int i = fac[0] = 1; i <= 8000; i++)
fac[i] = (ull) fac[i - 1] * i % Mod;
rfac[8000] = fexp(fac[8000], Mod - 2);
for(int i = 8000; i; i--)
rfac[i - 1] = (ull) rfac[i] * i % Mod;
for(int i = 1; i <= n; i++)
{
scanf("%d%d", &a[i], &b[i]);
++F[-a[i] + 2001][-b[i] + 2001];
}
for(int i = 1; i <= 4001; i++)
for(int j = 1; j <= 4001; j++)
F[i][j] = add(F[i][j], add(F[i - 1][j], F[i][j - 1]));
int ans = 0;
for(int i = 1; i <= n; i++)
{
ans = add(ans, F[a[i] + 2001][b[i] + 2001]);
ans = inc(ans, C(2 * a[i] + 2 * b[i], 2 * a[i]));
}
ans = (ull) ans * inv2 % Mod;
printf("%d\n", ans);
return 0;
}
| codenet | -1 | 1,294 |
s321361223 | p04051 | 1,580,488,029 | cpp | Accepted | 172 | 135,424 | #include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long MAXN=4010;
long long n,x[200010],y[200010];
long long dp[MAXN+100][MAXN+100];
long long fac[2*MAXN+100],inv[2*MAXN+100];
long long C(long long x,long long y){return fac[x]*inv[y]%mod*inv[x-y]%mod;}
long long fpm(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;
}
long long ans=0;
int main(){
scanf("%lld",&n);
for(register long long i=1;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]);
fac[0]=1;for(register long long i=1;i<=8000;i++)fac[i]=fac[i-1]*i%mod;
inv[1]=1;for(register long long i=2;i<=8000;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
inv[0]=1;for(register long long i=1;i<=8000;i++)inv[i]=inv[i-1]*inv[i]%mod;
memset(dp,0,sizeof(dp));
for(register long long i=1;i<=n;i++) dp[2005-x[i]][2005-y[i]]++;
for(register long long i=-2005+1;i<=2005;i++){
for(register long long j=-2005+1;j<=2005;j++){
dp[2005+i][2005+j]=(dp[2005+i][2005+j]+dp[2005+i][2005+j-1]+dp[2005+i-1][2005+j])%mod;
}
}
for(register long long i=1;i<=n;i++) ans=(ans+dp[2005+x[i]][2005+y[i]])%mod;
for(register long long i=1;i<=n;i++) ans=((ans-C(2ll*x[i]+2ll*y[i],2ll*x[i]))%mod+mod)%mod;
ans=ans*fpm(2,mod-2)%mod;
printf("%lld\n",ans);
return 0;
} | codenet | -1 | 1,295 |
s194794046 | p04051 | 1,556,628,835 | cpp | Accepted | 115 | 65,664 | #include <bits/stdc++.h>
inline int Pow(int x,int P,int MOD){
int ans=1;
for (;P;P>>=1,x=1LL*x*x%MOD)
if (P&1)
ans=1LL*ans*x%MOD;
return ans;
}
const int MOD=1e9+7;
const int INV2=(MOD+1)/2;
inline int add(int a,int b){return (a+=b)>=MOD?(a-MOD):a;}
inline int minus(int a,int b){return (a-=b)<0?(a+MOD):a;}
const int maxn=2e5+10;
int Fac[maxn];
int Facinv[maxn];
inline int C(int n,int m){
if (n==m||m==0)return 1;
if (n<m||n<0||m<0)return 0;
return 1LL*Fac[n]*Facinv[n-m]%MOD*Facinv[m]%MOD;
}
const int ZERO=2005;
const int maxv=4e3+10;
int n,ans;
int a[maxn];
int b[maxn];
int buc[maxv][maxv];
inline int& F(int i,int j){
return buc[i+ZERO][j+ZERO];
}
int main (){
#ifdef LOCAL
freopen("input","r",stdin);
#endif
for (int i=Fac[0]=1;i<=1e4;i++)Fac[i]=1LL*Fac[i-1]*i%MOD;
Facinv[10000]=Pow(Fac[10000],MOD-2,MOD),Facinv[0]=1;
for (int i=1e4-1;i>=1;i--)Facinv[i]=1LL*Facinv[i+1]*(i+1)%MOD;
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
++F(-a[i],-b[i]);
}
for (int i=-2e3;i<=2e3;i++)
for (int j=-2e3;j<=2e3;j++){
F(i,j)=add(F(i,j),F(i-1,j));
F(i,j)=add(F(i,j),F(i,j-1));
}
for (int i=1;i<=n;i++){
ans=add(ans,F(a[i],b[i]));
ans=minus(ans,C(a[i]+b[i]+a[i]+b[i],a[i]+a[i]));
}
printf("%lld\n",1LL*ans*INV2%MOD);
return 0;
}
| codenet | -1 | 1,295 |
s685623769 | p04051 | 1,517,188,583 | cpp | Accepted | 167 | 3,812 | #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int , int> pii;
const ll MOD = 1000*1000*1000LL + 7;
const int N = 2005;
ll d[10*N] , fact[N*10] , pfact[N*10];
vector <pii> ar[2];
ll pw(ll a , ll b){
if(b == 0)
return 1;
ll k = pw(a , b/2);
k = (k*k)%MOD;
if(b%2)
k*= a;
return (k % MOD);
}
int main(){
ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
ll ans = 0 , n , x , y , pt1 = 0 , pt2 = 0;
cin >> n;
fact[0] = 1;
for(ll i = 1 ; i < N*5 + 100 ; i++){
fact[i] = (fact[i-1]*i) % MOD;
pfact[i] = pw(fact[i] , MOD-2);
}
for(int i = 0 ; i < n ; i++){
cin >> x >> y;
ar[0].pb({N-x , N-y});
ar[1].pb({N+x , N+y});
ans -= (fact[2*x+2*y]*pfact[2*x] % MOD) * pfact[2*y] % MOD;
ans = (ans+MOD) % MOD;
}
for(int i = 0 ; i < 2 ; i++)
sort(ar[i].begin() , ar[i].end());
for(int i = 0 ; i < 2*N+10 ; i++){
for(int j = 1 ; j < 2*N+10 ; j++){
d[j] += d[j-1];
while(pt1 < n && ar[0][pt1] == mp(i , j))
d[j]++ , pt1++;
d[j] %= MOD;
while(pt2 < n && ar[1][pt2] == mp(i , j))
ans = (ans + d[j]) % MOD , pt2++;
}
}
cout << (ans*pfact[2])%MOD << endl;
return 0;
} | codenet | -1 | 1,295 |
s095861227 | p04051 | 1,468,731,600 | cpp | Accepted | 748 | 253,184 | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXN 200010
#define MOD 1000000007
int n, a[MAXN], b[MAXN];
ll dp[4010][4010], has[4010][4010], fat[8010], inv_fat[8010];
ll exp(ll a, int p){
ll resp = 1LL;
while(p>0){
if(p%2){
resp = (resp*a)%MOD;
}
a = (a*a)%MOD;
p/=2;
}
return resp;
}
int main(){
fat[0]=1;
inv_fat[0]=1;
for(ll i=1; i<=8010; i++){
fat[i] = (i*fat[i-1])%MOD;
inv_fat[i] = exp(fat[i], MOD-2);
}
while(scanf("%d", &n)!=EOF){
memset(dp, 0, sizeof(dp) );
memset(has, 0, sizeof(has));
for(int i=0; i<n; i++){
scanf("%d %d", &a[i], &b[i]);
a[i] += 2000;
b[i] += 2000;
dp[4000-a[i]][4000-b[i]]++;
has[a[i]][b[i]]++;
}
ll X=0;
for(int x=0; x<=4000; x++){
for(int y=0; y<=4000; y++){
if(x>0){
dp[x][y] = (dp[x][y] + dp[x-1][y])%MOD;
}
if(y>0){
dp[x][y] = (dp[x][y] + dp[x][y-1])%MOD;
}
X = (X + has[x][y]*dp[x][y])%MOD;
}
}
ll same=0;
for(int i=0; i<n; i++){
ll nn = (a[i]-(4000-a[i])), mm = (b[i]-(4000-b[i]));
ll parc = fat[nn+mm];
parc = (parc*inv_fat[nn])%MOD;
parc = (parc*inv_fat[mm])%MOD;
same = (same + parc)%MOD;
}
ll resp = (X - same + MOD)%MOD;
resp = (resp*inv_fat[2])%MOD;
printf("%lld\n", resp);
}
return 0;
}
| codenet | -1 | 1,296 |
s088411412 | p04051 | 1,570,776,314 | cpp | Accepted | 227 | 130,816 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 4040, maxm = 200200, mod = 1'000'000'007;
int mul(long long a, long long b){
return a * b % mod;
}
int add(int a, int b){
a += b;
if(a >= mod) a -= mod;
return a;
}
int pwr(int a, long long b){
int r = 1;
for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
return r;
}
int fat[maxm], ifat[maxm];
void init(){
fat[0] = 1;
for(int i = 1; i < maxm; i++) fat[i] = mul(i, fat[i - 1]);
ifat[maxm - 1] = pwr(fat[maxm - 1], mod - 2);
for(int i = maxm - 2; i >= 0; i--) ifat[i] = mul(ifat[i + 1], i + 1);
}
int coef(int n, int k){
if(n < k) return 0;
return mul(fat[n], mul(ifat[k], ifat[n - k]));
}
int cnt[maxn][maxn], f[maxn][maxn], x[maxm], y[maxm];
int main(){
init();
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
for(int i = 0; i < n; i++){
cnt[2001-x[i]][2001-y[i]] += 1;
cnt[x[i]+2001][y[i]+2001] += 1;
}
int ans = 0;
for(int i = 1; i < maxn; i++){
for(int j = 1; j < maxn; j++){
f[i][j] = add(f[i - 1][j], f[i][j - 1]);
if(i > 2000 && j > 2000) ans = add(ans, mul(cnt[i][j], f[i][j]));
else f[i][j] = add(f[i][j], cnt[i][j]);
}
}
for(int i = 0; i < n; i++) ans = add(ans, mod - coef(2 * x[i] + 2 * y[i], 2 * x[i]));
cout << mul(ans, (mod + 1) / 2) << endl;
return 0;
}
| codenet | -1 | 1,297 |
s735220797 | p04051 | 1,568,252,276 | cpp | Accepted | 1,432 | 61,440 | #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
#define ll long long
#define db double
#define vi vector<int>
#define pb push_back
#define mod 1000000007
int c[4005][4005];
int a[4005];
const int mxs = 4005;
void read(int &a) {
a = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
}
int main() {
for (int i = 0; i < 4005; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) c[i][j] = 1;
else {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
}
int test = 0;
int n;
if (test) n = 200000;
else
read(n);
const int pls = 2001;
ll ans = 0;
for (int i = 1; i <= n; i++) {
int x, b;
if (test) b = 1900 + rand() % 100, x = 1900 + rand() % 100;
else read(x), read(b);
x += b;
double nans = 0;
for (int j = pls - b; j <= min(mxs - 1, x + pls - b); j++) {
ll q = 1ll * a[j] * c[x][b + j - pls];
nans = (nans + q), ans = (ans + q);
}
ans -= (ll)(nans / mod) * mod;
ans %= mod;
if (ans < 0) ans += mod;
// cout << ans << ' ' << nans << endl;
for (int j = b + pls - x; j <= b + pls; j++) {
a[j] += c[x][b + pls - j];
a[j] = (a[j] >= mod ? a[j] - mod : a[j]);
}
}
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,299 |
s735220797 | p04051 | 1,568,252,276 | cpp | Accepted | 1,432 | 61,440 | #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
#define ll long long
#define db double
#define vi vector<int>
#define pb push_back
#define mod 1000000007
int c[4005][4005];
int a[4005];
const int mxs = 4005;
void read(int &a) {
a = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
}
int main() {
for (int i = 0; i < 4005; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) c[i][j] = 1;
else {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
}
int test = 0;
int n;
if (test) n = 200000;
else
read(n);
const int pls = 2001;
ll ans = 0;
for (int i = 1; i <= n; i++) {
int x, b;
if (test) b = 1900 + rand() % 100, x = 1900 + rand() % 100;
else read(x), read(b);
x += b;
double nans = 0;
for (int j = pls - b; j <= min(mxs - 1, x + pls - b); j++) {
ll q = 1ll * a[j] * c[x][b + j - pls];
nans = (nans + q), ans = (ans + q);
}
ans -= (ll)(nans / mod) * mod;
ans %= mod;
if (ans < 0) ans += mod;
// cout << ans << ' ' << nans << endl;
for (int j = b + pls - x; j <= b + pls; j++) {
a[j] += c[x][b + pls - j];
a[j] = (a[j] >= mod ? a[j] - mod : a[j]);
}
}
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,299 |
s401267934 | p04051 | 1,498,542,937 | cpp | Accepted | 278 | 130,176 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxx = 4004, maxn = 2e5 + 20, mod = 1e9 + 7, gaam = 2001;
ll dp[maxx][maxx], fac[maxn], a[maxn], b[maxn], n;
ll pw(ll a, ll b)
{
if (!b) return 1ll;
ll x = pw(a, b / 2);
x = (x * x) % mod;
if (b % 2) x = (x * a) % mod;
return x;
}
ll sel(ll a, ll b)
{
ll x = 1ll;
x = (x * fac[a]) % mod;
x = (x * pw(fac[b], mod - 2)) % mod;
x = (x * pw(fac[a-b], mod - 2)) % mod;
return x;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
fac[0] = 1ll;
for(ll i = 1; i < maxn; i++) fac[i] = (fac[i - 1] * 1ll * i) % mod;
cin >> n;
for(ll i = 0; i < n; i++) cin >> a[i] >> b[i], dp[-a[i] + gaam][-b[i] + gaam] += 1;
for(ll i = -gaam; i <= gaam; i++)
for(ll j = -gaam; j <= gaam; j++)
// if (dp[i + gaam][j + gaam] == 0)
dp[i + gaam][j + gaam] = (dp[i + gaam][j + gaam] + ((i + gaam) ? dp[i-1 + gaam][j + gaam] : 0ll)
+ ((j + gaam) ? dp[i + gaam][j-1 + gaam] : 0ll)) % mod;
// cout << i << " " << j << " " << dp[i + gaam][j + gaam] << endl;
ll ans = 0;
for(ll i = 0; i < n; i++) ans = (ans + dp[a[i] + gaam][b[i] + gaam]) % mod,
ans = (((ans - sel(a[i]*2 + b[i]*2, a[i]*2)) % mod) + mod) % mod;
ans = (ans * pw(2, mod - 2)) % mod;
cout << ans << endl;
return 0;
} | codenet | -1 | 1,300 |
s401267934 | p04051 | 1,498,542,937 | cpp | Accepted | 278 | 130,176 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxx = 4004, maxn = 2e5 + 20, mod = 1e9 + 7, gaam = 2001;
ll dp[maxx][maxx], fac[maxn], a[maxn], b[maxn], n;
ll pw(ll a, ll b)
{
if (!b) return 1ll;
ll x = pw(a, b / 2);
x = (x * x) % mod;
if (b % 2) x = (x * a) % mod;
return x;
}
ll sel(ll a, ll b)
{
ll x = 1ll;
x = (x * fac[a]) % mod;
x = (x * pw(fac[b], mod - 2)) % mod;
x = (x * pw(fac[a-b], mod - 2)) % mod;
return x;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
fac[0] = 1ll;
for(ll i = 1; i < maxn; i++) fac[i] = (fac[i - 1] * 1ll * i) % mod;
cin >> n;
for(ll i = 0; i < n; i++) cin >> a[i] >> b[i], dp[-a[i] + gaam][-b[i] + gaam] += 1;
for(ll i = -gaam; i <= gaam; i++)
for(ll j = -gaam; j <= gaam; j++)
// if (dp[i + gaam][j + gaam] == 0)
dp[i + gaam][j + gaam] = (dp[i + gaam][j + gaam] + ((i + gaam) ? dp[i-1 + gaam][j + gaam] : 0ll)
+ ((j + gaam) ? dp[i + gaam][j-1 + gaam] : 0ll)) % mod;
// cout << i << " " << j << " " << dp[i + gaam][j + gaam] << endl;
ll ans = 0;
for(ll i = 0; i < n; i++) ans = (ans + dp[a[i] + gaam][b[i] + gaam]) % mod,
ans = (((ans - sel(a[i]*2 + b[i]*2, a[i]*2)) % mod) + mod) % mod;
ans = (ans * pw(2, mod - 2)) % mod;
cout << ans << endl;
return 0;
} | codenet | -1 | 1,300 |
s015136771 | p04051 | 1,595,267,676 | cpp | Accepted | 146 | 69,684 | #include <bits/stdc++.h>
const int MAXN = 2e5 + 10, MOD = 1e9 + 7;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }
inline int inv(int a) { return Qpow(a, MOD - 2); }
int n;
int a[MAXN], b[MAXN], fac[10010], ifac[10010], dp[4100][4100];
inline void init() {
fac[0] = 1;
for (int i = 1; i <= 10000; ++i) fac[i] = mul(fac[i - 1], i);
ifac[10000] = inv(fac[10000]);
for (int i = 9999; ~i; --i) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int binom(int n, int m) { return mul(fac[n], mul(ifac[m], ifac[n - m])); }
int main() {
scanf("%d", &n), init();
for (int i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i), ++dp[2003 - a[i]][2003 - b[i]];
for (int i = 1; i <= 4010; ++i)
for (int j = 1; j <= 4010; ++j) dp[i][j] = add(add(dp[i - 1][j], dp[i][j - 1]), dp[i][j]);
int ans = 0;
for (int i = 1; i <= n; ++i) ans = add(ans, dp[2003 + a[i]][2003 + b[i]]);
for (int i = 1; i <= n; ++i) ans = sub(ans, binom(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
printf("%d\n", mul(ans, inv(2)));
return 0;
} | codenet | -1 | 1,303 |
s015136771 | p04051 | 1,595,267,676 | cpp | Accepted | 146 | 69,684 | #include <bits/stdc++.h>
const int MAXN = 2e5 + 10, MOD = 1e9 + 7;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }
inline int inv(int a) { return Qpow(a, MOD - 2); }
int n;
int a[MAXN], b[MAXN], fac[10010], ifac[10010], dp[4100][4100];
inline void init() {
fac[0] = 1;
for (int i = 1; i <= 10000; ++i) fac[i] = mul(fac[i - 1], i);
ifac[10000] = inv(fac[10000]);
for (int i = 9999; ~i; --i) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int binom(int n, int m) { return mul(fac[n], mul(ifac[m], ifac[n - m])); }
int main() {
scanf("%d", &n), init();
for (int i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i), ++dp[2003 - a[i]][2003 - b[i]];
for (int i = 1; i <= 4010; ++i)
for (int j = 1; j <= 4010; ++j) dp[i][j] = add(add(dp[i - 1][j], dp[i][j - 1]), dp[i][j]);
int ans = 0;
for (int i = 1; i <= n; ++i) ans = add(ans, dp[2003 + a[i]][2003 + b[i]]);
for (int i = 1; i <= n; ++i) ans = sub(ans, binom(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
printf("%d\n", mul(ans, inv(2)));
return 0;
} | codenet | -1 | 1,303 |
s429224630 | p04051 | 1,571,756,560 | cpp | Accepted | 284 | 162,816 | #include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
char cc = getchar() ; int cn = 0, flus = 1 ;
while( cc < '0' || cc > '9' ) { if( cc == '-' ) flus = - flus ; cc = getchar() ; }
while( cc >= '0' && cc <= '9' ) cn = cn * 10 + cc - '0', cc = getchar() ;
return cn * flus ;
}
const int P = 1e9 + 7 ;
const int N = 5000 + 5 ;
const int M = 3e5 + 5 ;
int A[M], B[M], dp[N][N], fac[N * 4], Ans, n, m ;
int fpow( int x, int k ) {
int ans = 1, base = x ;
while( k ) {
if( k & 1 ) ans = ( ans * base ) % P ;
base = ( base * base ) % P, k >>= 1 ;
} return ans ;
}
int C( int x, int y ) {
return ( fac[y] * fpow( fac[x], P - 2 ) % P ) * fpow( fac[y - x], P - 2 ) % P ;
}
signed main()
{
n = gi(), m = 2001 ; int inv2 = fpow( 2, P - 2 ) ;
rep( i, 1, n ) A[i] = gi(), B[i] = gi(), ++ dp[m - A[i]][m - B[i]] ;
rep( i, 1, 2 * m ) rep( j, 1, 2 * m ) {
dp[i][j] += ( dp[i - 1][j] + dp[i][j - 1] ) % P, dp[i][j] %= P ;
} fac[0] = 1 ;
rep( i, 1, 4 * m ) fac[i] = ( fac[i - 1] * i ) % P ;
rep( i, 1, n ) Ans += dp[m + A[i]][m + B[i]], Ans %= P ;
rep( i, 1, n ) Ans -= C( 2 * A[i], ( A[i] + B[i] ) * 2 ), Ans = ( Ans + P ) % P ;
printf("%lld\n", ( Ans * inv2 ) % P ) ;
return 0 ;
}
| codenet | -1 | 1,306 |
s408719517 | p04051 | 1,563,253,573 | cpp | Accepted | 156 | 128,896 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 3;
const int maxB = 8000 + 10;
const int mod = 1e9 + 7;
int B = 2000;
int x[maxn], y[maxn];
int fac[maxB], rev[maxB], dp[maxB][maxB];
int power(int a, int b){
if (b == 0)
return 1;
int ret = power(a, b / 2);
ret = 1ll * ret * ret % mod;
if (b & 1)
ret = 1ll * ret * a % mod;
return ret;
}
int Choose(int n, int r){
return 1ll * fac[n] * rev[r] % mod * rev[n - r] % mod;
}
int main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
fac[0] = 1;
for (int i = 1; i <= 4 * B; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
rev[4 * B] = power(fac[4 * B], mod - 2);
for (int i = 4 * B - 1; i >= 0; i--)
rev[i] = 1ll * rev[i + 1] * (i + 1) % mod;
for (int i = 0; i < n; i++)
dp[-x[i] + B][-y[i] + B] ++;
for (int i = 0; i <= 2 * B; i++){
for (int j = 0; j <= 2 * B; j++){
if (i > 0)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
if (j > 0)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
int answer = 0;
for (int i = 0; i < n; i++){
answer = (answer + dp[x[i] + B][y[i] + B]) % mod;
answer = (answer - Choose(2 * (x[i] + y[i]), 2 * x[i]) + mod) % mod;
}
cout << 1ll * answer * power(2, mod - 2) % mod << endl;
}
| codenet | -1 | 1,306 |
s316122310 | p04051 | 1,595,268,814 | cpp | Accepted | 191 | 133,976 | #include<bits/stdc++.h>
#define int ll
typedef long long ll;
using namespace std;
inline int read()
{
char c; int sign=1;
while ((c=getchar())<'0'||c>'9')
if (c=='-') sign=-1;
int res=(c-'0');
while ((c=getchar())>='0'&&c<='9')
res=(res<<1)+(res<<3)+c-'0';
return res*sign;
}
inline void print(int x)
{
if (x>9) print(x/10);
putchar(x%10+'0');
}
inline void write(int x)
{
if (x<0) putchar('-'),x=-x;
print(x);
}
const int maxn=200005;
const ll P=1e9+7;
const int T=2005;
ll jc[maxn];
int a[maxn],n,m;
ll X[maxn],Y[maxn];
ll mp[4050][4050];
ll fac[maxn],inv[maxn],ifac[maxn];
int C(int x, int y) {
return 1ll*fac[x]* ifac[y]%P*ifac[x-y]%P;
}
signed main()
{
n=read();
inv[0]=inv[1]=1;
fac[0]=ifac[0]=1;
for (int i=2;i<=10000;i++) inv[i]=1ll*(P-P/i)*inv[P%i]%P;
for (int i=1;i<=10000;i++) fac[i]=1ll*fac[i-1]*i%P;
for (int i=1;i<=10000;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%P;
for (int i=1;i<=n;i++) X[i]=read(),Y[i]=read();
for (int i=1;i<=n;i++) mp[T-X[i]][T-Y[i]]++;
for (int i=1;i<=T+T;i++)
{
for (int j=1;j<=T+T;j++)
{
mp[i][j]=(mp[i][j]+mp[i-1][j]+mp[i][j-1])%P;
}
}
ll ans=0;
for (int i=1;i<=n;i++) ans=(ans+mp[T+X[i]][T+Y[i]])%P;
for (int i=1;i<=n;i++) ans=(ans+P-C(2*X[i]+2*Y[i],2*X[i]))%P;
printf("%lld\n",(ans*inv[2])%P);
} | codenet | -1 | 1,307 |
s316122310 | p04051 | 1,595,268,814 | cpp | Accepted | 191 | 133,976 | #include<bits/stdc++.h>
#define int ll
typedef long long ll;
using namespace std;
inline int read()
{
char c; int sign=1;
while ((c=getchar())<'0'||c>'9')
if (c=='-') sign=-1;
int res=(c-'0');
while ((c=getchar())>='0'&&c<='9')
res=(res<<1)+(res<<3)+c-'0';
return res*sign;
}
inline void print(int x)
{
if (x>9) print(x/10);
putchar(x%10+'0');
}
inline void write(int x)
{
if (x<0) putchar('-'),x=-x;
print(x);
}
const int maxn=200005;
const ll P=1e9+7;
const int T=2005;
ll jc[maxn];
int a[maxn],n,m;
ll X[maxn],Y[maxn];
ll mp[4050][4050];
ll fac[maxn],inv[maxn],ifac[maxn];
int C(int x, int y) {
return 1ll*fac[x]* ifac[y]%P*ifac[x-y]%P;
}
signed main()
{
n=read();
inv[0]=inv[1]=1;
fac[0]=ifac[0]=1;
for (int i=2;i<=10000;i++) inv[i]=1ll*(P-P/i)*inv[P%i]%P;
for (int i=1;i<=10000;i++) fac[i]=1ll*fac[i-1]*i%P;
for (int i=1;i<=10000;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%P;
for (int i=1;i<=n;i++) X[i]=read(),Y[i]=read();
for (int i=1;i<=n;i++) mp[T-X[i]][T-Y[i]]++;
for (int i=1;i<=T+T;i++)
{
for (int j=1;j<=T+T;j++)
{
mp[i][j]=(mp[i][j]+mp[i-1][j]+mp[i][j-1])%P;
}
}
ll ans=0;
for (int i=1;i<=n;i++) ans=(ans+mp[T+X[i]][T+Y[i]])%P;
for (int i=1;i<=n;i++) ans=(ans+P-C(2*X[i]+2*Y[i],2*X[i]))%P;
printf("%lld\n",(ans*inv[2])%P);
} | codenet | -1 | 1,307 |
s724389619 | p04051 | 1,536,679,587 | cpp | Accepted | 189 | 64,384 | #include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 200001
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
while(ch=getchar(),ch<33);
if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
while(ch=getchar(),ch>33)x=x*10+ch-48;
if(fs)x=-x;
}
using namespace std;
const int mod=1000000007;
int n,ans,a[N],b[N],f[4001][4001],fac[8001],ifac[8001],inv[8001];
int C(int n,int m)
{
return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
re(n);
for(int i=1;i<=n;++i)
re(a[i]),re(b[i]),f[2000-a[i]][2000-b[i]]++;
for(int i=0;i<=4000;++i)
for(int j=0;j<=4000;++j)
f[i][j]=(((i?f[i-1][j]:0)+(j?f[i][j-1]:0))%mod+f[i][j])%mod;
fac[0]=ifac[0]=inv[0]=inv[1]=1;
for(int i=1;i<=8000;++i)
{
if(i>1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
fac[i]=1ll*fac[i-1]*i%mod;
ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
}
for(int i=1;i<=n;++i)
ans=(ans+f[a[i]+2000][b[i]+2000]-C((a[i]+b[i])*2,a[i]+a[i]))%mod;
ans=(1ll*ans*inv[2]%mod+mod)%mod;
printf("%d\n",ans);
}
/*
ans = sigma C(ai+bi+aj+bj,ai+aj)
*/ | codenet | -1 | 1,307 |
s831130001 | p04051 | 1,538,435,108 | cpp | Accepted | 147 | 128,768 | #include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<climits>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
return x*f;
}
#define MAXV 2000
#define MAXN 200000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
LL fac[4*MAXV+5],inv[4*MAXV+5];
LL f[2*MAXV+5][2*MAXV+5],a[MAXN+5],b[MAXN+5];
LL Pow(LL x,LL y){
LL ret=1;
while(y){
if(y&1) ret=ret*x%Mod;
x=x*x%Mod;
y>>=1;
}
return ret;
}
inline LL C(int n,int m){return fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int main(){
int n=read();
for(int i=1;i<=n;i++){
a[i]=read(),b[i]=read();
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]+f[i][j-1])%Mod;
fac[0]=1;
for(int i=1;i<=4*MAXV+2;i++)
fac[i]=fac[i-1]*i%Mod;
inv[4*MAXV+2]=Pow(fac[4*MAXV+2],Mod-2);
for(int i=4*MAXV+1;i>=0;i--)
inv[i]=inv[i+1]*(i+1)%Mod;
LL 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]+b[i])<<1,a[i]<<1))%Mod+Mod)%Mod;
printf("%lld\n",ans*Pow(2,Mod-2)%Mod);
return 0;
} | codenet | -1 | 1,313 |
s074025235 | p04051 | 1,533,321,233 | cpp | Accepted | 181 | 134,016 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define int ll
const int maxn = 2e5 + 20;
const int maxm = 2e3 + 20;
const int mod = 1e9 + 7;
int dp[2 * maxm][2 * maxm] , a[maxn] , b[maxn] , fac[maxn] , caf[maxn];
void mkay(int &a)
{
a %= mod;
if(a < 0)
a += mod;
}
int bpw(int a , int b)
{
if(!b)
return 1;
int x = bpw(a , b / 2);
x = 1LL * x * x % mod;
if(b&1)
x = 1LL * x * a % mod;
return x;
}
int c(int s , int r)
{
if(r < 0 || r > s)
return 0;
return 1LL * (1LL * fac[s] * caf[r] % mod) * caf[s - r] % mod;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fac[0] = 1;
for(int i = 1; i < maxn; i++)
fac[i] = 1LL * fac[i - 1] * i % mod;
caf[maxn - 1] = bpw(fac[maxn - 1] , mod - 2);
for(int i = maxn - 1; i > 0; i--)
caf[i - 1] = 1LL * caf[i] * i % mod;
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i] , dp[-a[i] + maxm][-b[i] + maxm]++;
for(int i = 1; i < 2 * maxm; i++)
for(int j = 1; j < 2 * maxm; j++)
mkay(dp[i][j] += dp[i - 1][j] + dp[i][j - 1]);
int res = 0;
for(int i = 0; i < n; i++)
{
mkay(res += dp[a[i] + maxm][b[i] + maxm]);
mkay(res -= c((a[i] + b[i]) * 2 , 2 * a[i]));
}
res = 1LL * res * bpw(2 , mod - 2) % mod;
cout << res << endl;
}
| codenet | -1 | 1,315 |
s438984156 | p04051 | 1,509,249,643 | cpp | Accepted | 199 | 102,016 | #include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int offset = 2010;
const int md = 1e9 + 7;
int n;
int a[N], b[N];
vector<int> _get[offset + offset];
int f[offset + offset][offset + offset];
int upd[offset + offset][offset + offset];
int ans;
int fact[N], inv[N];
void add(int &x, int y) { x += y; x %= md; if(x < 0) x += md; }
int pw(int a, int b) {
int res = 1;
for(int i = 0; (1LL << i) <= b; ++i) {
if (b & (1LL << i)) res = 1LL * res * a % md;
a = 1LL * a * a % md;
}
return res;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
_get[a[i] + offset].push_back(b[i] + offset);
upd[-a[i] + offset][-b[i] + offset]++;
}
for(int x = 0; x < offset + offset; ++x) {
for(int y = 0; y < offset + offset; ++y) {
if(x > 0) add(f[x][y], f[x - 1][y]);
if(y > 0) add(f[x][y], f[x][y - 1]);
if(upd[x][y]) add(f[x][y], upd[x][y]);
}
for (int y : _get[x]) add(ans, f[x][y]);
}
fact[0] = 1; for(int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % md;
for(int i = 0; i < N; ++i) inv[i] = pw(fact[i], md - 2);
for(int i = 1; i <= n; ++i) {
int A = a[i] * 2, B = b[i] * 2;
add(ans, md - (1LL * fact[A + B] * (1LL * inv[A] * inv[B] % md) % md));
}
ans = 1LL * ans * pw(2, md - 2) % md;
printf("%d\n", ans);
} | codenet | -1 | 1,315 |
s660943854 | p04051 | 1,543,198,876 | cpp | Accepted | 130 | 64,640 | #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
const int N=2005;
const int M=2e5+5;
const int mod=1e9+7;
int n,mx,x[M],y[M],C[N<<1][N<<1];
int fac[N<<3],infac[N<<3],inv[N<<3];
void init()
{
int i;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%d%d",&x[i],&y[i]);
mx=max(mx,x[i]),mx=max(mx,y[i]);
}
// cout<<mx<<"#######"<<endl;
for(i=1;i<=n;++i) ++C[x[i]+mx][y[i]+mx];
// cout<<C[4][3]<<"++++++++"<<endl;
}
void work()
{
int i,j;
for(i=2*mx;~i;--i)
for(j=2*mx;~j;--j)
{
C[i][j]+=C[i+1][j];
if(C[i][j]>=mod) C[i][j]-=mod;
C[i][j]+=C[i][j+1];
if(C[i][j]>=mod) C[i][j]-=mod;
}
}
void prework()
{
int i,mm=mx<<2,kk=mx<<1;
fac[0]=1;for(i=1;i<=mm;++i) fac[i]=1LL*fac[i-1]*i%mod;
inv[1]=1;for(i=2;i<=kk;++i) inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
infac[0]=1;for(i=1;i<=kk;++i) infac[i]=1LL*infac[i-1]*inv[i]%mod;
}
int CC(int x,int y)
{
return 1LL*fac[x]*infac[x-y]%mod*infac[y]%mod;
}
void calc()
{
int i,ans=0;
for(i=1;i<=n;++i)
{
ans-=CC(2*x[i]+2*y[i],x[i]+x[i]);
if(ans<0) ans+=mod;
}
for(i=1;i<=n;++i)
{
ans+=1LL*C[-x[i]+mx][-y[i]+mx];
if(ans>=mod) ans-=mod;
}
printf("%d\n",500000004LL*ans%mod);
}
int main()
{
init();
work();
prework();
calc();
return 0;
} | codenet | -1 | 1,316 |
s415664082 | p04051 | 1,548,386,132 | cpp | Accepted | 278 | 187,776 | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>
using namespace std;
typedef long long ll;
const int MAXN = 4005;
const int MOD = 1000000007;
int n,ans1,ans2;
int f[MAXN << 1][MAXN];
int mrk[MAXN][MAXN];
int power(int a,int b)
{
int res = 1;
while (b)
{
if (b & 1)
res = (ll)res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
for (int i = 0;i <= 8000;i++)
{
f[i][0] = 1;
for (int j = 1;j <= min(i,4000);j++)
f[i][j] = (f[i - 1][j] + f[i - 1][j - 1]) % MOD;
}
cin >> n;
for (int a,b,i = 1;i <= n;i++)
{
cin >> a >> b;
(ans2 += f[(a + b) << 1][a << 1]) %= MOD;
mrk[2000 - a][2000 - b]++;
mrk[2000 + a][2000 + b]++;
}
memset(f,0,sizeof(f));
for (int i = 0;i <= 4000;i++)
for (int j = 0;j <= 4000;j++)
{
if (i < 2000 && j < 2000)
f[i][j] = mrk[i][j];
if (i)
(f[i][j] += f[i - 1][j]) %= MOD;
if (j)
(f[i][j] += f[i][j - 1]) %= MOD;
if (i > 2000 && j > 2000)
ans1 = ((ll)mrk[i][j] * f[i][j] + ans1) % MOD;
}
cout << ((ll)(ans1 - ans2 + MOD) * (MOD + 1) / 2) % MOD << endl;
return 0;
} | codenet | -1 | 1,317 |
s635095603 | p04051 | 1,527,020,775 | cpp | Accepted | 145 | 67,840 | #include<cstdio>
using namespace std;
typedef long long LL;
const int N=4003,M=200005,p=1000000007;
int A[M],B[M],c[N<<1],fc[N<<1],f[N][N],i,j,k,n,m,an,D=2001,X=8000,ni2=p+1>>1;
inline char getc()
{
#define VV 10000000
static char s[VV],*l=s,*r=s;
if (l==r)
l=s,r=s+fread(s,1,VV,stdin);
return l==r?0:*l++;
}
int read(){ char c; int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }
void Plus(int &a,int b){ a+=b,a-=a<p?0:p; }
void Minus(int &a,int b){ a-=b,a+=a<0?p:0; }
int power(int z,int k)
{
int d=1;
for (;k;z=(LL)z*z%p,k>>=1) if (k&1) d=(LL)d*z%p;
return d;
}
int C(int n,int m)
{
return (LL)c[n]*fc[m]%p*fc[n-m]%p;
}
int main()
{
//freopen("1.in","r",stdin);
for (c[0]=i=1;i<=X;++i) c[i]=(LL)c[i-1]*i%p;//printf("%d %d\n",i,c[i]);
for (fc[X]=power(c[X],p-2),i=X;i;--i) fc[i-1]=(LL)fc[i]*i%p;//printf("%d %d\n",i,fc[i]);
n=read();
for (i=1;i<=n;++i) A[i]=read(),B[i]=read(),++f[-A[i]+D][-B[i]+D];
for (i=1;i<=(D<<1)-1;++i)
for (j=1;j<=(D<<1)-1;++j)
Plus(f[i][j],(f[i-1][j]+f[i][j-1])%p);
for (i=1;i<=n;++i)
Plus(an,f[A[i]+D][B[i]+D]);
//printf("%d\n",an);
for (i=1;i<=n;++i) Minus(an,C(A[i]+B[i]<<1,A[i]<<1));//printf("%d ",C(A[i]+B[i]<<1,A[i]<<1));
//puts("");
//printf("%d\n",an);
printf("%d\n",(LL)an*ni2%p);
return 0;
} | codenet | -1 | 1,317 |
s334738278 | p04051 | 1,509,677,269 | cpp | Accepted | 145 | 64,512 | #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX_N = 200005, MOD = 1000000007;
typedef long long i64;
int A[MAX_N], B[MAX_N], N;
int f[4005][4005];
i64 fac[8005], ifac[8005], inv[8005];
i64 binom(int n, int m) {
if (n < m) return 0;
return 1LL * fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i)
scanf("%d%d", &A[i], &B[i]);
i64 res = 0;
fac[0] = ifac[0] = inv[1] = 1;
for (int i = 1; i <= 8000; ++i) fac[i] = 1LL * fac[i - 1] * i % MOD;
for (int i = 2; i <= 8000; ++i) inv[i] = -1LL * (MOD / i) * inv[MOD % i] % MOD;
for (int i = 1; i <= 8000; ++i) ifac[i] = 1LL * ifac[i - 1] * inv[i] % MOD;
int base = 2001;
for (int i = 1; i <= N; ++i) f[base - A[i]][base - 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;
// i64 temp = 0;
// for (int i = 1; i <= N; ++i)
// temp = (temp + binom(A[i] + B[i], A[i]) % MOD) % MOD;
// printf("%lld %d\n", temp, f[base][base]);
for (int i = 1; i <= N; ++i)
res = (res + f[A[i] + base][B[i] + base] - binom(A[i] + B[i] + A[i] + B[i], A[i] + A[i])) % MOD;
res = res * inv[2] % MOD;
printf("%lld\n", (res + MOD) % MOD);
return 0;
}
| codenet | -1 | 1,319 |
s441711957 | p04051 | 1,468,895,841 | cpp | Accepted | 343 | 64,640 | #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
const int M = 8010;
const int L = 4010;
const int mod = 1e9 + 7;
typedef long long LL;
LL F[M], R[M];
int dp[L][L];
int X[N], Y[N];
inline void add(int &x, int y){
x += y;
if(x >= mod) x -= mod;
}
LL pow_mod(LL x, int p){
LL s = 1;
while(p){
if(p & 1) s = s * x % mod;
x = x * x % mod;
p >>= 1;
}
return s;
}
LL C(int n, int m){
return F[n] * R[m] % mod * R[n-m] % mod;
}
int main(){
F[0] = R[0] = 1;
for(int i=1; i<M; i++){
F[i] = F[i-1] * i % mod;
R[i] = pow_mod(F[i], mod-2);
}
int n;
while(~scanf("%d", &n)){
memset(dp, 0, sizeof(dp));
for(int i=0; i<n; i++){
scanf("%d %d", X+i, Y+i);
dp[2000-X[i]][2000-Y[i]]++;
}
for(int i=0; i<L; i++){
for(int j=0; j<L; j++){
if(i==0 && j==0){
continue;
} else if(i == 0){
add(dp[i][j], dp[i][j-1]);
} else if(j == 0){
add(dp[i][j], dp[i-1][j]);
} else{
add(dp[i][j], dp[i][j-1]);
add(dp[i][j], dp[i-1][j]);
}
}
}
LL ans = 0;
for(int i=0; i<n; i++){
ans = ans + dp[2000+X[i]][2000+Y[i]] - C(X[i]+Y[i]<<1, X[i]<<1);
ans = (ans % mod + mod) % mod;
}
printf("%lld\n", ans * pow_mod(2, mod-2) % mod);
}
return 0;
}
| codenet | -1 | 1,319 |
s490700690 | p04051 | 1,487,357,692 | cpp | Accepted | 146 | 133,632 | #include <bits/stdc++.h>
#define u +2000
#define mod 1000000007
#define int ll
using namespace std;
typedef long long ll;
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;
}
int n,a[300010],b[300010];
int val[4100][4100],ans;
int fac[9010],inv[9010];
void add(int &x,int y)
{
x+=y; if(x>=mod) x-=mod;
while(x<0) x+=mod;
}
inline ll qpow(ll bas,ll pw)
{
ll ans=1; for(;pw;pw>>=1,(bas*=bas)%=mod)
if(pw&1) (ans*=bas)%=mod;
return ans;
}
void init()
{
fac[0]=1; for(int i=1;i<=9000;i++) fac[i]=1ll*fac[i-1]*i%mod;
for(int i=0;i<=9000;i++) inv[i]=1ll*qpow(fac[i],mod-2)%mod;
}
inline int C(int m,int n)
{
return 1ll*fac[m]%mod*inv[m-n]%mod*inv[n]%mod;
}
signed main()
{
init(); n=read();
for(int i=1;i<=n;i++)
a[i]=read(),b[i]=read();
for(int i=1;i<=n;i++)
val[-a[i] u][-b[i] u]++;
for(int i=1;i<=4000;i++) add(val[0][i],val[0][i-1]);
for(int i=1;i<=4000;i++) add(val[i][0],val[i-1][0]);
for(int i=1;i<=4000;i++)
for(int j=1;j<=4000;j++)
add(val[i][j],val[i][j-1]),
add(val[i][j],val[i-1][j]);
for(int i=1;i<=n;i++)
add(ans,val[a[i] u][b[i] u]);
for(int i=1;i<=n;i++)
add(ans,-C(a[i]+b[i]+a[i]+b[i],a[i]+a[i]));
cout<<((ans*inv[2])%mod+mod)%mod<<endl;
return 0;
} | codenet | -1 | 1,320 |
s690159973 | p04051 | 1,564,503,876 | cpp | Accepted | 145 | 64,768 | #include <bits/stdc++.h>
using namespace std;
#define forn(i, a, b) for(int i=a; i<=b; ++i)
#define repn(i, a, b) for(int i=a; i <b; ++i)
typedef long long llong;
const int N = 4010;
const int M = 2e5 +10;
const int maxN = 2000;
const int MOD = 1e9+7;
llong gt[2*N], in[2*N];
int n, mxa, mxb, a[M], b[M];
int ans, dp[N][N];
void add(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int pw(int x, int q) {
if (!q) return 1;
llong tmp = pw(x, q>>1);
tmp = tmp * tmp % MOD;
if (q & 1) tmp = (tmp * x) % MOD;
return tmp;
}
int C(int k, int n) {
return gt[n] * in[k] % MOD * in[n-k] % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
gt[0] = in[0] = 1;
repn(i, 1, 2*N) {
gt[i] = gt[i-1] * i % MOD;
in[i] = in[i-1] * pw(i, MOD-2) % MOD;
}
int mxa = 0, mxb = 0;
forn(i, 1, n) {
cin >> a[i] >> b[i];
dp[-a[i]+maxN][-b[i]+maxN] += 1;
mxa = max(mxa, a[i]+maxN);
mxb = max(mxb, b[i]+maxN);
}
forn(i, 0, mxa) forn(j, 0, mxb) {
add(dp[i+1][j], dp[i][j]);
add(dp[i][j+1], dp[i][j]);
}
forn(i, 1, n) add(ans, dp[a[i]+maxN][b[i]+maxN]);
forn(i, 1, n) ans = (ans - C(2*a[i], 2*a[i] + 2*b[i])) % MOD;
ans = (llong) ans * in[2] % MOD;
cout << (ans + MOD) % MOD;
} | codenet | -1 | 1,321 |
s210946379 | p04051 | 1,533,318,687 | cpp | Accepted | 234 | 135,424 | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=2050;
const ll mod=1e9+7;
const ll inf=1e9+500;
int s[maxn*2][maxn*2];
int t[maxn*2][maxn*2];
int dp[maxn*2][maxn*2];
ll fac[maxn*16];
ll rfac[maxn*16];
ll poww(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
b/=2;
}
return ans;
}
ll ent(ll n,ll k){
if(k>n || k<0)return 0;
return (((fac[n]*rfac[n-k])%mod)*rfac[k])%mod;
}
int main(){
ll n;
cin>>n;
fac[0]=1;
rfac[0]=1;
for(ll i=1;i<maxn*16;i++){
fac[i]=(fac[i-1]*i)%mod;
rfac[i]=poww(fac[i],mod-2);
}
ll ans=0;
for(ll i=0;i<n;i++){
ll a,b;
cin>>a>>b;
s[-a+maxn][-b+maxn]++;
t[+a+maxn][+b+maxn]++;
ans-=ent(2*(a+b),2*a);
}
ans%=mod;
ans+=mod;
ans%=mod;
for(int i=1;i<maxn*2;i++){
for(int j=1;j<maxn*2;j++){
dp[i][j]=(dp[i-1][j]+dp[i][j-1]+s[i][j]);
if(dp[i][j]>=mod)dp[i][j]-=mod;
if(t[i][j])
ans+=((ll)t[i][j]*(ll)dp[i][j])%mod;
}
}
ans%=mod;
cout<<(ans*poww(2,mod-2))%mod;
}
| codenet | -1 | 1,322 |
s210946379 | p04051 | 1,533,318,687 | cpp | Accepted | 234 | 135,424 | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=2050;
const ll mod=1e9+7;
const ll inf=1e9+500;
int s[maxn*2][maxn*2];
int t[maxn*2][maxn*2];
int dp[maxn*2][maxn*2];
ll fac[maxn*16];
ll rfac[maxn*16];
ll poww(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
b/=2;
}
return ans;
}
ll ent(ll n,ll k){
if(k>n || k<0)return 0;
return (((fac[n]*rfac[n-k])%mod)*rfac[k])%mod;
}
int main(){
ll n;
cin>>n;
fac[0]=1;
rfac[0]=1;
for(ll i=1;i<maxn*16;i++){
fac[i]=(fac[i-1]*i)%mod;
rfac[i]=poww(fac[i],mod-2);
}
ll ans=0;
for(ll i=0;i<n;i++){
ll a,b;
cin>>a>>b;
s[-a+maxn][-b+maxn]++;
t[+a+maxn][+b+maxn]++;
ans-=ent(2*(a+b),2*a);
}
ans%=mod;
ans+=mod;
ans%=mod;
for(int i=1;i<maxn*2;i++){
for(int j=1;j<maxn*2;j++){
dp[i][j]=(dp[i-1][j]+dp[i][j-1]+s[i][j]);
if(dp[i][j]>=mod)dp[i][j]-=mod;
if(t[i][j])
ans+=((ll)t[i][j]*(ll)dp[i][j])%mod;
}
}
ans%=mod;
cout<<(ans*poww(2,mod-2))%mod;
}
| codenet | -1 | 1,322 |
s553176514 | p04051 | 1,568,403,808 | cpp | Accepted | 325 | 196,992 | #include <bits/stdc++.h>
#define rep(i,j,k) for(int i = j; i <= k; i++)
#define dow(i,j,k) for(int i = j; i >= k; i--)
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
const int M = 4105;
int n, a[N], b[N];
long long f[M<<2], inv[M<<2];
long long dp[M][M];
long long vis[M][M];
int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = res * 1ll * x % mod;
x = 1ll * x * x % mod; y >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin >> n;
rep (i, 1, n) cin >> a[i] >> b[i], vis[2000-a[i]][2000-b[i]]++;
for (int i = 0; i <= 8000; i ++) {
for (int j = 0; j <= 4000 && j <= i; j++) {
int k = i - j;
if (j != 0) dp[j][k] += vis[j-1][k] + dp[j-1][k];
if (k != 0) dp[j][k] += vis[j][k-1] + dp[j][k-1];
dp[j][k] %= mod;
}
}
long long ans = 0;
rep (i, 1, n) ans = (ans + dp[a[i] + 2000][b[i] + 2000]) % mod;
f[0] = 1; inv[0] = 1;f[1] = inv[1] = 1;
rep (i, 2, 8000) f[i] = f[i-1] * i % mod, inv[i] = qpow(f[i], mod-2);
// rep (i, 1, 10) cout << f[i] << " " << f[i] * inv[i] % mod << endl;
// rep (i, 1, n) cout << f[a[i] + b[i] << 1] * inv[a[i] + b[i]] % mod * inv[a[i] + b[i]] % mod << endl;
rep (i, 1, n) ans = (ans - f[a[i] + b[i] << 1] * inv[a[i] + a[i]] % mod * inv[b[i] + b[i]] % mod + mod) % mod;
cout << ans * inv[2] % mod << endl;
} | codenet | -1 | 1,326 |
s961490860 | p04051 | 1,537,129,250 | cpp | Accepted | 141 | 64,384 | #include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
#define MAXV 4000
#define MO 1000000007
using namespace std;
int n,A[MAXN+5],B[MAXN+5];
int dp[MAXV+5][MAXV+5];
int fact[MAXV*2+5],inv[MAXV*2+5];
int PowMod(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)
ret=1LL*ret*a%MO;
a=1LL*a*a%MO;
b>>=1;
}
return ret;
}
void prepare()
{
fact[0]=1;
for(int i=1;i<=MAXV*2;i++)
fact[i]=1LL*fact[i-1]*i%MO;
inv[MAXV*2]=PowMod(fact[MAXV*2],MO-2);
for(int i=MAXV*2-1;i>=0;i--)
inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
int C(int a,int b)
{
return 1LL*fact[a]*inv[b]%MO*inv[a-b]%MO;
}
int main()
{
// freopen("bbq.in","r",stdin);
// freopen("bbq.out","w",stdout);
prepare();
scanf("%d",&n);
int maxval=-1;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&A[i],&B[i]);
maxval=max(maxval,A[i]);
maxval=max(maxval,B[i]);
}
maxval++;
for(int i=1;i<=n;i++)
dp[maxval-A[i]][maxval-B[i]]++;
for(int i=-maxval+1;i<=maxval;i++)
for(int j=-maxval+1;j<=maxval;j++)
dp[i+maxval][j+maxval]=(1LL*dp[i+maxval][j+maxval]+1LL*dp[i-1+maxval][j+maxval]+1LL*dp[i+maxval][j-1+maxval])%MO;
int ans=0;
for(int i=1;i<=n;i++)
{
ans=(1LL*ans+1LL*dp[A[i]+maxval][B[i]+maxval])%MO;
ans=((1LL*ans-1LL*C(A[i]+B[i]+A[i]+B[i],A[i]+A[i]))%MO+MO)%MO;
}
ans=1LL*ans*PowMod(2,MO-2)%MO;
printf("%d\n",ans);
return 0;
} | codenet | -1 | 1,328 |
s495739744 | p04051 | 1,595,467,323 | cpp | Accepted | 164 | 92,720 | #include<bits/stdc++.h>
using namespace std;
typedef long long D;
const int maxn=200003,maxm=4005,N=4002,mod=1000000007;
int Plus(int x,int y){return (x+=y)>=mod?x-mod:x;}
void Pluseq(int &x,int y){if((x+=y)>=mod)x-=mod;}
int Minus(int x,int y){return Plus(x,mod-y);}
void Minuseq(int &x,int y){Pluseq(x,mod-y);}
int mul(D x,int y){return x*y%mod;}
void muleq(int &x,int y){x=mul(x,y);}
int qpow(int x,int y){
int ans=1;
while(y){
if(y&1)muleq(ans,x);
muleq(x,x);
y>>=1;
}
return ans;
}
int n,fac[maxn],facinv[maxn],dp[maxm][maxm],b[maxm][maxm],a[maxn][2];
int C(int n,int m){return mul(mul(fac[n],facinv[m]),facinv[n-m]);}
int main(){
fac[0]=1;
for(int i=1;i<maxn;i++)fac[i]=mul(fac[i-1],i);
facinv[maxn-1]=qpow(fac[maxn-1],mod-2);
for(int i=maxn-2;i>=0;i--)facinv[i]=mul(facinv[i+1],i+1);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",a[i],a[i]+1);
b[N/2-a[i][0]][N/2-a[i][1]]++;
}
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
dp[i][j]=Plus(Plus(dp[i-1][j],dp[i][j-1]),b[i][j]);
}
}
int ans=0;
for(int i=1;i<=n;i++){
Pluseq(ans,dp[N/2+a[i][0]][N/2+a[i][1]]);
Minuseq(ans,C((a[i][0]+a[i][1])*2,a[i][0]*2));
}
muleq(ans,500000004);
printf("%d\n",ans);
return 0;
} | codenet | -1 | 1,330 |
s316626517 | p04051 | 1,552,661,262 | cpp | Accepted | 147 | 70,400 | #include<bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
const int M = 2e3 + 10;
const int Mod = 1e9 + 7;
int n, a[N], b[N], cnt[N];
int fac[N], inv[N], f[M << 1][M << 1];
int add(int a, int b) {
return (a += b) >= Mod ? a - Mod : a;
}
int sub(int a, int b) {
return (a -= b) < 0 ? a + Mod : a;
}
int mul(int a, int b) {
return 1ll * a * b % Mod;
}
int fast_pow(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = mul(a, a)) {
if (b & 1) {
res = mul(res, a);
}
}
return res;
}
int C(int a, int b) {
return mul(fac[a], mul(inv[b], inv[a - b]));
}
void init(int n) {
fac[0] = inv[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = mul(fac[i - 1], i);
}
inv[n] = fast_pow(fac[n], Mod - 2);
for (int i = n - 1; i >= 1; i--) {
inv[i] = mul(inv[i + 1], i + 1);
}
}
int main() {
init(N - 1);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i], &b[i]);
f[M - a[i]][M - b[i]]++;
}
for (int i = 1; i < M * 2; i++) {
for (int j = 1; j < M * 2; j++) {
f[i][j] = add(f[i][j], add(f[i - 1][j], f[i][j - 1]));
}
}
int res = 0;
for (int i = 1; i <= n; i++) {
res = add(res, f[M + a[i]][M + b[i]]);
res = sub(res, C((a[i] + b[i]) * 2, a[i] * 2));
}
printf("%d\n", mul(res, fast_pow(2, Mod - 2)));
return 0;
} | codenet | -1 | 1,330 |
s346739205 | p04051 | 1,595,274,799 | cpp | Accepted | 203 | 132,584 | #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
typedef std::pair<int,int> pii;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
bool umin(ll& a,ll t){if(t<a)return a=t,1;return 0;}
#define MAXN 200011
#define MAXV 4011
const int mod=ll(1e9)+7;
ll f[MAXV][MAXV],a[MAXN],b[MAXN];
int D=2001;
ll fac[MAXV*2],inv[MAXV*2];
ll Qpow(ll a,ll p)
{
ll res=1;
while(p)
{
if(p&1)res=res*a%mod;
a=a*a%mod,p>>=1;
}
return res;
}
void init()
{
fac[0]=inv[0]=1;
for(ll i=1;i<MAXV*2;++i)fac[i]=fac[i-1]*i%mod,inv[i]=Qpow(fac[i],mod-2);
}
ll C(ll n,ll m){return fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
init();
ll n=read();
for(ll i=1;i<=n;++i)a[i]=read(),b[i]=read(),++f[D-a[i]][D-b[i]];
for(ll i=1;i<MAXV;++i)
for(ll j=1;j<MAXV;++j)f[i][j]=(f[i][j]+f[i][j-1]+f[i-1][j])%mod;
ll ans=0;
for(ll i=1;i<=n;++i)ans=(ans+f[D+a[i]][D+b[i]]-C(2*a[i]+2*b[i],2*a[i]))%mod;
printf("%lld",(ans*inv[2]%mod+mod)%mod);
return 0;
} | codenet | -1 | 1,332 |
s018895951 | p04051 | 1,587,482,638 | cpp | Accepted | 214 | 64,768 | #include <bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 8010;
const int mod = 1e9 + 7;
int n, a[MAXN], b[MAXN], fac[MAXM], inv[MAXM], dp[MAXM / 2 + 10][MAXM / 2 + 10], total = MAXM / 4 + 2;
int fastpow(int a, int b) {
int ret = 1;
while(b) {
if(b & 1) ret = 1ll * ret * a % mod;
b >>= 1, a = 1ll * a * a % mod;
}
return ret;
}
int getc(int n, int m) {
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
inline void work() {
fac[1] = inv[1] = 1;
for(reg int i = 2; i <= MAXM - 10; ++i) fac[i] = 1ll * fac[i - 1] * i % mod, inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for(reg int i = 2; i <= MAXM - 10; ++i) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
scanf("%d", &n);
for(reg int i = 1; i <= n; ++i) scanf("%d%d", &a[i], &b[i]), ++dp[total - a[i]][total - b[i]];
for(reg int i = 1; i <= MAXM / 2; ++i) for(reg int j = 1; j <= MAXM / 2; ++j) dp[i][j] = (dp[i][j] + (dp[i][j - 1] + dp[i - 1][j]) % mod) % mod;
int ans = 0;
for(reg int i = 1; i <= n; ++i) ans = (ans + dp[a[i] + total][b[i] + total]) % mod, ans = (ans - getc(a[i] * 2 + b[i] * 2, a[i] * 2) + mod) % mod;
printf("%d\n", 1ll * ans * fastpow(2, mod - 2) % mod);
}
int main() {
int _ = 1;
// scanf("%d", &_);
while(_--) work();
return 0;
}
| codenet | -1 | 1,332 |
s554837117 | p04051 | 1,540,511,772 | cpp | Accepted | 152 | 132,608 | #include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define re register
#define il inline
#define pi pair<int,int>
#define mk make_pair
#define fp(i,a,b) for(re int i=a;i<=b;++i)
#define fq(i,a,b) for(re int i=a;i>=b;--i)
using namespace std;
const int N=2e5+100,M=2005,mod=1e9+7;
int n,a[N],b[N],jc[N],inv[N];
ll mp[4100][4100],ans;
il int gi()
{
re int x=0,t=1;
re char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') t=-1,ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*t;
}
il ll ksm(re ll S,re ll n)
{
re ll T=S;S=1;
while(n)
{
if(n&1) S=S*T%mod;
T=T*T%mod;
n>>=1;
}
return S;
}
il ll C(re int x,re int y)
{
if(x<0||y<0||x<y) return 0;
return 1ll*jc[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
jc[0]=inv[0]=1;
fp(i,1,M<<2) jc[i]=1ll*jc[i-1]*i%mod;
inv[M<<2]=ksm(jc[M<<2],mod-2);
fq(i,(M<<2)-1,1) inv[i]=1ll*inv[i+1]*(i+1)%mod;
n=gi();
fp(i,1,n) a[i]=gi(),b[i]=gi();
fp(i,1,n) ++mp[M-a[i]][M-b[i]];
fp(i,1,4005)
fp(j,1,4005)
(mp[i][j]+=mp[i-1][j]+mp[i][j-1])%=mod;
fp(i,1,n) (ans+=mp[M+a[i]][M+b[i]])%=mod;
fp(i,1,n) (ans+=mod-C(2*a[i]+2*b[i],2*a[i]))%=mod;
printf("%lld\n",ans*ksm(2,mod-2)%mod);
return 0;
} | codenet | -1 | 1,335 |
s125575028 | p04051 | 1,577,209,390 | cpp | Accepted | 187 | 65,280 | #include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define maxn 200010
#define mod 1000000007
#define INV 500000004
using namespace std;
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct P{
int a,b;
}p[maxn];
int n;
int f[4010][4010];
int ans;
int quick_pow(int x,int p)
{
int an=1,po=x;
while(p)
{
if(p&1) an=1ll*an*po%mod;
po=1ll*po*po%mod;
p>>=1;
}
return an;
}
int fac[100010],inv[100010];
int C(int x,int y)
{
return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
n=read();
for(int i=1;i<=n;i++) p[i].a=read(),p[i].b=read();
for(int i=1;i<=n;i++) f[2001-p[i].a][2001-p[i].b]++;
for(int i=1;i<=4001;i++)
for(int j=1;j<=4001;j++) f[i][j]=((f[i-1][j]+f[i][j-1])%mod+f[i][j])%mod;
for(int i=1;i<=n;i++) ans=(ans+f[p[i].a+2001][p[i].b+2001]%mod)%mod;
fac[0]=1;
for(int i=1;i<=100000;i++) fac[i]=1ll*fac[i-1]*i%mod;
inv[100000]=quick_pow(fac[100000],mod-2);
for(int i=99999;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
for(int i=1;i<=n;i++) ans=(ans-C(2*p[i].a+2*p[i].b,2*p[i].a)+mod)%mod;
cout<<1ll*ans*INV%mod<<endl;
return 0;
} | codenet | -1 | 1,337 |
s096701641 | p04051 | 1,468,722,340 | cpp | Accepted | 885 | 129,904 | #include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[4020][4020];
typedef pair<int, int>pii;
#define SIZE 100000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
inv[1] = 1;
for (int i = 2; i <= SIZE; i++)
{
inv[i] = mod - (mod / i)*inv[mod%i] % mod;
}
kai[0] = invkai[0] = 1;
for (int i = 1; i <= SIZE; i++)
{
kai[i] = kai[i - 1] * i%mod;
invkai[i] = invkai[i - 1] * inv[i] % mod;
}
}
ll com(ll a, ll b)
{
if (b < 0 || a < b)return 0;
return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
int main()
{
int num;
scanf("%d", &num);
vector<pii>vec;
for (int i = 0; i < num; i++)
{
int za, zb;
scanf("%d%d", &za, &zb);
vec.push_back(make_pair(za, zb));
dp[2010 - za][2010 - zb]++;
}
for (int i = -2000; i <= 2000; i++)
{
for (int j = -2000; j <= 2000; j++)
{
dp[2010 + i][2010 + j] += dp[2010 + i - 1][2010 + j] + dp[2010 + i][2010 + j - 1];
dp[2010 + i][2010 + j] %= mod;
}
}
ll ans = 0;
for (int i = 0; i < num; i++)
{
ans += dp[2010 + vec[i].first][2010 + vec[i].second];
ans %= mod;
}
invinit();
for (int i = 0; i < num; i++)
{
ans += mod - com(vec[i].first * 2 + vec[i].second * 2, vec[i].first * 2);
ans %= mod;
}
ans *= (mod + 1) / 2;
ans %= mod;
printf("%lld\n", ans);
} | codenet | -1 | 1,339 |
s864413324 | p04051 | 1,537,720,079 | cpp | Accepted | 150 | 136,960 | #include<bits/stdc++.h>
#define maxn 500005
#define kcz 1000000007
#define int long long
using namespace std;
inline int read()
{
char x = getchar();
int lin = 0, f = 1;
while(x < '0' || x > '9')
{
if(x == '-') f = -1;
x = getchar();
}
while(x >= '0' && x <= '9')
{
lin = lin * 10 + x - '0';
x = getchar();
}
return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
int n,f[4002][4002],a[maxn],b[maxn],fac[maxn],ni[maxn],ans;
int ksm(int a,int b)
{
int ans = 1;
while(b)
{
if(b & 1) ans = ans * a % kcz;
a = a * a % kcz;
b >>= 1;
}
return ans;
}
int get_c(int n,int m)
{
if(n >= 0 && m >= 0 && n >= m) return fac[n] * ni[m] % kcz * ni[n - m] % kcz;
return 0;
}
void pre()
{
fac[0] = 1; ni[0] = 1;
for(int i = 1; i <= 8001; i++)
{
fac[i] = fac[i - 1] * i % kcz;
ni[i] = ksm(fac[i],kcz - 2);
}
}
main(){
n = read();
pre();
for(int i = 1; i <= n; i++)
{
a[i] = read(); b[i] = read();
++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] + f[i][j - 1]) % kcz;
for(int i = 1; i <= n; i++)
{
ans = (ans + f[2001 + a[i]][2001 + b[i]]) % kcz;
ans = (ans - get_c((a[i] << 1) + (b[i] << 1),a[i] << 1)) % kcz;
}
cout << (ans % kcz + kcz) * ksm(2,kcz - 2) % kcz;
} | codenet | -1 | 1,346 |
s539200745 | p04051 | 1,523,846,085 | cpp | Accepted | 270 | 127,360 | #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define dF2(i,a,b) for(int i=a;i>(b);--i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
#define ll long long
#define ld double
using namespace std;
typedef pair<int,int> pii;
inline int Gcd(int X,int Y){return Y?Gcd(Y,X%Y):X;}
inline ll Gcd(ll X,ll Y){return Y?Gcd(Y,X%Y):X;}
inline int Pow(int base,ll exp,int _mod){int _ans=1;for(;exp;exp>>=1,base=(ll)base*base%_mod)exp&1?_ans=(ll)_ans*base%_mod:0;return _ans;}
inline ll Pow(ll base,ll exp,ll _mod){ll _ans=1;for(;exp;exp>>=1,base=base*base%_mod)exp&1?_ans=_ans*base%_mod:0;return _ans;}
const int INF=0x3f3f3f3f;
const int Mod=1000000007;
int n,Ans;
int A[200001],B[200001];
#define rs(X) (X+2003)
// x : [-2000 , 2000] -> [3 , 4003]
int Tri[4009][4009];
int Ori[4009][4009]; // Ori[i][j] == C( i+j-2 , i-1 ) == Pascal[i-1][j-1]
int main(){
scanf("%d",&n);
F(i,1,n) scanf("%d%d",A+i,B+i), ++Tri[rs(-A[i])][rs(-B[i])];
F(i,3,4003) F(j,3,4003) Tri[i][j]=(Tri[i][j]+Tri[i][j-1]+Tri[i-1][j])%Mod;
Ori[1][1]=1;
F(i,1,4001) F(j,1,4001) Ori[i][j]=(Ori[i][j]+Ori[i][j-1]+Ori[i-1][j])%Mod;
F(i,1,n) Ans=(Ans+Tri[rs(A[i])][rs(B[i])])%Mod;
F(i,1,n) Ans=(Ans-Ori[2*A[i]+1][2*B[i]+1]+Mod)%Mod;
Ans=Ans*500000004ll%Mod;
printf("%d",Ans);
return 0;
} | codenet | -1 | 1,346 |
s857413402 | p04051 | 1,508,360,134 | cpp | Accepted | 273 | 128,768 | #include <bits/stdc++.h>
#define LL long long
using namespace std ;
void Read ( LL &x, char c = getchar(), bool f = 0 ) {
for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
for ( ; isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
}
const int modd = 1e9+7, maxn = 8005, base = 2001, N = 4002, maxN = 2e5+5 ;
LL f[4005][4005], ans = 0, n, m, a[maxN], b[maxN] ;
LL fac[8005], inv[8005] ;
LL Qpow ( LL a, LL b ) {
LL rec = 1 ;
for ( ; b ; b >>= 1, (a *= a) %= modd )
if (b&1) (rec *= a) %= modd ;
return rec ;
}
void init() {
LL i ;
fac[0] = 1 ;
for ( i = 1 ; i <= 8000 ; i ++ ) fac[i] = fac[i - 1]*i%modd ;
inv[8000] = Qpow(fac[8000], modd-2) ;
for ( i = 8000 ; i ; i -- ) inv[i - 1] = inv[i]*i%modd ;
}
LL gn ;
LL C ( LL a, LL b ) {
LL rec = fac[a] ;
(rec *= Qpow(fac[b], modd-2)) %= modd ;
(rec *= Qpow(fac[a-b], modd-2)) %= modd ;
return rec ;
}
int main() {
LL i, j, k ;
init() ;
Read(n) ;
for ( i = 1 ; i <= n ; i ++ ) {
Read(a[i]) ; Read(b[i]) ;
++f[base-a[i]][base-b[i]] ;
ans = (ans - C((a[i]+b[i])<<1,a[i]<<1) + modd)%modd ;
}
for ( i = 1 ; i <= N ; i ++ )
for ( j = 1 ; j <= N ; j ++ )
(f[i][j] += (f[i - 1][j]+f[i][j - 1])%modd)%=modd ;
for ( i = 1 ; i <= n ; i ++ ) (ans += f[base+a[i]][base+b[i]]) %= modd ;
(ans *= Qpow(2, modd-2)) %= modd ;
printf ( "%lld\n", ans ) ;
return 0 ;
} | codenet | -1 | 1,347 |
s856827702 | p04051 | 1,578,602,001 | cpp | Accepted | 234 | 67,584 | #include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 5, M = 8e3 + 10, S = 2002, L = 4e3 + 5;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair <int, int> pii;
int sum(int a, int b) {
ll k = a + b;
if(k < 0)
k += mod;
if(k >= mod)
k -= mod;
return k;
}
ll pw(int a, int b) {
if(!b)
return 1;
ll ans = pw(a, b / 2);
ans *= ans;
ans %= mod;
if(b & 1)
ans *= a;
ans %= mod;
return ans;
}
int a[N], b[N], dp[L][L];
ll fact[N], rev[N];
void prep() {
fact[0] = 1;
for (int i = 1; i < N; i++)
fact[i] = (fact[i - 1] * i) % mod;
rev[N - 1] = pw(fact[N - 1], mod - 2);
for (int i = N - 2; ~i; i--)
rev[i] = (rev[i + 1] * (i + 1)) % mod;
}
ll c(int n, int k) {
if(k > n)
return 0;
ll ans = fact[n] * rev[k];
ans %= mod;
ans *= rev[n - k];
return ans % mod;
}
int n;
int main() {
cin >> n;
prep();
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
dp[-a[i] + S][-b[i] + S]++;
}
for (int i = -2000; i <= 2000; i++) {
for (int j = -2000; j <= 2000; j++) {
dp[i + S][j + S] = sum(dp[i + S][j + S], sum(dp[i - 1 + S][j + S], dp[i + S][j - 1 + S]));
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll x = a[i], y = b[i];
ans = sum(ans, dp[x + S][y + S]);
ans = sum(ans, -c(x + x + y + y, x + x));
}
// cout << ans << "\n";
cout << (ans * pw(2, mod - 2)) % mod << "\n";
} | codenet | -1 | 1,349 |
s734202743 | p04051 | 1,490,232,542 | cpp | Accepted | 219 | 64,384 | #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout);
using namespace std;
typedef long long ll;
const int MAXN = 200005;
const int MAXM = 4005;
const int MAXD = 2000;
const int MOD = 1e9 + 7;
int n;
int A[MAXN], B[MAXN];
int f[MAXM][MAXM], ans;
int jc[MAXM << 1] = {1};
int quick_pow(int a, int x) {
int res = 1;
while (x) {
if (x & 1)
res = 1ll * res * a % MOD;
a = 1ll * a * a % MOD, x >>= 1;
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &A[i], &B[i]);
f[MAXD - A[i]][MAXD - B[i]]++;
}
for (int i = 0; i <= 4000; i++)
for (int j = 0; j <= 4000; j++) {
f[i + 1][j] = (f[i + 1][j] + f[i][j]) % MOD;
f[i][j + 1] = (f[i][j + 1] + f[i][j]) % MOD;
}
for (int i = 1; i <= n; i++)
ans = (ans + f[A[i] + MAXD][B[i] + MAXD]) % MOD;
for (int i = 1; i <= 8000; i++)
jc[i] = 1ll * jc[i - 1] * i % MOD;
for (int i = 1; i <= n; i++)
ans = (ans - 1ll * jc[(A[i] + B[i]) << 1] * quick_pow(jc[A[i] << 1], MOD - 2) % MOD * quick_pow(jc[B[i] << 1], MOD - 2)
% MOD + MOD) % MOD;
ans = 1ll * ans * 500000004 % MOD;
printf("%d", ans);
return 0;
}
| codenet | -1 | 1,352 |
s490335074 | p04051 | 1,595,275,155 | cpp | Accepted | 218 | 132,752 | #include <bits/stdc++.h>
using namespace std;
#define ZHOU 2002
#define MAXN 200010
#define MOD 1000000007
typedef long long LL;
int n;
LL a[MAXN], b[MAXN];
LL dp[ZHOU * 2 + 10][ZHOU * 2 + 10];
LL ans;
LL fac[ZHOU * 5 + 10], inv[ZHOU * 5 + 10];
inline LL ksm(LL x, LL y)
{
LL ret = 1;
while(y)
{
if(y & 1) ret = (ret * x) % MOD;
x = (x * x) % MOD;
y >>= 1;
}
return ret;
}
inline LL C(LL x, LL y){return (fac[x] * inv[y]) % MOD * inv[x - y] % MOD;}
int main()
{
scanf("%d", &n);
fac[0] = 1;
for (register int i = 1;i <= ZHOU * 5;i ++) fac[i] = (1ll * fac[i - 1] * i) % MOD;
inv[ZHOU * 5] = ksm(fac[ZHOU * 5] , MOD - 2);
for (register int i = ZHOU * 5 - 1;i >= 0;i --) inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD;
for (register int i = 1;i <= n;i ++)
{
scanf("%lld%lld", &a[i], &b[i]);
ans = ans - C((a[i] + b[i]) << 1, a[i] << 1);
ans = (ans + MOD) % MOD;
dp[ZHOU - a[i]][ZHOU - b[i]] ++;
}
for (register int i = 1;i <= ZHOU * 2 + 2;i ++)
{
for (register int j = 1;j <= ZHOU * 2 + 2;j ++)
{
dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % MOD;
}
}
for (register int i = 1;i <= n;i ++){ans = (ans + dp[ZHOU + a[i]][ZHOU + b[i]]) % MOD;}
printf("%lld\n", ans * ksm(2, MOD - 2) % MOD);
}
| codenet | -1 | 1,356 |
s744599718 | p04051 | 1,555,553,206 | cpp | Accepted | 181 | 65,536 | #include<bits/stdc++.h>
#define ha 1000000007
#define inv2 500000004
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
if(H==T) return -1;return *H++;
}
inline int read()
{
int x=0;char c=Get();
while(!isdigit(c)) c=Get();
while(isdigit(c)) x=x*10+c-'0',c=Get();
return x;
}
const int N=200010;
const int M=8000;
int fac[M+10],ifac[M+10];
int f[M/2+10][M/2+10],base=M/4+2;
int n,A[N],B[N];
int Pow(int a,int b)
{
int ans=1;
for(;b;b>>=1,a=1ll*a*a%ha)
if(b&1) ans=1ll*ans*a%ha;
return ans;
}
void Init()
{
fac[0]=1;
for(int i=1;i<=M;i++)
fac[i]=1ll*fac[i-1]*i%ha;
ifac[M]=Pow(fac[M],ha-2);
for(int i=M-1;i>=0;i--)
ifac[i]=1ll*ifac[i+1]*(i+1)%ha;
}
int C(int n,int m){return 1ll*fac[n]*ifac[m]%ha*ifac[n-m]%ha;}
int main()
{
Init(); 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<=M/2+2;i++)
for(int j=1;j<=M/2+2;j++)
f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%ha)%ha;
int ans=0;
for(int i=1;i<=n;i++)
{
ans=(ans+f[A[i]+base][B[i]+base])%ha;
ans=(ans-C(2*A[i]+2*B[i],2*A[i]))%ha;
}
ans=(ans+ha)%ha;
ans=1ll*inv2*ans%ha;
cout<<ans<<endl;
return 0;
} | codenet | -1 | 1,357 |
s299669851 | p04051 | 1,586,809,120 | cpp | Accepted | 177 | 253,440 | #include <cstdio>
#include <iostream>
inline int read() {
int x = 0; char ch = getchar();
while(ch > '9' || ch < '0') ch = getchar();
do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
return x;
}
typedef long long ll;
const int MAXN = 200001;
const int MAXM = 8001;
const int base = 2002;
const int mod = 1000000007;
int n,a[MAXN],b[MAXN];
ll map[MAXM][MAXM];
ll fac[MAXM],invfac[MAXM];
ll Quick_Pow(ll a,ll b) {
ll res = 1;
while(b) {
if(b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void Init() {
fac[0] = 1;
for(int i = 1;i <= MAXM;i++) fac[i] = fac[i - 1] * i % mod;
invfac[MAXM] = Quick_Pow(fac[MAXM],mod - 2);
for(int i = MAXM - 1;i >= 0;i--) invfac[i] = invfac[i + 1] * (i + 1) % mod;
}
ll C(int n,int m) {
return fac[n] % mod * invfac[m] % mod * invfac[n - m] % mod;
}
int main() {
n = read();
Init();
for(int i = 1;i <= n;i++) {
a[i] = read(), b[i] = read();
map[-a[i] + base][-b[i] + base]++;
}
for(int i = 1;i <= 4002;i++)
for(int j = 1;j <= 4002;j++)
map[i][j] = (map[i][j] + map[i - 1][j] + map[i][j - 1]) % mod;
ll ans = 0;
for(int i = 1;i <= n;i++) {
ans = (ans + map[a[i] + base][b[i] + base]) % mod;
ans = ((ans - C(2 * a[i] + 2 * b[i],2 * a[i])) % mod + mod) % mod;
}
std::printf("%lld\n",((ans * invfac[2]) % mod + mod) % mod);
return 0;
}
| codenet | -1 | 1,359 |
s682378006 | p04051 | 1,517,783,532 | cpp | Accepted | 119 | 65,024 | #include<bits/stdc++.h>
const int N = 200010;
const int M = 2010;
const int moder = 1e9 + 7;
const int inv2 = 5e8 + 4;
int fac[M << 2], inv[M << 2];
int a[N], b[N];
int dp[M << 1][M << 1];
int powermod(int a, int exp){
int ret = 1;
for ( ; exp > 0; exp >>= 1){
if (exp & 1){
ret = 1ll * ret * a % moder;
}
a = 1ll * a * a % moder;
}
return ret;
}
int comb(int n, int m){
if (n < m || m < 0) return 0;
return 1ll * fac[n] * inv[m] % moder * inv[n - m] % moder;
}
int main(){
fac[0] = 1;
for (int i = 1; i < M << 2; ++ i){
fac[i] = 1ll * fac[i - 1] * i % moder;
}
inv[(M << 2) - 1] = powermod(fac[(M << 2) - 1], moder - 2);
for (int i = (M << 2) - 1; i; -- i){
inv[i - 1] = 1ll * inv[i] * i % moder;
}
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++ i){
scanf("%d%d", &a[i], &b[i]);
++ dp[M - a[i]][M - b[i]];
}
for (int i = 1; i < M << 1; ++ i){
dp[0][i] = (dp[0][i - 1] + dp[0][i]) % moder;
}
for (int i = 1; i < M << 1; ++ i){
dp[i][0] = (dp[i - 1][0] + dp[i][0]) % moder;
for (int j = 1; j < M << 1; ++ j){
dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % moder;
}
}
int ans = 0;
for (int i = 0; i < n; ++ i){
ans = (ans + dp[a[i] + M][b[i] + M]) % moder;
ans = (ans - comb(a[i] + b[i] << 1, a[i] << 1) + moder) % moder;
}
ans = 1ll * ans * inv2 % moder;
printf("%d\n", ans);
return 0;
} | codenet | -1 | 1,359 |
s684696682 | p04051 | 1,601,047,459 | cpp | Accepted | 474 | 132,152 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 8000;
long long kai[MAXN+1];
long long inv[MAXN+1];
long long mod = 1e9+7;
long long mp(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
}
return res;
}
void init() {
kai[0] = 1;
for (long long i = 1; i <= MAXN; i++) kai[i] = kai[i - 1] * i % mod;
inv[MAXN] = mp(kai[MAXN], mod-2);
for (long long i = MAXN; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
}
long long calc(long long n, long long k) {
if (n < k) return 0;
return (kai[n] * inv[k]) % mod * inv[n - k] % mod;
}
int n;
ll a[200010], b[200010];
ll dp[4010][4010];
int main() {
init();
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
dp[2000-a[i]][2000-b[i]]++;
}
for (int i = 0; i <= 4000; i++) {
for (int j = 0; j <= 4000; j++) {
dp[i+1][j] += dp[i][j];
dp[i+1][j] %= mod;
dp[i][j+1] += dp[i][j];
dp[i][j+1] %= mod;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += dp[a[i]+2000][b[i]+2000];
ans %= mod;
ans += mod - calc(2 * a[i] + 2 * b[i], 2 * a[i]);
ans %= mod;
}
cout << ans * inv[2] % mod << endl;
return 0;
} | codenet | -1 | 1,360 |
s958479742 | p04051 | 1,547,216,994 | cpp | Accepted | 155 | 127,232 | #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;
const int maxn=2*1e5+5;
const int mod=1e9+7;
int n,a[maxn],b[maxn];
ll inv[4005],f[4005][4005],ans,fac[8005];
inline int rd(){
int ret=0,af=1; char gc=getchar();
while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
return ret*af;
}
void pre(){
fac[1]=inv[1]=1;
go(i,4001,2){
inv[i]=-(mod/i)*inv[mod%i];
inv[i]=(inv[i]%mod+mod)%mod;
}
go(i,4001,2)
inv[i]=(inv[i]*inv[i-1])%mod;
go(i,8001,2)
fac[i]=(fac[i-1]*i)%mod;
}
inline ll work(int i){
return fac[a[i]*2+b[i]*2]*inv[a[i]*2]%mod*inv[b[i]*2]%mod;
}
int main(){
n=rd(); pre();
go(i,n+1,1) a[i]=rd(),b[i]=rd();
go(i,n+1,1) f[2000-a[i]][2000-b[i]]++;
go(i,4001,0)
go(j,4001,0){
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;
}
go(i,n+1,1) ans=(ans+f[a[i]+2000][b[i]+2000])%mod;
go(i,n+1,1)
ans=(ans-work(i))%mod;
printf("%lld",(ans*inv[2]%mod+mod)%mod);
return 0;
}//Faze
| codenet | -1 | 1,360 |
s370500328 | p04051 | 1,530,220,539 | cpp | Accepted | 111 | 64,512 | #include<bits/stdc++.h>
using namespace std;
using LL=long long;
using Point=pair<int,int>;
const int MX=4005,mod=1000000007;
#define st first
#define nd second
int N,ans,fac[MX<<1],inv[MX<<1];
int Pool[MX][MX],*f[MX],**dp;
Point P[200005];
inline int read()
{
int x=0,c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return x;
}
inline void update(int& a,int b){((a+=b)>=mod)&&(a-=mod);}
int Inv(int u){return u==1?1:LL(mod-mod/u)*Inv(mod%u)%mod;}
inline int C(int n,int m){return (LL)fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
N=read();
for(int i=0;i<MX;i++)f[i]=Pool[i]+2002;
dp=f+2002;
fac[0]=1;
for(int i=1;i<=8000;i++)fac[i]=(LL)fac[i-1]*i%mod;
inv[8000]=Inv(fac[8000]);
for(int i=8000;i;i--)inv[i-1]=(LL)inv[i]*i%mod;
for(int i=1,x,y;i<=N;i++)
x=read(),y=read(),dp[-x][-y]+=1,P[i]=make_pair(x,y);
for(int i=-1999;i<=2000;i++)update(dp[-2000][i],dp[-2000][i-1]);
for(int i=-1999;i<=2000;i++)update(dp[i][-2000],dp[i-1][-2000]);
for(int i=-1999;i<=2000;i++)for(int j=-1999;j<=2000;j++)
update(dp[i][j],dp[i-1][j]),update(dp[i][j],dp[i][j-1]);
for(int i=1;i<=N;i++)update(ans,dp[P[i].st][P[i].nd]);
for(int i=1;i<=N;i++)update(ans,mod-C((P[i].st+P[i].nd)*2,P[i].st*2));
printf("%lld\n",(LL)ans*Inv(2)%mod);
return 0;
}
| codenet | -1 | 1,360 |
s993408316 | p04051 | 1,505,703,990 | cpp | Accepted | 149 | 127,360 | #include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int MAXN = 200010;
const ll MOD = 1000000007;
int n, a[MAXN], b[MAXN];
int x0 = 2005, y0 = 2005;
ll g[4010][4010], fac[8010];
ll ifac[8010], ans;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
for(; isdigit(ch); ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
return x * f;
}
inline ll qpow(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1LL) res = res * a % MOD;
b >>= 1, a = a * a % MOD;
}
return res;
}
int main() {
int i, j;
n = read();
for(i = 1; i <= n; i++)
a[i] = read(), b[i] = read();
fac[0] = 1;
for(i = 1; i <= 8000; i++) fac[i] = fac[i-1]*i%MOD;
ifac[8000] = qpow(fac[8000], MOD-2);
for(i = 8000; i >= 1; i--) ifac[i-1] = ifac[i]*i%MOD;
for(i = 1; i <= n; i++)
ans = (ans-fac[2*a[i]+2*b[i]]*ifac[2*a[i]]%MOD*ifac[2*b[i]]%MOD+MOD)%MOD;
for(i = 1; i <= n; i++) g[x0-a[i]][y0-b[i]]++;
for(i = -2000; i <= 2000; i++)
for(j = -2000; j <= 2000; j++)
g[i+x0][j+y0] = (g[i+x0][j+y0]+g[i+x0][j-1+y0]+g[i-1+x0][j+y0])%MOD;
/*for(i = 3; i >= -3; i--) {
for(j = -3; j <= 3; j++)
printf("%lld ", g[i+x0][j+y0]);
printf("\n");
}*/
for(i = 1; i <= n; i++)
ans = (ans+g[x0+a[i]][y0+b[i]])%MOD;
printf("%lld\n", ans*qpow(2, MOD-2)%MOD);
return 0;
}
| codenet | -1 | 1,362 |
s229843769 | p04051 | 1,534,980,385 | cpp | Accepted | 235 | 129,152 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount
#define INF 1e16
#define mod 1000000007
ll mod_pow(ll a,ll n){
ll res=1;
while(n>0){
if(n&1)res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll N;
ll A[200001],B[200001];
ll dp[4011][4011];
ll fac[8011],finv[8011];
ll comb(ll n,ll r){
if(n<0||r<0||n<r)return 0;
else return (fac[n]*finv[r]%mod)*finv[n-r]%mod;
}
int main(){
fac[0]=1;
rep(i,8000)fac[i+1]=fac[i]*(i+1)%mod;
rep(i,8001)finv[i]=mod_pow(fac[i],mod-2);
cin>>N;
rep(i,N){
cin>>A[i]>>B[i];
dp[2000-A[i]][2000-B[i]]++;
}
rep(i,4001)rep(j,4001){
(dp[i+1][j]+=dp[i][j])%=mod;
(dp[i][j+1]+=dp[i][j])%=mod;
}
ll res=0,sub=0;
rep(i,N){
(res+=dp[A[i]+2000][B[i]+2000])%=mod;
(sub+=comb(2*(A[i]+B[i]),2*A[i]))%=mod;
}
cout<<(res-sub+mod)*mod_pow(2,mod-2)%mod<<endl;
return 0;
}
| codenet | -1 | 1,366 |
s735943637 | p04051 | 1,550,891,270 | cpp | Accepted | 200 | 103,424 | #include <bits/stdc++.h>
#define res register int
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1000000007
#define gc getchar()
#define MAXN 400005
#define lc pos<<1
#define rc pos<<1|1
using namespace std;
inline int read()
{
int ch=gc,f=0;
int x=0;
while(ch<'0'||ch>'9')
{
f|=ch=='-';
ch=gc;
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=gc;
}
return f?-x:x;
}
const int kcz=INF;
int n;
int x[MAXN],y[MAXN];
int f[5005][5005];
int js[400005],inv[400005];
inline int power(int a,int p)
{
int ret=1;
while(p>0)
{
if(p&1)
ret=ret*1ll*a%kcz;
a=1ll*a*a%kcz;
p>>=1;
}
return ret;
}
inline void init(int n)
{
js[0]=inv[0]=1;
for(int i=1;i<=n;i++)
js[i]=js[i-1]*1ll*i%kcz;
inv[n]=power(js[n],kcz-2);
for(int i=n-1;i;i--)
inv[i]=inv[i+1]*1ll*(i+1)%kcz;
}
inline int C(int n,int m)
{
return js[n]*1ll*inv[m]%kcz*inv[n-m]%kcz;
}
int main()
{
n=read();
init(400000);
for(int i=1;i<=n;i++)
{
x[i]=read()+2500,y[i]=read()+2500;
f[5000-x[i]][5000-y[i]]++;
}
for(int i=1;i<=5000;i++)
for(int j=1;j<=5000;j++)
{
f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%kcz;
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans=((ans+f[x[i]][y[i]])%kcz-C(2*x[i]+2*y[i]-10000,2*x[i]-5000))%kcz;
}
printf("%d\n",(ans*1ll*inv[2]%kcz+kcz)%kcz);
return 0;
} | codenet | -1 | 1,381 |