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
|
---|---|---|---|---|---|---|---|---|---|---|
s657415179 | p04051 | 1,468,788,647 | cpp | Accepted | 1,443 | 188,160 | #include<bits/stdc++.h>
using namespace std;
const int maxm = 4012;
int f[maxm][maxm];
int m;
int mod = 1e9+7;
int ans = 0;
int x,y;
int g[maxm*2][maxm];
int maxx,maxy;
bool flag[maxm][maxm];
struct self
{
int x,y;
self(const int &xx, const int &yy)
{
x=xx;
y=yy;
}
};
queue<self> q;
void calc()
{
q.push(self(2000-maxx,2000-maxy));
flag[2000-maxx][2000-maxy]=1;
while(!q.empty())
{
self u=q.front();q.pop();
int x,y;
x=u.x;
y=u.y+1;
if(x<=maxx+2000 && y<=maxy+2000)
{
f[x][y]=(f[x][y]+f[u.x][u.y])%mod;
if(!flag[x][y])
{
flag[x][y]=1;
q.push(self(x,y));
}
}
x=u.x+1;
y=u.y;
if(x<=maxx+2000 && y<=maxy+2000)
{
f[x][y]=(f[x][y]+f[u.x][u.y])%mod;
if(!flag[x][y])
{
flag[x][y]=1;
q.push(self(x,y));
}
}
}
}
long long rev(long long a)
{
if(a==1)return 1;
return rev(mod%a)*(mod-mod/a)%mod;
}
struct node
{
int x,y;
}s[200011];
int main()
{
g[1][0]=g[1][1]=1;
for(int i=2;i<=8000;i++)
{
g[i][0]=1;
for(int j=1;j<=min(i,4000);j++)
g[i][j]=(g[i-1][j]+g[i-1][j-1])%mod;
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
s[i].x=x;s[i].y=y;
f[2000-x][2000-y]++;
maxx=max(maxx,x);
maxy=max(maxy,y);
ans=(ans+mod-g[x*2+y*2][x*2])%mod;
}
calc();
for(int i=1;i<=m;i++)
{
ans=(ans+f[s[i].x+2000][s[i].y+2000])%mod;
}
cout<<ans*rev(2)%mod<<endl;
return 0;
}
| codenet | -1 | 1,723 |
s612022136 | p04051 | 1,557,688,651 | cpp | Accepted | 370 | 189,568 | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int64 mod = 2 * 1000000007;
const int K = 2000;
const int KK = 2 * K + 1;
int col[KK][KK];
int64 dp[KK][KK];
void add(int64 &a, int64 b){
a += b;
if (a >= mod)
a -= mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
int64 answer = 0;
vector<pii> points(n);
for (int i = 0; i < n; ++i){
int x, y; cin >> x >> y;
col[K - x][K - y]++;
col[K + x][K + y]--;
points[i] = {x, y};
// add(answer, nk[2 * x + 2 * y][2 * x]);
}
sort(points.begin(), points.end(), [&](pii &a, pii &b){
return a.first + a.second < b.first + b.second;
});
vector<int64> nk(1, 1);
for (int i = 1, j = 0; j < n; ++i){
vector<int64> nnk(i + 1, 0);
nnk[0] = nnk.back() = 1;
for (int k = 1; k < i; ++k){
add(nnk[k], nk[k]);
add(nnk[k], nk[k - 1]);
}
while (j < n && 2 * (points[j].first + points[j].second) == i){
add(answer, nnk[2 * points[j].first]);
j++;
}
nk.swap(nnk);
}
answer = mod - answer;
if (answer == mod)
answer = 0;
for (int i = 0; i < KK; ++i)
for (int j = 0; j < KK; ++j){
if (col[i][j] > 0) dp[i][j] = col[i][j];
if (i) add(dp[i][j], dp[i - 1][j]);
if (j) add(dp[i][j], dp[i][j - 1]);
while (col[i][j]++ < 0)
add(answer, dp[i][j]);
}
cout << answer / 2 << endl;
return 0;
} | codenet | -1 | 1,727 |
s100442967 | p04051 | 1,596,751,412 | cpp | Accepted | 368 | 245,648 | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define ld long double
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int, int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
const ll maxn = 1e4 + 100 , N = 2000 + 30 , Q = 5000 , mod = 1e9 + 7 , INF = 1e18 , lg = 32;
int n;
int is1[Q][Q] , is2[Q][Q];
ll dp[Q][Q] , fac[maxn] , inv[maxn] , bad , ans;
inline ll power(ll a , ll b) {
ll res = 1;
while(b) {
if(b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b /= 2;
}
return res;
}
inline ll c(ll a , ll b) {
ll res = (fac[a] * inv[b]) % mod;
res = (res * inv[a - b]) % mod;
return res;
}
int main() {
fac[0] = inv[0] = 1;
for (int i = 1; i < maxn; ++i) {
fac[i] = (i * fac[i - 1]) % mod;
inv[i] = power(fac[i] , mod - 2);
}
cin >> n;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
is1[x + N][y + N]++;
is2[N + -x][N + -y]++;
bad = (bad + c(2 * (x + y) , 2 * x)) % mod;
dp[N + -x][N + -y]++;
}
for (int i = 1; i < Q; ++i) {
for (int j = 1; j < Q; ++j) {
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
if(is1[i][j]) {
ans = (ans + dp[i][j] * is1[i][j]) % mod;
}
}
}
ans -= bad;
ans += mod; ans %= mod;
ans = (ans * power(2 , mod - 2)) % mod;
cout << ans << endl;
}
| codenet | -1 | 1,728 |
s726522838 | p04051 | 1,540,496,347 | cpp | Accepted | 147 | 98,304 | # include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <iostream>
# include <math.h>
# include <algorithm>
using namespace std;
typedef long long ll;
namespace IO {
const int maxn(1 << 21 | 1);
char ibuf[maxn], *iS, *iT, c;
int f;
inline char Getc() {
return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++)) : *iS++;
}
template <class Int> inline void In(Int &x) {
for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
}
using IO :: In;
const int mod(1e9 + 7);
const int maxm(8005);
const int maxn(2e5 + 5);
inline void Inc(int &x, int y) {
if ((x += y) >= mod) x -= mod;
}
int fac[maxm], ifac[maxm], n, a[maxn], b[maxn], ans, f[4005][4005], cnt[4005][4005];
inline int C(int x, int y) {
if (y > x) return 0;
return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int main() {
fac[1] = fac[0] = 1, ifac[1] = ifac[0] = 1, In(n);
register int i, j;
for (i = 2; i <= 8000; ++i) {
fac[i] = 1LL * fac[i - 1] * i % mod;
ifac[i] = 1LL * (mod - mod / i) * ifac[mod % i] % mod;
}
for (i = 2; i <= 8000; ++i) ifac[i] = 1LL * ifac[i] * ifac[i - 1] % mod;
for (i = 1; i <= n; ++i) {
In(a[i]), In(b[i]);
Inc(ans, mod - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
++f[2000 - a[i]][2000 - b[i]];
a[i] += 2000, b[i] += 2000, ++cnt[a[i]][b[i]];
}
for (i = 0; i <= 4000; ++i)
for (j = 0; j <= 4000; ++j) {
if (i) Inc(f[i][j], f[i - 1][j]);
if (j) Inc(f[i][j], f[i][j - 1]);
if (cnt[i][j]) Inc(ans, 1LL * f[i][j] * cnt[i][j] % mod);
}
ans = 1LL * ans * ((mod + 1) / 2) % mod;
printf("%d\n", ans);
return 0;
} | codenet | -1 | 1,729 |
s570538428 | p04051 | 1,575,317,539 | cpp | Accepted | 79 | 65,920 | #include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}
namespace ae86
{
const int bufl = 1<<15;
char buf[bufl],*s=buf,*t=buf;
inline int fetch()
{
if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
return *s++;
}
inline int ty()
{
int a=0,b=1,c=fetch();
while(!isdigit(c))b^=c=='-',c=fetch();
while(isdigit(c))a=a*10+c-48,c=fetch();
return b?a:-a;
}
}
using ae86::ty;
const int _ = 200007 , N = 2000 , _N = N + N + 3 , mo = 1000000007;
template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
inline lint powa(lint a,lint t)
{
lint b=1;
while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
return b;
}
inline lint inva(lint a)
{
return powa(a,mo-2);
}
int jc[_],rjc[_];
inline void fuck(int n=_-1)
{
jc[0]=jc[1]=rjc[0]=1;
for(int i=2;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mo;
rjc[n]=inva(jc[n]);
for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}
inline lint C(int n,int m)
{
if(n<m || n<0 || m<0)return 0;
return 1ll*jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}
int n,va[_],vb[_],g[_N][_N]={0};
#define gs(a,b) (g[(a)+N+1][(b)+N+1])
int main()
{
n=ty();
for(int i=1;i<=n;i++)va[i]=ty(),vb[i]=ty(),gs(-va[i],-vb[i])++;
fuck();
lint ans=0;
for(int i=-N;i<=N;i++)
for(int j=-N;j<=N;j++)
ad(gs(i,j),gs(i-1,j)),ad(gs(i,j),gs(i,j-1));
for(int i=1;i<=n;i++)
ad(ans,gs(va[i],vb[i])),dl(ans,C(va[i]+va[i]+vb[i]+vb[i],va[i]+va[i]));
printf("%lld\n",ans*inva(2)%mo);
return 0;
}
| codenet | -1 | 1,731 |
s048109052 | p04051 | 1,579,622,332 | cpp | Accepted | 155 | 160,128 | #include <bits/stdc++.h>
#define itn int
#define gI gi
#define int long long
using namespace std;
typedef long long ll;
inline int gi()
{
int f = 1, x = 0; 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;
}
inline ll gl()
{
ll f = 1, x = 0; 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;
}
const int N = 200003, maxn = 16003, maxm = 5003, mod = 1000000007;
int inv[maxn], jc[maxn], f[maxm][maxm];
int n, m, x[N], y[N], ans;
inline int qpow(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1) res = res * a % mod;
a = a * a % mod, b >>= 1;
}
return res % mod;
}
inline int C(int x, int y)
{
return jc[x] % mod * inv[y] % mod * inv[x - y] % mod;
}
signed main()
{
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
n = gi();
int ds = 2002;
jc[0] = 1;
for (int i = 1; i <= 8000; i+=1) jc[i] = jc[i - 1] * i % mod;
inv[8000] = qpow(jc[8000], mod - 2);
for (int i = 7999; i >= 0; i-=1) inv[i] = inv[i + 1] * (i + 1) % mod;
for (int i = 1; i <= n; i+=1)
{
x[i] = gi(), y[i] = gi();
++f[ds - x[i]][ds - y[i]];
}
for (int i = 1; i <= ds + 2000; i+=1)
{
for (int j = 1; j <= ds + 2000; j+=1)
{
f[i][j] = (1ll * f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;
}
}
for (int i = 1; i <= n; i+=1)
{
(ans += f[ds + x[i]][ds + y[i]]) %= mod;
//cout << ans << endl;
(ans -= C(x[i] * 2 + y[i] * 2, x[i] * 2)) %= mod;
//cout << ans << endl << endl;
}
(ans += mod) %= mod;
(ans *= 500000004) %= mod;
printf("%lld\n", ans % mod);
return 0;
} | codenet | -1 | 1,735 |
s982262012 | p04051 | 1,468,771,026 | cpp | Accepted | 773 | 129,664 | #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>
const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, -1, 0, 1 };
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int MAXN = 200200;
const int MAXM = 2022;
const int MOD = 1e9 + 7;
const int inv2 = 5e8 + 4;
int A[MAXN], B[MAXN];
ll fact[4 * MAXM], rfact[4 * MAXM];
ll dp[2 * MAXM][2 * MAXM];
ll mod_pow(ll x, ll p, ll MOD) {
ll a = 1;
while (p) {
if (p%2) a = a*x%MOD;
x = x*x%MOD;
p/=2;
}
return a;
}
// mod_inverse
ll mod_inverse(ll a, ll m) {
return mod_pow(a, m-2, m);
}
ll nCr(int n, int r) {
return fact[n] * rfact[r] % MOD * rfact[n - r]%MOD;
}
int main() {
fact[0] = rfact[0] = 1;
for (int i = 1; i < 4 * MAXM; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
rfact[i] = mod_inverse(fact[i], MOD);
}
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
dp[MAXM - A[i]][MAXM - B[i]] += 1;
}
for (int x = 1; x < 2 * MAXM; x++) for (int y = 1; y < 2 * MAXM; y++) {
dp[x][y] += dp[x - 1][y] + dp[x][y - 1];
dp[x][y] %= MOD;
}
ll ans = 0;
for (int i = 0; i < N; i++) {
(ans += dp[MAXM + A[i]][MAXM + B[i]]) %= MOD;
(ans -= nCr(2 * A[i] + 2 * B[i], 2 * A[i])) %= MOD;
if (ans < 0) ans += MOD;
}
(ans *= inv2) %= MOD;
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,741 |
s987161931 | p04051 | 1,588,959,923 | cpp | Accepted | 173 | 161,664 | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif
const ll MOD=1e9+7,tw=MOD+1>>1,C=2005;
ll a[200005],b[200005];
ll dp[5000][5000],J[10000],inv[10000],invJ[10000];
int main()
{
IOS();
ll n,ans=0,mix=MOD,miy=MOD,mxx=0,mxy=0;
cin >> n,J[0]=J[1]=inv[1]=invJ[0]=invJ[1]=1;
for(int i=2;i<=4*C;++i)
J[i]=J[i-1]*i%MOD,inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD,invJ[i]=invJ[i-1]*inv[i]%MOD;
for(int i=0;i<n;++i)
cin >> a[i] >> b[i],++dp[C-a[i]][C-b[i]],mix=min(mix,C-a[i]),miy=min(miy,C-b[i]),mxx=max(mxx,C+a[i]),mxy=max(mxy,C+b[i]);
for(int i=mix;i<=mxx;++i)
for(int j=miy;j<=mxy;++j)
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
for(int i=0;i<n;++i)
ans=(ans+dp[C+a[i]][C+b[i]]+MOD-J[a[i]+a[i]+b[i]+b[i]]*invJ[a[i]+a[i]]%MOD*invJ[b[i]+b[i]]%MOD)%MOD;
cout << ans*tw%MOD << "\n";
} | codenet | -1 | 1,746 |
s990332096 | p04051 | 1,584,148,490 | cpp | Accepted | 195 | 166,144 | #include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#define LL long long
using namespace std;
const int maxa=2010;
const int maxn=2000100;
const int mod=1e9+7;
const int maxc=40010;
LL ans;
int n;
int a[maxn];
int b[maxn];
int ma[maxa*2][maxa*2];
LL f[maxa*2][maxa*2];
LL fac[maxc], inv[maxc];
LL power_mod(LL p, LL q) {
LL ret = 1;
while (q) {
if (q & 1) ret = ret * p % mod;
p = p * p % mod;
q >>= 1;
}
return ret;
}
void init() {
fac[0] = 1;
for (int i = 1; i <= maxc - 10; ++i) fac[i] = fac[i - 1] * i % mod;
inv[maxc - 10] = power_mod(fac[maxc - 10], mod - 2);
for (int i = maxc - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}
LL C(int x, int y) {
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main(){
//freopen("P2742_8.in","r",stdin);
int maxa=0;
int maxb=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int p,q;
scanf("%d%d",&p,&q);
a[i]=p;
b[i]=q;
ma[p][q]++;
if (p>maxa) maxa=p;
if (q>maxb) maxb=q;
}
init();
for(int i=1;i<=2*maxa+1;i++){
for(int j=1;j<=2*maxb+1;j++){
f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
if (maxa+1-i>=0 && maxb+1-j>=0){
f[i][j]+=ma[maxa+1-i][maxb+1-j];
f[i][j]%=mod;
}
}
}
LL ans=0;
for(int i=1;i<=n;i++){
int p,q;
p=a[i]+maxa+1;
q=b[i]+maxb+1;
ans=(ans+f[p][q])%mod;
}
for (int i=1;i<=n;i++){
ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod) % mod;
}
printf("%lld",ans * power_mod(2, mod - 2) % mod);
//fclose(stdin);
}
| codenet | -1 | 1,752 |
s708069885 | p04051 | 1,509,324,770 | cpp | Accepted | 153 | 64,512 | #include <cstdio>
#include <iostream>
#define rs register short
#define ri register int
using namespace std;
typedef long long LL;
const int N = 2001;
const int K = N << 2;
const int M = 2e5 + 5;
const LL mod = 1e9 + 7;
template <typename T> inline void read(T &x) {
char ch; x = 0;
while (!isdigit(ch = getchar()));
do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}
namespace MathCal {
LL fac[K], inv[K];
inline LL Co(int x, int y) {
if (x < y) return 0;
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
inline LL pow(LL x, LL exp) {
LL ret = 1;
for (; exp; exp >>= 1, x = x * x % mod)
if (exp & 1) ret = ret * x % mod;
return ret;
}
inline void pre() {
for (int i = fac[0] = 1; i < K; i ++) fac[i] = fac[i - 1] * i % mod;
inv[K - 1] = pow(fac[K - 1], mod - 2);
for (int i = K - 1; i >= 1; i --) inv[i - 1] = inv[i] * i % mod;
}
}
using namespace MathCal;
int dp[N << 1][N << 1];
int a[M], b[M], n;
inline void adj(int &x) {
if (x >= mod) x -= mod;
}
int main() {
int Maxx = 0, Maxy = 0;
pre();
read(n);
for (ri i = 1; i <= n; i ++) {
read(a[i]); read(b[i]);
Maxx = max(Maxx, a[i]);
Maxy = max(Maxy, b[i]);
dp[N - a[i]][N - b[i]] ++;
}
int A = N - Maxx, B = N + Maxx, C = N - Maxy, D = N + Maxy;
for (rs i = A; i <= B; i ++)
for (rs j = C; j <= D; j ++) {
dp[i][j] += dp[i - 1][j];
adj(dp[i][j]);
dp[i][j] += dp[i][j - 1];
adj(dp[i][j]);
}
LL ans = 0;
for (ri i = 1; i <= n; i ++) {
ans += dp[a[i] + N][b[i] + N] - Co(a[i] + a[i] + b[i] + b[i], a[i] + a[i]);
if (ans < 0) ans += mod;
if (ans >= mod) ans -= mod;
}
printf("%lld\n", ans * pow(2LL, mod - 2) % mod);
return 0;
}
| codenet | -1 | 1,754 |
s708069885 | p04051 | 1,509,324,770 | cpp | Accepted | 153 | 64,512 | #include <cstdio>
#include <iostream>
#define rs register short
#define ri register int
using namespace std;
typedef long long LL;
const int N = 2001;
const int K = N << 2;
const int M = 2e5 + 5;
const LL mod = 1e9 + 7;
template <typename T> inline void read(T &x) {
char ch; x = 0;
while (!isdigit(ch = getchar()));
do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}
namespace MathCal {
LL fac[K], inv[K];
inline LL Co(int x, int y) {
if (x < y) return 0;
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
inline LL pow(LL x, LL exp) {
LL ret = 1;
for (; exp; exp >>= 1, x = x * x % mod)
if (exp & 1) ret = ret * x % mod;
return ret;
}
inline void pre() {
for (int i = fac[0] = 1; i < K; i ++) fac[i] = fac[i - 1] * i % mod;
inv[K - 1] = pow(fac[K - 1], mod - 2);
for (int i = K - 1; i >= 1; i --) inv[i - 1] = inv[i] * i % mod;
}
}
using namespace MathCal;
int dp[N << 1][N << 1];
int a[M], b[M], n;
inline void adj(int &x) {
if (x >= mod) x -= mod;
}
int main() {
int Maxx = 0, Maxy = 0;
pre();
read(n);
for (ri i = 1; i <= n; i ++) {
read(a[i]); read(b[i]);
Maxx = max(Maxx, a[i]);
Maxy = max(Maxy, b[i]);
dp[N - a[i]][N - b[i]] ++;
}
int A = N - Maxx, B = N + Maxx, C = N - Maxy, D = N + Maxy;
for (rs i = A; i <= B; i ++)
for (rs j = C; j <= D; j ++) {
dp[i][j] += dp[i - 1][j];
adj(dp[i][j]);
dp[i][j] += dp[i][j - 1];
adj(dp[i][j]);
}
LL ans = 0;
for (ri i = 1; i <= n; i ++) {
ans += dp[a[i] + N][b[i] + N] - Co(a[i] + a[i] + b[i] + b[i], a[i] + a[i]);
if (ans < 0) ans += mod;
if (ans >= mod) ans -= mod;
}
printf("%lld\n", ans * pow(2LL, mod - 2) % mod);
return 0;
}
| codenet | -1 | 1,754 |
s982266946 | p04051 | 1,470,520,057 | cpp | Accepted | 384 | 86,272 | #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <queue>
#include <set>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define N 201000
#define M 600050
#define pii pair<int,int>
#define MP make_pair
#define inf 0x3f3f3f3f
#define md ((ll+rr)>>1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define ls rt<<1
#define rs rt<<1|1
#define Pi acos(-1.0)
#define mod 1000000007
#define ui unsigned int
// curiosity , go.
LL powmod(LL a,LL b,LL p){
if(b < 0) return 0;
LL res = 1; a %= p;
for(;b;b>>=1){
if(b & 1) res = res * a % p;
a = a * a % p;
}
return res;
}
int dp[4010][4010],vis[4010][4010];
int fac[8010],invf[8010];
void add(int &a,int b){
a += b;
if(a >= mod) a -= mod;
}
int main(){
int n;
fac[1] = invf[1] = 1;
for(int i = 2; i <= 8000; i++){
fac[i] = 1LL * fac[i - 1] * i % mod;
invf[i] = (int)powmod(fac[i], mod-2, mod);
}
scanf("%d",&n);
int ans = 0;
for(int i = 1,x,y; i <= n; i++){
scanf("%d%d",&x,&y);
dp[2000-x][2000-y]++;
vis[2000+x][2000+y]++;
ans -= 1LL * fac[2*x+2*y] * invf[2*x] % mod * invf[2*y] % mod;
if(ans < 0) ans += mod;
}
//cout<<mod - ans<<endl;
for(int i = 0; i <= 4000; i++)
for(int j = 0; j <= 4000; j++){
if(i >= 1) add(dp[i][j],dp[i-1][j]);
if(j >= 1) add(dp[i][j],dp[i][j-1]);
if(vis[i][j]) add(ans, 1LL * dp[i][j] * vis[i][j] % mod);
}
printf("%d\n",1LL * ans * powmod(2, mod - 2, mod) % mod);
} | codenet | -1 | 1,758 |
s056819155 | p04051 | 1,538,613,429 | cpp | Accepted | 216 | 130,304 | #include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=200000+10,MAXM=4000+10,Mod=1e9+7,base=2001;
int n;
ll f[MAXM][MAXM],ans,fac[MAXN],inv[MAXN];
struct node{
int A,B;
};
node BBQ[MAXN];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)res=res*a%Mod;
a=a*a%Mod;
b>>=1;
}
return res;
}
inline void init()
{
fac[0]=1;
for(register int i=1;i<MAXN;++i)fac[i]=1ll*fac[i-1]*i%Mod;
inv[MAXN-1]=qexp(fac[MAXN-1],Mod-2);
for(register int i=MAXN-2;i>=0;--i)inv[i]=1ll*inv[i+1]*(i+1)%Mod;
}
inline ll C(int n,int m)
{
return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
read(n);init();
for(register int i=1;i<=n;++i)
{
int A,B;read(A);read(B);
BBQ[i]=(node){A,B};f[-A+base][-B+base]++;
}
for(register int i=1;i<=(base<<1);++i)
for(register int j=1;j<=(base<<1);++j)(f[i][j]+=(f[i-1][j]+f[i][j-1])%Mod)%=Mod;
for(register int i=1;i<=n;++i)(ans+=(f[BBQ[i].A+base][BBQ[i].B+base]-C(BBQ[i].A*2+BBQ[i].B*2,BBQ[i].A*2)+Mod)%Mod)%=Mod;
write(1ll*ans*qexp(2,Mod-2)%Mod,'\n');
return 0;
}
| codenet | -1 | 1,761 |
s395712785 | p04051 | 1,571,753,316 | cpp | Accepted | 683 | 252,160 | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define drep(i, s, t) for(re int i = t; i >= s; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 8005
#define maxm 200005
int n, m, dp[maxn][maxn], a[maxm], b[maxm], jie[maxn], inv[maxn];
il int qpow(int a, int b) {
int r = 1;
while(b) {
if(b & 1) r = 1ll * r * a % mod;
a = 1ll * a * a % mod, b >>= 1;
}
return r;
}
il int C(int a, int b) {
int x = 2 * (a + b), y = 2 * a;
return 1ll * jie[x] * (1ll * inv[y] * inv[x - y] % mod) % mod;
}
int main() {
n = read(), jie[0] = 1, inv[0] = 1;
rep(i, 1, 8000) jie[i] = 1ll * jie[i - 1] * i % mod, inv[i] = qpow(jie[i], mod - 2);
rep(i, 1, n) a[i] = read(), b[i] = read(), ++ dp[4001 - a[i]][4001 - b[i]];
rep(i, 1, 8002) {
rep(j, 1, 8002) {
dp[i][j] = ((dp[i][j] + dp[i][j - 1]) % mod + dp[i - 1][j]) % mod;
}
}
int ans = 0;
rep(i, 1, n) ans = (ans + dp[a[i] + 4001][b[i] + 4001]) % mod;
rep(i, 1, n) ans = (ans - C(a[i], b[i]) + mod) % mod;
printf("%d", 1ll * ans * qpow(2, mod - 2) % mod);
return 0;
} | codenet | -1 | 1,762 |
s442708241 | p04051 | 1,554,253,118 | cpp | Accepted | 118 | 64,384 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int mod = 1e9 + 7;
const int N = 200001;
const int M = 2001;
int read() {
int s = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * f;
}
void put(int x) {
if(x >= 10) put(x / 10);
putchar(x % 10 + '0');
}
int a[N], b[N];
int f[M * 2][M * 2], jc[M * 4], inv[M * 4];
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int dec(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}
int pow_mod(int a, int k) {
int ans = 1;
while(k) {
if(k & 1) ans = (LL)ans * a % mod;
a = (LL)a * a % mod; k /= 2;
} return ans;
}
int main() {
// freopen("bbq.in", "r", stdin);
// freopen("bbq.out", "w", stdout);
int n = read();
int mx = 0, my = 0;
for(int i = 1; i <= n; i++) {
a[i] = read(), b[i] = read();
f[M - a[i]][M - b[i]]++;
mx = _max(mx, a[i]), my = _max(my, b[i]);
} for(int i = 1; i <= M + mx; i++) for(int j = 1; j <= M + my; j++) f[i][j] = add(f[i][j], add(f[i][j - 1], f[i - 1][j]));
jc[0] = inv[0] = 1; for(int i = 1; i <= (mx + my) * 2; i++) jc[i] = (LL)jc[i - 1] * i % mod;
inv[(mx + my) * 2] = pow_mod(jc[(mx + my) * 2], mod - 2); for(int i = (mx + my) * 2 - 1; i >= 1; i--) inv[i] = (LL)inv[i + 1] * (i + 1) % mod;
int ans = 0, zz = pow_mod(2, mod - 2);
for(int i = 1; i <= n; i++) ans = add(ans, f[M + a[i]][M + b[i]]);
for(int i = 1; i <= n; i++) ans = dec(ans, C(2 * (a[i] + b[i]), a[i] + a[i]));
put((LL)ans * zz % mod);
return 0;
}
| codenet | -1 | 1,763 |
s442708241 | p04051 | 1,554,253,118 | cpp | Accepted | 118 | 64,384 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int mod = 1e9 + 7;
const int N = 200001;
const int M = 2001;
int read() {
int s = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * f;
}
void put(int x) {
if(x >= 10) put(x / 10);
putchar(x % 10 + '0');
}
int a[N], b[N];
int f[M * 2][M * 2], jc[M * 4], inv[M * 4];
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int dec(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}
int pow_mod(int a, int k) {
int ans = 1;
while(k) {
if(k & 1) ans = (LL)ans * a % mod;
a = (LL)a * a % mod; k /= 2;
} return ans;
}
int main() {
// freopen("bbq.in", "r", stdin);
// freopen("bbq.out", "w", stdout);
int n = read();
int mx = 0, my = 0;
for(int i = 1; i <= n; i++) {
a[i] = read(), b[i] = read();
f[M - a[i]][M - b[i]]++;
mx = _max(mx, a[i]), my = _max(my, b[i]);
} for(int i = 1; i <= M + mx; i++) for(int j = 1; j <= M + my; j++) f[i][j] = add(f[i][j], add(f[i][j - 1], f[i - 1][j]));
jc[0] = inv[0] = 1; for(int i = 1; i <= (mx + my) * 2; i++) jc[i] = (LL)jc[i - 1] * i % mod;
inv[(mx + my) * 2] = pow_mod(jc[(mx + my) * 2], mod - 2); for(int i = (mx + my) * 2 - 1; i >= 1; i--) inv[i] = (LL)inv[i + 1] * (i + 1) % mod;
int ans = 0, zz = pow_mod(2, mod - 2);
for(int i = 1; i <= n; i++) ans = add(ans, f[M + a[i]][M + b[i]]);
for(int i = 1; i <= n; i++) ans = dec(ans, C(2 * (a[i] + b[i]), a[i] + a[i]));
put((LL)ans * zz % mod);
return 0;
}
| codenet | -1 | 1,763 |
s251302347 | p04051 | 1,583,889,434 | cpp | Accepted | 77 | 33,280 | /*
Author: zxy_hhhh
date: 2020/03/10
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
#define ll long long
inline ll rd() {
ll _x=0;int _ch=getchar(),_f=1;
for(;!isdigit(_ch)&&(_ch!='-')&&(_ch!=EOF);_ch=getchar());
if (_ch=='-'){_f=0;_ch=getchar();}
for(;isdigit(_ch);_ch=getchar()) _x=_x*10+_ch-'0';
return _f?_x:-_x;
}
void write(ll _x){if (_x>=10) write(_x/10),putchar(_x%10+'0'); else putchar(_x+'0'); }
inline void wrt(ll _x,char _p){if (_x<0) putchar('-'),_x=-_x; write(_x); if (_p) putchar(_p);}
#define maxn 200005
#define mod 1000000007
int a[maxn],b[maxn];
int dp[2005][4005],fac[8005],inv[8005];
int n,L,R;
int main() {
n=rd();
for(int i=1;i<=n;i++) {
a[i]=rd(),b[i]=rd();
L=std::max(L,a[i]),R=std::max(R,b[i]);
}
for(int i=1;i<=n;i++) {
dp[a[i]][b[i]+R]++;
}
for(int i=L;i>=0;i--) {
for(int j=R;j>=-R;j--) {
dp[i][j+R]=((ll)dp[i+1][j+R]+dp[i][j+1+R]+dp[i][j+R])%mod;
}
}
// for(int i=0;i<=L;i++) {
// for(int j=-R;j<=R;j++) {
// wrt(dp[i][j+R],' ');
// }
// putchar('\n');
// }
int ans=0;
for(int i=-R;i<=R;i++) {
ans=(ans+1ll*dp[0][i+R]*dp[1][R-i])%mod;
}
fac[0]=inv[0]=fac[1]=inv[1]=1;
for(int i=2;i<=L+L+R+R;i++) {
fac[i]=1ll*fac[i-1]*i%mod;
inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
}
for(int i=2;i<=L+L+R+R;i++)
inv[i]=(1ll*inv[i]*inv[i-1])%mod;
for(int i=1;i<=n;i++) {
ans=(ans-1ll*fac[a[i]+b[i]+a[i]+b[i]]*inv[a[i]+a[i]]%mod*inv[b[i]+b[i]]%mod+mod)%mod;
}
wrt(1ll*ans*((mod+1)/2)%mod,'\n');
} | codenet | -1 | 1,764 |
s331733291 | p04051 | 1,534,110,659 | cpp | Accepted | 163 | 127,488 | #include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5,M=2e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
T ans=0,f=1;
char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
return ans*f;
}
template<typename T>void write(T x,char y)
{
if(x==0)
{
putchar('0'),putchar(y);
return;
}
if(x<0)
{
putchar('-');
x=-x;
}
static char wr[20];
int top=0;
for(;x;x/=10)wr[++top]=x%10+'0';
while(top)putchar(wr[top--]);
putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
freopen("E.in","r",stdin);
freopen("E.out","w",stdout);
#endif
}
const int mo=1e9+7;
int n,a[N],b[N];
void input()
{
n=read<int>();
For(i,1,n)a[i]=read<int>(),b[i]=read<int>();
}
ll dp[M*2][M*2],mc[M<<2],inv[M<<2];
ll power(ll x,int y)
{
ll res=1;
for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
return res;
}
ll C(int x,int y)
{
return mc[x]*inv[y]%mo*inv[x-y]%mo;
}
void work()
{
For(i,1,n)dp[2001-a[i]][2001-b[i]]++;
For(i,1,4001)For(j,1,4001)
{
dp[i][j]=(dp[i-1][j]+dp[i][j-1]+dp[i][j])%mo;
}
mc[0]=inv[0]=1;
For(i,1,8000)mc[i]=mc[i-1]*i%mo;
inv[8000]=power(mc[8000],mo-2);
Fordown(i,7999,1)inv[i]=inv[i+1]*(i+1)%mo;
ll ans=0;
For(i,1,n)
{
ans=(ans+dp[a[i]+2001][b[i]+2001])%mo;
ans=(ans+mo-C(a[i]+b[i]+a[i]+b[i],a[i]+a[i]))%mo;
}
write(1ll*ans*power(2,mo-2)%mo,'\n');
}
int main()
{
// file();
input();
work();
return 0;
} | codenet | -1 | 1,764 |
s906180456 | p04051 | 1,533,606,185 | cpp | Accepted | 183 | 64,512 | #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <utility>
using pii = std::pair<int, int>;
const int ha = 1000000007;
using ll = long long;
ll pow_mod(ll a, ll b) {
ll ans = 1, res = a;
while(b) {
if(1LL & b) ans = ans * res % (ll)ha;
res = res * res % (ll)ha; b >>= 1;
}
return ans;
}
ll inv(ll x) {
return pow_mod(x, ha - 2);
}
ll fac[10005], ifac[10005];
void process() {
int n = 10000;
fac[0] = 1;
for(int i = 1; i <= n; i ++) {
fac[i] = (fac[i - 1] * (ll(i))) % (ll)ha;
}
ifac[n] = inv(fac[n]);
for(int i = n - 1; i >= 0; i --) {
ifac[i] = ifac[i + 1] * (ll(i + 1)) % (ll)ha;
}
}
ll C(int x, int y) {
ll ret = fac[x];
ret = ret * ifac[x - y] % (ll)ha;
ret = ret * ifac[y] % (ll)ha;
return ret;
}
pii P[200005]; int d[4005][4005];
int n;
int dp() {
#ifdef LOCAL
puts("11111");
fflush(stdout);
#endif
for(int i = 1; i <= n; i ++) {
int x = P[i].first, y = P[i].second;
d[2000 - x][2000 - y] ++;
}
for(int dis = 1; dis <= 8000; dis ++) {
for(int i = std::max(0, dis - 4000); i <= std::min(4000, dis); i ++) {
int j = dis - i;
if(i > 0) d[i][j] = (d[i][j] + d[i - 1][j]) % ha;
if(j > 0) d[i][j] = (d[i][j] + d[i][j - 1]) % ha;
}
}
#ifdef LOCAL
puts("Gou!"); fflush(stdout);
#endif
int ans = 0;
for(int i = 1; i <= n; i ++) {
int x = P[i].first, y = P[i].second;
ans = (ans + d[x + 2000][y + 2000]) % ha;
ans = (ans - C(2 * x + 2 * y, 2 * x) + ha) % ha;
}
static const ll inv_2 = 500000004;
ans = (((ll(ans)) * inv_2) % (ll)ha);
return ans;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%d%d", &P[i].first, &P[i].second);
}
process();
printf("%d\n", dp());
return 0;
} | codenet | -1 | 1,769 |
s624033547 | p04051 | 1,539,651,448 | cpp | Accepted | 149 | 128,896 | /*
Author: CNYALI_LK
LANG: C++
PROG: e.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T>ll chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>ll chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>ll dcmp(T a,T b){return a>b;}
template<ll *a>ll cmp_a(ll x,ll y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
ll read(){
ll s=0;
ll base=0;
char c;
while(!isdigit(c=getchar()))if(c=='-')base=1;
while(isdigit(c)){s=s*10+(c^48);c=getchar();}
if(base)s=-s;
return s;
}
ll x[200005],y[200005];
ll f[4005][4005],fac[8005],inv[8005],invf[8005];
const ll p=1000000007,t=2001;
int main(){
#ifdef cnyali_lk
freopen("e.in","r",stdin);
freopen("e.out","w",stdout);
#endif
ll n;
fac[0]=fac[1]=inv[1]=invf[0]=invf[1]=1;
for(ll i=2;i<=t*4;++i){
fac[i]=fac[i-1]*i%p;
inv[i]=(p-p/i)*inv[p%i]%p;
invf[i]=invf[i-1]*inv[i]%p;
}
n=read();
for(ll i=1;i<=n;++i){
x[i]=read();y[i]=read();
++f[t-x[i]][t-y[i]];
}
for(ll i=1;i<=t*2;++i)for(ll j=1;j<=t*2;++j)f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%p;
ll cnt=0;
for(ll i=1;i<=n;++i)cnt=(cnt+f[t+x[i]][t+y[i]]-fac[x[i]*2+y[i]*2]*invf[x[i]*2]%p*invf[y[i]*2]%p+p)%p;
printf("%lld\n",cnt*((p+1)>>1)%p);
return 0;
}
| codenet | -1 | 1,786 |
s328677824 | p04051 | 1,576,520,381 | cpp | Accepted | 76 | 64,768 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)
template<typename T>
inline void read(T &x) {
char ch, t = 0; x = 0;
while(!isdigit(ch = ge)) t |= ch == '-';
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }
template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }
const int MAXN = 200010;
const int mod = 1e9 + 7;
inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int&x, int y) { x = Mod(x + y); }
inline int ksm(int x, int k = mod - 2) {
int s = 1;
while(k) {
if(k & 1) s = 1LL * s * x % mod;
x = 1LL * x * x % mod, k >>= 1;
} return s;
}
int fac[8010];
int ifac[8010];
int f[4010][4010];
int X[MAXN];
int Y[MAXN];
int main() {
#ifdef LOCAL
FILE("");
#endif
int n = ri;
int res = 0, t = 2001;
fac[0] = ifac[0] = 1;
for(int i = 1; i <= 8000; i++)
ifac[i] = ksm(fac[i] = 1LL * fac[i - 1] * i % mod);
for(register int i = 1; i <= n; i++) {
int x = X[i] = ri, y = Y[i] = ri, s = x + y;
res = (res + 1LL * fac[s << 1] * ifac[y << 1] % mod * ifac[x << 1]) % mod;
f[t - x][t - y]++;
}
for(register int i = 1; i <= 4001; i++)
for(register int j = 1; j <= 4001; j++)
f[i][j] = Mod(Mod(f[i][j] + f[i - 1][j]) + f[i][j - 1]);
res = Mod(mod - res);
for(register int i = 1; i <= n; i++) Add(res, f[t + X[i]][t + Y[i]]);
res = 500000004LL * res % mod;
cout << res << endl;
return 0;
}
| codenet | -1 | 1,788 |
s400330473 | p04051 | 1,542,140,620 | cpp | Accepted | 336 | 82,304 | #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MOD 1000000007
using namespace std;
inline int read(){
int re=0,flag=1;char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-') flag=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
return re*flag;
}
const int dx[3]={0,0,1},dy[3]={0,1,0};
int dp[4020][4020];int N=2005;bool vis[4020][4020];
int n,xx[200010],yy[200010],qx[200010],qy[200010],head=0,tail=1,maxq=200000;
ll inv[8010],finv[8010],f[8010];
void init(){
int i;inv[1]=finv[1]=1;
for(i=2;i<=8000;i++){
inv[i]=((MOD-MOD/i)*inv[MOD%i])%MOD;
}
f[1]=1;
for(i=2;i<=8000;i++){
f[i]=(f[i-1]*i)%MOD;
finv[i]=(finv[i-1]*inv[i])%MOD;
}
}
int main(){
init();
int i,maxx=0,maxy=0,x,y,tx,ty;ll X=0;
n=read();
for(i=1;i<=n;i++){
xx[i]=read();yy[i]=read();
dp[N-xx[i]][N-yy[i]]+=1;
maxx=max(maxx,xx[i]);maxy=max(maxy,yy[i]);
}
qx[0]=N-maxx,qy[0]=N-maxy;vis[N-maxx][N-maxy]=1;
while(head!=tail){
x=qx[head];y=qy[head];head=(head+1)%maxq;
// cout<<"dp "<<x<<ends<<y<<ends<<dp[x][y]<<endl;;
for(i=1;i<=2;i++){
tx=x+dx[i];ty=y+dy[i];
if(tx>N+maxx||ty>N+maxy) continue;
dp[tx][ty]=(dp[tx][ty]+dp[x][y])%MOD;
// cout<<" to "<<tx<<ends<<ty<<ends<<dp[tx][ty]<<endl;
if(!vis[tx][ty]){
vis[tx][ty]=1;
qx[tail]=tx;qy[tail]=ty;tail=(tail+1)%maxq;
}
}
}
for(i=1;i<=n;i++){
X=X+dp[N+xx[i]][N+yy[i]];X%=MOD;
X=X-((f[xx[i]*2+yy[i]*2]*finv[xx[i]*2])%MOD*finv[yy[i]*2])%MOD+MOD;
X%=MOD;
}
printf("%lld\n",(X*inv[2])%MOD);
} | codenet | -1 | 1,796 |
s178346870 | p04051 | 1,484,709,832 | cpp | Accepted | 590 | 252,672 | #include<algorithm>
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
ll dp[4001][4001];
ll combi[4001][4001];
void setcombi() {
for (int i = 0; i <= 4000; i++) {
for (int j = 0; j <= 4000; j++) {
combi[i][j] = 0;
}
}
combi[0][0] = 1;
for (int i = 1; i <= 4000; i++) {
combi[i][0] += combi[i - 1][0];
combi[i][0] %= MOD;
}
for (int j = 1; j <= 4000; j++) {
combi[0][j] += combi[0][j - 1];
combi[0][j] %= MOD;
}
for (int i = 1; i <= 4000; i++) {
for (int j = 1; j <= 4000; j++) {
combi[i][j] += combi[i][j - 1] + combi[i - 1][j];
combi[i][j] %= MOD;
}
}
}
ll combination(ll a, ll b) {
if (b > a / 2)b = a - b;
if (b < 0)return 0;
if (b == 0)return 1;
return combi[a - b][b];
}
int main() {
int n;
cin >> n;
vi A(n), B(n), D(n);
for (int i = 0; i <= 4000; i++) {
for (int j = 0; j <= 4000; j++) {
dp[i][j] = 0;
}
}
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
A[i] = a;
B[i] = b;
D[i] = a + b;
dp[2000 - a][2000 - b] += 1;
}
for (int i = 1; i <= 4000; i++) {
dp[i][0] += dp[i - 1][0];
dp[i][0] %= MOD;
}
for (int j = 1; j <= 4000; j++) {
dp[0][j] += dp[0][j - 1];
dp[0][j] %= MOD;
}
for (int i = 1; i <= 4000; i++) {
for (int j = 1; j <= 4000; j++) {
dp[i][j] += dp[i][j - 1] + dp[i - 1][j];
dp[i][j] %= MOD;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += dp[2000 + A[i]][2000 + B[i]];
ans %= MOD;
}
ll same = 0;
setcombi();
for (int i = 0; i < n; i++) {
same += combination(2 * D[i], 2 * A[i]);
same %= MOD;
}
ans = (ans - same) % MOD;
ans += MOD;
ans %= MOD;
if (ans % 2 == 0)ans /= 2;
else ans = (ans + MOD) / 2;
cout << ans << endl;
} | codenet | -1 | 1,798 |
s475243250 | p04051 | 1,528,484,247 | cpp | Accepted | 95 | 64,384 | #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
const int mod = 1e9 + 7;
const int half = 5e8 + 4;
int n;
int a[200000];
int b[200000];
int arr[4001][4001];
int fact[8001], ifact[4001];
llong sq(int x) {
return (llong)x * x % mod;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", a + i, b + i);
++arr[a[i] + b[i]][a[i] + 2000];
}
ifact[1] = 1;
for (int i = 2; i <= 4000; ++i) {
int q = mod / i, r = mod - i * q;
ifact[i] = mod - ((llong)ifact[r] * q) % mod;
}
fact[0] = 1;
for (int i = 1; i <= 8000; ++i) {
fact[i] = (llong)i * fact[i - 1] % mod;
}
ifact[0] = 1;
for (int i = 1; i <= 4000; ++i) {
ifact[i] = (llong)ifact[i - 1] * ifact[i] % mod;
}
for (int i = 4000; i; --i) {
for (int j = i; j <= 4000; ++j) {
arr[i - 1][j - 1] += arr[i][j];
arr[i - 1][j - 1] %= mod;
arr[i - 1][j] += arr[i][j];
arr[i - 1][j] %= mod;
}
}
int ans = 0;
for (int i = 1; i <= 2000; ++i) {
ans = (ans + (llong)arr[0][2000 - i] * arr[0][2000 + i] % mod) % mod;
}
ans <<= 1;
ans %= mod;
ans += sq(arr[0][2000]);
ans %= mod;
for (int i = 0; i < n; ++i) {
ans += mod - (llong)fact[(a[i] + b[i]) << 1] * ifact[a[i] << 1] % mod * ifact[b[i] << 1] % mod;
ans %= mod;
}
ans = (llong)ans * half % mod;
printf("%d\n", ans);
return 0;
}
| codenet | -1 | 1,802 |
s838690231 | p04051 | 1,468,725,661 | cpp | Accepted | 384 | 64,384 | #include <cstdio>
#include <algorithm>
using namespace std;
int m = 1000000007;
int a[200000][2];
int dp[4001][4001];
long long inv[8001];
long long fact[8001];
long long invfact[8001];
void calc_inv(int n, int mod) {
inv[1] = 1;
for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
fact[0] = invfact[0] = 1;
for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}
long long comb(int x, int y) {
return fact[x] * invfact[y] % m * invfact[x - y] % m;
}
long long mod_inverse(long long a, long long m) {
long long b = m, x = 1, y = 0;
while (b) {
long long t = a / b;
a -= t * b;
x -= t * y;
swap(a, b);
swap(x, y);
}
return (m + x % m) % m;
}
int main() {
int n, i, j;
long long ans = 0;
calc_inv(8000, m);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &a[i][0], &a[i][1]);
dp[2000 - a[i][0]][2000 - a[i][1]]++;
}
for (i = 0; i <= 4000; i++) {
for (j = 0; j <= 4000; j++) {
if (dp[i][j] == 0) continue;
if (i + 1 <= 4000) {
dp[i + 1][j] += dp[i][j];
if (dp[i + 1][j] >= m) dp[i + 1][j] -= m;
}
if (j + 1 <= 4000) {
dp[i][j + 1] += dp[i][j];
if (dp[i][j + 1] >= m) dp[i][j + 1] -= m;
}
}
}
for (i = 0; i < n; i++) {
ans += dp[2000 + a[i][0]][2000 + a[i][1]];
ans += m - comb(a[i][0] * 2 + a[i][1] * 2, a[i][0] * 2);
}
printf("%lld\n", ans % m * mod_inverse(2, m) % m);
return 0;
}
| codenet | -1 | 1,804 |
s553933928 | p04051 | 1,582,020,313 | cpp | Accepted | 140 | 64,512 | // IOI 2021
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef unsigned long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
////////////////////////////////////////////////////////////////////
const int N = 2e5 + 2, M = 2e3 + 2;
int X[N], Y[N], DP[M << 1][M << 1];
int F[M << 2], I[M << 2];
int Power(int a, int b) {
int res = 1;
for(; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
return res;
}
int C(int n, int r) { return r > n ? 0 : 1LL * I[r] * I[n - r] % MOD * F[n] % MOD; }
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
F[0] = 1;
for (int i = 1; i < 4 * M; i++) F[i] = 1LL * i * F[i - 1] % MOD;
I[(M << 2) - 1] = Power(F[(M << 2) - 1], MOD - 2);
for (int i = (M << 2) - 1; i; i--) I[i - 1] = 1LL * i * I[i] % MOD;
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> X[i] >> Y[i];
for (int i = 0; i < n; i++) DP[-X[i] + M][- Y[i] + M]++;
for (int i = 1; i < 2 * M; i++) DP[0][i] = (DP[0][i] + DP[0][i - 1]) % MOD, DP[i][0] = (DP[i][0] + DP[i - 1][0]) % MOD;
for (int i = 1; i < 2 * M; i++) for (int j = 1; j < M + M; j++) DP[i][j] = (DP[i][j] + DP[i - 1][j] + DP[i][j - 1]) % MOD;
int ans = 0;
for (int i = 0; i < n; i++) ans = (ans + DP[X[i] + M][Y[i] + M]) % MOD;
for (int i = 0; i < n; i++) ans = (ans - C(X[i] + X[i] + Y[i] + Y[i], X[i] + X[i]) + MOD) % MOD;
cout << 1LL * ans * I[2] % MOD << endl;
return 0;
}
| codenet | -1 | 1,805 |
s956982344 | p04051 | 1,581,841,599 | cpp | Accepted | 259 | 132,736 | //khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 2000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
int n, x[200010], y[200010], dp[N << 1][N << 1], inv[200010], fac[200010];
int POW(int x, int t){
int res = 1;
while(t){
if (t & 1) res = res * x % MOD;
t >>= 1;
x = x * x % MOD;
}
return res;
}
void calc(){
fac[0] = 1;
inv[0] = 1;
for (int i = 1; i < 200010; i++){
fac[i] = fac[i - 1] * 1ll * i % MOD;
inv[i] = POW(fac[i], MOD - 2);
}
}
int nCr(int x, int y){
if (y > x || y < 0 || x < 0) return 0;
int res = fac[x];
res = res * 1ll * inv[y] % MOD;
res = res * 1ll * inv[x - y] % MOD;
return res;
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
calc();
ll ans = 0;
for (int i = 1; i <= n; i++){
dp[-x[i] + N][-y[i] + N] ++;
}
for (int j = 1; j < 2 * N; j++) dp[0][j] = (dp[0][j] + dp[0][j - 1]) % MOD;
for (int i = 1; i < 2 * N; i++) dp[i][0] = (dp[i - 1][0] + dp[i][0]) % MOD;
for (int i = 1; i < N * 2; i++) for (int j = 1; j < N * 2; j++){
dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % MOD;
dp[i][j] %= MOD;
}
for (int i = 1; i <= n; i++){
ans = (ans + dp[x[i] + N][y[i] + N]) % MOD;
// cout << i << ' ' << dp[x[i] + N][y[i] + N] << '\n';
}
//cout << ans << '\n';
for (int i = 1; i <= n; i++){
ans -= nCr(x[i] * 2 + y[i] * 2, y[i] * 2);
ans %= MOD;
ans += MOD;
ans %= MOD;
}
cout << ans * inv[2] % MOD;
return 0;
}
| codenet | -1 | 1,807 |
s047639448 | p04051 | 1,570,281,944 | cpp | Accepted | 114 | 65,024 | #include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inver(a) power(a, mod - 2)
using namespace std;
inline char nc() {
return getchar();
static char buf[100000], *l = buf, *r = buf;
return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
x = 0; int f = 1, ch = nc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
x *= f;
}
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxA = 2000 + 10;
int n;
int A[maxn], B[maxn];
int H, W;
int fac[maxA << 2];
int fac_inv[maxA << 2];
int f[maxA << 1][maxA << 1];
inline int add(int x) {
return x >= mod ? x - mod : x;
}
inline int dec(int x) {
return x < 0 ? x + mod : x;
}
ll power(ll x, ll y) {
ll re = 1;
while(y) {
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
inline ll C(int x, int y) {
return (ll)fac[x] * fac_inv[y] % mod * fac_inv[x - y] % mod;
}
void init(int n) {
fac[0] = 1;
for(int i = 1; i <= n; ++i) {
fac[i] = (ll)fac[i - 1] * i % mod;
}
fac_inv[n] = inver(fac[n]);
for(int i = n; i >= 1; --i) {
fac_inv[i - 1] = (ll)fac_inv[i] * i % mod;
}
}
int solve() {
init(8000);
for(int i = 1; i <= n; ++i) {
++f[W - A[i]][H - B[i]];
}
for(int i = 1; i <= (W << 1); ++i) {
for(int j = 1; j <= (H << 1); ++j) {
f[i][j] = add(f[i][j] + add(f[i - 1][j] + f[i][j - 1]));
}
}
int an = 0;
for(int i = 1; i <= n; ++i) {
an = add(an + f[W + A[i]][H + B[i]]);
an = dec(an - C((A[i] << 1) + (B[i] << 1), A[i] << 1));
}
return (ll)an * fac_inv[2] % mod;
}
int main() {
read(n);
for(int i = 1; i <= n; ++i) {
read(A[i]), read(B[i]);
W = max(W, A[i] + 1);
H = max(H, B[i] + 1);
}
printf("%d\n", solve());
return 0;
} | codenet | -1 | 1,809 |
s429152847 | p04051 | 1,550,026,688 | cpp | Accepted | 206 | 64,640 | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int mod = 1e9 + 7;
template< int mod >
struct Combination {
vector< int64_t > mfact, rfact;
Combination(int sz) : mfact(sz + 1), rfact(sz + 1) {
mfact[0] = 1;
for(int i = 1; i < mfact.size(); i++) {
mfact[i] = mfact[i - 1] * i % mod;
}
rfact[sz] = inv(mfact[sz]);
for(int i = sz - 1; i >= 0; i--) {
rfact[i] = rfact[i + 1] * (i + 1) % mod;
}
}
int64_t fact(int k) const {
return (mfact[k]);
}
int64_t pow(int64_t x, int64_t n) const {
int64_t ret = 1;
while(n > 0) {
if(n & 1) (ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return (ret);
}
int64_t inv(int64_t x) const {
return (pow(x, mod - 2));
}
int64_t P(int n, int r) const {
if(r < 0 || n < r) return (0);
return (mfact[n] * rfact[n - r] % mod);
}
int64_t C(int p, int q) const {
if(q < 0 || p < q) return (0);
return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
}
int64_t H(int n, int r) const {
if(n < 0 || r < 0) return (0);
return (r == 0 ? 1 : C(n + r - 1, r));
}
};
int main() {
int N, A[200000], B[200000];
cin >> N;
for(int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
int tap[4005][4005] = {{}};
for(int i = 0; i < N; i++) {
tap[2000 - A[i]][2000 - B[i]]++;
}
for(int i = 0; i <= 4000; i++) {
for(int j = 0; j <= 4000; j++) {
if(i) (tap[i][j] += tap[i - 1][j]) %= mod;
if(j) (tap[i][j] += tap[i][j - 1]) %= mod;
}
}
int ret = 0;
Combination< mod > tapi(8005);
for(int i = 0; i < N; i++) {
(ret += tap[2000 + A[i]][2000 + B[i]]) %= mod;
(ret += mod - tapi.C(A[i] + B[i] + A[i] + B[i], A[i] + A[i])) %= mod;
}
cout << ret * tapi.inv(2) % mod << endl;
}
| codenet | -1 | 1,810 |
s119813020 | p04051 | 1,574,996,381 | cpp | Accepted | 329 | 127,104 | #include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
//#define MXN 300000
#define N 100005
LL dp[4005][4005];
LL fra[10005];
LL inv[10005];
int mod=1e9+7;
LL f_pow(LL a,LL b){
LL res=1,temp=a;
while(b){
if(b&1)res=res*temp%mod;
temp=temp*temp%mod;
b>>=1;
}
return res;
}
void build(){
fra[0]=1;
for(int i = 1;i<10000;i++){
fra[i]=fra[i-1]*i%mod;
}
inv[9999]=f_pow(fra[9999],mod-2);
for(int i = 9998;i>=0;i--)
inv[i]=inv[i+1]*(i+1)%mod;
}
int main(){
int n;
scanf("%d",&n);
pii p[200005];
for(int i=0;i<n;i++){
int x,y;
scanf("%d %d",&x,&y);
p[i]=mp(x,y);
dp[2000-x][2000-y]++;
}
for(int i = 0;i<=4000;i++)
for(int j=0;j<=4000;j++){
if(i!=0)
dp[i][j]+=dp[i-1][j];
if(j!=0)
dp[i][j]+=dp[i][j-1];
// dp[i][j]+=dp[i-1][j]+dp[i][j-1];
dp[i][j]%=mod;
}
LL ans=0;
for(int i = 0;i<n;i++){
ans+=dp[p[i].x+2000][p[i].y+2000];
ans%=mod;
}
build();
for(int i = 0;i<n;i++){
ans-=fra[(p[i].x+p[i].y)*2]*inv[p[i].x*2]%mod*inv[p[i].y*2]%mod;
ans=(ans%mod+mod)%mod;
}
printf("%lld\n",ans*(mod+1)/2%mod);
}
| codenet | -1 | 1,817 |
s005653120 | p04051 | 1,518,322,261 | cpp | Accepted | 239 | 127,104 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
template<typename T>
T add(T x) {
return x;
}
template<typename T, typename... Ts>
T add(T x, Ts... y) {
T res = x + add(y...);
if (res >= mod)
res -= mod;
return res;
}
template<typename T, typename... Ts>
T sub(T x, Ts... y) {
return add(x, mod - add(y...));
}
template<typename T, typename... Ts>
void udd(T &x, Ts... y) {
x = add(x, y...);
}
template<typename T>
T mul(T x) {
return x;
}
template<typename T, typename... Ts>
T mul(T x, Ts... y) {
return (x * 1ll * mul(y...)) % mod;
}
template<typename T, typename... Ts>
void uul(T &x, Ts... y) {
x = mul(x, y...);
}
int bin(int a, ll deg) {
int r = 1;
while (deg) {
if (deg & 1)
uul(r, a);
deg >>= 1;
uul(a, a);
}
return r;
}
int inv(int x) {
assert(x);
return bin(x, mod - 2);
}
const int maxn = 4005;
int d[maxn][maxn];
const int sh = maxn / 2;
int c[maxn][maxn];
signed main() {
#ifdef LOCAL
assert(freopen("e.in", "r", stdin));
#endif
c[0][0] = 1;
for (int i = 0; i < maxn; ++i) {
for (int j = 0; j < maxn; ++j) {
if (i > 0) {
udd(c[i][j], c[i - 1][j]);
}
if (j > 0) {
udd(c[i][j], c[i][j - 1]);
}
}
}
int n;
cin >> n;
int res = 0;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
d[sh - a[i]][sh - b[i]]++;
res = sub(res, c[a[i] * 2][b[i] * 2]);
}
for (int i = 0; i < maxn; ++i) {
for (int j = 0; j < maxn; ++j) {
if (i > 0) {
udd(d[i][j], d[i - 1][j]);
}
if (j > 0) {
udd(d[i][j], d[i][j - 1]);
}
}
}
for (int i = 0; i < n; ++i) {
udd(res, d[sh + a[i]][sh + b[i]]);
}
uul(res, (mod + 1) / 2);
cout << res << '\n';
}
| codenet | -1 | 1,820 |
s500363278 | p04051 | 1,489,636,346 | cpp | Accepted | 183 | 127,872 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 4e3+10;
inline int add(int x,int y){
x += y;
if(x >= mod) x -= mod;
return x;
}
inline int mul(int x,int y){
x = (1LL * x * y) % mod;
return x;
}
int dp[N][N],mark[N][N];
int fac[10010],ifac[10010],inv[10010];
void FAC(int n){
fac[0] = ifac[0] = inv[1] = 1;
for(int i = 1; i < n; ++i)fac[i] = 1LL*i*fac[i-1] % mod;
for(int i = 2; i < n; ++i)inv[i] = mod - ((mod/i)*1LL*inv[mod%i]) % mod;
for(int i = 1; i < n; ++i)ifac[i] = 1LL*ifac[i-1]*inv[i] % mod;
}
inline int C(int n,int k){
if(k > n)return 0;
return 1LL * ifac[n-k]*( (1LL*fac[n]*ifac[k]) % mod ) % mod;
}
int DP(int x,int y){
if(x < 0 || y < 0)return 0;
int &ret = dp[x][y];
if(~ret)return ret;
ret = 0;
ret += mark[x][y];
ret = add(ret,DP(x-1,y));
ret = add(ret,DP(x,y-1));
return ret;
}
int main(){
fast;
int n;cin >> n;
vector<ii> v(n);
FAC(10010);
fill(mark,0);
fill(dp,-1);
FOR(i,0,n-1){
cin >> v[i].F >> v[i].S;
mark[2000-v[i].F][2000-v[i].S] += 1;
}
int ans = 0;
FOR(i,0,n-1){
//cout << ans << " ";
ans = add(ans,DP(v[i].F + 2000,v[i].S + 2000));
//cout << ans << "\n";
}
//cout << ans << "\n";
FOR(i,0,n-1){
//cout << C(2*v[i].F + 2*v[i].S,v[i].F + v[i].S) << "\n";
ans = add(ans,mod - C(2*v[i].F + 2*v[i].S,2*v[i].F));
}
ans = mul(ans,500000004);
cout << ans << "\n";
return 0;
} | codenet | -1 | 1,829 |
s211845822 | p04051 | 1,578,611,843 | cpp | Accepted | 166 | 189,696 | /* بسم الله الرحمن الرحیم */
/* شهید حاج قاسم سلیمانی
انتقام سخت نزدیک است
*/
#include <bits/stdc++.h>
using namespace std ;
//#define int ll
#define all(x) x.begin() , x.end()
#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()
#define debug(x) cerr << #x << " = " << x << endl
typedef long long ll ;
typedef pair<int , int> pii ;
const int MAX_N = 2010 , MAX_X = 2010 * 2 , MAX_Y = 2010 * 4 , MAX_M = 200 * 1000 + 19 ;
const int inf = 2e9 + 19 ;
const int MOD = 1e9 + 7 ;
int a[MAX_M] , b[MAX_M] , n ;
int dp[MAX_X][MAX_X] , C[MAX_Y][MAX_X] ;
ll ans = 0 ;
ll mul(ll x , ll y) {
return 1LL * x * y % MOD ;
}
ll sum(ll x , ll y) {
x += y;
if (x < 0)
x += MOD;
else if (x >= MOD)
x -= MOD;
return x;
}
int main() {
ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
cin >> n ;
for (int i = 1 ; i <= n ; i ++) {
cin >> a[i] >> b[i] ;
dp[MAX_N - a[i]][MAX_N - b[i]] ++ ;
}
for (int i = 1 ; i < MAX_X ; i ++)
for (int j = 1 ; j < MAX_X ; j ++)
dp[i][j] = sum(sum(dp[i][j] , dp[i - 1][j]) , dp[i][j - 1]) ;
for (int i = 0 ; i < MAX_Y ; i ++) {
C[i][0] = C[i][i] = 1 ;
for (int j = 1 ; j < min(i , MAX_X) ; j ++) {
C[i][j] = sum(C[i - 1][j] , C[i - 1][j - 1]) ;
//if (i == 8038)
// debug(j) ;
}
}
for (int i = 1 ; i <= n ; i ++)
ans = sum(ans , dp[MAX_N + a[i]][MAX_N + b[i]]) , ans = sum(ans, -C[a[i] * 2 + b[i] * 2][a[i] * 2]);
ans = mul(ans , (MOD + 1) / 2) ;
if (ans < 0)
ans += MOD ;
cout << ans ;
return (0) ;
}
| codenet | -1 | 1,834 |
s559876378 | p04051 | 1,472,616,562 | cpp | Accepted | 1,763 | 129,280 | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
const double eps = 1e-11;
lli MOD=1000000007;
//Ax=bをとくAは正方行列
//rankA<=min(m,n)ならば配列0のvecが帰る
lli fact[10050],factinv[10050];
lli powm(lli a,lli p,lli mod){
lli ans =1;
while(p>0){
if(p&1)ans=(ans*a) % mod;
a=(a*a)%mod;
p >>=1;
}
return ans%mod;
}
lli inv(lli a){
return powm(a,MOD-2,MOD);
}
lli gcd(lli A,lli B){
if(A%B==0)return B;
else return gcd(B,A%B);
}
lli cmb(lli a,lli b ){
lli ans =1;
rep(i,b){
ans = ans %MOD* (a-i)%MOD*inv(b-i)%MOD;
}
return ans ;
}
lli comb(lli a,lli b){
return fact[a]%MOD*factinv[b]%MOD*factinv[a-b]%MOD;
}
int main(){
int N;
int a[200005],b[200005];
cin >> N;
factinv[0]=fact[0]=1;
rep(i,10020) {
fact[i+1]=fact[i]*(i+1);
fact[i+1]%=MOD;
factinv[i+1]=factinv[i]%MOD*inv(i+1)%MOD;
factinv[i+1]%=MOD;
}
rep(i,N)cin >> a[i]>>b[i];
lli g[4040][4040];
rep(i,N){
g[2010-a[i]][2010-b[i]]++;
}
rep(i,4030)rep(j,4030){
g[i+1][j+1]+=g[i][j+1]%MOD+g[i+1][j]%MOD;
g[i+1][j+1]%=MOD;
}
lli ans =0;
rep(i,N){
ans+= g[2010+a[i]][2010+b[i]]%MOD;
ans%=MOD;
}
rep(i,N){
ans += MOD-comb(2*a[i]+2*b[i],2*a[i])%MOD;
ans %=MOD;
}
if(ans&1)ans+=MOD;
cout << ans/2 << endl;
}
| codenet | -1 | 1,837 |
s149245156 | p04051 | 1,518,284,544 | cpp | Accepted | 255 | 95,872 | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fr first
#define sc second
const ll M = 1000000007;
ll modpow(ll x,ll k){
if(k == 0)return 1;
ll ret = modpow(x,k/2);
ret *= ret; ret %= M;
if(k&1LL){ ret *= x; ret %= M; }
return ret;
}
ll C[4002][2002];
void C_init(){
C[0][0] = 1;
for(int i = 0 ; i < 4001 ; i ++){
for(int j = 0 ; j <= min(i,2000) ; j ++){
if(C[i][j] >= M)C[i][j] -= M;
C[i+1][j] += C[i][j];
C[i+1][j+1] += C[i][j];
}
}
}
ll f[8004];
void f_init(){
f[0] = 1;
for(int i = 1 ; i < 8004 ; i ++){
f[i] = f[i-1]*i;
f[i] %= M;
}
}
ll CC(ll n,ll k){
ll ret = f[n];
ret *= modpow(f[k],M-2); ret %= M;
ret *= modpow(f[n-k],M-2); ret %= M;
return ret;
}
int main(){
C_init();
f_init();
static ll N;
static ll A[200010],B[200010];
scanf("%lld",&N);
for(int i = 1 ; i <= N ; i ++){
scanf("%lld%lld",&A[i],&B[i]);
}
static ll D[2002][2002] = {};
for(int i = 1 ; i <= N ; i ++){
D[A[i]][B[i]] ++;
}
for(int i = 2000 ; i >= 1 ; i --){
for(int j = 2000 ; j >= 1 ; j --){
if(D[i][j] >= M)D[i][j] -= M;
D[i-1][j] += D[i][j];
D[i][j-1] += D[i][j];
}
}
static ll ret = 0;
ll sum = 0;
for(int i = 1 ; i <= 2000 ; i ++){
sum += D[i][0];
}
sum %= M;
sum *= sum; sum %= M;
ret += sum;
sum = 0;
for(int i = 1 ; i <= 2000 ; i ++){
sum += D[0][i];
}
sum %= M;
sum *= sum; sum %= M;
ret += sum;
for(int i = 1 ; i <= 2000 ; i ++){
for(int j = 1 ; j <= 2000 ; j ++){
ll r = D[i][0]*D[0][j];
r %= M;
r *= C[i+j][j]*2;
ret += r;
ret %= M;
}
}
for(int i = 1 ; i <= N ; i ++){
ret += M-CC(A[i]*2+B[i]*2,B[i]*2);
}
ret %= M;
ret *= modpow(2,M-2);
cout << ret%M << endl;
}
| codenet | -1 | 1,838 |
s853380762 | p04051 | 1,520,969,843 | cpp | Accepted | 145 | 67,840 | #include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
typedef long long LL;
const int md=1000000007;
int fac[8010],inv[8010];
int dp[4111][4111];
int a[200010],b[200010];
LL pwr(LL a,int x){
LL res=1;
int cur=1;
while(x){
if (x&cur){
res=res*a%md;
x^=cur;
}
cur<<=1;
a=a*a%md;
}
return res;
}
int main(void){
fac[0]=inv[0]=1;
for (int i=1;i<=8000;++i){
fac[i]=1ll*fac[i-1]*i%md;
inv[i]=pwr(fac[i],md-2);
}
int n;
scanf("%d",&n);
for (int i=1;i<=n;++i){
scanf("%d%d",&a[i],&b[i]);
++dp[2005-a[i]][2005-b[i]];
}
for (int i=1;i<=4020;++i){
for (int j=1;j<=4020;++j){
dp[i][j]+=dp[i-1][j]+dp[i][j-1];
if (dp[i][j]>=md) dp[i][j]-=md;
}
}
int res=0;
for (int i=1;i<=n;++i){
res+=dp[a[i]+2005][b[i]+2005];
if (res>=md) res-=md;
res-=(1ll*fac[(a[i]+b[i])<<1]*inv[a[i]<<1]%md*inv[b[i]<<1]%md);
if (res<0) res+=md;
}
printf("%d",1ll*res*inv[2]%md);
return 0;
} | codenet | -1 | 1,841 |
s704453087 | p04051 | 1,528,277,119 | cpp | Accepted | 143 | 129,408 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
ll add(ll a, ll b) {
ll res = a + b;
if (res >= MOD) {
res -= MOD;
}
return res;
}
ll sub(ll a, ll b) {
ll res = a - b;
if (res < 0) {
res += MOD;
}
return res;
}
ll mul(ll a, ll b) {
return (a * b) % MOD;
}
ll rev(ll a, ll m = MOD) {
if (a == 1) {
return 1;
}
return (1 - rev(m % a, a) * m) / a + m;
}
ll divv(ll a, ll b) {
return (a * rev(b)) % MOD;
}
const int maxn = 4040;
int n;
ll dp[maxn][maxn];
ll fact[2 * maxn], rev_fact[2 * maxn];
ll f(ll a, ll b) {
return mul(mul(fact[a + b], rev_fact[a]), rev_fact[b]);
}
void pre_calc() {
fact[0] = rev_fact[0] = 1;
for (int i = 1; i < 2 * maxn; i++) {
fact[i] = mul(fact[i - 1], i);
rev_fact[i] = rev(fact[i]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
pre_calc();
cin >> n;
vector<int> a(n), b(n);
ll ans = 0;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
ans = sub(ans, f(a[i] + a[i], b[i] + b[i]));
dp[2000 - a[i]][2000 - b[i]]++;
}
for (int i = 0; i < maxn; i++) {
for (int j = 0; j < maxn; j++) {
if (i) {
dp[i][j] = add(dp[i][j], dp[i - 1][j]);
}
if (j) {
dp[i][j] = add(dp[i][j], dp[i][j - 1]);
}
}
}
for (int i = 0; i < n; i++) {
ans = add(ans, dp[2000 + a[i]][2000 + b[i]]);
}
ans = divv(ans, 2);
cout << ans << '\n';
return 0;
} | codenet | -1 | 1,842 |
s093598016 | p04051 | 1,537,477,342 | cpp | Accepted | 232 | 129,280 | //By Don4ick
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int M = 2000;
const int N = (int)5e5 + 228;
const int MOD = (int)1e9 + 7;
using namespace std;
ll binpow(ll a, ll b)
{
ll res = 1;
while(b)
{
if (b & 1)
res = res * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return res;
}
int n, a[N], b[N], cnt[M + M + 5][M + M + 5], dp[M + M + 5][M + M + 5];
ll f[M + M + M + M + 5];
ll C(int x, int y)
{
return f[x] * binpow(f[y], MOD - 2) % MOD * binpow(f[x - y], MOD - 2) % MOD;
}
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie();
//cout.tie();
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
//~read
scanf("%d", &n);
forn(i, n)
scanf("%d%d", &a[i], &b[i]);
//~precalc_cnt
forn(i, n)
{
cnt[M - a[i]][M - b[i]]++;
cnt[a[i] + M][b[i] + M]++;
}
//~calc_dp
for (int i = M + M; i >= 0; i--)
{
for (int j = M + M; j >= 0; j--)
{
dp[i][j] = dp[i + 1][j] + dp[i][j + 1];
if (dp[i][j] >= MOD)
dp[i][j] -= MOD;
if (i > M && j > M)
{
dp[i][j] += cnt[i][j];
if (dp[i][j] >= MOD)
dp[i][j] -= MOD;
}
}
}
//~precalc
f[0] = 1;
for (int i = 1; i < M + M + M + M + 1; i++)
f[i] = f[i - 1] * i % MOD;
//~calc_ans
ll ans = 0;
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++)
ans = (ans + 1ll * dp[i][j] * cnt[i][j]) % MOD;
forn(i, n)
{
ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + MOD);
if (ans >= MOD)
ans -= MOD;
}
ans = ans * binpow(2, MOD - 2) % MOD;
cout << ans << endl;
return 0;
}
| codenet | -1 | 1,845 |
s255858797 | p04051 | 1,528,095,897 | cpp | Accepted | 142 | 68,336 | // In the name of God
#include <bits/stdc++.h>
using namespace std ;
//#define int long long
#define all(v) v.begin() , v.end()
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}
const int N = 2000 + 10 , mod = ( int ) 1e9 + 7 ;
int n , dp [ ( N << 1 ) + 100 ] [ ( N << 1 ) + 100 ] , fact [ N << 2 ] , inv [ N << 2 ] ;
vector < pair < int , int > > vec ;
int pw ( int x , int y ) {
int ret = 1 ;
for ( ; y ; y >>= 1 , ( x = 1LL * x * x % mod ) %= mod )
if ( y & 1 )
( ret = 1LL * ret * x % mod ) %= mod ;
return ret ;
}
int comb ( int n , int r ) {
return ( 1LL * fact [ n ] * inv [ r ] % mod * 1LL * inv [ n - r ] % mod ) % mod ;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n ;
for ( int i = 0 ; i < n ; ++i ) {
int a , b ;
cin >> a >> b ;
vec.push_back ( { a , b } ) ;
++ dp [ -a + N ] [ -b + N ] ;
}
for ( int i = 0 ; i < ( N << 1 ) + 100 ; ++i ) {
for ( int j = 0 ; j < ( N << 1 ) + 100 ; ++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 ;
}
}
fact [ 0 ] = inv [ 0 ] = 1 ;
for ( int j = 1 ; j < ( N << 2 ) ; ++j ) {
fact [ j ] = 1LL * fact [ j - 1 ] * j % mod ;
inv [ j ] = pw ( fact [ j ] , mod - 2 ) ;
}
int res = 0 ;
for ( auto pi : vec ) {
res += dp [ pi.first + N ] [ pi.second + N ] ;
if ( res >= mod ) res -= mod ;
}
for ( auto pi : vec ) {
res -= comb ( 2 * ( pi.first + pi.second ) , 2 * pi.first ) ;
if ( res < 0 ) res += mod ;
}
( res = 1LL * res * pw ( 2 , mod - 2 ) % mod ) %= mod ;
cout << res << '\n' ;
}
| codenet | -1 | 1,845 |
s979754067 | p04051 | 1,468,946,720 | cpp | Accepted | 480 | 64,512 | #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;
#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl
typedef long long ll;
constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;
constexpr int ESP = 1e-9;
constexpr double PI = acos(-1);
constexpr int MAX = 2000;
int dp[MAX*2+1][MAX*2+1];
int a[200000], b[200000];
vector<ll> get_fractorial(int n) {
vector<ll> ret;
int i;
ret.push_back(1);
REP (i,1,n) {
ret.push_back(ret[i-1] * i % MOD);
}
return ret;
}
ll modpow(ll x, int n) {
ll ret = 1;
while (n) {
if (n % 2)
ret = ret * x % MOD;
x = x * x % MOD;
n /= 2;
}
return ret;
}
ll modinv(int x) {
return modpow(x,MOD-2);
}
int main(void) {
int i, j, n;
scanf("%d",&n);
REP (i,n) {
scanf("%d%d",&a[i],&b[i]);
dp[a[i]+MAX][b[i]+MAX]++;
}
RREP (i,2*MAX,0) RREP (j,2*MAX,0) {
if (i < 2*MAX) {
dp[i][j] += dp[i+1][j];
dp[i][j] %= MOD;
}
if (j < 2*MAX) {
dp[i][j] += dp[i][j+1];
dp[i][j] %= MOD;
}
}
auto frac = get_fractorial(MAX * 4);
int ans = 0;
REP (i,n) ans = (ans + dp[MAX-a[i]][MAX-b[i]]) % MOD;
REP (i,n) ans = (ans - frac[(a[i]+b[i]) * 2] * modinv(frac[a[i]*2] * frac[b[i]*2] % MOD) % MOD + MOD) % MOD;
ans = ans * modinv(2) % MOD;
printf("%d\n",ans);
return 0;
}
| codenet | -1 | 1,854 |
s694623254 | p04051 | 1,490,390,790 | cpp | Accepted | 90 | 64,512 | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
const int maxn = 4004;
const int M = maxn * 2;
const int maxm = 2E5 + 20;
const int dx[2] = {0,1};
const int dy[2] = {1,0};
typedef long long LL;
const LL mo = 1000000007;
int n,Ans,f[maxn][maxn],Fac[M],Inv[M],A[maxm],B[maxm];
inline int Get(const int &k) {return k + 2001;}
inline int Mul(const LL &x,const LL &y) {return x * y % mo;}
inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}
inline int Dec(const int &x,const int &y) {return x - y >= 0 ? x - y : x - y + mo;}
inline int C(const int &N,const int &M) {return Mul(Fac[N],Mul(Inv[M],Inv[N - M]));}
inline int getint()
{
char ch = getchar(); int ret = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9')
ret = ret * 10 + ch - '0',ch = getchar();
return ret;
}
int ksm(int x,int y)
{
int ret = 1;
for (; y; y >>= 1)
{
if (y & 1) ret = Mul(ret,x);
x = Mul(x,x);
}
return ret;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
n = getint();
for (int i = 1; i <= n; i++)
{
A[i] = getint(); B[i] = getint();
++f[Get(-A[i])][Get(-B[i])];
}
for (int i = 1; i <= 4001; i++)
for (int j = 1; j <= 4001; j++)
{
f[i][j] = Add(f[i][j],f[i - 1][j]);
f[i][j] = Add(f[i][j],f[i][j - 1]);
}
Fac[0] = 1; for (int i = 1; i < M; i++) Fac[i] = Mul(i,Fac[i - 1]);
Inv[M - 1] = ksm(Fac[M - 1],mo - 2); for (int i = M - 2; i >= 0; i--) Inv[i] = Mul(Inv[i + 1],i + 1);
for (int i = 1; i <= n; i++)
{
Ans = Add(Ans,f[Get(A[i])][Get(B[i])]);
Ans = Dec(Ans,C((A[i] << 1) + (B[i] << 1),A[i] << 1));
}
cout << Mul(Ans,ksm(2,mo - 2)) << endl;
return 0;
} | codenet | -1 | 1,856 |
s734157729 | p04051 | 1,468,735,913 | cpp | Accepted | 981 | 252,288 | #define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
const int MOD = 1000000007;
const int MOD_INV2 = 500000004;
const int MAX = 2000;
void combination(int n, vector<vector<int> >& comb)
{
comb.assign(n+1, vector<int>(n+1, 0));
for(int i=0; i<=n; ++i){
comb[i][0] = 1;
for(int j=1; j<=i; ++j){
comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
comb[i][j] %= MOD;
}
}
}
int main()
{
int n;
cin >> n;
vector<int> a(n), b(n);
vector<vector<int> > cnt(MAX+1, vector<int>(MAX+1, 0));
for(int i=0; i<n; ++i){
cin >> a[i] >> b[i];
++ cnt[a[i]][b[i]];
}
long long ans = 0;
vector<int> dp(2*MAX+2, 0);
for(int y=0; y<=2*MAX; ++y){
vector<int> nextDp(2*MAX+2, 0);
for(int x=0; x<=2*MAX; ++x){
if(y < MAX && x < MAX){
dp[x] += cnt[MAX-y][MAX-x];
dp[x] %= MOD;
}
else if(y > MAX && x > MAX){
ans += dp[x] * (long long)cnt[y-MAX][x-MAX];
ans %= MOD;
}
nextDp[x] += dp[x];
nextDp[x] %= MOD;
dp[x+1] += dp[x];
dp[x+1] %= MOD;
}
}
cnt.clear();
vector<vector<int> > comb;
combination(4*MAX, comb);
for(int i=0; i<n; ++i){
ans += MOD - comb[2*(a[i]+b[i])][2*a[i]];
ans %= MOD;
}
ans *= MOD_INV2;
ans %= MOD;
cout << ans << endl;
return 0;
} | codenet | -1 | 1,861 |
s857207969 | p04051 | 1,519,240,191 | cpp | Accepted | 206 | 94,976 | #include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define mp make_pair
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define FO(i,a,b) for (int i=(a);i<=(b);++i)
#define FD(i,a,b) for (int i=(a);i>=(b);--i)
#define FE(i,G,x) for(int i=(G).h[x];~i;i=(G).v[i].nxt)
typedef long long LL;
typedef pair<int, int> PII;
template <class T> inline bool chkmin(T& x, T y) { return x > y ? x = y, true : false; }
template <class T> inline bool chkmax(T& x, T y) { return x < y ? x = y, true : false; }
inline LL read(void) {
LL x, f = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return x * f;
}
#define MO 1000000007
#define M 2000
int f[2 * M + 5][2 * M + 5], c[2 * M + 5][2 * M + 5];
LL fac[4 * M + 5], nfac[4 * M + 5];
int n, x, y, ans;
inline int C(int x, int y) { return fac[x] * nfac[y] % MO * nfac[x - y] % MO; }
inline LL ppow(LL a, LL b) {
LL ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = ret * a % MO;
a = a * a % MO;
}
return ret;
}
int main(void) {
n = read();
nfac[0] = fac[0] = 1;
FO(i, 1, 8000) fac[i] = fac[i - 1] * i % MO;
FO(i, 1, 8000) nfac[i] = ppow(fac[i], MO - 2);
FO(i, 1, n) {
x = read(); y = read();
f[M - x][M - y]++; // f[-x][-y]++
c[M + x][M + y]++;
(ans += MO - C((x + y) * 2, y * 2)) %= MO;
}
FO(i, 0, 2 * M)FO(j, 0, 2 * M) {
if (j && !i) (f[i][j] += f[i][j - 1]) %= MO;
if (i && !j) (f[i][j] += f[i - 1][j]) %= MO;
if (i && j) f[i][j] = ((LL)f[i][j] + f[i - 1][j] + f[i][j - 1]) % MO;
}
FO(i, 0, 2 * M)FO(j, 0, 2 * M) (ans += (LL)f[i][j] * c[i][j] % MO) %= MO;
printf("%lld\n", ans * 500000004ll % MO);
return 0;
} | codenet | -1 | 1,865 |
s958949989 | p04051 | 1,552,612,504 | cpp | Accepted | 166 | 130,432 | /*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define int long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;
const int inf = 0x3f3f3f3f;
inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}
void print(int x) {
if(x < 0) pc('-') , x = -x;
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxN = 200000 + 7;
const int inv2 = 500000004;
int f[4007][4007] , fac[maxN], a[maxN],b[maxN], inv[maxN];
const int mod = 1e9 + 7;
int Pow(int a,int b)
{
int ans=1;
for(;b;b>>=1,a=1ll*a*a%mod)
if(b&1) ans=1ll*ans*a%mod;
return ans;
}
void Pre() {
fac[0] = 1;
for(int i = 1;i <= 8000;++ i)
fac[i] = 1ll * fac[i - 1] * i % mod;
inv[8000] = Pow(fac[8000],mod - 2);
for(int i = 7999;i >= 0;i --)
inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
return ;
}
const int base = 2001;
int C(int n , int m) {
return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
signed main() {
Pre();
int n = gi();
for(int i = 1;i <= n;++ i) a[i] = gi() , b[i] = gi();
for(int i = 1;i <= n;++ i) f[base - a[i]][base - b[i]] ++;
for(int i = 1;i <= 4000 + 4;++ i) {
for(int j = 1;j <= 4000 + 4;++ j) {
f[i][j] += f[i - 1][j] + f[i][j - 1];
f[i][j] %= mod;
}
}
int Ans = 0;
for(int i = 1;i <= n;++ i) {
Ans += f[a[i] + base][b[i] + base] ;
Ans %= mod;
Ans -= C(2 * a[i] + 2 * b[i] , 2 * a[i]);
Ans %= mod;
}
Ans += mod;
Ans %= mod;
Ans = Ans * inv2 % mod;
std::cout << Ans;
return 0;
} | codenet | -1 | 1,866 |
s507136356 | p04051 | 1,568,688,459 | cpp | Accepted | 148 | 68,224 | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int U = 2048, N = 4096, M = 2e5 + 10, Mod = 1e9 + 7;
inline void Read(int &x)
{
x = 0; register char cc = '\0'; int fff = 1;
for (; cc < '0' || cc > '9'; cc = getchar())
if (cc == '-') fff = -1;
for (; cc >= '0' && cc <= '9'; cc = getchar())
x = (x << 1) + (x << 3) + (cc & 15);
x *= fff;
}
int n, fans, minpx, minpy, maxpx, maxpy, fac[N * 2 + 10], ifac[N * 2 + 10], ptx[M], pty[M], rptx[M], rpty[M], f[N][N];
inline int Pow(int x, int y) {
int sum = 1;
while (y) {
if (y & 1) sum = (LL)sum * x % Mod;
x = (LL)x * x % Mod; y >>= 1;
}
return sum;
}
inline int C(int x, int y) {
return (LL)fac[x] * ifac[y] % Mod * ifac[x - y] % Mod;
}
int main()
{
fac[0] = ifac[0] = 1;
for (int i = 1; i <= N * 2; ++i) fac[i] = (LL)fac[i - 1] * i % Mod;
ifac[N * 2] = Pow(fac[N * 2], Mod - 2);
for (int i = N * 2 - 1; i >= 1; --i) ifac[i] = (LL)ifac[i + 1] * (i + 1) % Mod;
Read(n);
minpx = minpy = N, maxpx = maxpy = -N;
for (int i = 1; i <= n; ++i) {
Read(ptx[i]), Read(pty[i]);
rptx[i] = U - ptx[i], rpty[i] = U - pty[i];
f[rptx[i]][rpty[i]] += 1; /* += !!! */
minpx = min(minpx, rptx[i]), minpy = min(minpy,rpty[i]);
ptx[i] += U, pty[i] += U;
maxpx = max(maxpx, ptx[i]), maxpy = max(maxpy, pty[i]);
}
for (int i = minpx; i <= maxpx; ++i)
for (int j = minpy; j <= maxpy; ++j)
f[i][j] = (f[i][j] + (LL)f[i][j - 1] + (LL)f[i - 1][j]) % Mod;
for (int i = 1; i <= n; ++i) {
// printf("%d %d : %d\n", ptx[i] - U, pty[i] - U, f[ptx[i]][pty[i]]);
fans = (fans + f[ptx[i]][pty[i]]) % Mod;
fans = (fans - C(ptx[i] - rptx[i] + pty[i] - rpty[i], ptx[i] - rptx[i]) + Mod) % Mod;
}
//printf("%d\n", fans);
fans = (LL)fans * Pow(2, Mod - 2) % Mod;
printf("%d\n", fans);
return 0;
}
| codenet | -1 | 1,871 |
s929193110 | p04051 | 1,579,647,639 | cpp | Accepted | 197 | 64,640 | /*
This code is made by ghy.
Oj: Atcoder
Language: C++
Status: AC
Complexity: O(n+val^2)
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
#include <ctime>
#define ll long long
#define rg register
#define il inline
#define pb(a) push_back(a)
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define mst(a,b) memset(a,b,sizeof a)
#define mp(a,b) make_pair(a,b)
#define smallrootpile priority_queue <int,vector<int>,greater<int> >
#define bigrootpile priority_queue <int>
using namespace std;
il int read(){
rg int x=0,f=1; rg char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48); c=getchar();
}
return x*f;
}
const int Inf1=0x3f3f3f3f;
const int Inf2=1e9,mod=1e9+7;
const int N=2e5+5,M=8005;
int n,a[N],b[N];
ll ans,fac[M],inv[M];
int dp[4005][4005],cnt=2001;
il ll qpow(ll a,int b){
ll ret=1;
while(b){
if(b&1)
ret=(ret*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ret;
}
il void init(){
fac[0]=1;
for(rg int i=1;i<=8000;++i)
fac[i]=(fac[i-1]*i)%mod;
inv[8000]=qpow(fac[8000],mod-2);
for(rg int i=7999;i;--i)
inv[i]=(inv[i+1]*(i+1))%mod;
}
il ll choose(int a,int b){
return (((fac[a]*inv[b])%mod)*inv[a-b])%mod;
}
int main(){
n=read();
init();
for(rg int i=1;i<=n;++i){
a[i]=read();
b[i]=read();
++dp[cnt-a[i]][cnt-b[i]];
}
for(rg int i=1;i<=(cnt<<1);++i)
for(rg int j=1;j<=(cnt<<1);++j)
dp[i][j]=((dp[i][j]+dp[i][j-1])%mod+dp[i-1][j])%mod;
for(rg int i=1;i<=n;++i){
ans=(ans+dp[a[i]+cnt][b[i]+cnt])%mod;
ans=(ans-choose((a[i]<<1)+(b[i]<<1),(a[i]<<1))+mod)%mod;
}
printf("%lld\n",(ans*500000004)%mod);
return 0;
}
| codenet | -1 | 1,873 |
s834960103 | p04051 | 1,582,836,995 | cpp | Accepted | 143 | 66,176 | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
const int maxN = 2e5 + 5;
const int maxA = 2e3 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll modP(ll a, ll b = MOD - 2){
if (b == 0)
return 1;
ll c = modP(a, b / 2);
c = (c * c) % MOD;
if (b & 1)
c = (a * c) % MOD;
return c;
}
int fact[maxN], inv[maxN];
int a[maxN], b[maxN];
int dp[2 * maxA][2 * maxA];
ll choose(ll k, ll r){
if (r < 0 || r > k)
return 0;
return (1ll * fact[k] * inv[r] % MOD) * inv[k - r] % MOD;
}
int main(){
time_t START = clock();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
fact[0] = 1;
for (int i = 1; i < maxN; i++)
fact[i] = (1ll * fact[i - 1] * i) % MOD;
inv[maxN - 1] = modP(fact[maxN - 1]);
for (int i = maxN - 2; i > -1; i--)
inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD;
int n; scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", a + i, b + i);
ll ans = 0;
for (int i = 0; i < n; i++){
ans = (ans + MOD - choose(2 * a[i] + 2 * b[i], 2 * a[i])) % MOD;
dp[maxA - a[i]][maxA - b[i]]++;
}
for (int i = 0; i < 2 * maxA; i++)
for (int j = 0; j < 2 * maxA; j++){
if (i)
dp[i][j] = (dp[i - 1][j] + dp[i][j]) % MOD;
if (j)
dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
}
for (int i = 0; i < n; i++)
ans = (ans + dp[maxA + a[i]][maxA + b[i]]) % MOD;
printf("%d\n", (modP(2) * ans) % MOD);
time_t FINISH = clock();
cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
return 0;
}
| codenet | -1 | 1,877 |
s076277310 | p04051 | 1,584,504,701 | cpp | Accepted | 292 | 252,288 | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
ll exgcd(ll a, ll b, ll& x, ll& y)
{
ll d = a;
if (b != 0) {
d = exgcd(b, a % b, y, x);
y -= (a / b) * x;
}
else {
x = 1; y = 0;
}
return d;
}
ll mod_inverse(ll a, ll m)
{
ll x, y;
exgcd(a, m, x, y);
return (m + x % m) % m;
}
ll dp[8005][4005];
int main()
{
ios::sync_with_stdio(false);
#ifdef RG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vi a(n), b(n);
rep(i, 0, n) cin >> a[i] >> b[i];
int ma = 0;
rep(i, 0, n) ma = max(ma, max(a[i], b[i]));
rep(i, 0, n) {
dp[ma - a[i]][ma - b[i]] += 1;
}
rep(i, 0, 2 * ma + 1) {
rep(j, 0, 2 * ma + 1) {
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;
rep(i, 0, n) {
ans += dp[ma + a[i]][ma + b[i]];
ans %= mod;
}
memset(dp, 0, sizeof(dp));
rep(i, 0, 4 * ma + 1) {
dp[i][0] = 1;
rep(j, 1, min(2*ma+1, i+1)) {
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
}
}
rep(i, 0, n) {
ans -= dp[(a[i] + b[i]) * 2][a[i] * 2];
ans = (ans + mod) % mod;
}
ans = ans * mod_inverse(2, mod) % mod;
cout << ans << endl;
return 0;
} | codenet | -1 | 1,880 |
s657197670 | p04051 | 1,587,039,178 | cpp | Accepted | 350 | 132,608 | #include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int INF = 1e8;
const int MAXN = 3e5 + 200;
const long double eps = 1e-16;
const long double pi = acos(-1.0);
using namespace std;
int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
ll MOD = 1e9 + 7;
ll dp[4005][4005];
int a[MAXN], b[MAXN];
ll base = 2002;
ll ch[MAXN], zn[MAXN];
int n;
long long per(long long x, ll step){
long long r = 1;
while (step){
if (step & 1) r = (r * x ) % MOD;
x *= x;
x %= MOD;
step >>= 1;
}
return r;
}
void calc(){
ch[0] = 1;
for (int i = 1; i <= MAXN - 10; i++)
ch[i] = ch[i - 1] * i % MOD;
zn[MAXN - 10] = per(ch[MAXN - 10], MOD - 2);
for (int i = MAXN - 11; i >= 0; i--){
zn[i] = zn[i + 1] * (i + 1) % MOD;
}
}
ll C(int n, int m){
return ch[n] % MOD * zn[m] % MOD * zn[n - m] % MOD;
}
void solve(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
dp[-a[i] + base ][ -b[i] + base ]++;
}
calc();
for (int i = 1; i <= 4004; i++){
for (int j = 1; j <= 4004; j++)
dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1] ) % MOD;
}
ll ans = 0;
for (int i = 1; i <= n; i++){
ans += dp[a[i] + base][b[i] + base];
ans %= MOD;
ans = ((ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) % MOD + MOD) % MOD);
}
cout << (ans * zn[2] ) % MOD;
}
int main(){
ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
cout.setf(ios::fixed), cout.precision(7);
//freopen("inevit.in", "r", stdin);
//freopen("inevit.out", "w", stdout);
int step;
step = 1;
//cin >> step;
for (int i = 1; i <= step; i++)
solve();
} | codenet | -1 | 1,894 |
s288371901 | p04051 | 1,515,623,992 | cpp | Accepted | 132 | 66,816 |
#include <cstdio>
#include <cstring>
using namespace std;
void Get_Val(int &Ret)
{
Ret = 0;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
;
do
{
(Ret *= 10) += ch - '0';
}
while (ch = getchar(), ch >= '0' && ch <= '9');
}
//(A[i] + A[j] + B[i] + B[j])! / (A[i] + A[j])! / (B[i] + B[j])!
//等价于(-A[j], -B[j])到(A[i], B[i])的路径计数
const int MOD(1000000000 + 7);
typedef long long int LL;
const int Max_N(200050);
const int Max_AB(4050);
const int Add(2005);
inline int Mult(const int &a, const int &b)
{
return static_cast<int>(static_cast<LL>(a) * static_cast<LL>(b) % static_cast<LL>(MOD));
}
void exgcd(const int &a, const int &b, int &x, int &y)
{
if (b == 0)
x = 1, y = 0;
else
exgcd(b, a % b, y, x), y -= x * (a / b);
}
inline int inverse(const int &a)
{
int invx, invy;
exgcd(a, MOD, invx, invy);
return (invx % MOD + MOD) % MOD;
}
int N, A[Max_N], B[Max_N], F[Max_AB + 5][Max_AB + 5];
int Fac[100000 + 5], Inv[100000 + 5];
void init()
{
Get_Val(N);
for (int i = 1;i <= N;++i)
Get_Val(A[i]), Get_Val(B[i]), ++F[A[i] + Add][B[i] + Add];
}
inline void update(int &a, const int &b)
{
((a += b) >= MOD) ? (a -= MOD) : 0;
}
void dp()
{
for (int i = Add;i >= -Add;--i)
for (int j = Add;j >= -Add;--j)
{
update(F[i + Add][j + Add], F[(i + 1) + Add][j + Add]);
update(F[i + Add][j + Add], F[i + Add][(j + 1) + Add]);
}
}
void work()
{
int Ans(0);
for (int i = 1;i <= N;++i)
update(Ans, F[-A[i] + Add][-B[i] + Add]);
Fac[0] = 1;
for (int i = 1;i <= 100000;++i)
Fac[i] = Mult(Fac[i - 1], i);
Inv[100000] = inverse(Fac[100000]);
for (int i = 100000 - 1;i >= 0;--i)
Inv[i] = Mult(Inv[i + 1], i + 1);
for (int i = 1;i <= N;++i)
Ans -= Mult(Fac[2 * A[i] + 2 * B[i]], Mult(Inv[A[i] + A[i]], Inv[B[i] + B[i]])), Ans = (Ans % MOD + MOD) % MOD;
printf("%d", Mult(Ans, inverse(2)));
}
int main()
{
init();
dp();
work();
return 0;
} | codenet | -1 | 1,894 |
s687877866 | p04051 | 1,569,892,319 | cpp | Accepted | 253 | 189,936 | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;
// #define int ll
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;
void GG(){cout<<"-1\n"; exit(0);}
ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
ll re=1;
while (n>0){
if (n&1) re = re*a %mo;
a = a*a %mo;
n>>=1;
}
return re;
}
ll inv (ll b, ll mo = mod){
if (b==1) return b;
return (mo-mo/b) * inv(mo%b) % mo;
}
const int maxn = 2e3+5;
const int mxn = 1e5+10;
const int K = 2002;
ll nway[4005][4005];
int C[4005][4005];
main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n; cin>>n;
vector<pii> v;
REP(i,n){
int a, b; cin>>a>>b; v.pb({a,b});
nway[K-a][K-b]+=1;
}
ll re = 0;
C[0][0]=1;
REP(i,4005) REP(j,4005){
if (i) C[i][j] += C[i-1][j];
if(C[i][j]>=mod) C[i][j]-=mod;
if (j) C[i][j] += C[i][j-1];
if(C[i][j]>=mod) C[i][j]-=mod;
}
FOR(i,1, 4005) FOR(j,1,4005){
nway[i][j] += nway[i-1][j] + nway[i][j-1]; while(nway[i][j]>=mod) nway[i][j]-=mod;
}
REP(i,n){
int a = v[i].f; int b = v[i].s;
re += nway[a+K][b+K];
re -= C[a*2][b*2]; if (re<0) re += mod;else if (re >= mod) re -= mod;
}
re *= inv(2); re %= mod;
cout<<re<<endl;
} | codenet | -1 | 1,895 |
s394287584 | p04051 | 1,557,525,874 | cpp | Accepted | 280 | 31,616 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX_N = 2000;
const ll MOD = 1000000007;
ll cnt[MAX_N + 1][MAX_N + 1];
ll frac[MAX_N * 4 + 1], inv[MAX_N * 4 + 1];
ll power(ll a, ll n) {
ll ans = 1;
while (n > 0) {
if (n % 2 == 1)
ans = ans * a % MOD;
a = a * a % MOD;
n /= 2;
}
return ans;
}
inline ll binom(int a, int b) {
return frac[a + b] * inv[a] % MOD * inv[b] % MOD;
}
int main() {
frac[0] = inv[0] = 1;
for (int i = 1; i <= 4 * MAX_N; i++)
frac[i] = frac[i - 1] * i % MOD, inv[i] = inv[i - 1] * power(i, MOD - 2) % MOD;
for (int i = 0; i <= MAX_N; i++)
for (int j = 0; j <= MAX_N; j++)
cnt[i][j] = 0;
ll ans = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
ans = (ans - binom(2 * a, 2 * b) + MOD) % MOD;
cnt[a][b]++;
}
for (int i = MAX_N; i > 0; i--)
for (int j = MAX_N; j > 0; j--) {
ll tmp = binom(2 * i, 2 * j) - (binom(2 * (i - 1), 2 * j) + 2 * binom(2 * i - 1, 2 * j - 1) + binom(2 * i, 2 * (j - 1))) % MOD;
tmp = (tmp + MOD) % MOD;
ans = (ans + tmp * cnt[i][j] % MOD * cnt[i][j]) % MOD;
cnt[i - 1][j] = (cnt[i - 1][j] + cnt[i][j]) % MOD;
cnt[i][j - 1] = (cnt[i][j - 1] + cnt[i][j]) % MOD;
}
ll mycnt = 0;
for (int i = 1; i <= MAX_N; i++)
mycnt = (mycnt + cnt[i][0]) % MOD;
ans = (ans + mycnt * mycnt) % MOD;
mycnt = 0;
for (int j = 1; j <= MAX_N; j++)
mycnt = (mycnt + cnt[0][j]) % MOD;
ans = (ans + mycnt * mycnt) % MOD;
for (int i = 1; i <= MAX_N; i++)
for (int j = 1; j <= MAX_N; j++)
ans = (ans + cnt[i][0] * cnt[0][j] % MOD * binom(i, j) % MOD * 2) % MOD;
ans = ans * power(2, MOD - 2) % MOD;
cout << ans << "\n";
}
| codenet | -1 | 1,902 |
s308998490 | p04051 | 1,596,077,356 | cpp | Accepted | 310 | 244,676 | // In The Name Of Allah
// Mohammad Hosseini
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e4 + 100, OO = 724249387, T = 4500 + 100, M = 1e9 + 7, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int fac[N], inv[N], dp[T][T], is[T][T], it[T][T];
int pw(int x, int y) {
if(y == 0)
return 1;
int cnt = pw(x, y / 2);
cnt = (cnt * cnt) % M;
cnt = (cnt * (y % 2 == 1 ? x : 1)) % M;
return cnt;
}
void prepro() {
fac[0] = 1;
for(int i = 1; i <= N - lg; i++)
fac[i] = (fac[i - 1] * i) % M;
inv[N - lg] = pw(fac[N - lg], M - 2);
for(int i = N - lg - 1; i > -1; i--)
inv[i] = (inv[i + 1] * (i + 1)) % M;
}
int c(int x, int y) {
return ((fac[x] * inv[y] % M) * inv[x - y]) % M;
}
int32_t main() {
use_fast;
prepro();
int n, cnt = 0;
cin >> n;
for(int i =0; i < n; i++) {
int x, y;
cin >> x >> y;
cnt -= c(2 * (x + y), 2 * x);
cnt = (cnt % M + M) % M;
is[-x + 2500][-y + 2500]++;
it[x + 2500][y + 2500]++;
}
for(int i = 1; i <= 4550; i++) {
for(int j = 1; j <= 4550; j++) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + is[i][j]) % M;
cnt = (cnt + dp[i][j] * it[i][j]) % M;
}
}
cnt = (cnt * pw(2, M - 2)) % M;
cout << cnt << endl;
return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/
| codenet | -1 | 1,920 |
s335431727 | p04051 | 1,576,121,149 | cpp | Accepted | 228 | 251,904 | #define C
typedef long long readtype;
/* Header {{{ */
#ifdef C
#include <stdio.h>
#include <math.h>
#include <string.h>
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
template<typename type> type abs(type a) { return a < 0 ? -a : a; }
template<typename type> type min(type a, type b) { return a < b ? a : b; }
template<typename type> type beMin(type &a, type b) { return a = (a < b ? a : b); }
template<typename type> type max(type a, type b) { return a > b ? a : b; }
template<typename type> type beMax(type &a, type b) { return a = (a > b ? a : b); }
template<typename type> void swap(type &a, type &b) { type c; c = a; a = b; b = c; }
#endif
#ifdef Cpp
#include <bits/stdc++.h>
using namespace std;
#endif
typedef long long var;
readtype read() {
readtype a = 0, c = getchar(), s = 0;
while (!isdigit(c)) s |= c == '-', c = getchar();
while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
return s ? -a : a;
}
/* }}} */
const int N = 210005;
const int SIZE = 2000;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
int n, a[N], b[N];
var val[SIZE << 1 | 1][SIZE << 1 | 1], f[SIZE << 1 | 1][SIZE << 1 | 1];
int main() {
/*
#ifndef ONLINE_JUDGE
freopen("source.in", "r", stdin);
freopen("source.out", "w", stdout);
#endif
*/
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
f[SIZE - a[i]][SIZE - b[i]]++;
}
val[0][0] = 1;
for (int i = 0; i <= SIZE << 1; ++i) {
for (int j = 0; j <= SIZE << 1; ++j) {
if (i) {
(f[i][j] += f[i - 1][j]) %= MOD;
(val[i][j] += val[i - 1][j]) %= MOD;
}
if (j) {
(f[i][j] += f[i][j - 1]) %= MOD;
(val[i][j] += val[i][j - 1]) %= MOD;
}
}
}
var res = 0;
for (int i = 1; i <= n; ++i) {
(res += f[SIZE + a[i]][SIZE + b[i]]) %= MOD;
(res += MOD - val[a[i] + a[i]][b[i] + b[i]]) %= MOD;
}
printf("%lld\n", (res * inv2) % MOD);
return 0;
}
| codenet | -1 | 1,933 |
s209215389 | p04051 | 1,554,223,181 | cpp | Accepted | 76 | 64,128 | #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
int f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int stack[20];
inline void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(!x){putchar('0');return;}
int top=0;
while(x)stack[++top]=x%10,x/=10;
while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXQ=200005;
const int MAXN=2005;
const int mod=1e9+7;
const int zero=2001;
int pow_mod(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)ret=1LL*ret*a%mod;
a=1LL*a*a%mod;b>>=1;
}
return ret;
}
int pre[4*MAXN],inv[4*MAXN];
int C(int n,int m){return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
int f[2*MAXN][2*MAXN],g[2*MAXN];
struct pt{int x,y;}w[MAXQ];
int n,m;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
// freopen("a.in","r",stdin);
pre[0]=1;for(int i=1;i<4*MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
inv[4*MAXN-1]=pow_mod(pre[4*MAXN-1],mod-2);
for(int i=4*MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
n=read();
for(int i=1;i<=n;i++)w[i].x=read(),w[i].y=read(),m=max(m,max(w[i].x,w[i].y));
for(int i=1;i<=n;i++)f[zero+w[i].x][w[i].y]++;
for(int i=zero+m;i>=zero-m;i--)
{
for(int j=m;j>=0;j--)ad(f[i][j],f[i+1][j]),ad(f[i][j],f[i][j+1]);
g[i]=f[i][1];//强行不走x轴
}
int ans=0;
for(int i=m;i>=-m;i--)
ad(ans,1LL*f[zero+i][0]*g[zero-i]%mod);
for(int i=1;i<=n;i++)dl(ans,C(w[i].x+w[i].x+w[i].y+w[i].y,w[i].x+w[i].x));
ans=1LL*ans*pow_mod(2,mod-2)%mod;
pr2(ans);
return 0;
}
| codenet | -1 | 1,941 |
s631684906 | p04051 | 1,468,796,686 | cpp | Accepted | 592 | 127,232 | #include<bits/stdc++.h>
using namespace std;
struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
const LL mod=1e9+7;
const LL r2=500000004;
LL fact[10000];
struct cww{cww(){
fact[0]=1;for(int i=1;i<10000;i++)fact[i]=(fact[i-1]*i)%mod;
}}ccw;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)
template<typename T>
class svector:private std::vector<T>{
using V=std::vector<T>;
using SV=svector;
private:int sz;
public:
using V::begin;
using V::end;
svector(int n,T ini):V(n*2+1,ini),sz(n){}
svector(int n):SV(n,T()){}
svector():V(),sz(0){}
int size(){return sz;}
T& operator[](int id){return V::operator[](id+sz);}
SV& copy(const SV& other){
V::operator=(other);
sz=other.sz;
return (*this);
}
SV& operator=(const SV &other){
return copy(other);
}
};
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
LL g = a; x = 1; y = 0;
if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
return g;
}
// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
LL x, y;
if (extgcd(a, mod, x, y) == 1)return (x + mod) % mod;
else return 0; // unsolvable
}
// 組み合わせnCk (mod MOD)
// O(n)
LL Comb(LL n,LL k){
LL u=fact[n];
LL d=(fact[k]*fact[n-k])%mod;
return (u*invMod(d))%mod;
}
int main(){
int N;
cin>>N;
vector<int> niku(N),yasai(N);
int t1=0,t2=0;
rep(i,N){
cin>>niku[i]>>yasai[i];
t1=max(t1,niku[i]);
t2=max(t2,yasai[i]);
}
using SV=svector<LL>;
svector<SV> dp(t1+1,SV(t2+1,0));
LL res=0;
rep(i,N){
dp[-niku[i]][-yasai[i]]++;
}
for(int i=-t1;i<=t1;i++)
for(int j=-t2;j<=t2;j++)
(dp[i][j]+=dp[i][j-1]+dp[i-1][j])%=mod;
rep(i,N){
(res+=dp[niku[i]][yasai[i]])%=mod;
}
rep(i,N){
(res+=mod-Comb(niku[i]+niku[i]+yasai[i]+yasai[i],niku[i]+niku[i]))%=mod;
}
(res*=r2)%=mod;
cout<<res<<endl;
return 0;
}
| codenet | -1 | 1,946 |
s281323832 | p04051 | 1,524,589,359 | cpp | Accepted | 229 | 205,056 | #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;
const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=acos(-1);
inline int getint()
{
char ch;int res;bool f;
while (!isdigit(ch=getchar()) && ch!='-') {}
if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
while (isdigit(ch=getchar())) res=res*10+ch-'0';
return f?res:-res;
}
int n;
int a[4248][4248];
LL dp[4248][4248];
const int BASE=2008;
LL fac[100048],inv[100048],finv[100048];
inline void init_inv()
{
fac[0]=fac[1]=1;inv[0]=inv[1]=1;finv[0]=finv[1]=1;
for (register int i=2;i<=100000;i++)
{
inv[i]=MOD-((long long)(MOD/i)*inv[MOD%i])%MOD;
fac[i]=(fac[i-1]*i)%MOD;
finv[i]=(finv[i-1]*inv[i])%MOD;
}
}
inline LL C(int x,int y)
{
if (x<y) return 0ll;
return ((fac[x]*finv[y])%MOD*finv[x-y])%MOD;
}
int main ()
{
int i,j,x,y;
init_inv();
n=getint();
for (i=1;i<=n;i++)
{
x=getint();y=getint();
a[BASE+x][BASE+y]++;
a[BASE-x][BASE-y]++;
}
for (i=1;i<=BASE;i++)
for (j=1;j<=BASE;j++)
dp[i][j]=a[i][j];
for (i=1;i<=BASE*2;i++)
for (j=1;j<=BASE*2;j++)
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
LL ans=0;
for (i=BASE+1;i<=BASE*2;i++)
for (j=BASE+1;j<=BASE*2;j++)
ans=(ans+(dp[i][j]*a[i][j])%MOD)%MOD;
for (i=BASE+1;i<=BASE*2;i++)
for (j=BASE+1;j<=BASE*2;j++)
ans=((ans-((long long)a[i][j]*C((i-BASE+j-BASE)*2,j-BASE+j-BASE))%MOD)%MOD+MOD)%MOD;
ans=(ans*finv[2])%MOD;
printf("%lld\n",ans);
return 0;
}
| codenet | -1 | 1,952 |
s763414289 | p04051 | 1,485,399,117 | cpp | Accepted | 381 | 127,488 | #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};
const int S=4005;
ll Pow_mod(ll n,ll p){
ll r=1;
for(;p>0;p>>=1){
if(p&1) r=(r*n)%mod;
n=(n*n)%mod;
}
return r;
}
vl fact(10000,-1);
ll Fact(ll n){
if(fact[n]!=-1) return fact[n];
if(!n) return fact[0]=1;
return fact[n]=Fact(n-1)*n%mod;
}
ll Division_mod(ll n,ll m){
return n*Pow_mod(m,mod-2)%mod;
}
ll Combination(ll n,ll k){
return Division_mod(Fact(n),Fact(n-k)*Fact(k)%mod);
}
inline int Ind(int x){
return x+2002;
}
int n;
vi a,b;
int main(){
cin>>n;
a=b=vi(n);
for(int i=0;i<n;i++) cin>>a[i]>>b[i];
vvl dp(S,vl(S));
for(int i=0;i<n;i++) dp[Ind(-a[i])][Ind(-b[i])]++;
for(int i=0;i<S;i++) for(int j=0;j<S;j++){
if(i) (dp[i][j]+=dp[i-1][j])%=mod;
if(j) (dp[i][j]+=dp[i][j-1])%=mod;
}
ll ans=0;
for(int i=0;i<n;i++) (ans+=dp[Ind(a[i])][Ind(b[i])])%=mod;
for(int i=0;i<n;i++) ((ans-=Combination(2*(a[i]+b[i]),2*a[i]))+=mod)%=mod;
cout<<Division_mod(ans,2)<<endl;
} | codenet | -1 | 1,952 |
s079955869 | p04051 | 1,554,735,890 | cpp | Accepted | 225 | 64,512 | //Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define orz 1000000007
using namespace std;
int n,x[200005],y[200005],f[4005][4005],ans;
void add(int &x,int y){
x+=y;
if(x>=orz)x-=orz;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d%d",x+i,y+i),++f[2000-x[i]][2000-y[i]];
for(int i=0;i<=4000;++i){
for(int j=0;j<=4000;++j)add(f[i+1][j],f[i][j]),add(f[i][j+1],f[i][j]);
}
for(int i=1;i<=n;++i)add(ans,f[x[i]+2000][y[i]+2000]);
memset(f,0,sizeof(f));
f[0][0]=1;
for(int i=0;i<=4000;++i){
for(int j=0;j<=4000;++j)add(f[i+1][j],f[i][j]),add(f[i][j+1],f[i][j]);
}
for(int i=1;i<=n;++i)add(ans,orz-f[x[i]<<1][y[i]<<1]);
if(ans&1)ans+=orz;
ans>>=1;
printf("%d\n",ans);
//system("pause");
return 0;
}
| codenet | -1 | 1,964 |
s596692509 | p04051 | 1,546,328,989 | cpp | Accepted | 203 | 133,120 | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>
using namespace std;
typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;
const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;
template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }
const Int MO = 1000000007;
int A[200050], B[200050];
Int dp[4096][4096], inv[8192], fact[8192], finv[8192];
const int Z = 2048;
Int comb(int n, int r) {
return fact[n] * finv[r] % MO * finv[n - r] % MO;
}
Int func(int u, int v) {
return comb(A[u] + A[v] + B[u] + B[v], A[u] + A[v]);
}
int main() {
inv[1] = 1;
for (int i = 2; i < 8192; ++i) {
inv[i] = MO - MO / i * inv[MO % i] % MO;
}
fact[0] = finv[0] = 1;
for (int i = 1; i < 8192; ++i) {
fact[i] = (fact[i - 1] * i) % MO;
finv[i] = (finv[i - 1] * inv[i]) % MO;
}
int N = in();
for (int i = 0; i < N; ++i) {
A[i] = in();
B[i] = in();
dp[Z - A[i]][Z - B[i]] += 1;
}
for (int a = 0; a < 4096; ++a) {
for (int b = 0; b < 4096; ++b) {
if (a > 0) dp[a][b] += dp[a - 1][b];
if (b > 0) dp[a][b] += dp[a][b - 1];
dp[a][b] %= MO;
}
}
Int res = 0;
for (int i = 0; i < N; ++i) {
(res += dp[Z + A[i]][Z + B[i]]) %= MO;
(res += MO - func(i, i)) %= MO;
}
(res *= inv[2]) %= MO;
printf("%lld\n", res);
return 0;
}
| codenet | -1 | 1,978 |
s596692509 | p04051 | 1,546,328,989 | cpp | Accepted | 203 | 133,120 | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>
using namespace std;
typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;
const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;
template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }
const Int MO = 1000000007;
int A[200050], B[200050];
Int dp[4096][4096], inv[8192], fact[8192], finv[8192];
const int Z = 2048;
Int comb(int n, int r) {
return fact[n] * finv[r] % MO * finv[n - r] % MO;
}
Int func(int u, int v) {
return comb(A[u] + A[v] + B[u] + B[v], A[u] + A[v]);
}
int main() {
inv[1] = 1;
for (int i = 2; i < 8192; ++i) {
inv[i] = MO - MO / i * inv[MO % i] % MO;
}
fact[0] = finv[0] = 1;
for (int i = 1; i < 8192; ++i) {
fact[i] = (fact[i - 1] * i) % MO;
finv[i] = (finv[i - 1] * inv[i]) % MO;
}
int N = in();
for (int i = 0; i < N; ++i) {
A[i] = in();
B[i] = in();
dp[Z - A[i]][Z - B[i]] += 1;
}
for (int a = 0; a < 4096; ++a) {
for (int b = 0; b < 4096; ++b) {
if (a > 0) dp[a][b] += dp[a - 1][b];
if (b > 0) dp[a][b] += dp[a][b - 1];
dp[a][b] %= MO;
}
}
Int res = 0;
for (int i = 0; i < N; ++i) {
(res += dp[Z + A[i]][Z + B[i]]) %= MO;
(res += MO - func(i, i)) %= MO;
}
(res *= inv[2]) %= MO;
printf("%lld\n", res);
return 0;
}
| codenet | -1 | 1,978 |
s798210284 | p04051 | 1,501,048,916 | cpp | Accepted | 188 | 133,120 | #include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
#define maxn 2010
int dp[2 * maxn + 100][2 * maxn + 100], jest[2 * maxn + 100][2 * maxn + 100];
ll fac[8010], invfac[8010];
ll potmod(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1) res = (res * a ) % mod;
a = (a * a)%mod;
b /= 2;
}
return res;
}
inline ll binom(int n, int k)
{
return fac[n] * invfac[k] % mod * invfac[n - k] % mod;
}
int x[200100], y[200100], n;
int main()
{
fac[0] = invfac[0] = 1;
FOR(i, 1, 8000)
{
fac[i] = fac[i-1] * i % mod;
invfac[i] = potmod(fac[i], mod - 2);
}
boost;
cin >> n;
FOR(i, 1, n)
{
cin >> x[i] >> y[i];
jest[x[i] + maxn][y[i] + maxn]++;
jest[-x[i] + maxn][-y[i] + maxn]++;
}
ll res = 0;
for (int i=-2000; i<=2000; ++i)
for (int j=-2000; j<=2000; ++j)
{
if (i < 0 && j < 0) dp[i + maxn][j + maxn] += jest[i + maxn][j + maxn];
dp[i + maxn][j + maxn] += dp[i + maxn - 1][j + maxn];
dp[i + maxn][j + maxn] += dp[i + maxn][j + maxn - 1];
while (dp[i + maxn][j + maxn] >= mod) dp[i + maxn][j + maxn] -= mod;
if (i > 0 && j > 0) res += (ll)jest[i + maxn][j + maxn] * dp[i + maxn][j + maxn];
res %= mod;
}
//here the part of doing the dp
FOR(i, 1, n)
FOR(j, i, i) res += mod - binom(x[i] + y[i] + x[j] + y[j], x[i] + x[j]);
res %= mod;
res *= potmod(2, mod - 2);
res %= mod;
cout << res;
}
| codenet | -1 | 1,983 |
s849658323 | p04051 | 1,511,714,792 | cpp | Accepted | 143 | 128,640 | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int mod = 1e9 + 7;
const int maxM = 2e5 + 7;
const int maxN = 8e3 + 7;
const int N = 2000;
inline int pls(int x, int y) {return (x + y) % mod;}
inline int mns(int x, int y) {return pls(x, mod - y);}
inline int mul(int x, int y) {return 1LL * x * y % mod;}
inline void Add(int &x, int y) {x = pls(x, y);}
inline void Mul(int &x, int y) {x = mul(x, y);}
inline void Minus(int &x, int y) {x = mns(x, y);}
inline int pwr(int x, int tms) {
int res = 1;
for (; tms > 0; tms >>= 1) {
if (tms & 1) Mul(res, x);
Mul(x, x);
}
return res;
}
inline int inv(int x) {return pwr(x, mod - 2);}
template<class T> inline T rd() {
bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}
int n, A[maxM], B[maxM];
int fac[maxN], ifac[maxN], iv[maxN];
int f[maxN][maxN];
void init() {
iv[1] = 1; For (i, 2, maxN) iv[i] = mul(mod - mod / i, iv[mod % i]);
fac[0] = 1; For (i, 1, maxN) fac[i] = mul(fac[i - 1], i);
ifac[0] = 1; For (i, 1, maxN) ifac[i] = mul(ifac[i - 1], iv[i]);
}
inline int C(int x, int y) {return (y <= x) ? mul(mul(fac[x], ifac[y]), ifac[x - y]) : 0;}
inline int ways(int x, int y) {return C(x + y, x);}
int main() {
init();
n = ri();
rep (i, 1, n) A[i] = ri(), B[i] = ri();
rep (i, 1, n) ++f[N - A[i]][N - B[i]];
rep (i, 0, N << 1) rep (j, 0, N << 1) {
if (i > 0) Add(f[i][j], f[i-1][j]);
if (j > 0) Add(f[i][j], f[i][j-1]);
}
int res = 0;
rep (i, 1, n) Add(res, f[N + A[i]][N + B[i]]);
rep (i, 1, n) Minus(res, ways(A[i] << 1, B[i] << 1));
Mul(res, iv[2]);
printf("%d\n", res);
return 0;
}
| codenet | -1 | 1,992 |
s573174668 | p04051 | 1,509,261,396 | cpp | Accepted | 290 | 191,232 | #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include<unordered_map>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;
const int L = 2000;
const int MAX = 2 * L + 47;
const int MOD = 1000 * 1000 * 1000 + 7;
int A[MAX][MAX];
int dp[MAX][MAX];
int C[MAX][MAX];
void ADD(int& key, int val)
{
key += val;
if (key >= MOD) key -= MOD;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false); cin.tie(0);
int n, m;
cin >> n;
FOR(i, 0, n)
{
int a, b;
cin >> a >> b;
A[L - a][L - b]++;
A[L + a][L + b]++;
}
C[0][0] = 1;
FOR(i, 0, MAX - 1)
{
FOR(j, 0, MAX - 1)
{
ADD(C[i + 1][j], C[i][j]);
ADD(C[i][j + 1], C[i][j]);
}
}
FOR(i, 0, MAX - 1)
{
FOR(j, 0, MAX - 1)
{
if (i < L && j < L && A[i][j])
{
ADD(dp[i][j], A[i][j]);
}
ADD(dp[i + 1][j], dp[i][j]);
ADD(dp[i][j + 1], dp[i][j]);
}
}
int res = 0;
FOR(i, L, MAX)
{
FOR(j, L, MAX)
{
if (A[i][j])
{
ADD(res, (A[i][j] * (LL)dp[i][j]) % MOD);
int a = i - L;
int b = j - L;
res -= (A[i][j] * (LL)C[2 * a][2 * b]) % MOD;
if (res < 0) res += MOD;
}
}
}
res = (res * (LL)500000004) % MOD;
cout << res << endl;
} | codenet | -1 | 2,007 |
s810085334 | p04051 | 1,596,246,230 | cpp | Accepted | 148 | 67,992 | #include<bits/stdc++.h>
namespace imzzy{
#define endl '\n'
#define ccf std::cout<<"phi**k"<<endl
#define rgi register int
#define ll long long
class fastin{private:int _ch,_f;
public:inline fastin&operator>>(char&c){c=getchar();return*this;}
template<typename _Tp>inline fastin&operator>>(_Tp&_x){
_x=0;while(!isdigit(_ch))_f|=(_ch==45),_ch=getchar();
while(isdigit(_ch))_x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
_f&&(_x=-_x,_f=0);return*this;}fastin(){_ch=_f=0;}
}fin;class fastout{private:int _num[32],_head;
public:inline fastout&operator<<(char c){putchar(c);return*this;}
template<typename _Tp> inline fastout&operator<<(_Tp _x){
_Tp _k;if(_x==0){putchar('0');return *this;}if(_x<0)putchar('-'),_x=-_x;
while(_x>0)_k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
while(_head>0)putchar(_num[_head]),--_head;return*this;}fastout(){_head=0;}
}fout;inline void P_INIT(){
#ifdef D_STDOUT_UNBUFFERED
setbuf(stdout,NULL);
#endif
}}using namespace imzzy;
// ----------------------------
// #define int ll
// using namespace std;
const int maxn=200004,maxm=2004;
const int mod=1000000007,inf=1201201201;
inline ll powmod(ll a,ll b) {
ll res=1;
while(b>0) {
if(b&1) (res*=a)%=mod;
(a*=a)%=mod,b>>=1;
} return res;
}
int f[maxm<<1][maxm<<1],x[maxn],y[maxn];
ll fact[maxm<<2],invfact[maxm<<2];
inline ll C(int n,int m) {return fact[n]*invfact[m]%mod*invfact[n-m]%mod;}
signed main()
{P_INIT();
// freopen("yy.in","r",stdin);
// freopen("yy.out","w",stdout);
int n,ans=0; fin>>n;
for(rgi i=1;i<=n;++i) fin>>x[i]>>y[i],++f[maxm-x[i]][maxm-y[i]];
for(rgi i=1;i<maxm<<1;++i) for(rgi j=1;j<maxm<<1;++j)
(f[i][j]+=f[i-1][j]+f[i][j-1])%=mod;
for(rgi i=1;i<=n;++i) (ans+=f[maxm+x[i]][maxm+y[i]])%=mod;
fact[0]=invfact[0]=1;
for(rgi i=1;i<maxm<<2;++i)
fact[i]=fact[i-1]*i%mod,invfact[i]=invfact[i-1]*powmod(i,mod-2)%mod;
for(rgi i=1;i<=n;++i) (ans+=mod-C(2*(x[i]+y[i]),2*x[i]))%=mod;
fout<<(ans*500000004ll)%mod;
return 0;
}
// ----------------------------
// by imzzy
| codenet | -1 | 2,008 |
s080695441 | p04051 | 1,585,344,204 | cpp | Accepted | 130 | 64,768 | #include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
typedef long long int int64;
const int MOD = (int) 1e9 + 7;
void sadd(int &a, int b)
{
a += b;
if (a >= MOD)
a -= MOD;
}
int add(int a, int b)
{
sadd(a, b);
return a;
}
void ssub(int &a, int b)
{
a -= b;
if (a < 0)
a += MOD;
}
int sub(int a, int b)
{
ssub(a, b);
return a;
}
int mul(int a, int b)
{
return (a * 1LL * b) % MOD;
}
const int N = (int) 2e5 + 100;
const int MID = 2005;
const int SZ = MID * 2;
int a[N], b[N];
int dp[SZ][SZ];
int fact[2 * SZ], rfact[2 * SZ], ri[2 * SZ];
void init()
{
fact[0] = rfact[0] = 1;
ri[1] = 1;
for (int i = 1; i < 2 * SZ; i++)
{
if (i != 1)
ri[i] = sub(0, mul(ri[MOD % i], MOD / i));
fact[i] = mul(fact[i - 1], i);
rfact[i] = mul(rfact[i - 1], ri[i]);
}
}
int C(int n, int k)
{
if (k < 0 || k > n)
return 0;
return mul(fact[n], mul(rfact[k], rfact[n - k]));
}
int main(int, char **)
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
init();
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i], &b[i]);
int ans = 0;
for (int i = 0; i < n; i++)
ssub(ans, C(2 * a[i] + 2 * b[i], 2 * a[i]));
for (int i = 0; i < n; i++)
sadd(dp[MID - a[i]][MID - b[i]], 1);
for (int i = 0; i < SZ - 1; i++)
for (int j = 0; j < SZ - 1; j++)
{
sadd(dp[i + 1][j], dp[i][j]);
sadd(dp[i][j + 1], dp[i][j]);
}
for (int i = 0; i < n; i++)
sadd(ans, dp[MID + a[i]][MID + b[i]]);
ans = mul(ans, ri[2]);
printf("%d\n", ans);
return 0;
}
| codenet | -1 | 2,008 |
s686350357 | p04051 | 1,496,969,941 | cpp | Accepted | 241 | 127,232 | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;
char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}
const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;
int n;
int a[200000], b[200000];
ll dp[4001][4001];
ll kai[10001];
ll mod_pow(ll x, ll y){
ll ret = 1;
while(y) {
if(y&1) ret = ret*x%MOD;
x = x*x%MOD;
y /= 2;
}
return ret;
}
ll conb(ll x, ll y) {
ll X = kai[x], Y = kai[y], Z = kai[x-y];
ll ret = X * mod_pow(Y, MOD-2)%MOD;
return ret * mod_pow(Z, MOD-2) % MOD;
}
int main() {
cin >> n;
kai[0] = 1;
for(ll i = 1; i <= 10000; i++) kai[i] = kai[i-1]*i%MOD;
rep(i,n) I(a[i],b[i]);
rep(i,n) {
dp[2000-a[i]][2000-b[i]]++;
}
rep(i,4001) rep(j,4001) {
if(i != 4000) dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
if(j != 4000) dp[i][j+1] = (dp[i][j+1]+dp[i][j])%MOD;
}
ll ans = 0;
rep(i,n) {
ans = (ans+dp[2000+a[i]][2000+b[i]])%MOD;
ans = (ans-conb((a[i]+b[i])*2, a[i]*2)+MOD)%MOD;
}
ans = ans * mod_pow(2, MOD-2) % MOD;
cout << ans << endl;
}
| codenet | -1 | 2,010 |
s224504602 | p04051 | 1,468,722,399 | cpp | Accepted | 1,488 | 47,360 | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
int add(int x, int y)
{
x += y;
if (x >= MOD) return x - MOD;
return x;
}
int sub(int x, int y)
{
x -= y;
if (x < 0) return x + MOD;
return x;
}
int mult(int x, int y)
{
return ((ll)x * y) % MOD;
}
int bin_pow(int x, int p)
{
if (p == 0) return 1;
if (p == 2 || (p & 1)) return mult(x, bin_pow(x, p - 1));
return bin_pow(bin_pow(x, p / 2), 2);
}
int rev(int x)
{
return bin_pow(x, MOD - 2);
}
const int N = 200100;
const int K = 4010;
const int Z = 2002;
int n;
int a[N][2];
int C[K][K];
ll b[K];
int f[2 * K], rf[2 * K];
int ans = 0;
void init()
{
f[0] = 1;
for (int i = 1; i < 2 * K; i++)
f[i] = mult(f[i - 1], i);
rf[2 * K - 1] = rev(f[2 * K - 1]);
for (int i = 2 * K - 1; i > 0; i--)
rf[i - 1] = mult(rf[i], i);
for (int i = 0; i < K; i++)
C[i][0] = C[i][i] = 1;
for (int i = 1; i < K; i++)
for (int j = 1; j < i; j++)
C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
return;
}
void read()
{
/*
n = 200000;
for (int i = 0; i < n; i++)
a[i][0] = a[i][1] = 2000;
*/
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
scanf("%d", &a[i][j]);
return;
}
void solve(int x, int y)
{
/*
for (int i = -x; i <= y; i++)
b[Z - i] = add(b[Z - i], C[x + y][x + i]);
*/
for (int i = -x; i <= y; i++)
b[Z - i] += C[x + y][x + i];
return;
}
int getC(int n, int k)
{
return mult(f[n], mult(rf[k], rf[n - k]));
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
init();
read();
for (int i = 0; i < n; i++)
solve(a[i][0], a[i][1]);
for (int i = -Z; i <= Z; i++)
b[Z + i] %= MOD;
for (int i = -Z; i <= Z; i++)
ans = add(ans, mult(b[Z + i], b[Z - i]));
for (int i = 0; i < n; i++)
ans = sub(ans, getC(2 * (a[i][0] + a[i][1]), 2 * a[i][0]));
if (ans & 1) ans += MOD;
ans /= 2;
printf("%d\n", ans);
return 0;
} | codenet | -1 | 2,017 |
s803346322 | p04051 | 1,509,414,199 | cpp | Accepted | 157 | 67,840 | // This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
char t=getchar();
bool neg=false;
x=0;
for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
if(x<0)putchar('-'),x=-x;
short a[20]= {},sz=0;
while(x>0)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
const int mod=1e9+7;
int dp[4111][4111],n,a[200111],b[200111];
int f[8111],invf[8111];
int power(int x,int y){int ret=1;do{if(y&1)ret=1ll*ret*x%mod;x=1ll*x*x%mod;}while(y>>=1);return ret;}
int calc(int x,int y){return 1ll*f[x+y]*invf[x]%mod*invf[y]%mod;}
int main()
{
f[0]=1;for(int i=1;i<8111;i++)f[i]=1ll*i*f[i-1]%mod;
invf[8111-1]=power(f[8111-1],mod-2);for(int i=8111-2;i>=0;i--)invf[i]=1ll*invf[i+1]*(i+1)%mod;
get1(n);
for(int i=1;i<=n;i++)
{
get2(a[i],b[i]);
dp[2001-a[i]][2001-b[i]]++;
}
for(int i=1;i<=4002;i++)for(int j=1;j<=4002;j++)
{
dp[i][j]+=dp[i-1][j]+dp[i][j-1];
while(dp[i][j]>=mod)dp[i][j]-=mod;
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=mod-calc(a[i]*2,b[i]*2);if(ans>=mod)ans-=mod;
ans+=dp[2001+a[i]][2001+b[i]];if(ans>=mod)ans-=mod;
}
ans=1ll*ans*(mod+1)/2%mod;
printendl(ans);
return 0;
} | codenet | -1 | 2,025 |
s390475465 | p04051 | 1,569,632,952 | cpp | Accepted | 168 | 128,768 | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define int long long
typedef pair<int, int> II;
typedef pair<int, II> III;
const int INF = (1 << 30) - 1;
const long long oo = (1ll << 62) - 1;
const long double PI = 3.1415926535898;
///BEGIN CODE
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int A = 4000 + 5;
int n;
II a[N];
int gt[2 * A], m[A];
int f[A][A];
void giaithua()
{
gt[0] = 1;;
for(int i = 1; i < 2 * A; i++)
gt[i] = (gt[i - 1] * i) % MOD;
}
int power(int a, int b)
{
if(b == 0) return 1;
if(b == 1) return a;
int ans = power(a, b / 2);
ans = (ans * ans) % MOD;
if(b & 1) ans = (ans * a) % MOD;
return ans;
}
void modulo()
{
for(int i = 1; i < A; i++)
{
m[i] = power(gt[i], MOD - 2);
}
}
int tinh(int x, int y)
{
int ans = 1;
int val = gt[x + y];
int m1 = m[x];
int m2 = m[y];
ans = (ans * val) % MOD;
ans = (ans * m2) % MOD;
ans = (ans * m1) % MOD;
return ans;
}
void xuly()
{
for(int i = 1; i <= n; i++)
{
int x = a[i].fi, y = a[i].se;
f[2001 - x][2001 - y] += 1;
}
for(int i = 1; i < A; i++)
{
for(int j = 1; j < A; j++)
{
f[i][j] = (f[i - 1][j] + f[i][j - 1] + f[i][j]) % MOD;
}
}
int res = 0;
for(int i = 1; i <= n; i++)
{
int x = a[i].fi, y = a[i].se;
res = (res + f[2001 + x][2001 + y]) % MOD;
res = (res - tinh(x * 2, y * 2) + MOD * MOD) % MOD;
}
res = (res + MOD * MOD) % MOD;
res = (res * power(2, MOD - 2)) % MOD;
cout << res;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
//freopen("BARECUE.inp", "r", stdin);
//freopen("BARECUE.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n ;i++)
cin >> a[i].fi >> a[i].se;
giaithua();
modulo();
xuly();
}
/**
Code by: Best_Nakroth 12TH.
*/
| codenet | -1 | 2,032 |
s299105386 | p04051 | 1,468,955,115 | cpp | Accepted | 1,079 | 252,160 | #include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> PP;
/*
freopen("input","r",stdin);
freopen("output","w",stdout);
*/
ll MOD = 1E9 + 7;
ll DP[4002][4002];
ll ANS[4002][4002];
ll fac[8010];
ll inv[8010];
ll power(ll a, ll b) {
ll res = 1;
ll crt = a;
while (b > 0) {
if (b % 2 == 1) {
res *= crt;
res %= MOD;
}
crt *= crt;
crt %= MOD;
b /= 2;
}
return res;
}
void init() {
fac[0] = 1;
inv[0] = 1;
ll crt = 1;
for (ll i = 1;i <= 8000;i++) {
crt *= i;
crt %= MOD;
fac[i] = crt;
inv[i] = power(crt, MOD - 2);
}
return;
}
ll cal(int a, int b) {
ll down = inv[a] * inv[b];
down %= MOD;
ll up = fac[a + b] * down;
up %= MOD;
return up;
}
int main() {
//ios::sync_with_stdio(false);
memset(DP, 0, sizeof(DP));
int N;
scanf("%d", &N);
int A[200000], B[200000];
for (int i = 0;i < N;i++) {
int a, b;
scanf("%d%d", &a, &b);
A[i] = a;
B[i] = b;
DP[2000 + a][2000 + b]++;
DP[2000 - a][2000 - b]++;
}
memset(ANS, 0, sizeof(ANS));
ll res = 0;
for (int a = -2000;a <= 2000;a++) {
for (int b = -2000;b <= 2000;b++) {
int i = a + 2000;
int j = b + 2000;
if (DP[i][j] != 0) {
if (a < 0 && b < 0) {
ANS[i][j] += DP[i][j];
ANS[i][j] %= MOD;
}
else {
res += (ANS[i][j] * DP[i][j]) % MOD;
res %= MOD;
ANS[i][j] %= MOD;
}
}
ANS[i + 1][j] += ANS[i][j];
ANS[i + 1][j] %= MOD;
ANS[i][j + 1] += ANS[i][j];
ANS[i][j + 1] %= MOD;
}
}
init();
for (int i = 0;i < N;i++) {
res += MOD - cal(A[i] * 2, B[i] * 2);
res %= MOD;
}
res *= (MOD + 1) / 2;
res %= MOD;
cout << res << endl;
return 0;
}
| codenet | -1 | 2,035 |
s858915000 | p04051 | 1,502,421,872 | cpp | Accepted | 182 | 128,868 | #include<bits/stdc++.h>
using namespace std;
#define MAX 200002
int n;
vector<pair<int, int> > v;
long long int dp[4002][4002];
vector<pair<int, int> > vv;
#define MOD 1000000007
class Combination{
long long int ppow(long long int i, long long int j){
long long int res = 1LL;
while (j){
if ((j & 1LL)){
res *= i;
if (res >= MOD){
res %= MOD;
}
}
j >>= 1;
i *= i;
if (i >= MOD){
i %= MOD;
}
}
return res;
}
public:
vector<long long int> k;
vector<long long int> r;
void resize(int N){
k.resize(N + 2);
r.resize(N + 2);
k[0] = 1;
for (int i = 1; i < N + 2; i++){
k[i] = k[i - 1];
k[i] *= i;
if (k[i] >= MOD)k[i] %= MOD;
}
long long int al = k[k.size() - 1];
long long int iv = ppow(k[k.size() - 1], MOD - 2);
r[k.size() - 1] = iv;
for (int i = (int)(r.size()) - 2; i >= 0; i--){
r[i] = r[i + 1] * (i + 1);
if (r[i] >= MOD){
r[i] %= MOD;
}
}
}
long long int C(int a, int b){
if (a < b)return 0;
long long int up = k[a];
long long int dw = r[b] * r[a - b];
dw %= MOD;
up *= dw;
up %= MOD;
return up;
}
long long int H(int a, int b){
return C(a + b - 1, b);
}
long long int catalan_number(int n){
return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
}
};
Combination C;
int main(){
cin >> n;
C.resize(8002);
for (int i = 0; i < n; i++){
int a, b;
scanf("%d%d", &a, &b);
v.push_back(make_pair(a, b));
dp[2000 - a][2000 - b]++;
vv.push_back(make_pair(2000+a, 2000+b));
}
for (int i = 0; i < 4001; i++){
for (int j = 0; j < 4001; j++){
if (dp[i][j] >= MOD){
dp[i][j] %= MOD;
}
dp[i + 1][j] += dp[i][j];
dp[i][j + 1] += dp[i][j];
}
}
long long int ans = 0;
for (auto i : vv){
ans += dp[i.first][i.second];
if (ans >= MOD){
ans %= MOD;
}
}
ans %= MOD;
for (auto i : vv){
ans += MOD - C.C((i.first - 2000) * 2 + (i.second - 2000) * 2, (i.second - 2000) * 2);
if (ans >= MOD){
ans %= MOD;
}
}
ans %= MOD;
ans *= C.r[2];
ans %= MOD;
printf("%lld\n", ans);
return 0;
} | codenet | -1 | 2,046 |
s353856687 | p04051 | 1,600,303,165 | cpp | Accepted | 127 | 67,348 | /*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;
template <typename T>
void read(T &x) {
x = 0; bool f = 0;
char c = getchar();
for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
for (;isdigit(c);c=getchar()) x=x*10+(c^48);
if (f) x=-x;
}
template<typename F>
inline void write(F x, char ed = '\n') {
static short st[30];short tp=0;
if(x<0) putchar('-'),x=-x;
do st[++tp]=x%10,x/=10; while(x);
while(tp) putchar('0'|st[tp--]);
putchar(ed);
}
template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }
template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }
const int N = 4005;
const int P = 1e9 + 7;
int f[N][N], x[200500], y[200500], lx, ly, n; ll inv[N<<2], fac[N<<2], ans;
inline ll C(int n, int m) { return fac[n] * inv[m] % P * inv[n-m] % P; }
int main() {
read(n);
for (int i = 1;i <= n; i++)
read(x[i]), read(y[i]), Mx(lx, x[i]), Mx(ly, y[i]);
lx++, ly++;
inv[0] = fac[0] = inv[1] = fac[1] = 1;
for (int i = 2;i <= 8002; i++) inv[i] = (P - P / i) * inv[P % i] % P;
for (int i = 2;i <= 8002; i++) fac[i] = fac[i-1] * i % P, inv[i] = inv[i-1] * inv[i] % P;
for (int i = 1;i <= n; i++) f[lx-x[i]][ly-y[i]]++;
for (int i = 1;i <= n; i++) ans -= C((x[i] + y[i]) * 2, x[i] + x[i]);
/* write(ans); */
ans = ans % P + P;
/* ans = 0; */
/* write(lx, ' '), write(ly); */
/* for (int i = 1;i <= n; i++) write(x[i] + lx, ' '), write(y[i] + ly); */
for (int i = 1;i <= 2 * lx; i++)
for (int j = 1;j <= 2 * ly; j++)
f[i][j] = (f[i][j] + f[i-1][j] + f[i][j-1]) % P;
for (int i = 1;i <= n; i++) ans = (ans + f[x[i] + lx][y[i] + ly]) % P;
write(ans * inv[2] % P);
return 0;
}
/*
5
2000 2000
1563 1535
1 565
23 656
153 32
*/ | codenet | -1 | 2,058 |
s031596511 | p04051 | 1,468,724,177 | cpp | Accepted | 189 | 16,128 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;
const int maxn = 2016;
int times[maxn][maxn];
int wys[2][maxn * 2];
int perm[maxn * 4];
int invperm[maxn * 4];
int inv(int x) {
return x < 2 ? x : MOD - (MOD / x) * 1ll * inv(MOD % x) % MOD;
}
int comb(int a, int b) {
return perm[a + b] * 1ll * invperm[a] % MOD * invperm[b] % MOD;
}
int main()
{
perm[1] = invperm[1] = 1;
for (int i = 2; i < maxn * 4; i++) {
perm[i] = perm[i - 1] * 1ll * i % MOD;
invperm[i] = inv(perm[i]);
}
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
int ai, bi;
scanf("%d%d", &ai, &bi);
times[ai][bi] ++;
ans = (ans + MOD - comb(ai * 2, bi * 2)) % MOD;
}
int now = 0;
memset(wys, 0, sizeof(wys));
for (int sum = (maxn - 1) * 2, len = 0; sum > 0; sum --, len ++) {
for (int i = 0; i <= len; i++) {
int x = maxn - 1 - len + i, y = maxn - 1 - i;
if (x > 0 && y > 0) {
(wys[now][i] += times[x][y]) %= MOD;
}
}
int next = now ^ 1;
memcpy(wys[next], wys[now], sizeof(wys[now][0]) * (len + 1));
wys[next][len + 1] = 0;
for (int i = 0; i <= len; i++)
(wys[next][i + 1] += wys[now][i]) %= MOD;
now = next;
}
int len = (maxn - 1) * 2;
for (int i = 0; i <= len; i++) {
(ans += wys[now][i] * 1ll * wys[now][len - i] % MOD) %= MOD;
}
ans = ans * 1ll * inv(2) % MOD;
printf("%d\n", ans);
}
| codenet | -1 | 2,059 |
s182129171 | p04051 | 1,553,612,414 | cpp | Accepted | 136 | 94,976 | //Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
// #include<unordered_map>
using namespace std;
int bin[40],lg[1<<21];
namespace mine
{
typedef long long ll;
#define double long double
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fll;
ll qread()
{
ll ans=0;char c=getchar();int f=1;
while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
return ans*f;
}
void write(ll num)
{
if(num<0) {num=-num;putchar('-');}
if(num>9) write(num/10);
putchar('0'+num%10);
}
void writeln(int num){write(num);puts("");}
#define FR first
#define SE second
#define MP make_pair
#define pr pair<int,int>
#define PB push_back
#define vc vector
inline void chmax(int &x,const int y) {x=x>y?x:y;}
inline void chmin(int &x,const int y) {x=x<y?x:y;}
const int MAX_N=2e5+10;
const int MOD=1e9+7;
void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}
int inv[MAX_N],fac[MAX_N],facinv[MAX_N];
int C(int n,int m) {return (ll)fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
int f[5100][5100];
#define F(i,j) (f[(i)+2100][(j)+2100])
int a[MAX_N],b[MAX_N];
void main()
{
inv[1]=1;for(int i=2;i<MAX_N;i++) inv[i]=ll(MOD-MOD/i)*inv[MOD%i]%MOD;
fac[0]=1;for(int i=1;i<MAX_N;i++) fac[i]=(ll)fac[i-1]*i%MOD;
facinv[0]=1;for(int i=1;i<MAX_N;i++) facinv[i]=(ll)facinv[i-1]*inv[i]%MOD;
int n=qread(),ans=0;
for(int i=1;i<=n;i++)
{
a[i]=qread(),b[i]=qread();
add(ans,MOD-C(2*a[i]+2*b[i],2*a[i]) );
F(-a[i],-b[i])++;
}
for(int i=-2000;i<=2000;i++) for(int j=-2000;j<=2000;j++) add(F(i+1,j),F(i,j)),add(F(i,j+1),F(i,j));
for(int i=1;i<=n;i++) add(ans,F(a[i],b[i]));
write((ll)ans*inv[2]%MOD);
}
};
int main()
{
srand(time(0));
bin[0]=1;for(int i=1;i<=30;i++) bin[i]=bin[i-1]<<1;
lg[1]=0;for(int i=2;i<(1<<21);i++) lg[i]=lg[i>>1]+1;
mine::main();
}
| codenet | -1 | 2,064 |
s791697204 | p04051 | 1,558,710,393 | cpp | Accepted | 115 | 65,280 | #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,V = 2000;
int A[MAXN],B[MAXN],dp[4005][4005];
int fac[100005],invfac[100005];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int C(int n,int m) {
if(n < m) return 0;
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {read(A[i]);read(B[i]);dp[V - A[i]][V - B[i]]++;}
fac[0] = 1;
for(int i = 1 ; i <= 100000 ; ++i) fac[i] = mul(fac[i - 1],i);
invfac[100000] = fpow(fac[100000],MOD - 2);
for(int i = 99999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
for(int i = 0 ; i <= 2 * V ; ++i) {
for(int j = 0 ; j <= 2 * V ; ++j) {
if(!dp[i][j]) continue;
update(dp[i + 1][j],dp[i][j]);
update(dp[i][j + 1],dp[i][j]);
}
}
int ans = 0;
for(int i = 1 ; i <= N ; ++i) {
update(ans,dp[V + A[i]][V + B[i]]);
update(ans,MOD - C(2 * (A[i] + B[i]),2 * A[i]));
}
ans = mul(ans,(MOD + 1) / 2);
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
| codenet | -1 | 2,066 |
s743501249 | p04051 | 1,500,525,139 | cpp | Accepted | 211 | 127,360 | #include <iostream>
#include <vector>
#include <utility>
using namespace std;
long long pow_mod(long long b, long long p, long long mod = 1'000'000'007){
long long ret = 1;
while (p){
if (p & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
p >>= 1;
}
return ret;
}
long long inv_mod(long long n, long long mod = 1'000'000'007){
return pow_mod(n, mod - 2, mod);
}
class ModuloMath{
private:
long long N;
long long mod;
vector<long long> fac;
vector<long long> invfac;
public:
ModuloMath(long long N, long long mod = 1'000'000'007): N{N}, mod{mod}{
fac.resize(N + 1, 1);
invfac.resize(N + 1, 1);
for (long long i = 1; i <= N; ++i) fac[i] = (fac[i - 1] * i) % mod;
invfac[N] = pow_mod(fac[N], mod - 2, mod);
for (long long i = N; i != 1; --i) invfac[i - 1] = (invfac[i] * i) % mod;
}
long long nCr(long long n, long long r){return (r > n or r < 0) ? 0 : (fac[n] * invfac[n - r] % mod * invfac[r] % mod);}
long long nPr(long long n, long long r){return (r > n or r < 0) ? 0 : (fac[n] * invfac[n - r] % mod);}
long long nHr(long long n, long long r){return nCr(n + r - 1, r);}
};
constexpr long long mod = 1'000'000'007;
constexpr int offset = 2002;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ModuloMath mm(offset * 4);
int N;
cin >> N;
vector<pair<int, int>> AB(N);
for (auto & p : AB) cin >> p.first >> p.second;
vector<vector<long long>> dp(offset * 2, vector<long long>(offset * 2, 0LL));
for (auto & p : AB) ++dp[offset - p.first][offset - p.second];
for (int i = 1; i != offset * 2; ++i){
for (int j = 1; j != offset * 2; ++j){
dp[i][j] += (dp[i][j - 1] + dp[i - 1][j]) % mod;
}
}
long long cum = 0LL;
for (auto & p : AB) {
cum = (cum + dp[offset + p.first][offset + p.second]) % mod;
cum = (cum - mm.nCr((p.first + p.second) * 2, p.first * 2) + mod) % mod;
}
if (cum & 1) cum += mod;
cout << (cum / 2) << endl;
return 0;
} | codenet | -1 | 2,070 |
s743501249 | p04051 | 1,500,525,139 | cpp | Accepted | 211 | 127,360 | #include <iostream>
#include <vector>
#include <utility>
using namespace std;
long long pow_mod(long long b, long long p, long long mod = 1'000'000'007){
long long ret = 1;
while (p){
if (p & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
p >>= 1;
}
return ret;
}
long long inv_mod(long long n, long long mod = 1'000'000'007){
return pow_mod(n, mod - 2, mod);
}
class ModuloMath{
private:
long long N;
long long mod;
vector<long long> fac;
vector<long long> invfac;
public:
ModuloMath(long long N, long long mod = 1'000'000'007): N{N}, mod{mod}{
fac.resize(N + 1, 1);
invfac.resize(N + 1, 1);
for (long long i = 1; i <= N; ++i) fac[i] = (fac[i - 1] * i) % mod;
invfac[N] = pow_mod(fac[N], mod - 2, mod);
for (long long i = N; i != 1; --i) invfac[i - 1] = (invfac[i] * i) % mod;
}
long long nCr(long long n, long long r){return (r > n or r < 0) ? 0 : (fac[n] * invfac[n - r] % mod * invfac[r] % mod);}
long long nPr(long long n, long long r){return (r > n or r < 0) ? 0 : (fac[n] * invfac[n - r] % mod);}
long long nHr(long long n, long long r){return nCr(n + r - 1, r);}
};
constexpr long long mod = 1'000'000'007;
constexpr int offset = 2002;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ModuloMath mm(offset * 4);
int N;
cin >> N;
vector<pair<int, int>> AB(N);
for (auto & p : AB) cin >> p.first >> p.second;
vector<vector<long long>> dp(offset * 2, vector<long long>(offset * 2, 0LL));
for (auto & p : AB) ++dp[offset - p.first][offset - p.second];
for (int i = 1; i != offset * 2; ++i){
for (int j = 1; j != offset * 2; ++j){
dp[i][j] += (dp[i][j - 1] + dp[i - 1][j]) % mod;
}
}
long long cum = 0LL;
for (auto & p : AB) {
cum = (cum + dp[offset + p.first][offset + p.second]) % mod;
cum = (cum - mm.nCr((p.first + p.second) * 2, p.first * 2) + mod) % mod;
}
if (cum & 1) cum += mod;
cout << (cum / 2) << endl;
return 0;
} | codenet | -1 | 2,070 |
s978827235 | p04051 | 1,540,496,691 | cpp | Accepted | 521 | 158,592 | #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"
using namespace std;
const long long int MOD = 1000000007;
long long int N, M, K, H, W, L, R;
long long int power(long long int x, long long int n, long long int M) {
long long int tmp = 1;
if (n > 0) {
tmp = power(x, n / 2, M);
if (n % 2 == 0) tmp = (tmp*tmp) % M;
else tmp = (((tmp*tmp) % M)*x) % M;
}
return tmp;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
vector<pair<int, int>>v(N);
for (auto &i : v)cin >> i.first >> i.second;
vector<vector<long long int>>dp(4002, vector<long long int>(4002));
for (auto i : v)dp[i.first + 2000][i.second + 2000]++;
for (int i = 4000; i >= 0; i--) {
for (int j = 4000; j >= 0; j--) {
dp[i][j] += dp[i + 1][j] + dp[i][j + 1];
dp[i][j] %= MOD;
}
}
vector<vector<long long int>>rev_dp(2001, vector<long long int>(2001));
for (auto i : v)rev_dp[2000 - i.first][2000 - i.second]++;
for (int i = 0; i < 2000; i++) {
for (int j = 0; j < 2000; j++) {
if (i)rev_dp[i][j] += rev_dp[i - 1][j];
if (j)rev_dp[i][j] += rev_dp[i][j - 1];
rev_dp[i][j] %= MOD;
}
}
long long int ans = 0;
for (int i = 0; i < 2000; i++) {
//if (i >= 1998) {
// cout << i << " " << dp[i][2000] << " " << rev_dp[i][1999] << endl;
// cout << i << " " << dp[2000][i] << " " << rev_dp[1999][i] << endl;
//}
ans += dp[i][2000] * rev_dp[i][1999];
ans %= MOD;
ans += dp[2000][i] * rev_dp[1999][i];
ans %= MOD;
}
//cout << ans << endl;
vector<long long int>by(8001, 1);
for (int i = 1; i <= 8000; i++) {
by[i] = by[i - 1] * i;
by[i] %= MOD;
}
for (auto i : v) {
long long int minus = by[(i.first + i.second) * 2];
minus *= power(by[i.first * 2], MOD - 2, MOD);
minus %= MOD;
minus *= power(by[i.second * 2], MOD - 2, MOD);
minus %= MOD;
ans += MOD;
ans -= minus;
}
ans %= MOD;
ans *= power(2, MOD - 2, MOD);
ans %= MOD;
cout << ans << endl;
return 0;
} | codenet | -1 | 2,072 |
s341653702 | p04051 | 1,556,066,049 | cpp | Accepted | 114 | 99,328 | #include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 200050
#define MAXM 4050
#define mod 1000000007
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
char ch = getchar(); int f = 1; x = 0;
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
read(x), read(args...);
}
int n, a[MAXN], b[MAXN];
ll jc[MAXM*2], invj[MAXM*2];
int dp[MAXM][MAXM], g[MAXM][MAXM];
ll ans;
int M(int x) {
return x >= mod ? x - mod : x;
}
ll fpow(ll x, ll y) {
ll ret = 1;
while(y) {
if(y & 1) ret = ret * x % mod;
x = x * x % mod;
y >>= 1;
}
return ret;
}
int C(int x, int y) {
return jc[x] * invj[x-y] % mod * invj[y] % mod;
}
int main() {
read(n);
rep(i, 1, n) read(a[i], b[i]);
jc[0] = 1;
rep(i, 1, 8000) jc[i] = jc[i-1] * i % mod;
invj[8000] = fpow(jc[8000], mod-2);
repd(i, 8000, 1) invj[i-1] = invj[i] * i % mod;
rep(i, 1, n)
dp[2000-a[i]][2000-b[i]]++, g[2000+a[i]][2000+b[i]]++;
rep(i, 0, 4000) {
rep(j, 0, 4000) {
ans = (ans + 1ll * g[i][j] * dp[i][j]) % mod;
dp[i+1][j] = M(dp[i+1][j] + dp[i][j]), dp[i][j+1] = M(dp[i][j+1] + dp[i][j]);
}
}
rep(i, 1, n) ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + mod) % mod;
cout << ans * (mod+1) / 2 % mod << endl;
return 0;
}
| codenet | -1 | 2,081 |
s325635587 | p04051 | 1,545,614,004 | cpp | Accepted | 217 | 129,536 | #include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
char ch = getchar();
int x = 0, flag = 1;
for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
return x * flag;
}
void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) write(x / 10);
putchar(x % 10 + 48);
}
const int Maxn = 200009, Maxc = 2009, Mod = (int)1e9 + 7;
int n, a[Maxn], b[Maxn], fac[Maxn], invFac[Maxn];
LL dp[Maxc * 2][Maxc * 2];
inline pair<int, int> getPos(int x, int y) { return make_pair(x + 2000, y + 2000); }
int fpm(int base, int tims) {
int r = 1;
while (tims) {
if (tims & 1) r = 1ll * r * base % Mod;
base = 1ll * base * base % Mod;
tims >>= 1;
}
return r;
}
void init() {
n = read();
rep (i, 1, n) a[i] = read(), b[i] = read();
rep (i, 1, n) {
pair <int, int> s = getPos(-a[i], -b[i]);
dp[s.first][s.second] += 1;
}
fac[0] = 1;
rep (i, 1, Maxn - 1) fac[i] = fac[i - 1] * 1ll * i % Mod;
invFac[Maxn - 1] = fpm(fac[Maxn - 1], Mod - 2);
drep (i, Maxn - 2, 0) invFac[i] = invFac[i + 1] * (i + 1ll) % Mod;
}
int C(int n, int m) {
if (n < m) return 0;
return fac[n] * 1ll * invFac[m] % Mod * invFac[n - m] % Mod;
}
void solve() {
rep (i, 0, 4000)
rep (j, 0, 4000)
(dp[i][j] += ((i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0)) % Mod) %= Mod;
LL ans = 0;
rep (i, 1, n) (ans += dp[2000 + a[i]][2000 + b[i]]) %= Mod;
rep (i, 1, n) (ans += Mod - C(2 * (a[i] + b[i]), 2 * a[i])) %= Mod;
cout << ans * 1ll * invFac[2] % Mod << endl;
}
int main() {
// freopen("AGC001E.in", "r", stdin);
// freopen("AGC001E.out", "w", stdout);
init();
solve();
#ifdef Qrsikno
debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
return 0;
}
| codenet | -1 | 2,081 |
s154058502 | p04051 | 1,590,030,656 | cpp | Accepted | 385 | 203,392 | #include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
ll ex(ll a,ll b){ll ans=1;while(b){if(b&1)ans=(ans*a)%md;a=(a*a)%md,b/=2;}return ans;}
inline ll add(ll a,ll b){a=a%md+b%md;if(a>md)a%=md;return a;}
inline ll sub(ll a,ll b){a=a%md-b%md;if(a<0)a+=md;return a;}
inline ll mul(ll a,ll b){return (a%md*b%md)%md;}
#define M 200010
ll f[M],iv[M];
ll C(ll n,ll r){
if(n<r)return 0;
return mul(f[n],mul(iv[r],iv[n-r]));
}
#define X 5010
ll dp[X+10][X+10];
int main(){
IOS;
tihs;
f[0]=1;
rep(i,1,M)f[i]=mul(i,f[i-1]);
iv[M-1]=ex(f[M-1],md-2);
for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
ll n;cin>>n;
ll a[n],b[n];
rep(i,0,n)cin>>a[i]>>b[i];
ll ans=0,c=2100;
rep(i,0,n)dp[c-a[i]][c-b[i]]++;
rep(i,0,X)rep(j,0,X)(dp[i+1][j+1]+=add(dp[i+1][j],dp[i][j+1]))%=md;
rep(i,0,n)ans=add(ans,dp[c+a[i]][c+b[i]]);
rep(i,0,n)ans=sub(ans,C(2*a[i]+2*b[i],2*b[i]));
ans=mul(ans,ex(2,md-2));
cout<<ans;
return 0;
} | codenet | -1 | 2,083 |
s839120704 | p04051 | 1,503,431,467 | cpp | Accepted | 191 | 68,096 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b) for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const int maxa = 2000 + 10;
const int maxn = 200000 + 10;
template<typename T> T read() {
T n(0), f(1);
char ch = getchar();
for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48;
return n * f;
}
LL fpm(LL base, LL exp) {
LL res = 1;
for(base %= mod; exp > 0; exp >>= 1) {
if(exp & 1)
res = res * base % mod;
base = base * base % mod;
}
return res;
}
LL fac[maxn], ifac[maxn];
LL C(int n, int k) { return fac[n] * ifac[k] % mod * ifac[n-k] % mod; }
void init() {
fac[0] = ifac[0] = 1;
for(int i = 1; i < maxn; ++i) fac[i] = fac[i-1] * i % mod;
ifac[maxn-1] = fpm(fac[maxn-1], mod-2);
for(int i = maxn-1; i >= 1; --i) ifac[i-1] = ifac[i] * i % mod;
}
int a[maxn], b[maxn], n;
int dp[maxa << 1][maxa << 1];
int main() {
//freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
init();
n = read<int>();
for(int i = 1; i <= n; ++i) {
a[i] = read<int>(), b[i] = read<int>();
dp[maxa - a[i]][maxa - b[i]] ++;
}
for(int i = 1; i < (maxa << 1); ++i)
for(int j = 1; j < (maxa << 1); ++j) {
dp[i][j] = (dp[i][j] + (dp[i-1][j] + dp[i][j-1]) % mod) % mod;
}
int ans = 0;
for(int i = 1; i <= n; ++i) {
ans = (ans + dp[maxa + a[i]][maxa + b[i]]) % mod;
ans = (ans - C(2*a[i] + 2*b[i], 2*a[i])) % mod;
}
ans = ans * fpm(2, mod-2) % mod;
printf("%d\n", (ans % mod + mod) % mod);
return 0;
}
| codenet | -1 | 2,084 |
s553526528 | p04051 | 1,527,626,178 | cpp | Accepted | 141 | 65,920 | #include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define all(x) (x).begin(), (x).end()
//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 18; // segment tree size
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f; // memset(dp, 0x3f, sizeof(dp)), 2*INF < INT_MAX
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10; // double EPS
ll mul_inv(ll a, ll b = MOD) {
ll t1 = a, t2 = b, t3;
ll v1 = 1, v2 = 0, v3;
while (t2 != 1) {
ll x = t1 / t2;
t3 = t1 - x*t2;
v3 = v1 - x*v2;
t1 = t2, t2 = t3;
v1 = v2, v2 = v3;
}
return (v2 + b) % b;
}
ll F[8050];
ll Finv[8050];
int sum[4050][4050];
int in[200050][2];
int main() {
int N, i, j;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%d %d", &in[i][0], &in[i][1]);
sum[2001 - in[i][0]][2001 - in[i][1]]++;
}
for (i = 1; i <= 4002; i++) {
for (j = 1; j <= 4002; j++) {
sum[i][j] = (sum[i][j] + sum[i - 1][j]) % MOD;
sum[i][j] = (sum[i][j] + sum[i][j - 1]) % MOD;
}
}
F[0] = 1;
for (i = 1; i <= 8020; i++) F[i] = F[i - 1] * i % MOD;
for (i = 0; i <= 8020; i++) Finv[i] = mul_inv(F[i]);
ll ans = 0;
for (i = 1; i <= N; i++) ans = (ans + sum[2001 + in[i][0]][2001 + in[i][1]]) % MOD;
for (i = 1; i <= N; i++) {
ll v = F[in[i][0] * 2 + in[i][1] * 2];
v = v * Finv[in[i][0] * 2] % MOD;
v = v * Finv[in[i][1] * 2] % MOD;
ans = (ans - v + MOD) % MOD;
}
return !printf("%lld\n", ans * mul_inv(2) % MOD);
} | codenet | -1 | 2,092 |
s700043753 | p04051 | 1,565,700,118 | cpp | Accepted | 161 | 68,480 | #include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {
K = 0 ; bool F = false ; char C = getchar() ; while( C < '0' or C > '9' ) { if( C == '-' ) F = true ; C = getchar() ; }
while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ; if( F ) K = -K ;
}
template < class R > inline void Checkmax( R &A , R B ) {
if( A < B ) A = B ;
}
template < class R > inline void Checkmin( R &A , R B ) {
if( A > B ) A = B ;
}
const int Mod = 1e9 + 7 ;
inline void Moding( int &A ) {
if( A >= Mod ) A -= Mod ;
if( A < 0 ) A += Mod ;
}
inline int Pow( int A , int B ) {
register int Ans = 1 ;
while( B ) {
if( B & 1 ) Ans = 1ll * Ans * A % Mod ;
A = 1ll * A * A % Mod ;
B >>= 1 ;
}
return Ans ;
}
const int MaxN = 400000 + 10 ;
const int MaxM = 4000 + 10 ;
int N ;
int A[MaxN] , B[MaxN] ;
int Fac[MaxN] , Inv[MaxN] ;
inline int C( int N , int M ) {
return 1ll * Fac[M] * Inv[N] % Mod * Inv[M-N] % Mod ;
}
inline int F( int N , int M ) {
return C( N , N + M ) ;
}
int Dp[MaxM][MaxM] ;
inline int DP() {
register int Ans = 0 ;
for(register int i = 0 ; ++i <= N ; ) {
++Dp[2001-A[i]][2001-B[i]] ;
--Dp[2001+A[i]][2001+B[i]] ;
}
for(register int i = 0 ; ++i <= 4001 ; )
for(register int j = 0 ; ++j <= 4001 ; ) {
register int Vot = 0 ;
if( Dp[i][j] < 0 ) {
Vot = -Dp[i][j] ;
Dp[i][j] = 0 ;
}
Moding( Dp[i][j] += Dp[i-1][j] + Dp[i][j-1] - Mod ) ;
Moding( Ans += 1ll * Vot * Dp[i][j] % Mod ) ;
}
return Ans ;
}
inline int MORE() {
register int Ans = 0 ;
for(register int i = 0 ; ++i <= N ; )
Moding( Ans += F( A[i] << 1 , B[i] << 1 ) ) ;
return Ans ;
}
int main() {
N = 400000 ;
Fac[0] = Inv[0] = 1 ;
for(register int i = 0 ; ++i <= N ; )
Fac[i] = 1ll * Fac[i-1] * i % Mod ;
Inv[N] = Pow( Fac[N] , Mod - 2 ) ;
for(register int i = N ; --i ; )
Inv[i] = 1ll * Inv[i+1] * (i+1) % Mod ;
Readin( N ) ;
for(register int i = 0 ; ++i <= N ; ) {
Readin( A[i] ) ;
Readin( B[i] ) ;
}
return not printf( "%lld\n" , 1ll * ( DP() - MORE() + Mod ) % Mod * ( Mod + 1 >> 1 ) % Mod ) ;
} | codenet | -1 | 2,094 |
s573152665 | p04051 | 1,468,911,032 | cpp | Accepted | 530 | 127,360 | #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
if(p) cout << fixed << setprecision(p) << a << "\n";
else cout << a << "\n";
}
// end of template
const int X = 2002;
const int Y = 4004;
vector<ll> fact(8008, 1);
vector<ll> inv_fact(8008, 1);
ll pow_mod(ll a, ll b, ll m){
ll ret = 1;
while (b > 0) {
if (b & 1) {
ret = ret * a % m;
}
a = a * a % m;
b >>= 1;
}
return ret;
}
ll inv_mod(ll a, ll m){
return pow_mod(a, m - 2, m);
}
void pre_fact(){
repd(i, 1, 8008){
fact[i] = (fact[i - 1] * i) % mod;
inv_fact[i] = inv_mod(fact[i], mod);
}
}
ll comb(int n, int m){
return ((fact[n] * inv_fact[m]) % mod * inv_fact[n - m]) % mod;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
pre_fact();
vector<vector<ll>> dp(Y, vector<ll>(Y, 0));
int N;
cin >> N;
vector<int> A(N), B(N);
ll sub = 0;
rep(i, N){
cin >> A[i] >> B[i];
dp[X - A[i]][X - B[i]]++;
(sub += comb(2 * (A[i] + B[i]), 2 * A[i])) %= mod;
}
rep(i, Y) rep(j, Y){
if(i > 0) (dp[i][j] += dp[i - 1][j]) %= mod;
if(j > 0) (dp[i][j] += dp[i][j - 1]) %= mod;
// if(i + 1 < Y) (dp[i + 1][j] += dp[i][j]) %= mod;
// if(j + 1 < Y) (dp[i][j + 1] += dp[i][j]) %= mod;
}
ll ret = 0;
rep(i, N) {
(ret += dp[X + A[i]][X + B[i]]) %= mod;
}
(ret -= sub) %= mod;
(((ret *= inv_mod(2, mod)) %= mod) += mod) %= mod;
output(ret, 0);
return 0;
} | codenet | -1 | 2,096 |
s595967697 | p04051 | 1,494,694,404 | cpp | Accepted | 221 | 95,872 | #define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int M = 2e3 + 10;
int dp[M << 1][M << 1];
int target[M << 1][M << 1];
int F[9000];
int64 power_mod(int64 a, int n) {
int64 ret = 1;
for (; n; n >>= 1) {
if (n & 1) ret = ret * a % MOD;
a = a * a % MOD;
}
return ret;
}
int64 inv_mod(int64 a) {
return power_mod(a, MOD - 2);
}
int comb(int n, int m) {
return (int64)F[n] * inv_mod(F[m]) % MOD * inv_mod(F[n - m]) % MOD;
}
int main() {
F[0] = 1;
for (int i = 1; i < 9000; ++i) {
F[i] = (int64)F[i - 1] * i % MOD;
}
int n, ret = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
dp[M - x][M - y] += 1;
target[M + x][M + y] += 1;
// trace(comb((x + y) << 1, x << 1));
ret = (ret + MOD - comb((x + y) << 1, x << 1)) % MOD;
}
// trace(ret);
for (int i = 0; i < (M << 1); ++i) {
for (int j = 0; j < (M << 1); ++j) {
if (i - 1 >= 0) {
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
}
if (j - 1 >= 0) {
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
}
if (target[i][j]) {
ret = (ret + (int64)target[i][j] * dp[i][j]) % MOD;
}
}
}
printf("%lld\n", ret * inv_mod(2) % MOD);
return 0;
}
| codenet | -1 | 2,102 |
s189121256 | p04051 | 1,581,211,445 | cpp | Accepted | 181 | 158,976 | #include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e3;
const int NN = N*2+1;
int n;
int c[NN][NN];
ll DP[NN][NN];
main(){
cin.tie(0);
ios::sync_with_stdio(false);
setF(N*4, MOD);
cin >> n;
ll ans = 0;
FOR(i, 0, n){
int a, b;
cin >> a >> b;
ans -= comb(a*2+b*2, a*2, MOD);
DP[N-a][N-b]++;
c[N+a][N+b]++;
}
FOR(i, 0, NN)FOR(j, 0, NN){
if(i) DP[i][j] += DP[i-1][j];
if(j) DP[i][j] += DP[i][j-1];
DP[i][j] %= MOD;
ans += DP[i][j] * c[i][j] % MOD;
}
cout << (ans%MOD+MOD)*modInv(2, MOD)%MOD << endl;
} | codenet | -1 | 2,107 |
s407770574 | p04051 | 1,558,632,400 | cpp | Accepted | 411 | 159,600 | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
long long dp[5000][5000] = {};
long long bobo[10000] = {};
long long inverse[10000] = {};
long long inv(long long now) {
long long ans = 1;
long long te = MAX_MOD - 2LL;
while (te != 0) {
if (te % 2 == 1) {
ans *= now;
ans %= MAX_MOD;
}
te /= 2;
now *= now;
now %= MAX_MOD;
}
return ans;
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> now_go;
REP(i, n) {
int a, b;
cin >> a >> b;
dp[2000 - a][2000 - b]++;
now_go.push_back(make_pair(2000+a, 2000+b));
}
for (int i = 0; i <= 4000; ++i) {
for (int q = 0; q <= 4000; ++q) {
dp[i + 1][q] += dp[i][q];
dp[i + 1][q] %= MAX_MOD;
dp[i][q + 1] += dp[i][q];
dp[i][q + 1] %= MAX_MOD;
}
}
bobo[1] = 1;
inverse[1] = 1;
for (long long i = 2; i <= 8000; ++i) {
bobo[i] = i * bobo[i - 1];
bobo[i] %= MAX_MOD;
inverse[i] = inv(bobo[i]);
}
long long ans = 0;
REP(i, now_go.size()) {
ans += dp[now_go[i].first][now_go[i].second];
ans %= MAX_MOD;
now_go[i].first -= 2000;
now_go[i].second -= 2000;
long long geko = bobo[(now_go[i].first + now_go[i].second)*2];
geko *= inverse[now_go[i].first * 2];
geko %= MAX_MOD;
geko *= inverse[now_go[i].second * 2];
geko %= MAX_MOD;
ans -= geko;
ans += MAX_MOD;
ans %= MAX_MOD;
}
ans *= MAX_MOD / 2LL + 1LL;
ans %= MAX_MOD;
cout << ans << endl;
return 0;
} | codenet | -1 | 2,109 |
s691173667 | p04051 | 1,558,626,347 | cpp | Accepted | 116 | 64,512 | #include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=2e5+10;
const int base=2000;
int n;
int a[maxn],b[maxn],f[4005][4005],fac[maxn],ifac[maxn];
int C(int x,int y){
if(x<y)return 0;
return mul(fac[x],ifac[y],ifac[x-y]);
}
int main(){
#ifdef LOCAL
freopen("/home/noilinux/Desktop/input.txt","r",stdin);
#endif
n=gi();
rep(i,1,n)a[i]=gi(),b[i]=gi(),f[base-a[i]][base-b[i]]++;
fac[0]=ifac[0]=1;
rep(i,1,8000)fac[i]=mul(fac[i-1],i);
ifac[8000]=inv(fac[8000]);
repd(i,7999,1)ifac[i]=mul(ifac[i+1],i+1);
rep(i,0,4000)rep(j,0,4000){
if(i!=0)f[i][j]=pls(f[i][j],f[i-1][j]);
if(j!=0)f[i][j]=pls(f[i][j],f[i][j-1]);
}
int ans=0;
rep(i,1,n)ans=pls(ans,f[a[i]+base][b[i]+base]);
rep(i,1,n)ans=dec(ans,C(a[i]+a[i]+b[i]+b[i],a[i]+a[i]));
printf("%d\n",mul(ans,(mod+1)/2));
return 0;
} | codenet | -1 | 2,113 |
s602265477 | p04051 | 1,550,883,520 | cpp | Accepted | 140 | 64,768 | //2019.2.22 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-10
inline int read() {
res s=0;
bool w=0;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-')w=1;
ch=getchar();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
return w?-s:s;
}
inline void _swap(res &x,res &y) {
x^=y^=x^=y;
}
inline int _abs(const res &x) {
return x>0?x:-x;
}
inline int _max(const res &x,const res &y) {
return x>y?x:y;
}
inline int _min(const res &x,const res &y) {
return x<y?x:y;
}
const int N=2e5+10;
const int kcz=1e9+7;
const int M=4e3+20;
namespace MAIN {
inline int qpow(res x,res y){
res ret=1;
while(y){
if(y&1)ret=1LL*ret*x%kcz;
y>>=1,x=1LL*x*x%kcz;
}
return ret;
}
int n;
inline void add(res &x,const res &y){
x+=y,x>=kcz?x-=kcz:1,x<0?x+=kcz:1;
}
int fac[M<<1],inv[M<<1];
inline void pre(){
fac[0]=fac[1]=inv[0]=inv[1]=1;
for(res i=2;i<=M*2-10;i++)fac[i]=1LL*fac[i-1]*i%kcz,inv[i]=1LL*inv[kcz%i]*(kcz-kcz/i)%kcz;
for(res i=2;i<=M*2-10;i++)inv[i]=1LL*inv[i]*inv[i-1]%kcz;
}
inline int mul(const res &x,const res &y){
return 1LL*x*y%kcz;
}
inline int C(const res &x,const res &y){
if(x<y)return 0;
return mul(fac[x],mul(inv[y],inv[x-y]));
}
int dp[M][M];
int a[N],b[N];
inline int Add(const res &x,const res &y){
return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y);
}
int ans;
inline void MAIN(){
n=read(),pre();
for(res i=1;i<=n;i++)a[i]=read(),b[i]=read(),dp[2001-a[i]][2001-b[i]]++;
for(res i=1;i<=4002;i++)
for(res j=1;j<=4002;j++)add(dp[i][j],Add(dp[i-1][j],dp[i][j-1]));
for(res i=1;i<=n;i++)add(ans,Add(dp[2001+a[i]][2001+b[i]],-C((a[i]+b[i])*2,a[i]*2)));
printf("%d\n",mul(ans,qpow(2,kcz-2)));
}
}
int main() {
// freopen("number.in","r",stdin);
// freopen("number.out","w",stdout);
MAIN::MAIN();
return 0;
} | codenet | -1 | 2,114 |
s351487558 | p04051 | 1,578,727,437 | cpp | Accepted | 285 | 64,384 | /*
[agc001] E - BBQ Hard
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()
const int MAX_N = 200000;
const int MAX_A = 2000;
const int MOD = 1e9 + 7;
class gf {
public:
int n;
static int mod_inv(int a, int m) {
int u = 0, v = 1;
while (a != 0) {
int t = m / a;
m -= t * a;
u -= t * v;
swap(a, m);
swap(u, v);
}
return (u + MOD) % MOD;
}
gf() : n(0) {}
gf(int n) : n(n % MOD) {}
gf operator+(gf x) { return gf((n + x.n) % MOD); }
gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
gf operator/(gf x) { return *this * x.inv(); }
gf& operator+=(gf x) { return *this = (*this + x); }
gf& operator-=(gf x) { return *this = (*this - x); }
gf& operator*=(gf x) { return *this = (*this * x); }
gf& operator/=(gf x) { return *this = (*this / x); }
gf inv() { return gf(mod_inv(n, MOD)); }
};
gf fact[4 * MAX_A + 1];
gf combi(int n, int k) {
return (n < 0 || k < 0 || n - k < 0) ? 0
: fact[n] / (fact[k] * fact[n - k]);
}
int N;
int A[MAX_N], B[MAX_N];
gf m_raw[2 * (MAX_A + 1)][2 * (MAX_A + 1)];
gf& m(int x, int y) { return m_raw[x + MAX_A][y + MAX_A]; }
ll solve() {
fact[0] = 1;
for (int i = 1; i <= 4 * MAX_A; i++) {
fact[i] = fact[i - 1] * i;
}
for (int i = 0; i < N; i++) {
m(-A[i], -B[i]) += 1;
}
for (int i = -MAX_A; i <= MAX_A; i++) {
for (int j = -MAX_A; j <= MAX_A; j++) {
m(i + 1, j) += m(i, j);
m(i, j + 1) += m(i, j);
}
}
gf ans = 0;
for (int i = 0; i < N; i++) {
ans += m(A[i], B[i]);
ans -= combi(2 * A[i] + 2 * B[i], 2 * A[i]);
}
ans /= 2;
return ans.n;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
cout << solve() << endl;
return 0;
}
| codenet | -1 | 2,139 |
s058504967 | p04051 | 1,514,324,930 | cpp | Accepted | 233 | 3,328 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define M 2000
#define MM 4010
int c[2][MM+10];
vector<int> v[M], v2[M];
ll inv[MM*2+1], fact[MM*2+1], ifact[MM*2+1];
void init_fact(ll n){
inv[1] = 1;
for(int i = 2; i < n; i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
fact[0] = ifact[0] = 1;
for(int i = 1; i < n; i++){
fact[i] = (fact[i-1]*i)%mod;
ifact[i]=(ifact[i-1]*inv[i])%mod;
}
}
ll comb(ll a, ll b){
return fact[a+b]*ifact[a]%mod*ifact[b]%mod;
}
ll pow_mod(ll a, ll r, ll m){
ll x = 1;
while(r){
if(r&1) (x*=a)%=m;
(a*=a)%=m;
r>>=1;
}
return x;
}
int main(){
int n;
cin>>n;
init_fact(MM*2);
ll res = 0;
rep(i, n){
int a, b;
cin>>a>>b;
v[M-a].push_back(M-b);
v2[a-1].push_back(M+b);
(res-=comb(2*a, 2*b))%=mod;
}
rep(i, M*2+1){
int t = i%2;
if(i<M){
for(auto b: v[i]){
c[t][b]++;
}
}
mset(c[!t], 0);
rep(j, MM){
(c[t][j+1]+=c[t][j])%=mod;
(c[!t][j]+=c[t][j])%=mod;
}
if(i>M){
for(auto b: v2[i-M-1]){
(res+=c[t][b])%=mod;
}
}
}
cerr<<res<<endl;
(res*=inv[2])%=mod;
cout<<(res+mod)%mod<<endl;
return 0;
}
| codenet | -1 | 2,150 |
s344089301 | p04051 | 1,559,001,872 | cpp | Accepted | 327 | 96,896 | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=2010;
const ll mod=1e9+7;
const ll maxm=1e5+500;
int s[maxn*2][maxn*2];
int t[maxn*2][maxn*2];
ll fac[maxm];
ll rfac[maxm];
ll ent(ll n,ll k){
if(k<0 || k>n)return 0;
return (fac[n]*((rfac[k]*rfac[n-k])%mod))%mod;
}
ll poww(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
b>>=1;
}
return ans;
}
int main(){
fac[0]=1;
for(ll i=1;i<maxm;i++){
fac[i]=(fac[i-1]*i)%mod;
}
for(ll i=0;i<maxm;i++){
rfac[i]=poww(fac[i],mod-2);
}
ll n;
cin>>n;
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(ll i=1;i<maxn*2;i++){
for(ll j=1;j<maxn*2;j++){
s[i][j]+=(s[i-1][j]+s[i][j-1])%mod;
s[i][j]%=mod;
ans+=((ll)s[i][j]*(ll)t[i][j])%mod;
ans%=mod;
}
}
cout<<(ans*poww(2,mod-2))%mod;
}
| codenet | -1 | 2,157 |
s109857625 | p04051 | 1,588,378,847 | cpp | Accepted | 268 | 66,432 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
bool prime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
vector<int>kaijo;
void init_fact(int n){
kaijo.resize(n+1);
kaijo[0]=1;
for(int i=1;i<=n;i++){
kaijo[i]=kaijo[i-1]*i;
kaijo[i]%=mod;
}
}
int modpow(int a,int b){
if(b==0)return 1;
if(b%2)return modpow(a,b-1)*a%mod;
int memo=modpow(a,b/2);
return memo*memo%mod;
}
int comb(int a,int b){
//if(!kaijo[0])init_fact();
return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
x=modpow(x,mod-2);
return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
return tc*td<0&&ta*tb<0;
}
int n,a[200010],b[200010],dp[2010][4010];
signed main(){
cin>>n;
rep(i,n){
cin>>a[i]>>b[i];
dp[2000-a[i]][2000-b[i]]++;
}
for(int i=0;i<=2000;i++){
for(int j=0;j<=4000;j++){
dp[i][j]%=mod;
dp[i+1][j]+=dp[i][j];
dp[i][j+1]+=dp[i][j];
}
}
int ans=0;
for(int i=0;i<=4000;i++){
ans+=dp[1999][i]*dp[2000][4000-i];
ans%=mod;
}
init_fact(10000);
rep(i,n){
a[i]*=2;
b[i]*=2;
ans-=comb(a[i]+b[i],a[i]);
ans+=mod;
ans%=mod;
}
ans*=inv(2);
ans%=mod;
cout<<ans<<endl;
return 0;
} | codenet | -1 | 2,159 |
s148692433 | p04051 | 1,487,745,955 | cpp | Accepted | 269 | 127,360 | #include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first
#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL MOD=1E9+7;
struct Problem{
int n;
vector<int> a,b;
const int nn=4004;
vector<vector<LL>> _dp;
Problem(LL n):n(n),a(n),b(n),_dp(nn,vector<LL>(nn)){};
long long modpow(long long a, long long n,long long mod=MOD){
long long i=1,ret=1,p=a;
while(i<=n){
if(i&n) ret=(ret*p)%mod;
i=(i<<1);
p=(p*p)%mod;
}
return ret;
}
void solve(){
vector<LL> fac(2*nn);
fac[0]=1;
for(int i=1; i<(int)fac.size(); ++i){
fac[i]=fac[i-1]*i%MOD;
}
auto dp = [&](int x, int y) -> auto& {return _dp[x+2001][y+2001];};
for(int i=0; i<n; ++i){
cin >> a[i] >> b[i];
dp(-a[i],-b[i])++;
}
for(int i=-2000; i<=2000; ++i){
for(int j=-2000; j<=2000; ++j){
dp(i,j)=(dp(i,j)+dp(i-1,j)+dp(i,j-1))%MOD;
}
}
LL ans =0;
for(int i=0; i<n; ++i){
ans=(ans+dp(a[i],b[i]))%MOD;
}
DBG(ans)
for(int i=0; i<n; ++i){
LL to_self=(fac[a[i]*2+b[i]*2]*modpow(fac[a[i]*2],MOD-2)%MOD)*modpow(fac[b[i]*2],MOD-2)%MOD;
DBG(to_self)
ans=(ans- to_self+MOD)%MOD;
}
cout << ans*modpow(2,MOD-2)%MOD <<"\n";
}
};
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
Problem p(n);
p.solve();
return 0;
}
| codenet | -1 | 2,160 |
s890992674 | p04051 | 1,571,757,993 | cpp | Accepted | 152 | 80,128 | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long ll;
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define Rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
#define Eep(i , u , v) for(int i = Head[u] , v = Node[i] ; i ; v = Node[i = Next[i]])
using namespace std;
const int N = 4000 + 7 , Blo = 2001 , Mod = 1000000000 + 7 , M = 2000000 + 7;
inline int Mul(int A , int B) { return 1ll * A * B % Mod; }
inline int Inc(int A , int B) { A += B; return A >= Mod ? A - Mod : A; }
inline int Dec(int A , int B) { A -= B; return A < 0 ? A + Mod : A; }
inline int KSM(int x , int p) {
int Ans = 1;
while(p) {
if(p & 1) Ans = Mul(Ans , x);
x = Mul(x , x) , p >>= 1;
}
return Ans;
}
int n , Dp[N][N] , tota , totb , Fac[M] , Inv[M];
struct YYZ {
int a , b;
}A[200000 + 7] , B[200000 + 7];
inline int C(int n , int m) { return Mul(Mul(Fac[n] , Inv[m]) , Inv[n - m]); }
inline int Solve1() {
int Ret = 0;
Rep(i , 1 , tota) inc(Dp[Blo - A[i].a][Blo - A[i].b]);
Rep(i , 1 , (Blo << 1)) Rep(j , 1 , (Blo << 1)) Dp[i][j] = Inc(Dp[i][j] , Inc(Dp[i][j - 1] , Dp[i - 1][j]));
Rep(i , 1 , tota) Ret = Inc(Ret , Dp[A[i].a + Blo][A[i].b + Blo]);
Rep(i , 1 , tota) Ret = Dec(Ret , C((A[i].a + A[i].b) << 1 , A[i].b << 1));
return Ret;
}
inline int Solve2() {
int Ret = 0;
Rep(i , 1 , totb) {
Rep(j , 1 , tota) Ret = Inc(Ret , C(B[i].a + B[i].b + A[j].a + A[j].b , B[i].a + A[j].a));
Rep(j , 1 , totb) if(i != j) Ret = Inc(Ret , C(B[i].a + B[i].b + B[j].a + B[j].b , B[i].a + B[j].a));
}
return Ret;
}
int main() {
// freopen("gift.in" , "r" , stdin);
// freopen("gift.out" , "w" , stdout);
Fac[0] = 1; Rep(i , 1 , M - 1) Fac[i] = Mul(Fac[i - 1] , i);
Inv[M - 1] = KSM(Fac[M - 1] , Mod - 2); rep(i , M - 2 , 0) Inv[i] = Mul(Inv[i + 1] , i + 1);
int x , y;
scanf("%d" , &n);
Rep(i , 1 , n) {
scanf("%d%d" , &x , &y);
if(x >= Blo || y >= Blo) B[inc(totb)] = (YYZ){x , y};
else A[inc(tota)] = (YYZ){x , y};
}
printf("%lld" , 1ll * Inc(Solve1() , Solve2()) * KSM(2 , Mod - 2) % Mod);
return 0;
} | codenet | -1 | 2,163 |
s847197338 | p04051 | 1,468,926,164 | cpp | Accepted | 488 | 127,232 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
const int mod = (int)1e9 + 7;
void add (int &a, int b)
{
a += b;
if (a >= mod)
a -= mod;
}
void sub (int &a, int b)
{
a -= b;
if (a < 0)
a += mod;
}
int mult (int a, int b)
{
return (ll)a * b % mod;
}
void solve (int n)
{
vi a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
const int bound = 2 * *max_element(ALL(a)) + 2 * *max_element(ALL(b)) + 2;
vi fact(bound, 1), invfact(bound, 1), inv(bound, 1);
for (int i = 2; i < bound; i++)
{
fact[i] = mult(fact[i - 1], i);
inv[i] = mult(inv[mod % i], mod / i);
inv[i] = mod - inv[i];
assert(mult(inv[i], i) == 1);
invfact[i] = mult(invfact[i - 1], inv[i]);
assert(mult(fact[i], invfact[i]) == 1);
}
const int D = max(*max_element(ALL(a)), *max_element(ALL(b)));
const int C = 2 * D + 5;
int dp[C + 1][C + 1];
memset(dp, 0, sizeof dp);
int cnt_f[C][C];
memset(cnt_f, 0, sizeof cnt_f);
for (int i = 0; i < n; i++)
{
dp[D - a[i]][D - b[i]]++;
cnt_f[D + a[i]][D + b[i]]++;
}
int ans = 0;
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
{
add(ans, mult(cnt_f[i][j], dp[i][j]));
add(dp[i + 1][j], dp[i][j]);
add(dp[i][j + 1], dp[i][j]);
}
// cerr << ans << endl;
for (int i = 0; i < n; i++)
{
int from = 2 * (a[i] + b[i]);
int what = 2 * a[i];
int cur = mult(fact[from], invfact[what]);
cur = mult(cur, invfact[from - what]);
sub(ans, cur);
}
// cerr << ans << endl;
const int inv2 = (mod + 1) / 2;
ans = mult(ans, inv2);
cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
while (cin >> n)
solve(n);
}
| codenet | -1 | 2,168 |
s313860460 | p04051 | 1,589,822,834 | cpp | Accepted | 377 | 246,656 | #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;
ll fac[MAX],finv[MAX],inv[MAX];
// テーブルを作る前処理
void COMinit(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2; i<MAX; ++i){
fac[i]=fac[i-1]*i%MOD;
inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
finv[i]=finv[i-1]*inv[i]%MOD;
}
}
// 二項係数計算
ll COM(ll n,ll k){
if(n<k) return 0;
if(n<0 || k<0) return 0;
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
ll N,ans=0ll;
cin>>N;
COMinit();
int A[N],B[N];
REP(i,N) cin>>A[i]>>B[i];
ll DP[4005][4005];
REP(i,4005){
REP(j,4005){
DP[i][j]=0;
}
}
REP(i,N){
DP[2000-A[i]][2000-B[i]]++;
}
REP(i,4003){
REP(j,4003){
DP[i+1][j]+=DP[i][j];
DP[i+1][j]%=MOD;
DP[i][j+1]+=DP[i][j];
DP[i][j+1]%=MOD;
}
}
REP(i,N){
ans+=DP[A[i]+2000][B[i]+2000];
ans-=COM(2*(A[i]+B[i]),2*A[i]);
ans%=MOD;
}
ans=1LL*ans*inv[2]%MOD;
if(ans<0) ans+=MOD;
cout<<ans<<endl;
return 0;
} | codenet | -1 | 2,173 |
s673712393 | p04051 | 1,586,248,247 | cpp | Accepted | 269 | 134,400 | #pragma GCC optimize ("O3")
#pragma GCC target (sse, sse1, sse2, tune=native, popcnt)
#include <bits/stdc++.h>
/*
const int MAX_MEM = 25e7;
int mpos = 0;
char mem[MAX_MEM];
inline void* operator new(size_t n) {
char *res = mem + mpos;
mpos += n;
assert(mpos <= MAX_MEM);
return (void *) res;
}
inline void operator delete(void *) {}
*/
using namespace std;
#define loop(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, n) for(int i = a; i < n; ++i)
#define vec vector
#define paii pair<int, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define SZ(x) (int)x.size()
#define Unique(x) x.erase(unique(all(x)), x.end())
#define int long long
const int inf = 1e17 + 47, MAXN = 2047, N = 20, mod = 1e9 + 7;
mt19937 rnd(time(0));
int n;
int dp[MAXN * 2][MAXN * 2];
int bin_pow(int a, int n) {
if(n == 0) return 1;
int b = bin_pow(a, n / 2);
b = (b * b) % mod;
if(n % 2 == 1) b = (b * a) % mod;
return b;
}
void solve() {
loop(i, MAXN * 2) loop(j, MAXN * 2) dp[i][j] = 0;
cin >> n;
vec<paii> p(n);
loop(i, n) {
int a, b;
cin >> a >> b;
p[i] = {a, b};
dp[MAXN - a][MAXN - b]++;
}
int ans = 0;
loop(a, 2 * MAXN) {
loop(b, 2 * MAXN) {
if(a != 0) dp[a][b] += dp[a - 1][b];
if(b != 0) dp[a][b] += dp[a][b - 1];
dp[a][b] %= mod;
}
}
vec<int> fact(MAXN * 4, 1);
FOR(i, 1, MAXN * 4) fact[i] = (fact[i - 1] * i) % mod;
loop(i, n) {
int a = 2 * p[i].fr, b = 2 * p[i].sc;
ans = (ans + dp[MAXN + a / 2][MAXN + b / 2]) % mod;
int t = (fact[a + b] * bin_pow(fact[a], mod - 2)) % mod;
t = (t * bin_pow(fact[b], mod - 2)) % mod;
ans = (ans + mod - t) % mod;
}
ans = (ans * bin_pow(2, mod - 2)) % mod;
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie();
#ifdef COFFEE_MACHINE
freopen("input.cpp", "r", stdin);
freopen("output.cpp", "w", stdout);
#endif // COFFEE_MACHINE
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
| codenet | -1 | 2,194 |