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
|
---|---|---|---|---|---|---|---|---|---|---|
s973607152 | p04051 | 1,468,763,967 | cpp | Accepted | 1,973 | 66,048 | #include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge
#ifdef DONLINE_JUDGE
// palindromic tree is better than splay tree!
#define lld I64d
#endif
long long mod =1000000007;
long long pw(long long a, long long e) {
if(e <= 0) return 1;
long long x =pw(a,e/2);
x =(x*x)%mod;
if(e%2 != 0) x =(x*a)%mod;
return x;}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int N;
cin >> N;
vector<long long> fac(10000,1),inv(10000,1);
for(int i =1; i < 10000; i++) {
fac[i] =(i*fac[i-1])%mod;
inv[i] =pw(fac[i],mod-2);}
vector< vector<long long> > P(2048,vector<long long>(2048,0));
for(int i =0; i < N; i++) {
int a,b;
cin >> a >> b;
P[a][b]++;}
vector< vector<long long> > P0 =P;
for(int i =2000; i > 0; i--) for(int j =2000; j > 0; j--) {
P[i][j-1] +=P[i][j];
if(P[i][j-1] >= mod) P[i][j-1] -=mod;
P[i-1][j] +=P[i][j];
if(P[i-1][j] >= mod) P[i-1][j] -=mod;
P[i][j] =0;}
long long ans =0;
for(int i =2000; i >= -2000; i--) for(int j =2000; j >= -2000; j--) {
int x1 =max(i,0), y1 =max(-i,0);
int x2 =max(j,0), y2 =max(-j,0);
long long x =(fac[x1+x2+y1+y2]*inv[x1+x2])%mod;
x =(x*inv[y1+y2])%mod;
long long p =(P[x1][y1]*P[x2][y2])%mod;
ans =(ans+p*x)%mod;}
for(int i =0; i < 2048; i++) for(int j =0; j < 2048; j++) {
long long x =(fac[2*(i+j)]*inv[2*i])%mod;
x =(x*inv[2*j])%mod;
ans =(ans-P0[i][j]%mod*x)%mod;}
ans =(ans*inv[2])%mod;
if(ans < 0) ans +=mod;
cout << ans << "\n";
return 0;}
// look at my code
// my code is amazing | codenet | -1 | 2,195 |
s083138940 | p04051 | 1,474,155,575 | cpp | Accepted | 986 | 127,616 | #include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).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 INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1e9 + 7;
int n,m,Q;
ll dp[4010][4010]={0};
ll fact[202020], frev[202020];//้ไน,้ๅ
ll C(int p, int q)
{
if (q < 0 || p < q) return 0;
return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}
ll modpow(ll a, ll b) {//a^b%mod
ll res = 1;
for (; b > 0; a = a * a % MOD, b /= 2) if (b & 1) res = res * a % MOD;
return res;
}
int main(){
cin>>n;
int a,b;
vector<pii> data(n);
fact[0] = frev[0] = 1;
for (int i = 1; i <= 10000; ++i) {
fact[i] = (fact[i - 1] * i) % MOD;
frev[i] = modpow(fact[i],MOD-2);
}
for(int i=0;i<n;i++){
cin>>a>>b;
dp[2001-a][2001-b]++;
data[i]=mp(a,b);
}
for(int i=1;i<=4009;i++){
for(int j=1;j<=4009;j++){
dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
}
}
//cout<<dp[0][9]<<endl;
ll ans=0;
for(int i=0;i<n;i++){
int p=data[i].first,q=data[i].second;
ans=(ans+dp[2001+p][2001+q])%MOD;
ans=(ans+MOD-C(2*p+2*q,2*q))%MOD;
}
ans=(ans*frev[2])%MOD;
cout<<ans<<endl;
} | codenet | -1 | 2,199 |
s969485256 | p04051 | 1,468,730,781 | cpp | Accepted | 721 | 130,432 | #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#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()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
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 (a>b) { a=b; return 1; } return 0; }
template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }
const int INF = 0x3fffffff;
//const int MOD = 10e9+7;
const int MOD = 1000000007;
// n^m%MOD ใๆฑใใใO( log(m) )
ll modpow(ll n, int m){
ll ret=1;
for(int i=1; i<=m; i<<=1, (n*=n)%=MOD){
if( m&i ) (ret *= n) %= MOD;
}
return ret;
}
// ้ๅ
ใๆฑใใ
ll modinv(ll n){
return modpow( n, MOD-2 );
}
// ้ไนใๆฑใใใO(1) ๆบๅO( n*log(n) )
// fact[n] : nใฎ้ไน
// fact.inv[n] : nใฎ้ไนใฎ้ๅ
class FACTORIAL{
public:
const int MAX_NUM = 10004; // ๆๅคงใฎn
vector<ll> fact;
vector<ll> inv;
FACTORIAL(): fact(MAX_NUM), inv(MAX_NUM) {
fact[0] = 1;
for(ll i=1; i<MAX_NUM; i++){
fact[i] = (fact[i-1] * i) % MOD;
inv[i] = modpow( fact[i], MOD-2 );
}
}
const ll& operator [ ] ( const int i ) const {
return fact[i];
}
} fact;
// ็ตใฟๅใใ(Combinationใๆฑใใ) O(1)
ll cmb(unsigned int n, unsigned int r){
if( n < r ) return 0;
return fact[n] * fact.inv[r] % MOD * fact.inv[n-r] % MOD;
}
ll f(ll a, ll b){
return cmb( a+b, a );
}
ll dp[4050][4050];
int main(){
ll N, A[200005], B[200005], ans=0;
int offset = 2005;
cin >> N;
rep(i,N){
cin >> A[i] >> B[i];
dp[ offset-A[i] ][ offset-B[i] ] += 1;
}
rep(i,4010) rep(j,4010){
dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
}
ll sum = 0;
rep(i,N){
sum = (sum + dp[ offset+A[i] ][ offset+B[i] ]) % MOD;
}
// cout << sum << endl;
// ll sum2 = 0;
// rep(i,N) rep(j,N){
// sum2 = (sum2 + f(A[i]+A[j], B[i]+B[j]) ) % MOD;
// }
// cout << sum2 << endl;
ll db = 0; // ใใใช
rep(i,N){
db = (db + f( A[i]+A[i], B[i]+B[i] ) ) % MOD;
}
ans = (((sum + MOD - db) % MOD) * modinv(2) ) % MOD;
cout << ans << endl;
return 0;
}
| codenet | -1 | 2,199 |
s836551848 | p04051 | 1,506,092,715 | cpp | Accepted | 168 | 139,904 | #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
const int MOD=1e9+7;
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
ll x=1; a%=MOD;
while(b)
{
if(b&1) x=x*a%MOD;
a=a*a%MOD; b>>=1;
}
return x;
}
ll cnt[4005][4005];
int n,a[SZ],b[SZ];
int main()
{
fac[0]=1;
for(int i=1;i<SZ;++i)
fac[i]=fac[i-1]*i%MOD;
rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
for(int i=SZ-1;i>=1;--i)
rfac[i-1]=rfac[i]*i%MOD;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d%d",a+i,b+i);
++cnt[2001-a[i]][2001-b[i]];
}
for(int i=1;i<=4002;++i)
for(int j=1;j<=4002;++j)
{
cnt[i][j]+=cnt[i][j-1]+cnt[i-1][j];
(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
}
ll ans=0,t=0;
for(int i=1;i<=n;++i)
{
(ans+=cnt[2001+a[i]][2001+b[i]])%=MOD;
t+=fac[a[i]+a[i]+b[i]+b[i]]
*rfac[a[i]+a[i]]%MOD*rfac[b[i]+b[i]]%MOD;
}
const ll i2=(MOD+1)/2;
t%=MOD; (ans-=t)%=MOD;
ans=ans*i2%MOD;
ans=(ans%MOD+MOD)%MOD;
printf("%d\n",int(ans));
}
| codenet | -1 | 2,203 |
s523911942 | p04051 | 1,513,054,141 | cpp | Accepted | 142 | 85,632 | #include"bits/stdc++.h"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int maxn = 200010;
const int mod = 1e9+7,bas = 2500;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}
int n;
int A[maxn],B[maxn];
int dp[5010][5010];
int fac[8010],inv[8010];
void Work(){
REP(i,-2000,2000)
REP(j,-2000,2000)dp[i+bas][j+bas]=(dp[i-1+bas][j+bas]+dp[i+bas][j-1+bas]+dp[i+bas][j+bas])%mod;
int ans=0;
REP(i,1,n)ans=(ans+dp[A[i]+bas][B[i]+bas])%mod;
REP(i,1,n)ans=(ans-1ll*fac[A[i]+A[i]+B[i]+B[i]]*inv[A[i]+A[i]]%mod*inv[B[i]+B[i]]%mod+mod)%mod;
ans=1ll*ans*fexp(2,mod-2)%mod;
iout(ans);
}
void Init(){
read(n);
REP(i,1,n)read(A[i],B[i]),dp[bas-A[i]][bas-B[i]]++;
fac[0]=1;REP(i,1,8000)fac[i]=1ll*fac[i-1]*i%mod;
REP(i,0,8000)inv[i]=fexp(fac[i],mod-2);
}
int main(){
Init();
Work();
return 0;
}
| codenet | -1 | 2,216 |
s402706464 | p04051 | 1,503,275,405 | cpp | Accepted | 181 | 96,768 | #include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define popcnt(x) __builtin_popcountll(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t) cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
using namespace std;
const int MAX = 200*1000 + 10,MAXA = 2*2000 + 10,MAXB = 2*MAXA,mod = 1e9 + 7;
int A[MAX],B[MAX],n;
int cnt[MAXA][MAXA],f[MAXA][MAXA];
int fact[MAXB],inv[MAXB];
int add(int a,int b){
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
return a;
}
int mul(int a,int b){
return (a*1LL*b)%mod;
}
int pow_mod(int a,int b){
if(!b) return 1;
int x = 1;
for(;b > 1;b >>= 1){
if(b & 1) x = mul(a,x);
a = mul(a,a);
}
return mul(a,x);
}
void init(){
fact[0] = 1;
loop(i,MAXB-1) fact[i + 1] = mul(fact[i],i + 1);
loop(i,MAXB) inv[i] = pow_mod(fact[i],mod-2);
}
int C(int n,int k){
if(n < k) return 0;
return mul(fact[n],mul(inv[k],inv[n - k]));
}
int main(){
#ifdef HOME
freopen("in.in", "r", stdin);
#endif
init();
scanf("%d",&n);
loop(i,n) {
scanf("%d %d",A + i,B + i);
cnt[2000-A[i]][2000-B[i]]++;
}
for(int x = 0;x <= 4000;x++)
for(int y = 0;y <= 4000;y++) {
f[x][y] = cnt[x][y];
if(x) f[x][y] = add(f[x][y],f[x - 1][y]);
if(y) f[x][y] = add(f[x][y],f[x][y - 1]);
}
int ans = 0;
loop(i,n){
int x = A[i],y = B[i];
ans = add(ans,f[x + 2000][y + 2000]);
ans = add(ans,-C(2*x + 2*y,2*y));
}
ans = (ans * 500000004LL)%mod;
cout << ans << endl;
return 0;
}
| codenet | -1 | 2,225 |
s233643637 | p04051 | 1,579,128,732 | cpp | Accepted | 258 | 192,512 | #include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
a = a*b % MOD;
}
vector<int64_t> fact, seq_inv, fact_inv;
void create_fact_mod(int num){
fact[0] = fact[1] = 1;
for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}
void create_seq_inv_mod(int num){
seq_inv[0] = seq_inv[1] = 1;
for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}
void create_fact_inv_mod(int num){
fact_inv[0] = fact_inv[1] = 1;
for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}
void create_mod_tables(int num){
fact.resize(num+1);
seq_inv.resize(num+1);
fact_inv.resize(num+1);
create_fact_mod(num);
create_seq_inv_mod(num);
create_fact_inv_mod(num);
}
int64_t comb_mod(int n, int k){
return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}
int64_t perm_mod(int n, int k){
return fact[n] * fact_inv[n-k] % MOD;
}
int64_t power_mod(int64_t num, int64_t power){
int64_t prod = 1;
num %= MOD;
while(power > 0){
if(power&1) prod = prod * num % MOD;
num = num * num % MOD;
power >>= 1;
}
return prod;
}
int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
int64_t d = a;
if(b != 0){
d = extgcd(b, a%b, y, x);
y -= (a/b) * x;
}else{
x = 1; y = 0;
}
return d;
}
int64_t inv_mod(int64_t a){
int64_t x, y;
extgcd(a, MOD, x, y);
return (MOD + x%MOD) % MOD;
}
int main(){
int N;
cin >> N;
vector<int> A(N), B(N);
static int in[4001][4001], out[4001][4001];
for(int i=0; i<N; i++){
cin >> A[i] >> B[i];
in[2000-A[i]][2000-B[i]]++;
out[2000+A[i]][2000+B[i]]++;
}
static int64_t dp[4001][4001];
int64_t ans = 0;
for(int i=0; i<=4000; i++) for(int j=0; j<=4000; j++){
dp[i][j] = in[i][j];
if(i) add(dp[i][j], dp[i-1][j]);
if(j) add(dp[i][j], dp[i][j-1]);
add(ans, dp[i][j] * out[i][j]);
}
create_mod_tables(8000);
for(int i=0; i<N; i++) add(ans, MOD - comb_mod(2*A[i]+2*B[i], 2*A[i]));
mul(ans, inv_mod(2));
cout << ans << endl;
}
| codenet | -1 | 2,258 |
s294263837 | p04051 | 1,482,167,406 | cpp | Accepted | 244 | 64,512 | #include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y) for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y) for(int i = (int)(x); i < (int)(y); i++)
#define PER(i ,x, y) for(int i = (int)(x); i >= (int)(y); i--)
#define CH ch = getchar()
#define Exit(...) printf(__VA_ARGS__), exit(0)
#define dln() fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const int inf=2e9;
const LL Inf=1e10;
const int P=1e9+7;
const int N=200005;
inline LL IN(){
LL x = 0;
int ch = 0, f = 0;
for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}
void renew(int &x, const int &y){
x += y;
if(x >= P) x -= P;
if(x < 0) x += P;
}
int Pow(int x, int y, int p){
int a = 1;
for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
return a;
}
int X[N], Y[N], n;
int V[4005][4005], ans, inv[8005], fac[8005];
int C(int x, int y){
return (LL)fac[x + y] * inv[x] % P * inv[y] % P;
}
int main(){
scanf("%d", &n);
REP(i, 0, 8002) inv[i] = Pow(i, P - 2, P);
inv[0] = 1;
REP(i, 1, 8002) inv[i] = (LL)inv[i - 1] * inv[i] % P;
REP(i, 0, 8002) fac[i] = Pow(inv[i], P - 2, P);
REP(i, 1, n) scanf("%d%d", X + i, Y + i);
REP(i, 1, n) renew(V[2001 - X[i]][2001 - Y[i]], 1);
REP(i, 0, 4002)
REP(j, 0, 4002){
renew(V[i][j + 1], V[i][j]);
renew(V[i + 1][j], V[i][j]);
}
REP(i, 1, n) renew(ans, V[X[i] + 2001][Y[i] + 2001]);
REP(i, 1, n) renew(ans, -C(X[i] + X[i], Y[i] + Y[i]));
printf("%d\n", (LL)ans * Pow(2, P - 2, P) % P);
return 0;
} | codenet | -1 | 2,258 |
s571382333 | p04051 | 1,502,685,343 | cpp | Accepted | 148 | 64,512 | #include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int mod=1e9+7;
const int inv2=(mod+1)>>1;
const int N=200005;
int a[N],b[N],n;
int sum[4003][4003];
ll fac[8003],inv[8003];
il int calc(int a,int b){
return fac[a+b]*inv[a]%mod*inv[b]%mod;
}
il void inc(int &x,const int &y=0){
x+=y;
if(x>=mod) x-=mod;
}
il void dec(int &x,const int &y=0){
x-=y;
if(x<0) x+=mod;
}
int main(){
inv[1]=1;
rep(i,2,8000) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
fac[0]=inv[0]=1;
rep(i,1,8000){
fac[i]=fac[i-1]*i%mod;
inv[i]=inv[i-1]*inv[i]%mod;
}
scanf("%d",&n);
rep(i,1,n){
scanf("%d%d",a+i,b+i);
++sum[2000-a[i]][2000-b[i]];
}
rep(i,0,4000) rep(j,0,4000){
if(i) inc(sum[i][j],sum[i-1][j]);
if(j) inc(sum[i][j],sum[i][j-1]);
}
int ans=0;
rep(i,1,n){
inc(ans,sum[2000+a[i]][2000+b[i]]);
dec(ans,calc(a[i]<<1,b[i]<<1));
}
ans=(ll)ans*inv[2]%mod;
printf("%d\n",ans);
return 0;
}
| codenet | -1 | 2,259 |
s545230958 | p04051 | 1,509,401,886 | cpp | Accepted | 287 | 253,312 | //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
char s[100000];
int it,len;
fastio(){it=len=0;}
inline char get()
{
if(it<len)return s[it++];it=0;
len=fread(s,1,100000,stdin);
if(len==0)return EOF;else return s[it++];
}
bool notend()
{
char c=get();
while(c==' '||c=='\n')c=get();
if(it>0)it--;
return c!=EOF;
}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
ll r=0;bool ng=0;char c;c=_buff.get();
while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
if(c=='-')ng=1,c=_buff.get();
while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
if(x<0)putchar('-'),x=-x;
register short a[20]={},sz=0;
while(x)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[200111],b[200111];
ll C[4011][4011],dp[4011][4011];
ll qpow(ll x,ll k){return k==0?1:qpow(x*x%mod,k>>1)*(k&1?x:1)%mod;}
int main()
{
for(int i=0;i<=4004;i++)C[i][0]=C[0][i]=1;
for(int i=1;i<=4004;i++)
{
for(int j=1;j<=4004;j++)
{
C[i][j]=(C[i-1][j]+C[i][j-1])%mod;
}
}
geti(n);
for(int i=1;i<=n;i++)
{
getii(a[i],b[i]);
dp[2002-a[i]][2002-b[i]]++;
// cerr<<a[i]<<" "<<b[i]<<" "<<C[a[i]][b[i]]<<endl;
}
for(int i=1;i<=4010;i++)
{
for(int j=1;j<=4010;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++)
{
// cerr<<dp[2002+a[i]][2002+b[i]]<<endl;
ans=(ans+dp[2002+a[i]][2002+b[i]])%mod;
ans=(ans-C[2*a[i]][2*b[i]]+mod)%mod;
}
cout<<ans*qpow(2,mod-2)%mod<<endl;
return 0;
}
| codenet | -1 | 2,263 |
s743564554 | p04051 | 1,500,494,628 | cpp | Accepted | 123 | 64,512 | #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define pb push_back
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
const string FILENAME = "input";
const int MAXN = 4e3 + 5, H = 2e3 + 1, p = 1e9 + 7;
typedef pair <int, int> point;
int sum(int a, int b) {
a += b;
if (a >= p)
return a - p;
return a;
}
int mul(long long a, int b) {
return a * b % p;
}
int powx(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = mul(ans, a);
a = mul(a, a);
b >>= 1;
}
return ans;
}
const int p2 = powx(2, p - 2);
int n;
int f[2][MAXN * 2];
vector <point> arr;
int dp[MAXN][MAXN];
int ans = 0;
int cnk(int n, int k) {
return mul(f[0][n], mul(f[1][n - k], f[1][k]));
}
int main() {
ios::sync_with_stdio(false);
srand(time(0));
//read(FILENAME);
f[0][0] = 1;
f[1][0] = 1;
for (int i = 1; i < MAXN * 2; ++i) {
f[0][i] = mul(f[0][i - 1], i);
f[1][i] = powx(f[0][i], p - 2);
}
cin >> n;
arr.resize(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i].x >> arr[i].y;
++dp[H - arr[i].x][H - arr[i].y];
}
for (int i = 0; i + 1 < MAXN; ++i) {
for (int j = 0; j + 1 < MAXN; ++j) {
dp[i][j + 1] = sum(dp[i][j], dp[i][j + 1]);
dp[i + 1][j] = sum(dp[i][j], dp[i + 1][j]);
}
}
for (auto i : arr) {
ans = sum(ans, dp[H + i.x][H + i.y]);
ans = sum(ans, p - cnk((i.x + i.y) * 2, i.x * 2));
}
// for (int i = 0; i < n; ++i) {
// for (int j = 0; j < n; ++j) {
// if (i == j) continue;
// ans = sum(ans, cnk(arr[i].x + arr[i].y + arr[j].x + arr[j].y, arr[i].x + arr[j].x));
// }
// }
cout << mul(ans, p2) << endl;
} | codenet | -1 | 2,264 |
s760332228 | p04051 | 1,491,449,305 | cpp | Accepted | 158 | 96,000 | //84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 200005
#define maxX 2000
#define oo 2000000007
#define EPS 1e-9
#define MOD 1000000007
const double PI = acos(-1.0);
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
int power(int x, int n) {
if (n == 0) return 1;
if (n&1) return ((ll)x*power(x, n-1))%MOD;
int p = power(x, n/2);
return ((ll)p*p)%MOD;
}
void add(int &a, int b) {a = (a+b)%MOD;}
int n, a[maxN], b[maxN], cnt[2*maxX+1][2*maxX+1], dp[2*maxX+1][2*maxX+1], fact[4*maxX+1], invFact[4*maxX+1];
int C(int n, int k) {
ll t = ((ll)fact[n]*invFact[k])%MOD;
return (t*invFact[n-k])%MOD;
}
int main () {
scanf("%d", &n);
fto(i, 1, n) {
scanf("%d%d", &a[i], &b[i]);
++cnt[maxX-a[i]][maxX-b[i]];
}
fact[0] = invFact[0] = 1;
fto(i, 1, 4*maxX) {
fact[i] = ((ll)fact[i-1]*i)%MOD;
invFact[i] = power(fact[i], MOD-2);
}
fto(x, 0, 2*maxX) {
fto(y, 0, 2*maxX) {
dp[x][y] = cnt[x][y];
if (x > 0) add(dp[x][y], dp[x-1][y]);
if (y > 0) add(dp[x][y], dp[x][y-1]);
}
}
int ans = 0;
fto(i, 1, n) {
add(ans, dp[maxX+a[i]][maxX+b[i]]);
add(ans, MOD-C(2*(a[i]+b[i]), 2*a[i]));
}
ans = ((ll)ans*power(2, MOD-2))%MOD;
printf("%d", ans);
return 0;
}
| codenet | -1 | 2,279 |
s409506315 | p04051 | 1,584,078,472 | cpp | Accepted | 132 | 128,896 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod_;
a = a * a % mod_;
n >>= 1;
}
return res;
}
const ll MAX_SIZE = 10005;
array<ll, MAX_SIZE> fac, inv, finv;
void fac_init() {
// combination init
fac[0] = 1;
for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
finv[0] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % MOD;
reverse(all(finv));
//inv init
repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}
ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }
ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }
const ll AB = 2000;
ll dp[AB*2 + 5][AB*2 + 5];
int main() {
init();
fac_init();
ll N;
cin >> N;
vl A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, N) dp[AB - A[i]][AB - B[i]] += 1;
rep(a,AB*2+1)rep(b,AB*2+1){
dp[a][b] %= MOD;
ll v = dp[a][b];
dp[a + 1][b] += v;
dp[a][b + 1] += v;
}
ll ans = 0;
rep(i,N){
ll a = A[i], b = B[i];
ans += dp[AB + a][AB + b];
ans -= comb(2 * (a + b), 2 * a);
ans = (ans % MOD + MOD) % MOD;
}
ans *= inv[2];
ans %= MOD;
cout << ans << endl;
} | codenet | -1 | 2,285 |
s147592103 | p04051 | 1,569,431,704 | cpp | Accepted | 156 | 65,920 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[100100];
ll FactorialInv[100100];
ll Factorial[100100];
ll beki(ll a, ll b){
if(b == 0){
return 1;
}
ll ans = beki(a, b / 2);
ans = ans * ans % mod;
if(b % 2 == 1){
ans = ans * a % mod;
}
return ans;
}
void init_combination(){
const int MAX = 10002;
Factorial[0] = 1;
inv[0] = 1;
for(int i = 1; i <= MAX; i++){
Factorial[i] = Factorial[i - 1] * i % mod;
}
FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
for(ll i = MAX - 1; i >= 0; i--) {
FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
}
for(int i = 1; i <= MAX; i++) {
inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
}
}
ll combination(ll a, ll b){
if((a == b) || (b == 0)){
return 1;
}
if(a < b) return 0;
ll ans = Factorial[a] * FactorialInv[b] % mod;
ans = ans * FactorialInv[a - b] % mod;
return ans;
}
int N;
int dp[4005][4005];
int A[200050], B[200050];
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
init_combination();
for(int i = 1; i <= N; i++) {
cin >> A[i] >> B[i];
dp[2000-A[i]][2000-B[i]]++;
}
for(int i = 0; i <= 4000; i++) {
for(int j = 0; j <= 4000; j++) {
if(i > 0) dp[i][j] += dp[i-1][j];
dp[i][j] %= mod;
if(j > 0) dp[i][j] += dp[i][j-1];
dp[i][j] %= mod;
}
}
ll ans = 0;
for(int i = 1; i <= N; i++) {
ans += dp[2000+A[i]][2000+B[i]];
ans %= mod;
ans -= combination(2*A[i]+2*B[i], 2*A[i]);
ans %= mod;
ans += mod;
ans %= mod;
}
//ans *= beki(2, mod - 2);
//ans %= mod;
ll answer = (ll)ans * beki(2, mod - 2);
answer %= mod;
cout << answer << endl;
return 0;
}
| codenet | -1 | 2,290 |
s181478958 | p04051 | 1,468,730,019 | cpp | Accepted | 480 | 65,520 | # include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define db long double
# define scn(x) scanf("%I64d",&x)
# define scan(x) scanf("%d",&x)
# define print(x) printf("%d ",x)
# define prnt(x) printf("%I64d ",x);
# define eol printf("\n")
# define IOS ios_base :: sync_with_stdio(0)
# define pe "Possible"
# define ie "Impossible"
# define halt(...) {fo << (__VA_ARGS__) << '\n';exit(0);}
# define rep1(n) for (int qwerty = 1;qwerty <= n;++qwerty)
# define CF
# ifdef CF
# define DEBUG
# endif // CF
# ifdef DEBUG
# define pp(n) cerr << #n << " = " << n << '\n'
# define ppp(v) for (auto it : v) cerr << it << ' ';cerr << '\n'
# define aprint(x,y,z) for (int i = x;i <= y;++i) cerr << z[i] << ' ';cerr << '\n'
# else
# define pp(n) ;
# define ppp(v) ;
# define aprint(x,y,z);
# endif // DEBUG
# define rep(n) for (int i = 1;i <= n;++i)
const int mod = 1e9 + 7;
int dp[4015][4015];
int f[1 << 20];
int c[1 << 20];
int pow(int a,int b,int mod)
{
int ans = 1;
while (b)
{
if (b&1) ans = (1ll * ans * a) % mod;
a = (1ll * a * a) % mod;
b /= 2;
}
return ans;
}
int main(void)
{
# ifdef CF
# endif // CF
srand(time(0));
fo << fixed << setprecision(7);
cerr << fixed << setprecision(7);
int n;
IOS;
fi>>n;
vector < pair < int , int > > want;
for (int i = 1;i <= n;++i)
{
int a,b;
fi>>a>>b;
dp[2000 - a][2000 - b] += 1;
want.push_back({a,b});
}
for (int i = 0;i < 4003;++i)
for (int j = 0;j < 4003;++j)
dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod,
dp[i][j+1] = (dp[i][j] + dp[i][j+1]) % mod;
f[0] = c[0] = 1;
for (int i = 1;i <= 1e5;++i)
{
f[i] = (1ll * f[i-1] * i) % mod;
c[i] = pow(f[i],mod - 2,mod);
}
auto C = [&](int n,int k)
{
int ans = (1ll * f[n] * c[k]) % mod;
ans = (1ll * ans * c[n - k]) % mod;
return ans;
};
int ans = 0;
for (auto it : want) ans = (ans + dp[it.x + 2000][it.y + 2000]) % mod;
for (auto it : want) ans = (ans + mod - 1ll * C((it.x+it.y) << 1,it.x << 1)) % mod;
ans = (ans * 1ll * pow(2,mod - 2,mod)) % mod;
fo << ans << '\n';
return 0;
} | codenet | -1 | 2,293 |
s345577625 | p04051 | 1,542,872,534 | cpp | Accepted | 115 | 64,768 | #ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif
#define sz(x) ((int) (x).size())
#define TASK "text"
const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);
#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif
int rnd(int x) {
return mrand() % x;
}
const int mod = (int) 1e9 + 7;
int mul(int a, int b) {
return (long long) a * b % mod;
}
void add(int &a, int b) {
a += b;
if (a >= mod) {
a -= mod;
}
}
const int maxm = (int) 1e4 + 5;
int f[maxm], inv[maxm], finv[maxm];
void precalc() {
f[0] = 1;
for (int i = 1; i < maxm; i++) {
f[i] = mul(f[i - 1], i);
}
inv[1] = 1;
for (int i = 2; i < maxm; i++) {
inv[i] = (mod - (long long) (mod / i) * inv[mod % i] % mod) % mod;
}
finv[0] = 1;
for (int i = 1; i < maxm; i++) {
finv[i] = mul(finv[i - 1], inv[i]);
}
}
int c(int n, int k) {
return mul(f[n], mul(finv[n - k], finv[k]));
}
const int maxn = (int) 2e5 + 5;
int n;
int a[maxn], b[maxn];
bool read() {
if (scanf("%d", &n) < 1) {
return false;
}
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
b[i] += a[i];
}
return true;
}
const int X = 2005, maxx = 2 * X + 1;
int s[maxx][maxx];
void solve() {
memset(s, 0, sizeof(s));
for (int i = 0; i < n; i++) {
int l = X + a[i] - b[i], r = X + a[i];
add(s[r - l][l], 1);
}
for (int i = maxx - 2; i >= 0; i--) {
for (int j = 0; j < maxx; j++) {
add(s[i][j], s[i + 1][j]);
if (j) {
add(s[i][j], s[i + 1][j - 1]);
}
}
}
int res = 0;
for (int i = -X; i < X; i++) {
add(res, mul(s[0][X + i], s[0][X - i]));
}
for (int i = 0; i < n; i++) {
add(res, mod - c(2 * b[i], 2 * a[i]));
}
res = mul(res, (mod + 1) / 2);
printf("%d\n", res);
}
int main() {
precalc();
#ifdef DEBUG
assert(freopen(TASK ".in", "r", stdin));
assert(freopen(TASK ".out", "w", stdout));
#endif
while (read()) {
solve();
#ifdef DEBUG
eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
}
return 0;
}
| codenet | -1 | 2,322 |
s969908136 | p04051 | 1,468,731,062 | cpp | Accepted | 337 | 64,512 | #include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int MOD = 1e9 + 7;
inline void ModSum(int& x, int y) {
x += y;
if (x >= MOD) {
x -= MOD;
}
if (x < 0) {
x += MOD;
}
}
inline int GetModSum(int x, int y) {
ModSum(x, y);
return x;
}
inline void ModMul(int& x, int y) {
x = (1LL * x * y) % MOD;
}
inline int GetModMul(int x, int y) {
ModMul(x, y);
return x;
}
int GetBinaryPow(int x, int pw) {
int result = 1;
while (pw > 0) {
if (pw & 1) {
ModMul(result, x);
}
ModMul(x, x);
pw >>= 1;
}
return result;
}
int GetInv(int x) {
return GetBinaryPow(x, MOD - 2);
}
#define LLD_SPEC "%lld"
const int BASE = 2e3;
const int COORD_COUNT = 2 * BASE + 1;
const int MAX_FACT = 4 * BASE + 1;
int fact[MAX_FACT];
int invFact[MAX_FACT];
void BuildFact() {
fact[0] = 1;
for (int i = 1; i < MAX_FACT; ++i) {
fact[i] = fact[i - 1];
ModMul(fact[i], i);
}
for (int i = 0; i < MAX_FACT; ++i) {
invFact[i] = GetInv(fact[i]);
}
}
int GetC(int n, int k) {
if (k > n) {
return 0;
}
int result = fact[n];
ModMul(result, invFact[k]);
ModMul(result, invFact[n - k]);
return result;
}
int main() {
BuildFact();
int n;
scanf("%d", &n);
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i].first, &a[i].second);
}
vector<vector<int>> sum(COORD_COUNT, vector<int>(COORD_COUNT, 0));
for (int i = 0; i < n; ++i) {
++sum[BASE - a[i].first][BASE - a[i].second];
}
for (int j = 1; j < COORD_COUNT; ++j) {
ModSum(sum[0][j], sum[0][j - 1]);
}
for (int i = 1; i < COORD_COUNT; ++i) {
ModSum(sum[i][0], sum[i - 1][0]);
}
for (int i = 1; i < COORD_COUNT; ++i) {
for (int j = 1; j < COORD_COUNT; ++j) {
ModSum(sum[i][j], sum[i - 1][j]);
ModSum(sum[i][j], sum[i][j - 1]);
}
}
int result = 0;
for (int i = 0; i < n; ++i) {
ModSum(result, sum[a[i].first + BASE][a[i].second + BASE]);
ModSum(result, -GetC(2 * (a[i].first + a[i].second), 2 * a[i].first));
}
ModMul(result, GetInv(2));
printf("%d\n", result);
return 0;
} | codenet | -1 | 2,343 |
s100619186 | p04051 | 1,587,792,058 | cpp | Accepted | 146 | 131,952 | #include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
ll fac[10000],finv[10000],inv[10000];
void cominit(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<10000;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;
}
mint dp[4005][4005];
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cominit();
ll n, a, b, N = 2001;
cin >> n;
vector<pair<ll,ll> > v;
for(int i=0;i<n;i++) {
cin >> a >> b;
dp[N - a][N - b] += 1;
v.push_back({a,b});
}
mint ans = 0;
ll M = N * 2;
for(int i=1;i<=M;i++){
for(int j=1;j<=M;j++){
dp[i][j] += dp[i-1][j] + dp[i][j-1];
}
}
for(auto& i:v){
ans += dp[i.first + N][i.second + N];
ans -= com( i.first * 2 + i.second * 2, i.first * 2);
}
ans /= 2;
cout << ans << endl;
return 0;
}
| codenet | -1 | 2,344 |
s009828317 | p04051 | 1,505,594,229 | cpp | Accepted | 182 | 64,384 | #include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define upadj(i,adj) if (adj.size()>0) up(i,0,adj.size()-1)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << "=" <<X << endl
#define debug2(X,Y) cerr<< #X << "=" <<X << ", " << #Y << "=" <<Y << endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;
inline void read(int &x)
{
register int c = gc();
x = 0;
int neg = 0;
for (;((c<48 || c>57) && c != '-') ;c = gc());
if(c=='-') {neg=1;c=gc();}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(neg) x=-x;
}
inline void writeln(int x){
char buffor[21];
register int i=0;
int neg=0; if (x<0) {neg=1; x= -x;}
do{
buffor[i++]=(x%10)+'0';
x/=10;
} while(x);
i--;
if (neg) pc('-');
while(i>=0) pc(buffor[i--]);
pc('\n');
}
const int base= 1e9+ 7;
const int M= 2001;
int n,a[200010],b[200010],f[4003][4003];
int res;
int Add(int a,int b)
{
return (a+b>= base)?a+b-base: a+b;
}
int Sub(int a,int b)
{
return (a-b<0)?a-b+base: a-b;
}
void input()
{
cin>>n;
up(i,1,n) cin>>a[i]>> b[i];
}
long power(int x,int k)
{
if (k==1) return x;
long t= power(x,k/2);
t= t*t% base;
if (k%2==1) t= t*x%base;
return t;
}
void solve()
{
up(i,1,n) f[-a[i]+M][-b[i]+M]++;// ( -a,-b)
up(x,-2000,2000)
up(y,-2000,2000)
f[x+M][y+M]= Add(f[x+M][y+M], Add(f[x-1+M][y+M],f[x+M][y-1+M]) );
res= 0;
up(i,1,n) res= Add(res, f[a[i]+M][b[i]+M]);
up(x,0,4000) f[x][0]= 1;
up(y,0,4000) f[0][y]= 1;
up(x,1,4000)
up(y,1,4000)
f[x][y]= Add(f[x-1][y],f[x][y-1]);
up(i,1,n) res= Sub(res, f[a[i]+a[i]][b[i]+b[i]]);
cout<<res* power(2,base-2)% base;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef I_Love_Pork
#define TASK "tmp"
freopen(TASK".inp","r",stdin);
freopen(TASK".out","w",stdout);
#endif
input();
solve();
return 0;
}
| codenet | -1 | 2,371 |
s084803709 | p04051 | 1,556,155,085 | cpp | Accepted | 289 | 80,256 | #ifndef ___CLASS_MODINT
#define ___CLASS_MODINT
#include <cstdint>
template<std::uint32_t mod>
class modint {
private:
std::uint32_t n;
public:
modint() : n(0) {};
modint(std::uint64_t n_) : n(n_ % mod) {};
bool operator==(const modint& m) const { return n == m.n; }
bool operator!=(const modint& m) const { return n != m.n; }
std::uint32_t get() const { return n; }
modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
modint operator+(const modint& m) const { return modint(*this) += m; }
modint operator-(const modint& m) const { return modint(*this) -= m; }
modint operator*(const modint& m) const { return modint(*this) *= m; }
modint binpow(std::uint64_t b) const {
modint ans = 1, m = modint(*this);
while (b) {
if (b & 1) ans *= m;
m *= m;
b >>= 1;
}
return ans;
}
modint inv() { return (*this).binpow(mod - 2); }
};
#endif // ___CLASS_MODINT
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using modulo = modint<1000000007>;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
int la = 0, lb = 0;
for (int i = 0; i < N; ++i) {
cin >> A[i] >> B[i];
la = max(la, A[i]);
lb = max(lb, B[i]);
}
vector<vector<modulo> > dp(la + 1, vector<modulo>(lb + 1)), comb(la * 2 + 1, vector<modulo>(lb * 2 + 1));
comb[0][0] = 1;
for (int i = 0; i <= la * 2; ++i) {
for (int j = 0; j <= lb * 2; ++j) {
if (i >= 1) comb[i][j] += comb[i - 1][j];
if (j >= 1) comb[i][j] += comb[i][j - 1];
}
}
for (int i = 0; i < N; ++i) {
dp[A[i]][B[i]] += 1;
}
for (int i = la; i >= 1; --i) {
for (int j = lb; j >= 1; --j) {
dp[i - 1][j] += dp[i][j];
dp[i][j - 1] += dp[i][j];
}
}
modulo ans = 0;
for (int i = 1; i <= la; ++i) {
for (int j = 1; j <= la; ++j) {
ans += dp[i][0] * dp[j][0];
}
}
for (int i = 1; i <= lb; ++i) {
for (int j = 1; j <= lb; ++j) {
ans += dp[0][i] * dp[0][j];
}
}
for (int i = 1; i <= la; ++i) {
for (int j = 1; j <= lb; ++j) {
ans += dp[i][0] * dp[0][j] * comb[i][j] * 2;
}
}
for (int i = 0; i < N; ++i) {
ans -= comb[A[i] * 2][B[i] * 2];
}
ans *= modulo(2).inv();
cout << ans.get() << endl;
return 0;
} | codenet | -1 | 2,376 |
s084803709 | p04051 | 1,556,155,085 | cpp | Accepted | 289 | 80,256 | #ifndef ___CLASS_MODINT
#define ___CLASS_MODINT
#include <cstdint>
template<std::uint32_t mod>
class modint {
private:
std::uint32_t n;
public:
modint() : n(0) {};
modint(std::uint64_t n_) : n(n_ % mod) {};
bool operator==(const modint& m) const { return n == m.n; }
bool operator!=(const modint& m) const { return n != m.n; }
std::uint32_t get() const { return n; }
modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
modint operator+(const modint& m) const { return modint(*this) += m; }
modint operator-(const modint& m) const { return modint(*this) -= m; }
modint operator*(const modint& m) const { return modint(*this) *= m; }
modint binpow(std::uint64_t b) const {
modint ans = 1, m = modint(*this);
while (b) {
if (b & 1) ans *= m;
m *= m;
b >>= 1;
}
return ans;
}
modint inv() { return (*this).binpow(mod - 2); }
};
#endif // ___CLASS_MODINT
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using modulo = modint<1000000007>;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
int la = 0, lb = 0;
for (int i = 0; i < N; ++i) {
cin >> A[i] >> B[i];
la = max(la, A[i]);
lb = max(lb, B[i]);
}
vector<vector<modulo> > dp(la + 1, vector<modulo>(lb + 1)), comb(la * 2 + 1, vector<modulo>(lb * 2 + 1));
comb[0][0] = 1;
for (int i = 0; i <= la * 2; ++i) {
for (int j = 0; j <= lb * 2; ++j) {
if (i >= 1) comb[i][j] += comb[i - 1][j];
if (j >= 1) comb[i][j] += comb[i][j - 1];
}
}
for (int i = 0; i < N; ++i) {
dp[A[i]][B[i]] += 1;
}
for (int i = la; i >= 1; --i) {
for (int j = lb; j >= 1; --j) {
dp[i - 1][j] += dp[i][j];
dp[i][j - 1] += dp[i][j];
}
}
modulo ans = 0;
for (int i = 1; i <= la; ++i) {
for (int j = 1; j <= la; ++j) {
ans += dp[i][0] * dp[j][0];
}
}
for (int i = 1; i <= lb; ++i) {
for (int j = 1; j <= lb; ++j) {
ans += dp[0][i] * dp[0][j];
}
}
for (int i = 1; i <= la; ++i) {
for (int j = 1; j <= lb; ++j) {
ans += dp[i][0] * dp[0][j] * comb[i][j] * 2;
}
}
for (int i = 0; i < N; ++i) {
ans -= comb[A[i] * 2][B[i] * 2];
}
ans *= modulo(2).inv();
cout << ans.get() << endl;
return 0;
} | codenet | -1 | 2,376 |
s329474692 | p04051 | 1,568,755,936 | cpp | Accepted | 157 | 129,536 | #include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 4e3 + 20, delta = 2005;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
int f = 1, r = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') {
f = -1;
}
c = getchar();
}
while (isdigit(c)) {
r = 10 * r + c - '0';
c = getchar();
}
return f * r;
}
inline void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int fac[maxn * 2], N, arr[200000 + 10][2], dp[maxn][maxn], invv[maxn * 2];
inline int exgcd(int a, int b, int& x, int& y)
{
if (b == 0) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, x, y);
int tmp = y;
y = x - a / b * y;
x = tmp;
return d;
}
inline int inv(int a, int b)
{
int x, y;
exgcd(a, b, x, y);
return (x + MOD) % MOD;
}
signed main()
{
//freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
N = read();
for (ri i = 1; i <= N; ++i) {
arr[i][0] = read(), arr[i][1] = read(), dp[-arr[i][0] + delta][-arr[i][1] + delta]++;
}
for (ri i = -2000 + delta; i <= 2000 + delta; ++i) {
for (ri j = -2000 + delta; j <= 2000 + delta; ++j) {
dp[i][j] = (dp[i - 1][j] + dp[i][j] + dp[i][j - 1]) % MOD;
}
}
fac[0] = 1;
for (ri i = 1; i < maxn * 2; ++i) {
fac[i] = fac[i - 1] * i % MOD;
}
for (ri i = 0; i < maxn * 2; ++i) {
invv[i] = inv(fac[i], MOD);
}
int ans = 0;
for (ri i = 1; i <= N; ++i) {
int down = 2 * (arr[i][0] + arr[i][1]), up = 2 * arr[i][0];
int tmp = fac[down] * invv[down - up] % MOD * invv[up] % MOD;
ans = (ans + tmp) % MOD;
}
int sum = 0;
for (ri i = 1; i <= N; ++i) {
sum = (sum + dp[arr[i][0] + delta][arr[i][1] + delta]) % MOD;
}
sum = (sum - ans + MOD) % MOD;
sum = (sum * inv(2, MOD)) % MOD;
writeln(sum);
return 0;
} | codenet | -1 | 2,381 |
s851669643 | p04051 | 1,487,643,457 | cpp | Accepted | 162 | 98,176 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()
#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second
#define x1 gray_cat_x1
#define y1 gray_cat_y1
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
#define file "cycle"
const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 2e5 + 5, MAXV = 2003;
int dp[2 * MAXV][2 * MAXV];
int a[MAXN], b[MAXN];
ll f[4 * MAXV], _f[4 * MAXV];
int cnt[2 * MAXV][2 * MAXV];
ll pow_mod(ll a, ll st){
ll ans = 1ll;
for(; st; st >>= 1){
if (st & 1){
ans = (ans * a) % MOD;
}
a = (a * a) % MOD;
}
return ans;
}
void solve(){
int n;
scanf("%d", &n);
REP(i, 0, n){
scanf("%d%d", &a[i], &b[i]);
}
f[0] = 1;
REP(i, 1, 4 * MAXV){
f[i] = (f[i - 1] * i) % MOD;
}
_f[4 * MAXV - 1] = pow_mod(f[4 * MAXV - 1], MOD - 2);
for(int i = 4 * MAXV - 2; i >= 0; i--){
_f[i] = (_f[i + 1] * (i + 1)) % MOD;
}
int offset = 2000;
REP(i, 0, n){
cnt[offset - a[i]][offset - b[i]]++;
}
ll ans = 0ll;
REP(i, 0, 2 * MAXV){
REP(j, 0, 2 * MAXV){
if (i){
dp[i][j] = dp[i - 1][j];
}
if (j){
dp[i][j] += dp[i][j - 1];
}
dp[i][j] += cnt[i][j];
if (dp[i][j] >= MOD){
dp[i][j] -= MOD;
if (dp[i][j] >= MOD){
dp[i][j] -= MOD;
}
}
if (i >= offset && j >= offset){
if (2 * offset - i >= 0 && 2 * offset - j >= 0){
ans = (ans + (ll)cnt[2 * offset - i][2 * offset - j] * (ll)dp[i][j]) % MOD;
}
}
}
}
REP(i, 0, n){
ll c = (f[a[i] + a[i] + b[i] + b[i]] * _f[a[i] + a[i]]) % MOD;
c = (c * _f[b[i] + b[i]]) % MOD;
//cout << a[i] + a[i] + b[i] + b[i] << " " << a[i] + a[i] << " " << c << endl;
ans = (ans + MOD - c) % MOD;
}
ll tmp = (MOD + 1) / 2;
ans = (ans * tmp) % MOD;
cout << ans << endl;
}
int main(){
//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
int t = 1;
//cin >> t;
while(t--){
solve();
}
} | codenet | -1 | 2,393 |
s712074402 | p04051 | 1,539,004,328 | cpp | Accepted | 196 | 64,640 | /************************************************
* Au: Hany01
* Prob: agc001e
* Email: hany01dxx@gmail.com & hany01@foxmail.com
* Inst: Yali High School
************************************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template <typename T> inline T read() {
static T _, __; static char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
//EOT
const int maxn = 2e5 + 5, maxm = 4007, MOD = 1e9 + 7, M = 4005, N = 2002;
int n, A[maxn], B[maxn], dp[maxm][maxm], fac[maxm << 1], ifac[maxm << 1], ans;
inline int Pow(int a, LL b) {
register int ans = 1;
for ( ; b; b >>= 1, a = (LL)a * a % MOD) if (b & 1) ans = (LL)ans * a % MOD;
return ans;
}
int main()
{
#ifdef hany01
freopen("agc001e.in", "r", stdin);
freopen("agc001e.out", "w", stdout);
#endif
n = read<int>();
For(i, 1, n) A[i] = read<int>(), B[i] = read<int>(), ++ dp[N - A[i]][N - B[i]];
For(i, 1, M) For(j, 1, M) dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD + dp[i][j]) % MOD;
fac[0] = 1;
For(i, 1, M * 2) fac[i] = (LL)fac[i - 1] * i % MOD;
ifac[M * 2] = Pow(fac[M * 2], MOD - 2);
Fordown(i, M * 2, 1) ifac[i - 1] = (LL)ifac[i] * i % MOD;
For(i, 1, n)
(ans += (dp[N + A[i]][N + B[i]] + MOD
- (LL)fac[A[i] * 2 + B[i] * 2] * ifac[A[i] * 2] % MOD * ifac[B[i] * 2] % MOD) % MOD) %= MOD;
printf("%lld\n", (LL)ans * ((MOD + 1) / 2) % MOD);
return 0;
} | codenet | -1 | 2,405 |
s473392639 | p04051 | 1,468,824,613 | cpp | Accepted | 550 | 80,000 | #define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
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 FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double Pi = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;
pair<int, int> A[200200];
int D[5000][5000];
int F[10000];
int bpow(int a, int b) {
int res = 1;
while (b) {
if (b % 2 == 1) {
res = (res * (long long)a) % MOD;
}
a = (a * (long long)a) % MOD;
b /= 2;
}
return res;
}
int main()
{
//freopen("in.txt", "r", stdin);
int n;
scanf("%d", &n);
//n = 200000;
int minx, miny, maxx, maxy;
minx = INF;
miny = INF;
maxx = -INF;
maxy = -INF;
FOR(i, 0, n) {
scanf("%d%d", &A[i].first, &A[i].second);
//A[i] = MP(rand() % 2000 + 1, rand() % 2000 + 1);
D[2000 - A[i].first][2000 - A[i].second]++;
// D[2000 + A[i].first][2000 + A[i].second]++;
minx = min(minx, 2000 - A[i].first);
maxx = max(maxx, 2000 + A[i].first);
miny = min(miny, 2000 - A[i].second);
maxy = max(maxy, 2000 + A[i].second);
}
FOR(i, minx, maxx + 1) {
FOR(j, miny, maxy + 1) {
D[i + 1][j] += D[i][j];
if (D[i + 1][j] >= MOD) D[i + 1][j] -= MOD;
D[i][j + 1] += D[i][j];
if (D[i][j + 1] >= MOD) D[i][j + 1] -= MOD;
}
}
int res = 0;
FOR(i, 0, n) {
res += D[2000 + A[i].first][2000 + A[i].second];
if (res >= MOD) res -= MOD;
}
F[0] = 1;
FOR(i, 1, 8001) {
F[i] = (F[i - 1] * (long long)i) % MOD;
}
FOR(i, 0, n) {
long long N = (A[i].first + A[i].second) * 2;
long long M = A[i].first * 2;
long long K = A[i].second * 2;
N = F[N];
M = F[M];
K = F[K];
M = bpow(M, MOD - 2);
K = bpow(K, MOD - 2);
res -= (((N * M) % MOD)*K) % MOD;
if (res < 0) res += MOD;
}
res = (res * (long long)bpow(2, MOD - 2)) % MOD;
cout << res << endl;
return 0;
} | codenet | -1 | 2,410 |
s574910778 | p04051 | 1,510,792,345 | cpp | Accepted | 155 | 134,912 | #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pb push_back
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=4e3+5,M=1e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);}
ll fac[M],ifac[M],n;
ll f[N][N],x[M],y[M];
il void ad(ll&x,ll y){(x+=y)%=mod;}
ll C(ll n,ll m){
if(n<0||m<0||n-m<0)return 0;
return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
read(n);
fac[0]=1;rep(i,1,8000)fac[i]=i*fac[i-1]%mod;
ifac[8000]=qpow(fac[8000],mod-2,mod);
repd(i,8000-1,0)ifac[i]=ifac[i+1]*(i+1)%mod;
rep(i,1,n){read(x[i],y[i]);f[-x[i]+2000][-y[i]+2000]++;}
rep(i,0,4000)rep(j,0,4000){
if(i)ad(f[i][j],f[i-1][j]);
if(j)ad(f[i][j],f[i][j-1]);
}ll res=0;
rep(i,1,n){
ad(res,f[x[i]+2000][y[i]+2000]);
ad(res,mod-C(x[i]+y[i]+x[i]+y[i],x[i]+x[i]));
}cout<<res*qpow(2,mod-2,mod)%mod;
} | codenet | -1 | 2,434 |
s063930586 | p04051 | 1,596,229,336 | cpp | Accepted | 226 | 149,268 | /*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;
inline int Isdigit(char c) {
if (c < '0' || c > '9') return 0;
return 1;
}
inline int readint(){
register int x = 0, flag = 1;
register char ch;
while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
return x * flag;
}
inline long long readlong() {
register long long x = 0, flag = 1;
register char ch;
while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
return x * flag;
}
template <class T>
inline void write(T x){
if (x < 0)
putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }
#define For(i, x, y) for (int i = (x); i <= (y); i++)
#define Rep(i, x, y) for (int i = (x); i >= (y); i--)
#define ri readint
#define rl readlong
#define int long long
const int Mod = 1e9 + 7;
const int maxn = 1010100;
const int maxm = 5040;
int n;
int a[maxn], b[maxn];
int dp[maxm][maxm];
int fac[maxn], inv[maxn];
int Pow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = 1ll * ans * x % Mod;
y >>= 1;
x = 1ll * x * x % Mod;
}
return ans;
}
long long C(int n, int m) {
int tmp = 1ll * fac[m] * fac[n - m] % Mod;
tmp = Pow(tmp, Mod - 2);
return 1ll * tmp * fac[n] % Mod;
}
signed main() {
n = ri();
int K = 2010;
fac[0] = 1;
for (int i = 1; i <= 4 * K; i++) {
fac[i] = 1ll * fac[i - 1] * i % Mod;
}
inv[4 * K] = Pow(fac[4 * K], Mod - 2);
for (int i = 4 * K - 1; i >= 0; i--) {
inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
}
for (int i = 1; i <= n; i++) {
a[i] = ri(), b[i] = ri();
dp[-1 * a[i] + K][-1 * b[i] + K] += 1;
}
for (int i = 0; i <= 2 * K; i++) {
for (int j = 0; j <= 2 * K; 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;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
(ans += dp[a[i] + K][b[i] + K]) %= Mod;
}
for (int i = 1; i <= n; i++) {
ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + Mod) % Mod;
}
ans = 1ll * ans * Pow(2, Mod - 2) % Mod;
printf("%lld\n", ans);
return 0;
}
| codenet | -1 | 2,440 |
s063930586 | p04051 | 1,596,229,336 | cpp | Accepted | 226 | 149,268 | /*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;
inline int Isdigit(char c) {
if (c < '0' || c > '9') return 0;
return 1;
}
inline int readint(){
register int x = 0, flag = 1;
register char ch;
while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
return x * flag;
}
inline long long readlong() {
register long long x = 0, flag = 1;
register char ch;
while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
return x * flag;
}
template <class T>
inline void write(T x){
if (x < 0)
putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }
#define For(i, x, y) for (int i = (x); i <= (y); i++)
#define Rep(i, x, y) for (int i = (x); i >= (y); i--)
#define ri readint
#define rl readlong
#define int long long
const int Mod = 1e9 + 7;
const int maxn = 1010100;
const int maxm = 5040;
int n;
int a[maxn], b[maxn];
int dp[maxm][maxm];
int fac[maxn], inv[maxn];
int Pow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = 1ll * ans * x % Mod;
y >>= 1;
x = 1ll * x * x % Mod;
}
return ans;
}
long long C(int n, int m) {
int tmp = 1ll * fac[m] * fac[n - m] % Mod;
tmp = Pow(tmp, Mod - 2);
return 1ll * tmp * fac[n] % Mod;
}
signed main() {
n = ri();
int K = 2010;
fac[0] = 1;
for (int i = 1; i <= 4 * K; i++) {
fac[i] = 1ll * fac[i - 1] * i % Mod;
}
inv[4 * K] = Pow(fac[4 * K], Mod - 2);
for (int i = 4 * K - 1; i >= 0; i--) {
inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
}
for (int i = 1; i <= n; i++) {
a[i] = ri(), b[i] = ri();
dp[-1 * a[i] + K][-1 * b[i] + K] += 1;
}
for (int i = 0; i <= 2 * K; i++) {
for (int j = 0; j <= 2 * K; 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;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
(ans += dp[a[i] + K][b[i] + K]) %= Mod;
}
for (int i = 1; i <= n; i++) {
ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + Mod) % Mod;
}
ans = 1ll * ans * Pow(2, Mod - 2) % Mod;
printf("%lld\n", ans);
return 0;
}
| codenet | -1 | 2,440 |
s471544577 | p04051 | 1,537,562,672 | cpp | Accepted | 155 | 130,304 | #include <bits/stdc++.h>
using namespace std;
#ifdef Lin1043
#define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
#define massert(...) assert(...)
#else
#define DEBUG(...)
#define massert(...)
#endif
#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )
struct iopener
{
iopener()
{
#ifdef Lin1043
freopen("./in" , "r" , stdin);
#endif
}
} iop;
typedef long long LL;
template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }
template<typename T>inline T read(T &f)
{
f = 0; int x = 1 ; char c = getchar();
while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
return f = x * f;
}
const int N = 200000 + 5;
const int KCZ = 1e9 + 7 , L = N - 5;
int n , A[N] , B[N];
LL fac[N] , inv[N];
LL mp(LL x , LL y = KCZ - 2)
{
LL res = 1;
while(y)
{
if(y & 1) res = res * x % KCZ;
x = x * x % KCZ;
y >>= 1;
}
return res;
}
void init()
{
fac[0] = 1;
rep(i , 1 , L)
fac[i] = fac[i - 1] * i % KCZ;
inv[0] = 1;
inv[L] = mp(fac[L]);
per(i , L - 1 , 1)
inv[i] = inv[i + 1] * (i + 1) % KCZ;
}
int delta;
const int M = 4000 + 5;
LL f[M][M];
void add(LL &x , const LL &y)
{
x += y ; if(x >= KCZ) x -= KCZ;
}
void sub(LL &x , const LL &y)
{
x -= y ; if(x < 0) x += KCZ;
}
LL C(int n , int m)
{
if(n < m) return 0;
return fac[n] * inv[m] % KCZ * inv[n - m] % KCZ;
}
int main()
{
read(n) , init();
rep(i , 1 , n)
read(A[i]) , read(B[i]);
rep(i , 1 , n)
chkmax(delta , max(A[i] , B[i]));
rep(i , 1 , n)
f[delta - A[i]][delta - B[i]]++;
rep(i , -delta , delta)
rep(j , -delta , delta)
{
if(i >= -delta + 1)
add(f[i + delta][j + delta] , f[i - 1 + delta][j + delta]);
if(j >= -delta + 1)
add(f[i + delta][j + delta] , f[i + delta][j - 1 + delta]);
}
LL Ans = 0;
rep(i , 1 , n)
{
add(Ans , f[delta + A[i]][delta + B[i]]);
sub(Ans , C(2 * (A[i] + B[i]) , 2 * A[i]));
}
Ans = Ans * mp(2) % KCZ;
cout << Ans << endl;
return 0;
}
| codenet | -1 | 2,444 |
s219188766 | p04051 | 1,505,604,096 | cpp | Accepted | 366 | 184,064 |
/*
ะ ะะะข! ะะะ ะะะะะะฏะฎะข!!!
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
๐น๐น๐น๐น๐น๐น๐น๐น๐น๐น
*/
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
using namespace std;
typedef long long ll;
mt19937 rnd(228);
const int N = 2e5 + 7;
const int M = 5000 + 1;
const int MOD = 1e9 + 7;
const int ADD = 2000;
int a[M][M], b[M][M];
int x[N], y[N];
int dp[M][M];
int cnt[M][M];
int fact[N];
int rev[N];
inline int add(int a, int b)
{
return (a + b >= MOD ? a + b - MOD : a + b < 0 ? a + b + MOD : a + b);
}
inline int mul(int a, int b)
{
return (a * (ll) b) % MOD;
}
int bin(int a, int n)
{
int res = 1;
while (n)
{
if (n % 2 == 0)
{
a = mul(a, a);
n /= 2;
}
else
{
res = mul(res, a);
n--;
}
}
return res;
}
int C(int n, int k)
{
return mul(fact[n], mul(rev[n - k], rev[k]));
}
int main()
{
#ifdef ONPC
freopen("a.in", "r", stdin);
#endif
fact[0] = 1;
for (int i = 1; i < N; i++)
{
fact[i] = mul(fact[i - 1], i);
}
/*
rev[N - 1] = mul(fact[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; i--)
{
rev[i] = mul(rev[i + 1], i + 1);
}
*/
for (int i = 0; i < N; i++)
{
rev[i] = bin(fact[i], MOD - 2);
}
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d", &x[i], &y[i]);
a[-x[i] + ADD][-y[i] + ADD]++;
b[x[i] + ADD][y[i] + ADD]++;
}
for (int i = 0; i + 1 < M; i++)
{
for (int j = 0; j + 1 < M; j++)
{
dp[i][j] = add(dp[i][j], a[i][j]);
dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
dp[i][j + 1] = add(dp[i][j + 1], dp[i][j]);
}
}
int ans = 0;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < M; j++)
{
ans = add(ans, mul(b[i][j], dp[i][j]));
}
}
for (int i = 0; i < n; i++)
{
int get = C(x[i] + x[i] + y[i] + y[i], x[i] + x[i]);
ans = add(ans, -get);
}
ans = mul(ans, rev[2]);
printf("%d\n", ans);
}
| codenet | -1 | 2,451 |
s185792908 | p04051 | 1,550,719,901 | cpp | Accepted | 133 | 66,816 | #include <bits/stdc++.h>
#define IL __inline__ __attribute__((always_inline))
#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)
typedef long long LL;
template <class T>
IL bool chkmax(T &a, const T &b) {
return a < b ? ((a = b), 1) : 0;
}
template <class T>
IL bool chkmin(T &a, const T &b) {
return a > b ? ((a = b), 1) : 0;
}
template <class T>
IL T mymax(const T &a, const T &b) {
return a > b ? a : b;
}
template <class T>
IL T mymin(const T &a, const T &b) {
return a < b ? a : b;
}
template <class T>
IL T myabs(const T &a) {
return a > 0 ? a : -a;
}
const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/
const int MAXN = 200000 + 5, MAXM = 2000 + 5, MOD = 1000000007, INV_2 = 500000004;
IL int add(int a, int b) {
a += b;
return a >= MOD ? a - MOD : a;
}
IL int sub(int a, int b) {
a -= b;
return a < 0 ? a + MOD : a;
}
IL int mul(int a, int b) {
return 1LL * a * b % MOD;
}
IL int pow_mod(int a, int p) {
int result = 1;
for (int base = a; p; p >>= 1, base = mul(base, base)) {
if (p & 1) {
result = mul(result, base);
}
}
return result;
}
int a[MAXN], b[MAXN], f[MAXM * 2][MAXM * 2], fac[MAXN * 4], ifac[MAXN * 4];
IL void Init(int n) {
fac[0] = 1;
For(i, 1, n) {
fac[i] = mul(fac[i - 1], i);
}
ifac[n] = pow_mod(fac[n], MOD - 2);
REP(i, n, 0) {
ifac[i] = mul(ifac[i + 1], i + 1);
}
}
IL int C(int n, int m) {
return mul(fac[n], mul(ifac[m], ifac[n - m]));
}
int main() {
int n;
scanf("%d", &n);
int max_a = 0, max_b = 0;
For(i, 1, n) {
scanf("%d%d", &a[i], &b[i]);
++ f[MAXM - a[i]][MAXM - b[i]];
chkmax(max_a, a[i]);
chkmax(max_b, b[i]);
}
For(i, MAXM - max_a, MAXM + max_a) {
For(j, MAXM - max_b, MAXM + max_b) {
f[i][j] = add(f[i][j], add(f[i][j - 1], f[i - 1][j]));
}
}
Init(max_a * 2 + max_b * 2);
int ans = 0;
For(i, 1, n) {
ans = add(ans, f[MAXM + a[i]][MAXM + b[i]]);
ans = sub(ans, C((a[i] + b[i]) << 1, a[i] << 1));
}
printf("%d\n", mul(ans, INV_2));
return 0;
}
| codenet | -1 | 2,466 |
s909813276 | p04051 | 1,599,244,748 | cpp | Accepted | 124 | 67,928 | #include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
int f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return f * x;
}
inline int lowbit(int x){
return x & (-x);
}
inline int modadd(int x, int y){
return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
int res = 1;
while (b > 0){
if (b & 1) res = 1ll * res * a % MOD;
a = 1ll * a * a % MOD, b >>= 1;
}
return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
const int inv2 = 1000000008 / 2;
const int offset = 2001;
int fac[8005], inv[8005], invfac[8005];
int n, a[200005], b[200005];
int f[4005][4005] = {0};
void init(){
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read(), b[i] = read(),
++f[-a[i] + offset][-b[i] + offset];
fac[0] = fac[1] = 1;
inv[1] = 1;
invfac[0] = invfac[1] = 1;
for (int i = 2; i <= 8000; ++i){
fac[i] = 1ll * fac[i - 1] * i % MOD;
inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
invfac[i] = 1ll * invfac[i - 1] * inv[i] % MOD;
}
}
void solve(){
for (int i = 1; i <= 4001; ++i)
for (int j = 1; j <= 4001; ++j){
f[i][j] = modadd(f[i - 1][j], modadd(f[i][j], f[i][j - 1]));
}
int ans = 0;
for (int i = 1; i <= n; ++i){
ans = modadd(ans, f[a[i] + offset][b[i] + offset]);
int cc = 1ll * fac[2 * a[i] + 2 * b[i]] * invfac[2 * a[i]] % MOD;
cc = 1ll * cc * invfac[2 * b[i]] % MOD;
ans = modadd(ans, MOD - cc);
}
ans = 1ll * ans * inv2 % MOD;
printf("%d\n", ans);
}
int main(){
int T = 1;
while (T--){
init();
solve();
}
return 0;
} | codenet | -1 | 2,507 |
s569160588 | p04051 | 1,577,283,779 | cpp | Accepted | 191 | 64,384 | #define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#define MOD 1000000007
int A[200000],B[200000];
int fact[8001];
int dp[4002][4002];
int inv(LLI n) {
LLI r = 1;
int e = MOD-2;
while (e > 0) {
if (e & 1) r *= n,r %= MOD;
e >>= 1;
n *= n,n %= MOD;
}
return r;
}
int main() {
int i;
int N;
scanf("%d",&N);
for (i = 0; i < N; i++) scanf("%d %d",&A[i],&B[i]),dp[2001-A[i]][2001-B[i]]++;
int j;
for (i = 1; i < 4002; i++) {
for (j = 1; j < 4002; j++) dp[i][j] += dp[i-1][j]+dp[i][j-1],dp[i][j] %= MOD;
}
fact[0] = 1;
for (i = 1; i <= 8000; i++) fact[i] = ((LLI) fact[i-1]*i) % MOD;
int ans = 0;
for (i = 0; i < N; i++) {
ans += dp[A[i]+2001][B[i]+2001],ans %= MOD;
ans -= ((LLI) fact[2*A[i]+2*B[i]]*inv(((LLI) fact[2*A[i]]*fact[2*B[i]]) % MOD)) % MOD,ans %= MOD;
}
if (ans < 0) ans += MOD;
printf("%lld\n",((LLI) ans*inv(2)) % MOD);
return 0;
}
| codenet | -1 | 2,512 |
s836727463 | p04051 | 1,468,722,791 | cpp | Accepted | 808 | 129,408 | #include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}
template<class T>
T pow(T x, ll n) {
T r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
template<uint MD>
struct ModInt {
uint v;
ModInt() : v(0) {}
ModInt(ll v) : v(normS(v%MD+MD)) {}
uint value() const {return v;}
static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
const ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
const ModInt operator-(const ModInt &r) const {return make(normS(v+normS(MD-r.v)));}
const ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);}
ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
static ModInt inv(const ModInt &x) {
return pow(ModInt(x), MD-2);
}
};
using Mint = ModInt<TEN(9)+7>;
const int MN = 4040;
Mint g[MN][MN];
Mint C[MN][MN];
Mint fact[2*MN], iFac[2*MN];
void first() {
fact[0] = 1;
for (int i = 1; i < 2*MN; i++) {
fact[i] = fact[i-1]*i;
}
for (int i = 0; i < 2*MN; i++) {
iFac[i] = Mint::inv(fact[i]);
}
C[0][0] = 1;
for (int i = 1; i < MN; i++) {
C[i][0] = C[i-1][0];
for (int j = 1; j < MN; j++) {
C[i][j] = C[i-1][j]+C[i-1][j-1];
}
}
}
int main() {
first();
int m;
cin >> m;
int a[m], b[m];
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
}
Mint off = 0;
for (int i = 0; i < m; i++) {
// off += C[2*a[i]+2*b[i]][2*b[i]];
off += fact[2*a[i]+2*b[i]]*iFac[2*a[i]]*iFac[2*b[i]];
}
for (int i = 0; i < m; i++) {
g[2010-a[i]][2010-b[i]] += 1;
}
for (int i = 1; i < MN; i++) {
for (int j = 1; j < MN; j++) {
g[i][j] += g[i-1][j]+g[i][j-1];
}
}
Mint ans = 0;
for (int i = 0; i < m; i++) {
ans += g[2010+a[i]][2010+b[i]];
}
ans -= off;
ans *= Mint::inv(2);
cout << ans.value() << endl;
return 0;
} | codenet | -1 | 2,575 |
s131640242 | p04051 | 1,565,893,017 | cpp | Accepted | 489 | 133,632 | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>
using namespace std;
typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
ll res = 1;
while(k > 0){
if(k % 2) res *= x;
x *= x;
k /= 2;
}
return res;
}
ll pow_mod(ll x, ll k){
x %= MOD; x += MOD; x %= MOD;
ll res = 1;
while(k > 0){
if(k % 2){
res *= x; res %= MOD;
}
x *= x; x %= MOD;
k /= 2;
}
return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
//ๆๅคงๅ
ฌ็ดๆฐ
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a % b);
}
//ๆๅฐๅ
ฌๅๆฐ
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};
//ใณใณใใใผใทใงใณ
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facใฏn!,finvใฏ1/n!
//invใฏ้ๅ
void COMinit(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for(int i = 2; i < MAXcomb; 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 comb(int n, int k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
ll dp[4010][4010];
int main(void){
COMinit();
ll N;
cin >> N;
vector<ll> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, N){
dp[2000-A[i]][2000-B[i]]++;
}
rep(i, 4005)rep(j, 4005){
dp[i+1][j] += dp[i][j];
dp[i][j+1] += dp[i][j];
dp[i+1][j] %= MOD;
dp[i][j+1] %= MOD;
}
ll ans = 0;
rep(i, N){
ans += dp[2000+A[i]][2000+B[i]];
ans %= MOD;
}
rep(i, N){
ans -= comb(2*A[i]+2*B[i], 2*A[i]);
ans %= MOD;
}
ans += MOD;
ans %= MOD;
ans *= inverse(2);
ans %= MOD;
cout << ans << endl;
}
| codenet | -1 | 2,592 |
s131640242 | p04051 | 1,565,893,017 | cpp | Accepted | 489 | 133,632 | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>
using namespace std;
typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
ll res = 1;
while(k > 0){
if(k % 2) res *= x;
x *= x;
k /= 2;
}
return res;
}
ll pow_mod(ll x, ll k){
x %= MOD; x += MOD; x %= MOD;
ll res = 1;
while(k > 0){
if(k % 2){
res *= x; res %= MOD;
}
x *= x; x %= MOD;
k /= 2;
}
return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
//ๆๅคงๅ
ฌ็ดๆฐ
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a % b);
}
//ๆๅฐๅ
ฌๅๆฐ
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};
//ใณใณใใใผใทใงใณ
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facใฏn!,finvใฏ1/n!
//invใฏ้ๅ
void COMinit(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for(int i = 2; i < MAXcomb; 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 comb(int n, int k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
ll dp[4010][4010];
int main(void){
COMinit();
ll N;
cin >> N;
vector<ll> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, N){
dp[2000-A[i]][2000-B[i]]++;
}
rep(i, 4005)rep(j, 4005){
dp[i+1][j] += dp[i][j];
dp[i][j+1] += dp[i][j];
dp[i+1][j] %= MOD;
dp[i][j+1] %= MOD;
}
ll ans = 0;
rep(i, N){
ans += dp[2000+A[i]][2000+B[i]];
ans %= MOD;
}
rep(i, N){
ans -= comb(2*A[i]+2*B[i], 2*A[i]);
ans %= MOD;
}
ans += MOD;
ans %= MOD;
ans *= inverse(2);
ans %= MOD;
cout << ans << endl;
}
| codenet | -1 | 2,592 |
s168290962 | p04051 | 1,584,645,062 | cpp | Accepted | 311 | 129,664 | #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 int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }
ll mod = 1000000007;
ll modsize = 10000;
ll modinv(ll a) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= mod;
if (u < 0) u += mod;
return u;
}
ll modpow(ll a, ll b) {
ll ans = 1;
a %= mod;
while (b) {
if (b & 1) ans = ans * a%mod;
a = a * a%mod;
b >>= 1;
}
return ans;
}
vector<ll> fac(modsize + 5);
vector<ll> inv(modsize + 5);
vector<ll> facinv(modsize + 5);
void modcalc() {
fac[0] = fac[1] = 1; inv[1] = 1;
facinv[0] = facinv[1] = 1;
for (int i = 2; i < modsize; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod%i] * (mod / i) % mod;
facinv[i] = facinv[i - 1] * inv[i] % mod;
}
}
ll modcomb(ll n, ll k) {
if (n < 0 || k < 0 || n < k) return 0;
return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}
ll modperm(ll n, ll k) {
if (n < 0 || k < 0 || n < k) return 0;
return fac[n] * facinv[n - k] % mod;
}
ll modhom(ll n, ll k) {
if (n < 0 || k < 0) return 0;
if (n == 0 && k == 0) return 1;
return modcomb(n + k - 1, k);
}
int dp[4020][4020];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
modcalc();
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i, n) {
cin >> a[i] >> b[i];
dp[2002 - a[i]][2002 - b[i]]++;
}
rep(i, 4010) {
rep(j, 4010) {
dp[i + 1][j + 1] += dp[i + 1][j];
dp[i + 1][j + 1] += dp[i][j + 1];
dp[i + 1][j + 1] %= mod;
}
}
int ans = 0;
rep(i, n) {
ans += dp[2002 + a[i]][2002 + b[i]];
ans -= modcomb(2 * (a[i] + b[i]), 2 * a[i]);
ans += mod;
}
cout << ans % mod * inv[2] % mod << endl;
} | codenet | -1 | 2,594 |
s202707976 | p04051 | 1,488,238,295 | cpp | Accepted | 181 | 66,944 |
/*{{{*/
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
typedef long long ll;
typedef std::pair<int, int> pii;
std::string Name = __FILE__;
std::string iput = Name.substr(0, Name.length() - 4) + ".in";
std::string oput = Name.substr(0, Name.length() - 4) + ".out";
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; }
template <class T> inline T &read(T &x)
{
static int f;
static char c;
for (f = 1; !isdigit(c = getchar()); ) {
if (c == '-')
f = -1;
}
for (x = 0; isdigit(c); c = getchar()) {
x = x * 10 + c - 48;
}
return x *= f;
}
template <class T> inline void write(T x, const char p = '\n')
{
static int top;
static int s[30];
if (x < 0) {
x = -x;
putchar('-');
}
do s[++ top] = x % 10 + 48;
while (x /= 10);
while (top)
putchar(s[top --]);
putchar(p);
}
/*}}}*/
const int maxn = 2e5 + 5;
const int maxm = 2000 + 5;
const int mo = 1e9 + 7;
const int inv2 = mo + 1 >> 1;
int n;
int m;
int a[maxn], b[maxn];
int c[maxm << 1][maxm << 1];
long long fac[maxn << 2], inv[maxn << 2];
int C(int a, int b)
{
return (long long)fac[a] * inv[b] % mo * inv[a - b] % mo;
}
int qpow(int a, int b)
{
int ret = 1;
while (b) {
if (b & 1) ret = (long long)ret * a % mo;
a = (long long)a * a % mo;
b >>= 1;
}
return ret;
}
void exec()
{
for (int i = fac[0] = 1; i <= 8000; ++ i) {
fac[i] = (long long)fac[i - 1] * i % mo;
}
inv[8000] = qpow(fac[8000], mo - 2);
for (int i = 8000 - 1; ~i; -- i) {
inv[i] = (long long)inv[i + 1] * (i + 1) % mo;
}
read(n);
for (int i = 1; i <= n; ++ i) {
read(a[i]), read(b[i]);
++ c[maxm - a[i]][maxm - b[i]];
}
for (int i = 1; i < maxm << 1; ++ i)
for (int j = 1; j < maxm << 1; ++ j)
(c[i][j] += (c[i - 1][j] + c[i][j - 1]) % mo) %= mo;
int ans = 0;
for (int i = 1; i <= n; ++ i) {
(ans += c[maxm + a[i]][maxm + b[i]]) %= mo;
(ans += mo - C(a[i] + b[i] << 1, a[i] << 1)) %= mo;
}
write((long long)ans * inv2 % mo);
}
/*{{{*/
int main()
{
if (fopen(iput.c_str(), "r") != NULL) {
freopen(iput.c_str(), "r", stdin);
freopen(oput.c_str(), "w", stdout);
}
exec();
fclose(stdin);
fclose(stdout);
return 0;
}
/*}}}*/
| codenet | -1 | 2,594 |
s799752264 | p04051 | 1,526,570,077 | cpp | Accepted | 227 | 64,512 | #include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
/*char __wzp[1<<15|1],*__S=__wzp+32768;
#define gc() (__S>=__wzp+32768?(__wzp[fread(__wzp,sizeof(char),1<<15,stdin)]=EOF),*((__S=__wzp)++):*(__S++))*/
#define gc getchar
IL ll read(){
RG ll x=0;char f=0;RG char c=gc();
for(;!isdigit(c);c=gc())f|=(c=='-');
for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
IL double readdb(){
RG double x=0,p=0.1;RG char f=0,c=gc();
for(;!isdigit(c);c=gc())f|=(c=='-');
for(;isdigit(c);c=gc())x=x*10+(c^48);
if(c=='.')for(c=gc();isdigit(c);c=gc(),p/=10)x=x+(c^48)*p;
return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
IL void writeln(ll x,char c,ll y){write(x);pc(c);writeln(y);}
IL void writeln(ll x,char c,ll y,char d,ll z){write(x);pc(c);write(y);pc(d);writeln(z);}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define y1 ____y1
#define hash __hash
#define union _union
const int Mod =1e9+7;
const int maxn = 205050;
int n,A[maxn],B[maxn],f[4005][4005];
int fac[8005],inv[8005];
int C(int n,int m){
// printf("(%d %d) = %d\n",n,m,1ll * fac[n] * inv[m] % Mod * inv[n-m] % Mod);
return 1ll * fac[n] * inv[m] % Mod * inv[n-m] % Mod;
}
int qpow(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;
}
int main(){
n = rd();
fac[0] = 1;
Rep(i,1,8001) fac[i] = 1ll * fac[i-1] * i % Mod;
inv[8001] = qpow(fac[8001],Mod-2);
Dep(i,8000,0) inv[i] = 1ll * inv[i+1] * (i+1) % Mod;
Rep(i,1,n){
A[i] = rd(),B[i] = rd();
f[-A[i]+2000][-B[i]+2000]++;
}
for(int i=0;i<=4000;i++)
for(int j=0;j<=4000;j++){
if(j) f[i][j] = (f[i][j] + f[i][j-1]) % Mod;
if(i) f[i][j] = (f[i][j] + f[i-1][j]) % Mod;
}
int ans = 0;
Rep(i,1,n){
ans = (ans + f[A[i]+2000][B[i]+2000]) % Mod;
ans = (ans - C(A[i]+A[i]+B[i]+B[i],A[i]+A[i]) + Mod) % Mod;
}
writeln(1ll*ans*inv[2]%Mod);
return 0;
} | codenet | -1 | 2,601 |
s473657856 | p04051 | 1,527,463,417 | cpp | Accepted | 838 | 63,232 | #include <bits/stdc++.h>
#include <string>
using namespace std;
/*******************************************
****************** BY **********************
******* FUTURE GOOGLE EMPLOYEE *************
****** KARTHICK KUPPURAJ M *****************
********************************************/
#define ms(s, n) memset(s, n, sizeof(s))
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define prec(n) fixed<<setprecision(n)
#define sll(x) scanf("%lld",&x);
#define pll(x) printf("%lld",x);
#define pn printf("\n");
#define ps printf(" ");
#define pc(c) printf("%c",c);
typedef long long int ll;
#define EPS 1e-9
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
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 solve(int x, int y) {
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() {
init();
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2; j++)
{
scanf("%d", &a[i][j]);
}
}
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,635 |
s159318775 | p04051 | 1,586,729,740 | cpp | Accepted | 127 | 68,480 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
namespace io
{
#define SIZ (1 << 21 | 1)
#define gc() (io::iS == io::iT ? (io::iT= (io::iS= io::ibuff) + fread(io::ibuff, 1, SIZ, stdin), (io::iS == io::iT ? EOF : *io::iS++)) : *io::iS++)
#define putc(x) (io::oS == io::oT ? (fwrite(io::obuff, 1, io::oS - io::obuff, stdout), io::oS= io::obuff, (*io::oS++= x)) : *io::oS++= x)
#define exit \
fwrite(io::obuff, 1, io::oS - io::obuff, stdout); \
return 0;
char *iS, *iT, ibuff[SIZ], obuff[SIZ], *oS= obuff, *oT= oS + SIZ - 1, fu[110], c;
int fr;
template <class Type>
inline void read(Type &x)
{
x= 0;
Type y= 1;
for(c= gc(); (c > '9' || c < '0') && c != '-'; c= gc())
;
c == '-' ? y= -1 : x= (c & 15);
for(c= gc(); c >= '0' && c <= '9'; c= gc()) x= x * 10 + (c & 15);
x*= y;
}
inline void reads(char *x)
{
for(c= gc(); c == ' ' || c == '\n'; c= gc())
;
for(; c != ' ' && c != '\n' && c != EOF; *x= c, c= gc(), ++x)
;
}
template <class Type>
inline void print(Type x, char text= '\n')
{
if(x < 0) putc('-'), x*= -1;
if(x == 0) putc('0');
while(x) fu[++fr]= x % 10 + '0', x/= 10;
while(fr) putc(fu[fr--]);
putc(text);
}
inline void prints(char *x, char *y= NULL, char text= '\n')
{
for(; *x && x != y; ++x) putc(*x);
putc(text);
}
} // namespace io
using io::print;
using io::prints;
using io::read;
using io::reads;
#define N 200001
#define M 4005
#define P 1000000007
int n, a[N], b[N], f[M][M], ans, jc[8005], invjc[8005];
inline int ksm(int a, int b)
{
int s= 1;
for(; b; b>>= 1, a= (long long)a * a % P)
if(b & 1) s= (long long)s * a % P;
return s;
}
inline int C(int n, int m) { return (long long)jc[n] * invjc[m] % P * invjc[n - m] % P; }
signed main()
{
read(n);
for(int i= 1; i <= n; i++) read(a[i]), read(b[i]);
for(int i= 1; i <= n; i++) f[2000 - a[i]][2000 - b[i]]++;
for(int i= 0; i <= 4000; i++)
{
for(int j= 0; j <= 4000; j++)
{
f[i + 1][j]= ((long long)f[i + 1][j] + f[i][j]) % P;
f[i][j + 1]= ((long long)f[i][j + 1] + f[i][j]) % P;
}
}
for(int i= 1; i <= n; i++) ans= ((long long)ans + f[2000 + a[i]][2000 + b[i]]) % P;
jc[0]= invjc[0]= 1;
for(int i= 1; i <= 8000; i++) jc[i]= (long long)jc[i - 1] * i % P, invjc[i]= ksm(jc[i], P - 2);
for(int i= 1; i <= n; i++)
{
ans= ((long long)ans - C(2 * (a[i] + b[i]), 2 * b[i])) % P;
if(ans < 0) ans+= P;
}
ans= (long long)ans * ksm(2, P - 2) % P;
print(ans);
exit;
} | codenet | -1 | 2,659 |
s457751162 | p04051 | 1,589,002,116 | cpp | Accepted | 268 | 162,176 | //{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}while(0)
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<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
_s<<"{";
for(It _it=_ita;_it!=_itb;_it++)
{
_s<<(_it==_ita?"":",")<<*_it;
}
_s<<"}";
return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}
const ll MAXn = 2e5 + 5, MAXc=5e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);
const int C = 2005;
ll a[MAXn], b[MAXn], fac[4 * MAXc], dp[MAXc][MAXc];
void add(ll &x, ll y){
x += y;
if (x >= MOD) x -= MOD;
}
ll mypw(ll x, ll k){
if (!k) return 1;
ll a = mypw(x, k / 2);
if (k & 1)return a * a % MOD * x % MOD;
else return a * a % MOD;
}
ll c(ll x, ll y){
return fac[x] * mypw(fac[y], MOD - 2) % MOD * mypw(fac[x - y], MOD - 2) % MOD;
}
int main()
{
IOS();
fac[0] = 1;
for(int i = 1;i < 4 * MAXc;i ++)
fac[i] = fac[i - 1] * i % MOD;
int n;
cin >> n;
for(int i = 1;i <= n;i ++)
cin >> a[i] >> b[i], dp[C - a[i]][C - b[i]]++;
for (int i = 1;i <= 2 * C;i ++)
for(int j = 1;j <= 2 * C;j ++)
add(dp[i][j], dp[i][j - 1]), add(dp[i][j], dp[i - 1][j]);
ll tt = 0;
for (int i = 1;i <= n;i ++)
add(tt, dp[C + a[i]][C + b[i]]);
debug(tt);
for (int i = 1;i <= n;i ++)
tt = (tt - c(a[i] + a[i] + b[i] + b[i], a[i] + a[i])) % MOD;
debug((tt + MOD) % MOD);
cout << (tt * mypw(2, MOD - 2) % MOD + MOD) % MOD << endl;
}
| codenet | -1 | 2,672 |
s641035063 | p04051 | 1,596,463,234 | cpp | Accepted | 215 | 130,344 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}while(0)
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<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
_s<<"{";
for(It _it=_ita;_it!=_itb;_it++)
{
_s<<(_it==_ita?"":",")<<*_it;
}
_s<<"}";
return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;
const ll C = 2000;
const ll M = 4e3+5;
int a[MAXn],b[MAXn];
int dp[M][M], grid[M][M];
int mod2 = 500000004;
int add(int x,int y){
int ret = x + y;
if (ret >= MOD) ret -= MOD;
return ret;
}
int sub(int x,int y){
int ret = x - y;
if (ret < 0) ret += MOD;
return ret;
}
int main(){
IOS();
int n;
cin >> n;
REP (i,n) {
cin >> a[i] >> b[i];
dp[a[i]+C][b[i]+C]++;
}
for (int i=2*C;i>=0;i--) {
for (int j=2*C;j>=0;j--) {
dp[i][j] = add(dp[i][j],add(dp[i+1][j],dp[i][j+1]));
}
}
grid[0][0] = 1;
REP (i,2*C+1) REP (j,2*C+1) {
if (i) grid[i][j] = add(grid[i][j],grid[i-1][j]);
if (j) grid[i][j] = add(grid[i][j],grid[i][j-1]);
}
ll ans = 0;
REP (i,n) {
ans = add(ans,dp[C-a[i]][C-b[i]]);
ans = sub(ans,grid[2*a[i]][2*b[i]]);
}
ans = ans*mod2 % MOD;
cout << ans << endl;
}
| codenet | -1 | 2,717 |
s689504742 | p04051 | 1,577,904,802 | cpp | Accepted | 257 | 76,928 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end
template<unsigned mod>struct mint {
int val;
int inv() const{
int tmp,a=val,b=mod,x=1,y=0;
while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
if(x<0)x+=mod; return x;
}
mint():val(0){}
mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
mint& operator*=(const mint& x){val=(ll)val*x.val%mod; return *this;}
mint& operator/=(const mint& x){val=(ll)val*x.inv()%mod; return *this;}
mint operator+(const mint& x)const{return mint(*this)+=x;}
mint operator-(const mint& x)const{return mint(*this)-=x;}
mint operator*(const mint& x)const{return mint(*this)*=x;}
mint operator/(const mint& x)const{return mint(*this)/=x;}
bool operator==(const mint& x)const{return val==x.val;}
bool operator!=(const mint& x)const{return val!=x.val;}
};
using Mint=mint<1000000007>;
struct factorial {
vector<Mint> Fact, Finv;
public:
factorial(int maxx){
Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
}
Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
Mint dp[4050][4050];
int main(){
int n; scanf("%d",&n);
map<pair<int,int>,int> mp;
rep(i,0,n){
int x,y; scanf("%d%d",&x,&y);
mp[{x,y}]++;
}
for(auto p:mp)dp[2010-p.first.first][2010-p.first.second]+=p.second;
rep(i,1,4030)rep(j,1,4030)dp[i][j]+=dp[i-1][j]+dp[i][j-1];
Mint res; factorial fact(8020);
for(auto p:mp){
res+=dp[2010+p.first.first][2010+p.first.second]*p.second;
res-=fact.nCr((p.first.first+p.first.second)*2,p.first.first*2)*p.second;
} res/=2;
printf("%d\n",res.val);
return 0;
} | codenet | -1 | 2,765 |
s757283760 | p04051 | 1,525,215,599 | cpp | Accepted | 313 | 207,360 | #include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define MOD 1000000007
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P],finv[MAX_P];;
Int extgcd(Int a,Int b,Int& x,Int& y){
Int d=a;
if(b!=0){
d=extgcd(b,a%b,y,x);
y-=(a/b)*x;
}else{
x=1;y=0;
}
return d;
}
Int mod_inverse(Int a,Int mod){
Int x,y;
extgcd(a,mod,x,y);
return (mod+x%mod)%mod;
}
Int mod_pow(Int x,Int n,Int mod){
Int res=1;
while(n){
if(n&1) (res*=x)%=mod;
(x*=x)%=mod;
n>>=1;
}
return res;
}
Int mod_inverse2(Int a,Int mod){
return mod_pow(a,mod-2,mod);
}
void init(Int mod){
fact[0]=1;
for(Int i=1;i<MAX_P;i++)
fact[i]=(fact[i-1]*i)%mod;
inv[1]=1;
for(Int i=2;i<MAX_P;i++)
inv[i]=inv[mod%i]*(mod-mod/i)%mod;
finv[0]=1;
for(Int i=1;i<MAX_P;i++)
finv[i]=finv[i-1]*inv[i]%mod;
}
Int mod_fact(Int n,Int mod,Int& e){
e=0;
if(n==0) return 1;
Int res=mod_fact(n/mod,mod,e);
e+=n/mod;
if(n/mod%2!=0)return res*(mod-fact[n%mod]) %mod;
return res*fact[n%mod]%mod;
}
Int mod_comb(Int n,Int k,Int mod){
if(n==k||k==0) return 1;
Int e1,e2,e3;
Int a1=mod_fact(n,mod,e1),a2=mod_fact(k,mod,e2),a3=mod_fact(n-k,mod,e3);
if(e1>e2+e3) return 0;
return a1*mod_inverse(a2*a3%mod,mod)%mod;
}
Int mod_comb2(Int n,Int k,Int mod){
Int res=1;
for(Int i=0;i<k;i++){
res*=(n-i)%mod;
res%=mod;
res*=mod_inverse(i+1,mod);
res%=mod;
}
return res;
}
//only for prime mod
Int mod_comb3(Int n,Int k,Int mod){
if(k<0||k>n) return 0;
return fact[n]*finv[k]%mod*finv[n-k]%mod;
}
Int montmort(Int n,Int mod){
Int res=0,inv=1;
for(Int k=2;k<=n;k++){
(inv*=mod_inverse(k,mod))%=mod;
if(k%2) (res+=mod-inv)%=mod;
else (res+=inv)%=mod;
}
for(Int i=1;i<=n;i++)
(res*=i)%=mod;
return res;
}
// calculate P(t) from given points in [0,N]
Int LagrangePolynomial(vector<Int> &y,Int t,const Int mod){
init(mod);
Int n=y.size()-1;
Int num=1;
for(Int i=0;i<=n;i++)
num=num*((t-i)%mod)%mod;
Int res=0;
for(Int i=0;i<=n;i++){
Int tmp=(y[i]*num%mod)*mod_inverse((t-i)%mod,mod)%mod;
tmp=tmp*finv[i]%mod;
tmp=tmp*finv[n-i]%mod;
if((n-i)&1) tmp=mod-tmp;
res=(res+tmp)%mod;
}
return res;
}
//INSERT ABOVE HERE
Int dp[5050][5050];
signed main(){
memset(dp,0,sizeof(dp));
Int n;
cin>>n;
vector<Int> a(n),b(n);
for(Int i=0;i<n;i++){
cin>>a[i]>>b[i];
dp[2500-a[i]][2500-b[i]]++;
}
for(Int i=1;i<5000;i++)
for(Int j=1;j<5000;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[2500+a[i]][2500+b[i]])%MOD;
init(MOD);
for(Int i=0;i<n;i++)
ans=(ans+MOD-mod_comb3((a[i]+b[i])*2,a[i]*2,MOD))%MOD;
ans=ans*mod_inverse(2,MOD)%MOD;
cout<<ans<<endl;
return 0;
}
| codenet | -1 | 2,785 |
s733935923 | p04051 | 1,588,395,751 | cpp | Accepted | 100 | 65,024 | // Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
namespace _buff {
const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, 1, BUFF, stdin);
}
return ib == ie ? -1 : *ib++;
}
}
LL read() {
using namespace _buff;
LL ret = 0;
bool pos = true;
char c = getc();
for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
assert(~c);
}
if (c == '-') {
pos = false;
c = getc();
}
for (; c >= '0' && c <= '9'; c = getc()) {
ret = (ret << 3) + (ret << 1) + (c ^ 48);
}
return pos ? ret : -ret;
}
using uint = unsigned;
const uint MOD = 1E9 + 7;
struct Z {
uint v;
Z(uint v = 0) : v(v) {}
Z& operator += (const Z &z) {
v += z.v;
if (v >= MOD) v -= MOD;
return *this;
}
Z& operator -= (const Z &z) {
if (v < z.v) v += MOD;
v -= z.v;
return *this;
}
Z& operator *= (const Z &z) {
v = static_cast<uint64_t>(v) * z.v % MOD;
return *this;
}
};
ostream& operator << (ostream &os, const Z &z) {
return os << z.v;
}
Z operator + (const Z &x, const Z &y) {
return Z(x.v + y.v >= MOD ? x.v + y.v - MOD : x.v + y.v);
}
Z operator - (const Z &x, const Z &y) {
return Z(x.v < y.v ? x.v + MOD - y.v : x.v - y.v);
}
Z operator * (const Z &x, const Z &y) {
return Z(static_cast<uint64_t>(x.v) * y.v % MOD);
}
Z qpow(Z base, uint e) {
Z ret(1);
for (; e; e >>= 1) {
if (e & 1) {
ret *= base;
}
base *= base;
}
return ret;
}
const size_t N = 2E5 + 5;
const size_t S = 2E3 + 2;
const size_t M = 4E3 + 5;
const size_t L = 8E3 + 5;
int n, a[N], b[N];
Z fac[L], inv[L], f[M][M];
void prep() {
fac[0] = 1;
for (uint i = 1; i < L; ++i) {
fac[i] = fac[i - 1] * i;
}
inv[L - 1] = qpow(fac[L - 1], MOD - 2);
for (uint i = L; --i; ) {
inv[i - 1] = inv[i] * i;
}
}
int main() {
prep();
n = read();
for (int i = 0; i < n; ++i) {
a[i] = read();
b[i] = read();
f[S - a[i]][S - b[i]] += 1;
}
for (uint i = 1; i < M; ++i) {
for (uint j = 1; j < M; ++j) {
f[i][j] += f[i - 1][j] + f[i][j - 1];
}
}
Z ans = 0;
for (int i = 0; i < n; ++i) {
ans += f[S + a[i]][S + b[i]];
ans -= fac[(a[i] + b[i]) << 1] * inv[a[i] << 1] * inv[b[i] << 1];
}
ans *= (MOD + 1) >> 1;
cout << ans;
return 0;
}
| codenet | -1 | 2,803 |
s104856820 | p04051 | 1,600,471,005 | cpp | Accepted | 164 | 68,324 | #include <bits/stdc++.h>
using namespace std;
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
~printer(){cerr<<endl;}
Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
Rics(string x){cerr<<x;return *this;}
Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
Gene c >Rics(rge<c> x){
*this,"["; for(auto it = x.b; it != x.e; ++it)
*this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
return uniform_int_distribution<int>(l, r) (rng);
}
const int N = 100000;
const int mod = 1e9 + 7;
namespace NT {
int fact[N], inv[N];
int bm(int b, int p, int m) {
if(p == 0) return 1%m;
int t = bm(b,p/2,m);
t = (1ll*t*t)%m;
if(p&1) return 1ll*t*b%m;
return t;
}
int C(int n, int r) {
if(n < 0 or r < 0 or r > n) return 0;
int ret = 1ll*fact[n]*inv[r]%mod;
ret = 1ll*ret*inv[n-r]%mod;
return ret;
}
void init() {
fact[0] = 1;
for(int i = 1; i < N; i++) {
fact[i] = 1ll*fact[i-1]*i%mod;
}
inv[N-1] = bm(fact[N-1], mod-2, mod);
for(int i = N-2; i >= 0; i--) {
inv[i] = 1ll*inv[i+1]*(i+1)%mod;
}
}
bool composite[N];
vector<int> prime;
void sieve() {
composite[1] = 1;
for(int i = 2; i < N; i++) {
if(!composite[i]) prime.push_back(i);
for(int j = 0; j < prime.size() && prime[j]*i < N; j++) {
composite[prime[j] * i] = 1;
if(i%prime[j] == 0) break;
}
}
}
}
const int M = 4005, B = 2001;
int dp[M][M];
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
NT::init();
int n;
cin >> n;
int sub = 0, ans = 0;
vector<int> a(n), b(n);
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
sub += NT::C(2*(x+y), 2*x);
sub %= mod;
dp[-x+B][-y+B]++;
a[i] = x+B, b[i] = y+B;
}
for(int i = 1; i < M; i++) {
for(int j = 1; j < M; j++) {
dp[i][j] += dp[i-1][j] + dp[i][j-1];
dp[i][j] %= mod;
}
}
for(int i = 0; i < n; i++) {
ans += dp[a[i]][b[i]];
ans %= mod;
}
ans -= sub;
ans %= mod;
ans = 1ll*ans*((mod+1)/2)%mod;
if(ans < 0) ans += mod;
cout << ans << endl;
}
| codenet | -1 | 2,805 |
s724801727 | p04051 | 1,527,377,973 | cpp | Accepted | 207 | 64,896 | #include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }
const int MOD = 1000000007;
const int MAXN = 200005;
const int MAXX = 2005;
int d[MAXX*2][MAXX*2];
ll fac[MAXX*8], invfac[MAXX*8];
int A[MAXN], B[MAXN];
int N, Ans;
ll pw(ll n, ll k) {
ll r = 1; for(n %= MOD; k; k >>= 1) {
if(k&1) r = r * n % MOD;
n = n * n % MOD;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
fac[0] = 1; for(int i = 1; i < MAXX*8; i++) fac[i] = fac[i-1] * i % MOD;
invfac[MAXX*8-1] = pw(fac[MAXX*8-1], MOD-2);
for(int i = MAXX*8-1; i; i--) invfac[i-1] = invfac[i] * i % MOD;
cin >> N;
for(int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
d[-A[i]+MAXX][-B[i]+MAXX]++;
}
for(int i = 1; i < MAXX*2; i++) for(int j = 1; j < MAXX*2; j++)
d[i][j] = (d[i][j] + (d[i-1][j] + d[i][j-1]) % MOD) % MOD;
for(int i = 0; i < N; i++) {
Ans = (Ans + d[A[i]+MAXX][B[i]+MAXX]) % MOD;
Ans = (Ans - fac[A[i]*2+B[i]*2] * invfac[A[i]*2] % MOD * invfac[B[i]*2] % MOD + MOD) % MOD;
}
Ans = (ll)Ans * pw(2, MOD-2) % MOD;
cout << Ans << endl;
return 0;
} | codenet | -1 | 2,817 |
s763260218 | p04051 | 1,510,657,646 | cpp | Accepted | 318 | 253,952 | #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define previous fake_previous
#define left fake_left
#define right fake_right
#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 REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 4001;
const LL MAXK = 2000;
int n;
VLL a;
VLL b;
VLL fact;
VLL revFact;
VVLL DP1;
VVLL DP2;
inline LL power(LL x, LL to)
{
LL res = 1;
while (to)
{
if (to & 1)
res = (res * x) % mod;
x = (x*x) % mod;
to >>= 1;
}
return res;
}
LL solve()
{
//C(2a, 2b);
LL res = 0, add;
FOR(i, 0, n)
{
add = (fact[a[i] * 2 + b[i] * 2]) * revFact[a[i] * 2] % mod;
add *= revFact[b[i] * 2];
add %= mod;
res += add;
}
res %= mod;
return res;
}
LL calculate()
{
DP1.assign(MAXN, VLL(MAXN, 0));
DP2.assign(MAXN, VLL(MAXN, 0));
FOR(i, 0, n)
DP2[a[i] + MAXK][b[i] + MAXK]++, DP1[MAXK - a[i]][MAXK - b[i]]++;
FOR(i, 0, MAXN)
FOR(j, 0, MAXN)
{
if (i)
DP1[i][j] = (DP1[i][j] + DP1[i - 1][j]) % mod;
if (j)
DP1[i][j] = (DP1[i][j] + DP1[i][j - 1]) % mod;
}
LL ans = 0;
FOR(i, 0, MAXN)
FOR(j, 0, MAXN)
{
ans += (DP1[i][j] * DP2[i][j]) % mod;
ans %= mod;
}
ans %= mod;
return ans;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//freopen("In.txt", "r", stdin);
fact.assign(MAXN*2, 0);
revFact.assign(MAXN * 2, 0);
fact[0] = 1;
FOR(i, 1, MAXN*2)
fact[i] = (fact[i - 1] * i) % mod;
FOR(i, 1, MAXN*2)
revFact[i] = power(fact[i], mod - 2);
cin >> n;
a.assign(n, 0);
b.assign(n, 0);
FOR(i, 0, n)
cin >> a[i] >> b[i];
LL ans = calculate();
ans += mod;
ans -= solve();
ans %= mod;
ans *= power(2, mod - 2);
ans %= mod;
cout << ans << endl;
cin >> n;
return 0;
} | codenet | -1 | 2,832 |
s699597540 | p04051 | 1,540,327,894 | cpp | Accepted | 97 | 66,048 | #include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
#define re register
#define de double
#define le long double
#define ri register int
#define ll long long
#define sh short
#define ui unsiged int
#define ull unsigned long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define tpr template <typename ra>
#define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
#define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)
#define gc getchar
inline int read() {
int p = 0, w = 1; char c = gc();
while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
return p * w;
}
int wr[50], rw;
#define pc(iw) putchar(iw)
tpr inline void write(ra o, char c = '\n') {
if(!o) pc('0');
if(o < 0) o = -o, pc('-');
while(o) wr[++ rw] = o % 10, o /= 10;
while(rw) pc(wr[rw --] + '0');
pc(c);
}
tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; }
tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; }
tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, 1 : 0; }
tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, 1 : 0; }
}
using namespace std;
using namespace remoon;
namespace mod_zone {
#define mod 1000000007
inline void inc(int &a, int b) { a += b; if(a >= mod) a -= mod; }
inline void dec(int &a, int b) { a -= b; if(a < 0) a += mod; }
inline int Inc(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
inline int Dec(int a, int b) { return (a - b < 0) ? a - b + mod : a - b; }
inline int mul(int a, int b) { return 1ll * a * b % mod; }
inline int fp(int a, int k) {
int ret = 1;
for( ; k; k >>= 1, a = mul(a, a))
if(k & 1) ret = mul(ret, a);
return ret;
}
}
using namespace mod_zone;
#define sid 4055
int n;
int a[200050], b[200050];
int f[sid][sid], jc[sid * 2], ny[sid * 2];
inline void Init() {
jc[0] = jc[1] = 1;
ny[0] = ny[1] = 1;
rep(i, 2, 8000) {
jc[i] = mul(jc[i - 1], i);
ny[i] = mul(mod - mod / i, ny[mod % i]);
}
rep(i, 2, 8000) ny[i] = mul(ny[i], ny[i - 1]);
}
inline int calc() {
int ret = 0;
rep(i, 1, n) f[2005 - a[i]][2005 - b[i]] ++;
rep(i, 1, 4010) rep(j, 1, 4010)
inc(f[i][j], Inc(f[i][j - 1], f[i - 1][j]));
rep(i, 1, n) inc(ret, f[2005 + a[i]][2005 + b[i]]);
return ret;
}
inline int C(int n, int m) {
return mul(mul(jc[n], ny[m]), ny[n - m]);
}
inline int solve() {
int ret = 0;
rep(i, 1, n)
inc(ret, C((a[i] + b[i]) << 1, a[i] << 1));
return ret;
}
int main() {
Init();
n = read();
rep(i, 1, n) a[i] = read(), b[i] = read();
write(mul(Dec(calc(), solve()), fp(2, mod - 2)));
return 0;
} | codenet | -1 | 2,892 |
s857483950 | p04051 | 1,598,475,491 | cpp | Accepted | 172 | 79,060 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IN freopen("perimetric_chapter_1_input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define xx first
#define yy second
#define ln 17
#define off 2002
#define sq(x) ((x)*(x))
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace __gnu_pbds;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;
#define log 20
#define mod 1000000007LL
#define INF 1000000000000000000LL
#define maxn 300005
const long double eps = 1e-9 ;
class numberTheory{
public:
numberTheory(){}
pii extendedEuclid(i64 a, i64 b) { // returns x, y | ax + by = gcd(a,b)
if(b == 0) return pii( a >= 0 ? 1 : -1 , 0LL);
else {
pii d = extendedEuclid(b, a % b);
return pii(d.yy, d.xx - d.yy * (a / b));
}
}
i64 modularInverse(i64 a, i64 n) {
pair<i64,i64> ret = extendedEuclid(a, n);
return ((ret.xx % n) + n) % n;
}
i64 bigMod(i64 a, i64 n , i64 m)
{
if(n==0) return 1 ;
i64 ret = bigMod(a,n/2,m) ;
ret = (ret*ret)%m ;
if(n%2) ret = (ret*a)%m ;
return ret ;
}
};
const i64 N = 700000 ;
i64 fact[N+5] , invFact[N+5] ;
i64 C(i64 n, i64 r)
{
if( n<0 || r<0 || r>n ) return 0 ;
// if(n<=50) return cc[n][r] ;
i64 ret = (fact[n]*invFact[r])%mod ;
return (ret*invFact[n-r])%mod ;
}
void preprocess()
{
numberTheory nt ;
fact[0] = 1 ;
for(i64 x=1 ; x<=N ; x++) fact[x] = (fact[x-1]*x)%mod ;
invFact[N] = nt.modularInverse(fact[N],mod) ;
for(i64 x=N-1 ; x>=0 ; x--) invFact[x] = (invFact[x+1]*(x+1) )%mod ;
}
pair<int,int> ara[maxn] ;
int dp[4015][4015] ;
int main()
{
preprocess() ;
int n ;
scanf("%d",&n) ;
for(int i=1 ; i<=n ; i++) scanf("%d %d",&ara[i].xx,&ara[i].yy) ;
for(int i=1 ; i<=n ; i++)
{
dp[ -ara[i].xx + off ][ -ara[i].yy+off ]++ ;
}
for(int i=-2000 ; i<=2000; i++)
{
for(int j=-2000 ; j<=2000 ; j++)
{
dp[ i+off ][ j+off ] = ( dp[i+off][j+off] + dp[i-1+off][j+off] + dp[i+off][j-1+off] )%mod ;
}
}
int ans = 0 ;
for(int i=1 ; i<=n ; i++)
{
ans = ( ans + dp[ ara[i].xx+off ][ ara[i].yy+off ] )%mod ;
ans = ( ans - C( 2*(ara[i].xx+ara[i].yy) , 2*ara[i].xx ) )%mod ;
ans = ( ans%mod + mod )%mod ;
}
if(ans%2) ans += mod ;
ans /= 2 ;
ans = (ans%mod + mod)%mod ;
printf("%d\n",ans) ;
return 0 ;
}
| codenet | -1 | 2,907 |
s555825328 | p04051 | 1,468,845,578 | cpp | Accepted | 523 | 90,880 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}
const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;
template<int N, int MOD>
struct Comb {
ll fact[N + 1], inv[N + 1];
Comb() {
fact[0] = inv[0] = inv[1] = 1;
for (int i = 2; i <= N; i++) inv[i] = (MOD + ((ll)-inv[MOD%i] * (MOD / i)) % MOD) % MOD;
REPS(i, N) {
fact[i] = fact[i - 1] * i%MOD;
inv[i] = inv[i] * inv[i - 1] % MOD;
}
}
ll operator()(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
ll res = inv[r] * inv[n - r];
if (res >= MOD) res %= MOD;
res *= fact[n];
if (res >= MOD) res %= MOD;
return res;
}
};
Comb<300000, MOD> C;
const int INV2 = (MOD + 1) / 2;
int T, n, m;
int d[4002][4002], out[4002][4002];
int main(int argc, char *argv[]){
ios::sync_with_stdio(false);
cin >> n;
ll ans = 0;
REP(i, n) {
int a, b;
cin >> a >> b;
d[2000 - a][2000 - b] ++;
out[2000 + a][2000 + b] ++;
ans = ans + MOD - C(2*a + 2*b, 2*a);
}
REP(i, 4001)REP(j, 4001) {
if (out[i][j]) {
ans += (ll)d[i][j] * out[i][j] % MOD;
}
d[i + 1][j] = (d[i + 1][j] + d[i][j]) % MOD;
d[i][j + 1] = (d[i][j + 1] + d[i][j]) % MOD;
}
cout << ans % MOD * INV2 % MOD << endl;
return 0;
}
| codenet | -1 | 2,947 |
s357522676 | p04051 | 1,590,547,586 | cpp | Accepted | 383 | 212,736 | #include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// mintใๅฟ
่ฆ
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
};
int const MAX = 2500;
mint dp[2*MAX][2*MAX];
int main(){
ll n;
cin >> n;
vector<P>s(n);
rep(i,n){
int a,b;
cin >> a >> b;
s[i]={a,b};
}
map<P,int>mp;
combination comb(1e5);
rep(i,n){
mp[s[i]]++;
}
mint ans = 0;
for(auto it=mp.begin();it!=mp.end();it++){
dp[MAX-it->first.first][MAX-it->first.second]+=it->second;
}
rep(i,2*MAX-1){
rep(j,2*MAX-1){
dp[i+1][j+1]+=dp[i][j+1]+dp[i+1][j];
}
}
for(auto it=mp.begin();it!=mp.end();it++){
ans += dp[it->first.first+MAX][it->first.second+MAX]*it->second;
}
rep(i,n){
P p = s[i];
int a = p.first;
int b = p.second;
ans -= comb(2*a+b*2,2*a);
}
ans /= 2;
cout << ans << endl;
return 0;
}
| codenet | -1 | 2,979 |
s313774699 | p04051 | 1,530,841,064 | cpp | Accepted | 135 | 101,632 | /*
created by scarlyw
*/
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iterator>
#include <map>
inline char read() {
static const int IN_LEN = 1024 * 1024;
static char buf[IN_LEN], *s, *t;
if (s == t) {
t = (s = buf) + fread(buf, 1, IN_LEN, stdin);
if (s == t) return -1;
}
return *s++;
}
// /*
template<class T>
inline void R(T &x) {
static char c;
static bool iosig;
for (c = read(), iosig = false; !isdigit(c); c = read()) {
if (c == -1) return ;
if (c == '-') iosig = true;
}
for (x = 0; isdigit(c); c = read())
x = ((x << 2) + x << 1) + (c ^ '0');
if (iosig) x = -x;
}
//*/
const int OUT_LEN = 1024 * 1024;
char obuf[OUT_LEN], *oh = obuf;
inline void write_char(char c) {
if (oh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf;
*oh++ = c;
}
template<class T>
inline void W(T x) {
static int buf[30], cnt;
if (x == 0) write_char('0');
else {
if (x < 0) write_char('-'), x = -x;
for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
while (cnt) write_char(buf[cnt--]);
}
}
inline void flush() {
fwrite(obuf, 1, oh - obuf, stdout);
}
/*
template<class T>
inline void R(T &x) {
static char c;
static bool iosig;
for (c = getchar(), iosig = false; !isdigit(c); c = getchar()) {
if (c == -1) return ;
if (c == '-') iosig = true;
}
for (x = 0; isdigit(c); c = getchar())
x = ((x << 2) + x << 1) + (c ^ '0');
if (iosig) x = -x;
}
// */
const int MAXM = 8000 + 33;
const int MAXN = 4000 + 33;
const int MAXX = 2000 + 5;
const int mod = 1000000000 + 7;
const int MAXC = 200000 + 11;
int n;
int start[MAXN][MAXN], fac[MAXM], inv_fac[MAXM], a[MAXC], b[MAXC];
int dp[MAXN][MAXN];
inline int mod_pow(int a, int b) {
int ans = 1;
for (; b; b >>= 1, a = (long long)a * a % mod)
if (b & 1) ans = (long long)ans * a % mod;
return ans;
}
inline int c(int n, int m) {
return (n < m) ? (0) : ((long long)fac[n]
* inv_fac[m] % mod * inv_fac[n - m] % mod);
}
inline void add(int &x, int t) {
x += t, (x >= mod) ? (x -= mod) : x;
}
inline void solve() {
R(n), fac[0] = 1;
for (int i = 1; i <= n; ++i)
R(a[i]), R(b[i]), start[MAXX - a[i]][MAXX - b[i]]++;
for (int i = 1; i < MAXM; ++i) fac[i] = (long long)fac[i - 1] * i % mod;
inv_fac[MAXM - 1] = mod_pow(fac[MAXM - 1], mod - 2);
for (int i = MAXM - 2; i >= 0; --i)
inv_fac[i] = (long long)inv_fac[i + 1] * (i + 1) % mod;
for (int i = 1; i < MAXN; ++i)
for (int j = 1; j < MAXN; ++j)
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + start[i][j]) % mod;
int ans = 0;
for (int i = 1; i <= n; ++i) add(ans, dp[MAXX + a[i]][MAXX + b[i]]);
for (int i = 1; i <= n; ++i)
add(ans, mod - c(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
std::cout << ((long long)ans * (mod + 1) / 2) % mod;
}
int main() {
// freopen("in.in", "r", stdin);
solve();
return 0;
} | codenet | -1 | 2,984 |
s846295371 | p04051 | 1,468,777,755 | cpp | Accepted | 572 | 127,104 | #define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
using namespace std;
#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;
namespace std{
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
out<<'('<<a.fr<<','<<a.sc<<')';
return out;
}
}
//const int INF=5e8;
template<lint mod>
struct Int_{
unsigned x;
unsigned mpow(Int_ a,unsigned k){
Int_ res=1;
while(k){
if(k&1) res=res*a;
a=a*a;
k>>=1;
}
return res.x;
}
unsigned inverse(Int_ a){
return mpow(a,mod-2);
}
Int_(): x(0) { }
Int_(long long sig) {
int sigt=sig%mod;
if(sigt<0) sigt+=mod;
x=sigt;
}
unsigned get() const { return (unsigned)x; }
Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
Int_ &operator=(Int_ that) { x=that.x; return *this;}
Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
bool operator==(Int_ that) const { return x==that.x; }
bool operator!=(Int_ that) const { return x!=that.x; }
Int_ operator-() const { return Int_(0)-Int_(*this);}
Int_ operator+(Int_ that) const { return Int_(*this) += that; }
Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
Int_ operator/(Int_ that) const { return Int_(*this) /= that; }
};
namespace std{
template<lint mod>
ostream &operator <<(ostream& out,const Int_<mod>& a){
out<<a.get();
return out;
}
template<lint mod>
istream &operator >>(istream& in,Int_<mod>& a){
in>>a.x;
return in;
}
};
typedef Int_<1000000007> Int;
Int dp[4005][4005];
Int comb[4005][4005];
pi ps[200005];
int n;
int main(){
comb[0][0]=1;
REP(i,4002) REP(j,4002){
comb[i+1][j]+=comb[i][j];
comb[i][j+1]+=comb[i][j];
}
cin>>n;
int M=2000;
REP(i,n){
scanf("%d%d",&ps[i].fr,&ps[i].sc);
dp[M-ps[i].fr][M-ps[i].sc].x++;
}
REP(i,4002) REP(j,4002){
dp[i+1][j]+=dp[i][j];
dp[i][j+1]+=dp[i][j];
}
Int res=0;
REP(i,n){
res+=dp[M+ps[i].fr][M+ps[i].sc];
}
REP(i,n){
res-=comb[ps[i].fr*2][ps[i].sc*2];
}
res/=2;
cout<<res<<endl;
return 0;
} | codenet | -1 | 3,015 |
s233921926 | p04051 | 1,587,302,005 | cpp | Accepted | 163 | 64,512 | #include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
int val;
Mint() { val = 0; }
Mint(const ll& x) {
val = (-MOD <= x && x < MOD) ? x : x % MOD;
if (val < 0) val += MOD;
}
friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
friend Mint modex(Mint a, ll p) {
assert(p >= 0);
Mint ans = 1;
for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
return ans;
}
Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
Mint& operator++() { return *this += 1; }
Mint& operator--() { return *this -= 1; }
Mint operator++(int) { Mint result(*this); *this += 1; return result; }
Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
Mint operator-() const { return Mint(-val); }
friend Mint operator+(Mint a, const Mint& b) { return a += b; }
friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
const int MAXN = 8005;
Mint fac[MAXN], invfac[MAXN];
Mint binom(ll a, ll b) {
if (b < 0) return 0;
if (b > a) return 0;
return fac[a] * invfac[b] * invfac[a - b];
}
const int ZERO = 2000;
Mint G[4005][4005];
int main() {
fac[0] = 1;
for (int i = 1; i < MAXN; ++i)
fac[i] = fac[i - 1] * i;
invfac[MAXN - 1] = 1 / fac[MAXN - 1];
for (int i = MAXN - 2; i >= 0; --i)
invfac[i] = invfac[i + 1] * (i + 1);
int n;
scanf("%d", &n);
vector<int> A(n), B(n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &A[i], &B[i]);
G[ZERO - A[i]][ZERO - B[i]]++;
}
for (int a = 0; a < 4005; ++a)
for (int b = 0; b < 4005; ++b) {
if (a) G[a][b] += G[a - 1][b];
if (b) G[a][b] += G[a][b - 1];
}
Mint ans = 0;
for (int i = 0; i < n; ++i) {
ans += G[A[i] + ZERO][B[i] + ZERO];
ans -= binom(2 * (A[i] + B[i]), 2 * A[i]);
}
ans /= 2;
printf("%d\n", ans.val);
}
| codenet | -1 | 3,046 |
s490969125 | p04051 | 1,509,148,129 | cpp | Accepted | 244 | 66,560 | #include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
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<LL> VI;
typedef pair<int, LL> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 1000 * 2 + 7;
int F[MAX * 4], RF[MAX * 4];
PII A[200007];
int BP(LL a, int n)
{
LL res = 1;
while(n)
{
if (n & 1)res = (res * a) % MOD;
a *= a;
a %= MOD;
n >>= 1;
}
return res;
}
int C(int a, int b)
{
LL res = F[a];
res *= RF[b];
res %= MOD;
res *= RF[a-b];
res %= MOD;
return res;
}
int DP[2 * MAX][2 * MAX];
int get(int x, int y)
{
//cout << x << " " << y << endl;
if (DP[x][y] != -1)
{
//if (DP[x][y])cout << x << " " << y << " " << DP[x][y] << endl;
return DP[x][y];
}
LL res = 0;
if (x)res += get(x-1, y);
if (y)res += get(x, y-1);
while(res >= MOD)res -= MOD;
return DP[x][y] = res;
}
int main()
{
//cout << f(2, 1) << endl;
//freopen("input.txt", "r", stdin);
//ios::sync_with_stdio(false);cin.tie(NULL);
int n;
scanf("%d", &n);
FILL(DP, -1);
RF[0] = F[0] = 1;
FOR(i, 1, 4 * MAX)
{
F[i] = (F[i-1] * 1LL * i) % MOD;
RF[i] = BP(F[i], MOD - 2);
}
int tot = 0;
FOR(i, 0, n)
{
scanf("%d%d", &A[i].first, &A[i].second);
int aa = -A[i].first + MAX;
int bb = -A[i].second + MAX;
// if (DP[aa][bb] == -1)DP[aa][bb] = 0;
// DP[aa][bb]++;
tot += C(2 * A[i].first + 2 * A[i].second, 2 * A[i].first);
if (tot >= MOD)tot -= MOD;
A[i].first = -A[i].first;
A[i].second = -A[i].second;
}
LL ans = 0;
sort(A, A + n);
FOR(i, 0, n)
{
// cout << A[i].first << " " << A[i].second << endl;
int aa = A[i].first + MAX, bb = A[i].second + MAX;
get(aa, bb);
DP[aa][bb]++;
if (DP[aa][bb] >= MOD)
DP[aa][bb] -= MOD;
// cout << DP[A[i].first + MAX][A[i].second + MAX] << endl;
}
FOR(i, 0, n)
{
ans += get(-A[i].first + MAX, -A[i].second + MAX);
if (ans >= MOD)ans -= MOD;
}
ans -= tot;
if (ans < 0)ans += MOD;
ans *= BP(2, MOD-2);
ans %= MOD;
printf("%lld\n", ans);
return 0;
}
| codenet | -1 | 3,065 |
s969408429 | p04051 | 1,594,167,545 | cpp | Accepted | 199 | 133,428 | //By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
out<<"{ ";
forstl(x,c) out<<x<<" ";
out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll dp[4005][4005];
const ll SHIFT = 2002;
const ll MAXN = 4005;
ll fastpow (ll a, ll p){
if(p == 0) return 1;
ll z = fastpow(a,p/2);
z = (z*z)%MOD;
if(p%2) z = (a*z)%MOD;
return z;
}
int main(){
fastio;
int n; cin>>n;
vp32 v;
forn(i,n){
int a,b;
cin>>a>>b;
v.pb(mp(a,b));
dp[SHIFT-a][SHIFT-b]++;
}
forn(i,MAXN-1){
forn(j,MAXN-1){
dp[i][j] %= MOD;
dp[i+1][j] += dp[i][j];
dp[i][j+1] += dp[i][j];
}
}
ll ans = 0;
forn(i,n){
ans += dp[SHIFT+v[i].fi][SHIFT+v[i].se];
ans %= MOD;
}
ll fact[LIM] = {0};
ll invfact[LIM] = {0};
fact[0] = 1;
forsn(i,1,LIM) fact[i] = (fact[i-1]*i)%MOD;
invfact[LIM-1] = fastpow(fact[LIM-1], MOD-2);
rforn(i,LIM-2) invfact[i] = (invfact[i+1]*(i+1))%MOD;
ll totsub = 0;
forn(i,n){
ll a = v[i].fi, b = v[i].se;
ll sub = fact[2*a+2*b];
sub = (sub * invfact[2*a])%MOD;
sub = (sub * invfact[2*b])%MOD;
totsub = (totsub+sub)%MOD;
}
ans -= totsub;
ans %= MOD;
if(ans < 0) ans += MOD;
ans = (ans * invfact[2]) % MOD;
cout<<ans<<ln;
return 0;
} | codenet | -1 | 3,095 |
s578866402 | p04051 | 1,554,321,108 | cpp | Accepted | 329 | 142,976 | #include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;
class comb{
private:
ll mod;
ll mx;
vector<ll> F;
vector<ll> FR;
public:
comb(ll mod=1000000007,ll mx=100000):mod(mod),mx(mx),F(mx+1,1),FR(mx+1,1){
mk_F();
}
ll mod_pow(ll a,ll x){
a%=mod;
ll ans=1;
while(x>0){
if(x&1){ans*=a; ans%=mod;}
a*=a;
a%=mod;
x>>=1;
}
return ans;
}
pll Ex_gcd(ll a,ll b){
if(b==0){return {1,0};}
pll ret=Ex_gcd(b,a%b);
ret.F-=a/b*ret.S;
return {ret.S,ret.F};
}
ll prime_R(ll a){
return mod_pow(a,mod-2);
}
ll R(ll a){
ll ret=Ex_gcd(a,mod).F;
ret%=mod;
if(ret<0){ret+=mod;}
return ret;
}
void mk_F(){
for(ll i=1;i<=mx;i++){F[i]=F[i-1]*i%mod; FR[i]=R(F[i]);}
}
ll c(ll n,ll k){
if(n<k){return 0;}
if(n==k || k==0){return 1;}
return F[n]*FR[n-k]%mod*FR[k]%mod;
}
//mod must be prime
ll Lucas_C(ll n,ll m){
ll ret=1;
while(n>0 || m>0){
ret*=c(n%mod,m%mod);
ret%=mod;
n/=mod; m/=mod;
}
return ret;
}
ll Stirling(ll n,ll k){
ll ret=0;
for(ll i=1;i<=k;i++){
if((k-i)%2){ret-=c(k,i)*mod_pow(i,n)%mod;}
else{ret+=c(k,i)*mod_pow(i,n)%mod;}
ret%=mod;
}
ret*=R(F[k]);
ret%=mod;
if(ret<0){ret+=mod;}
return ret;
}
ll Bell(ll n,ll k){
ll ret=0;
for(ll i=1;i<=k;i++){ret+=Stirling(n,i); ret%=mod;}
return ret;
}
};
comb Comb;
int main(){
ll n;
cin>>n;
const ll C=2100;
vector<vector<ll>> A(2*C,vector<ll>(2*C,0));
vector<pll> p(n);
for(int i=0;i<n;i++){
ll a,b;
cin>>a>>b;
A[C-a][C-b]++;
p[i]={a,b};
}
for(int i=0;i+1<2*C;i++){
for(int t=0;t+1<2*C;t++){
A[i][t]%=MOD;
A[i+1][t]+=A[i][t];
A[i][t+1]+=A[i][t];
}
}
ll ans=0;
for(int i=0;i<n;i++){
ans+=A[C+p[i].F][C+p[i].S];
}
ans%=MOD;
for(int i=0;i<n;i++){
ans-=Comb.c((p[i].F+p[i].S)*2,p[i].F*2);
}
ans%=MOD;
ll inv=(MOD+1)/2;
ans*=inv;
ans%=MOD;
if(ans<0){ans+=MOD;}
cout<<ans<<endl;
return 0;
}
| codenet | -1 | 3,116 |
s403998366 | p04051 | 1,526,418,590 | cpp | Accepted | 226 | 135,424 | #include<bits/stdc++.h>
using namespace std;
#define ll int
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y) for(int i=int(x);i<int(y);++i)
#define For(i,x,y) for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y) for(int i=int(x);i>=int(y);--i)
#define pi acos(-1)
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y) ((x)<(y)?(y):(x))
#define min(x,y) ((x)<(y)?(x):(y))
#define sqr(x) ((x)*(x))
#define Mul(x,y) ((x)=1LL*(x)*(y)%mod)
#define Add(x,y) ((x)=((x)+(y))%mod)
#define Max(x,y) ((x)=((x)<(y)?(y):(x)))
#define Min(x,y) ((x)=((x)>(y)?(y):(x)))
#define E(x) return writeln(x),0
#define p(x) printf("~%lld~\n",LL(x))
#define pp(x,y) printf("~~%lld %lld~~\n",LL(x),LL(y))
#define LL (long long)
#define ppp(x,y,z) printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d) printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x) freopen(x".in","r",stdin)
#define f_out(x) freopen(x".out","w",stdout)
#define open(x) f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
static const int GYN=2333333;
char SZB[GYN],*S=SZB,*T=SZB;
inline char gc(){ if (S==T){ T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n'; } return *S++; }
#if NEG
inline ll read(){ ll x=0,g=1; char ch=gc(); for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1; for (;isdigit(ch);ch=gc()) x=x*10-48+ch; return x*g; }
inline void write(ll x){ if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0'); }
#else
inline ll read(){ ll x=0; char ch=gc(); for (;!isdigit(ch);ch=gc()); for (;isdigit(ch);ch=gc()) x=x*10-48+ch; return x; }
inline void write(ll x){ if (x>=10) write(x/10); putchar(x%10+'0'); }
#endif
inline char readchar(){ char ch=gc(); for(;isspace(ch);ch=gc()); return ch; }
inline ll readstr(char *s){ char ch=gc(); int cur=0; for(;isspace(ch);ch=gc()); for(;!isspace(ch);ch=gc()) s[cur++]=ch; s[cur]='\0'; return cur; }
void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=200100,mod=1e9+7;
ll mp[4100][4100],a[N],b[N],n,cogito=2000,answ,c[4100][4100];
int main(){
For(i,0,cogito*2)For(j,0,cogito*2){
if (!i&&!j) c[i][j]=1;
lf (!i) c[i][j]=c[i][j-1];
lf (!j) c[i][j]=c[i-1][j];
else c[i][j]=(c[i-1][j]+c[i][j-1])%mod;
}
n=read();
For(i,1,n)a[i]=read(),b[i]=read(),mp[-a[i]+cogito][-b[i]+cogito]++;
For(i,0,2*cogito)For(j,0,2*cogito){
if(i)Add(mp[i][j],mp[i-1][j]);
if(j)Add(mp[i][j],mp[i][j-1]);
}
For(i,1,n)Add(answ,mp[a[i]+cogito][b[i]+cogito]),Add(answ,-c[a[i]*2][b[i]*2]);
writeln((1ll*answ*(mod+1)/2%mod+mod)%mod);
} | codenet | -1 | 3,200 |
s450503558 | p04051 | 1,569,717,598 | cpp | Accepted | 238 | 126,976 | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'
const int m = 2000;
ll dp[2*m + 1][2*m + 1];
const int MAXN = 10010;
ll fact[MAXN];
ll rfact[MAXN];
ll mod_pow(ll x, ll p, ll M = MOD) {
ll a = 1;
while (p) {
if (p % 2)
a = a*x%M;
x = x*x%M;
p /= 2;
}
return a;
}
ll mod_inverse(ll a, ll M = MOD) {
return mod_pow(a, M - 2, M);
}
void set_fact(ll n, ll M = MOD) {
fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
for (ll i = 2; i <= n; i++) {
fact[i] = i * fact[i - 1] % M;
rfact[i] = mod_inverse(fact[i], M);
}
}
int main() {
set_fact(5*m);
int n;
cin >> n;
vi a(n), b(n);
rep (i, n) {
cin >> a[i] >> b[i];
dp[m - a[i]][m - b[i]]++;
}
rep (i, 2*m + 1) {
rep (j, 2*m + 1) {
if (i > 0) {
(dp[i][j] += dp[i - 1][j]) %= MOD;
}
if (j > 0) {
(dp[i][j] += dp[i][j - 1]) %= MOD;
}
}
}
//DEBUG_MAT(dp);
ll ans = 0;
rep (idx, n) {
int i = a[idx] + m, j = b[idx] + m;
(ans += dp[i][j]) %= MOD;
}
rep (i, n) {
ans -= fact[2*a[i] + 2*b[i]] * rfact[2*a[i]] % MOD * rfact[2*b[i]] % MOD;
}
ans %= MOD;
ans = ans * mod_inverse(2) % MOD;
ans = (ans + MOD) % MOD;
cout << ans << endl;
}
| codenet | -1 | 3,205 |
s153306452 | p04051 | 1,580,004,276 | cpp | Accepted | 177 | 143,360 | #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;
ll mod_pow(ll a, ll n) {
ll res = 1;
while (n) {
if (n & 1)res = res * a%mod;
a = a * a%mod; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n%mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)return modint(1);
modint res = (a*a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
modint dp[4002][4002];
void solve() {
int n; cin >> n;
vector<int> a(n), b(n);
rep(i, n) {
cin >> a[i] >> b[i];
dp[2000 - a[i]][2000 - b[i]] += 1;
}
rep(i, 4001)rep(j, 4001) {
dp[i + 1][j] += dp[i][j];
dp[i][j + 1] += dp[i][j];
}
modint ans = 0;
rep(i, n) {
ans -= comb(2 * a[i] + 2 * b[i], 2 * a[i]);
ans += dp[2000 + a[i]][2000 + b[i]];
}
ans = ans / (modint)2;
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//expre();
//cout << fixed << setprecision(10);
init();
//int t; cin >> t; rep(i, t)solve();
//while (cin >> n, n)solve();
solve();
stop
return 0;
}
| codenet | -1 | 3,237 |
s444964136 | p04051 | 1,509,985,739 | cpp | Accepted | 128 | 64,640 | #include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
if(Bufferhead==Buffertail){
int l=fread(buffer,1,BufferSize,stdin);
if(!l){Terminal=1;return 0;}
Buffertail=(Bufferhead=buffer)+l;
}
return *Bufferhead++;
}
template<class T>inline bool read(T &x){
x=0;char c=Getchar(),rev=0;
while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
if(c=='.'){
c=Getchar();double t=0.1;
while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
}
x=rev?-x:x;
return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
char c=Getchar();
while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
while(c>=33&&c<=126) (*x++)=c,c=Getchar();
*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
if(!x){putchar('0');putchar(c);return;}
if(x<0) putchar('-'),x=-x;
int m=0,a[20];
while(x) a[m++]=x%10,x/=10;
while(m--) putchar(a[m]+'0');
putchar(c);
}
//--------------------------------head---------------------------------------------
const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
int ans=1;
while(y){
if(y&1) ans=(ll)ans*x%mod;
x=(ll)x*x%mod;y>>=1;
}return ans;
}
int n,ans,a[N],b[N];
int cnt[4005][4005],fac[8005],ifac[8005];
int main(){
#ifdef rqgao2014
freopen("input.txt","r",stdin);
#endif
read(n);fac[0]=1;
for(int i=1;i<=8000;i++) fac[i]=(ll)fac[i-1]*i%mod;
ifac[8000]=exp(fac[8000],mod-2);
for(int i=8000;i;i--) ifac[i-1]=(ll)ifac[i]*i%mod;
for(int i=1 ;i<=n;i++)
read(a[i],b[i]),cnt[2000-a[i]][2000-b[i]]++;
for(int i=0;i<=4000;i++)
for(int j=0;j<=4000;j++)
cnt[i][j]=((ll)cnt[i][j]+(i?cnt[i-1][j]:0)+(j?cnt[i][j-1]:0))%mod;
for(int i=1;i<=n;i++)
ch(ans,cnt[2000+a[i]][2000+b[i]]);
for(int i=1;i<=n;i++)
ch(ans,mod-(ll)fac[a[i]*2+b[i]*2]*ifac[a[i]*2]%mod*ifac[b[i]*2]%mod);
print((ll)ans*(mod+1)/2%mod);
return 0;
} | codenet | -1 | 3,247 |
s082359608 | p04051 | 1,468,740,191 | cpp | Accepted | 522 | 127,616 | /*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline int ri() {int x; scanf("%d", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++)
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;}
/*}}}*/
//mod int
struct mint{
const static long long mod = 1e9 + 7;
long long x;
mint():x(0){}
mint(long long x):x(((x%mod)+mod)%mod){};
mint operator+=(const mint&a){if((x+=a.x)>=mod) x-=mod; return *this;}
mint operator-=(const mint&a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint operator*=(const mint&a){(x*=a.x)%=mod; return *this;}
mint operator*(const mint&a){return mint(*this)*=a;}
mint operator-(const mint&a){return mint(*this)-=a;}
mint operator+(const mint&a){return mint(*this)+=a;}
template<typename T>mint operator*(const T&a){return mint(*this)*=a;}
template<typename T>mint operator-(const T&a){return mint(*this)-=a;}
template<typename T>mint operator+(const T&a){return mint(*this)+=a;}
template<typename T>friend mint operator*(T x,const mint&m){return mint(x)*=m;}
template<typename T>friend mint operator-(T x,const mint&m){return mint(x)-=m;}
template<typename T>friend mint operator+(T x,const mint&m){return mint(x)+=m;}
bool operator==(const mint& a)const{ return x == a.x;}
operator long long () const {return x;}
};
mint pw(mint a, long long b){mint res(1);while(b){if(b&1)res*=a;a*=a;b>>=1;}return res;}
mint inv(mint a){return pw(a, mint::mod - 2);}
//mod int
const int maxn = 4010, base = 2001;
mint p[maxn][maxn];
int n, a[200010], b[200010];
mint fac[maxn * 2], ifac[maxn * 2];
mint c(int a, int b) {
return fac[a + b] * ifac[a] * ifac[b];
}
int main() {
#ifdef _TEST_
freopen("input.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
cin >> n;
fac[0] = ifac[0] = 1;
rep(i, 1, maxn * 2) fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * inv(i);
rep(i, n) {
cin >> a[i] >> b[i];
p[base - a[i]][base - b[i]] += 1;
}
rep(i, 1, maxn) rep(j, 1, maxn) {
p[i][j] += p[i - 1][j] + p[i][j - 1];
}
mint res;
rep(i, n) res += p[base + a[i]][base + b[i]];
rep(i, n) res -= c(2 * a[i], 2 * b[i]);
cout << res * inv(2) << endl;
return 0;
}
| codenet | -1 | 3,250 |
s071249265 | p04051 | 1,580,025,398 | cpp | Accepted | 195 | 126,328 | #include <bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
}
public:
modnum() : v(0) {}
modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
modnum inv() const {
modnum res;
res.v = minv(v, MOD);
return res;
}
friend modnum inv(const modnum& m) { return m.inv(); }
modnum neg() const {
modnum res;
res.v = v ? MOD-v : 0;
return res;
}
friend modnum neg(const modnum& m) { return m.neg(); }
modnum operator- () const {
return neg();
}
modnum operator+ () const {
return modnum(*this);
}
modnum& operator ++ () {
v ++;
if (v == MOD) v = 0;
return *this;
}
modnum& operator -- () {
if (v == 0) v = MOD;
v --;
return *this;
}
modnum& operator += (const modnum& o) {
v += o.v;
if (v >= MOD) v -= MOD;
return *this;
}
modnum& operator -= (const modnum& o) {
v -= o.v;
if (v < 0) v += MOD;
return *this;
}
modnum& operator *= (const modnum& o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum& operator /= (const modnum& o) {
return *this *= o.inv();
}
friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
template <typename T> T pow(T a, long long b) {
assert(b >= 0);
T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}
using num = modnum<int(1e9) + 7>;
vector<num> fact, ifact;
void init(){
int N = 110000;
fact = {1};
for(int i = 1; i < N; i++) fact.push_back(i * fact[i-1]);
ifact.resize(N);
ifact.back() = 1 / fact.back();
for(int i = N - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}
num ncr(int n, int k){
if(k < 0 || k > n) return 0;
return fact[n] * ifact[k] * ifact[n-k];
}
num dp[4001][4001];
num collect[4001][4001];
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
init();
num ans = 0;
int n;
cin >> n;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
ans -= ncr(2*a + 2*b, 2*a);
dp[2000-a][2000-b] += 1;
collect[2000+a][2000+b] += 1;
}
for(int i = 0; i <= 4000; i++){
for(int j = 0; j <= 4000; j++){
if(i) dp[i][j] += dp[i-1][j];
if(j) dp[i][j] += dp[i][j-1];
ans += collect[i][j] * dp[i][j];
}
}
ans /= 2;
cout << ans << '\n';
} | codenet | -1 | 3,262 |
s890930979 | p04051 | 1,583,961,416 | cpp | Accepted | 116 | 126,976 | #pragma GCC optimize("Ofast,fast-math,unroll-loops")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using pld = pair <ld, ld>;
/*
const ll MAX_MEM = 5e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
auto ret = MEM + MEM_POS;
MEM_POS += x;
assert(MEM_POS < MAX_MEM);
return ret;
}
void operator delete(void*)
{}
*/
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
for (auto &i : a)
in >> i;
return in;
}
template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
for (auto &i : a)
out << i << ' ';
return out;
}
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
in >> p.first >> p.second;
return in;
}
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
out << p.first << " " << p.second << " ";
return out;
}
inline void Start()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
//freopen("circlecover.in", "r", stdin);
//freopen("circlecover.out", "w", stdout);
}
const int P = 1e9 + 7;
int add(int a, int b)
{
return a + b >= P ? a + b - P : a + b;
}
int mul(int a, int b)
{
return ll(a) * b % P;
}
int bpow(int a, int n)
{
int res = 1;
while (n)
{
if (n & 1)
res = mul(res, a);
a = mul(a, a);
n >>= 1;
}
return res;
}
int rev(int x)
{
return bpow(x, P - 2);
}
int divi(int a, int b)
{
return mul(a, rev(b));
}
int sub(int a, int b)
{
return add(a, P - b);
}
const int N = 2001;
int _dp[2 * N][2 * N];
int _d[2 * N][2 * N];
int& dp(int i, int j)
{
return _dp[i + N][j + N];
}
int& d(int i, int j)
{
return _d[i + N][j + N];
}
const int INF = 1e9;
signed main()
{
Start();
int n;
cin >> n;
vector <int> a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
for (int i = 0; i < 2 * N; ++i)
for (int j = 0; j < 2 * N; ++j)
_dp[i][j] = 0, _d[i][j] = INF;
for (int i = 0; i < n; ++i)
dp(-a[i], -b[i]) = add(dp(-a[i], -b[i]), 1);
for (int i = 1; i < 2 * N; ++i)
for (int j = 1; j < 2 * N; ++j)
_dp[i][j] = add(_dp[i][j], add(_dp[i - 1][j], _dp[i][j - 1]));
int sum = 0;
for (int i = 0; i < n; ++i)
sum = add(sum, dp(a[i], b[i]));
vector <int> fact(4 * N, 1), revfact(4 * N, 1);
for (int i = 1; i < 4 * N; ++i)
fact[i] = mul(fact[i - 1], i), revfact[i] = divi(revfact[i - 1], i);
for (int i = 0; i < n; ++i)
sum = sub(sum, mul(fact[a[i] + b[i] + a[i] + b[i]], mul(revfact[a[i] + a[i]], revfact[b[i] + b[i]])));
sum = divi(sum, 2);
cout << sum;
return 0;
}
| codenet | -1 | 3,269 |
s593086959 | p04051 | 1,533,158,399 | cpp | Accepted | 257 | 252,672 | /// {{{ Author: Wang, Yen-Jen
// include
#include <bits/stdc++.h>
// using
using namespace std;
// types
typedef long long ll;
typedef pair<int,int> pii;
// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))
// input
inline bool SR(int &x) {
return scanf("%d",&x) == 1;
}
inline bool SR(ll &x) {
return scanf("%lld",&x) == 1;
}
inline bool SR(double &x) {
return scanf("%lf",&x) == 1;
}
inline bool SR(char *s) {
return scanf("%s",s) == 1;
}
inline bool RI() {
return true;
}
template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
return SR(x) && RI(tail...);
}
// output
inline void SP(const int x) {
printf("%d",x);
}
inline void SP(const ll x) {
printf("%lld",x);
}
inline void SP(const double x) {
printf("%.16lf",x);
}
inline void SP(const char *s) {
printf("%s",s);
}
inline void PL() {
puts("");
}
template<typename I , typename... T> inline void PL(const I x , const T... tail) {
SP(x);
if(sizeof...(tail)) putchar(' ');
PL(tail...);
}
// debug
#define WangYenJen
#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
cerr << s << " = " << x << endl;
}
template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
int c = 0;
while(*s != ',' || c != 0) {
if(*s == '(' || *s == '[' || *s == '{') c++;
if(*s == ')' || *s == ']' || *s == '}') c--;
cerr << *s++;
}
cerr << " = " << x << " , ";
_DOING(s + 1 , tail...);
}
#define DEBUG(...) \
do {\
fprintf(stderr , "%s: Line %d - ",__PRETTY_FUNCTION__,__LINE__);\
_DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);
#else
#define DEBUG(...)
#endif
// constant number
const int INF = 0x3f3f3f3f;
const ll INF64 = 0x3f3f3f3f3f3f3f3fll;
// random function
inline int RAND() {
static int x = 880301;
return (x = x * 0xdefaced + 1) % 0x7fffffff;
}
/// }}}
const ll MOD = 1000000000 + 7;
const int MAX_N = 200000 + 7;
const int MAX_X = 4000 + 7;
const int DELTA = 2000;
ll dp[MAX_X][MAX_X];
ll dp2[MAX_X][MAX_X];
int A[MAX_N], B[MAX_N];
ll power(ll a, ll n) {
ll x = 1;
while (n) {
if (n & 1) x = x * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return x;
}
ll inv(ll x) {
return power(x, MOD - 2);
}
int main() {
int N;
RI(N);
REP(i, N) {
RI(A[i], B[i]);
dp[-A[i] + DELTA][-B[i] + DELTA]++;
}
dp2[0][0] = 1;
REP(i, MAX_X) {
REP(j, MAX_X) {
if (i) {
dp[i][j] += dp[i - 1][j];
dp2[i][j] += dp2[i - 1][j];
if (dp[i][j] >= MOD) dp[i][j] -= MOD;
if (dp2[i][j] >= MOD) dp2[i][j] -= MOD;
}
if (j) {
dp[i][j] += dp[i][j - 1];
dp2[i][j] += dp2[i][j - 1];
if (dp[i][j] >= MOD) dp[i][j] -= MOD;
if (dp2[i][j] >= MOD) dp2[i][j] -= MOD;
}
}
}
ll ans = 0;
REP(i, N) {
ans += dp[A[i] + DELTA][B[i] + DELTA];
if (ans >= MOD) ans -= MOD;
ans -= dp2[A[i] * 2][B[i] * 2];
if (ans < 0) ans += MOD;
}
(ans *= inv(2)) %= MOD;
PL(ans);
return 0;
}
| codenet | -1 | 3,293 |
s795450533 | p04051 | 1,513,783,241 | cpp | Accepted | 117 | 64,640 | ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// _oo0oo_ //
// o8888888o //
// 88" . "88 ------ hzt1 //
// (| -_- |) //
// 0\ = /0 //
// ___/`---'\___ //
// .' \| |// '. //
// / \||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \ - /// | | //
// | \_| ''\---/'' |_/ | //
// \ .-\__ '-' ___/-. / //
// ___'. .' /--.--\ `. .'___ //
// ."" '< `.___\_<|>_/___.' >' "". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `_. \_ __\ /__ _/ .-` / / //
// =====`-.____`.___ \_____/___.-`___.-'===== //
// `=---=' //
// //
// //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// //
// God-He Bless All. //
// This Code Will Never Explode. //
// //
// //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,Size,stdin);
tail=(head=buffer)+l;
}
if(head==tail) return -1;
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=200010;
const int maxm=4010;
const int mod=1000000007;
const int inv2=500000004;
int n,x[maxn],y[maxn];
int f[maxm][maxm];
int fac[maxn],ifac[maxn];
void init(int m) {
ifac[0]=ifac[1]=fac[0]=1;
rep(i,2,m*2) ifac[i]=(ll)(mod-mod/i)*ifac[mod%i]%mod;
rep(i,1,m*2) ifac[i]=(ll)ifac[i-1]*ifac[i]%mod;
rep(i,1,m*2) fac[i]=(ll)fac[i-1]*i%mod;
rep(i,1,m) rep(j,1,m) (f[i][j]+=f[i-1][j])%=mod,(f[i][j]+=f[i][j-1])%=mod;
}
int main() {
n=read();
rep(i,1,n) x[i]=read(),y[i]=read(),f[-x[i]+2001][-y[i]+2001]++;
init(4002);
int ans=0;
rep(i,1,n) (ans+=f[x[i]+2001][y[i]+2001])%=mod;
rep(i,1,n) (ans-=(ll)fac[x[i]*2+y[i]*2]*ifac[x[i]*2]%mod*ifac[y[i]*2]%mod)%=mod;
(ans+=mod)%=mod;
printf("%d\n",(ll)ans*inv2%mod);
return 0;
} | codenet | -1 | 3,302 |
s914130935 | p04051 | 1,468,723,446 | cpp | Accepted | 938 | 252,416 | #include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
template<int MOD>
struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
signed a = x, b = MOD, u = 1, v = 0;
while(b) {
signed t = a / b;
a -= t * b; std::swap(a, b);
u -= t * v; std::swap(u, v);
}
if(u < 0) u += Mod;
ModInt res; res.x = (unsigned)u;
return res;
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while(k) {
if(k & 1) r *= a;
a *= a;
k >>= 1;
}
return r;
}
typedef ModInt<1000000007> mint;
vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
N = min(N, mint::Mod - 1);
fact.resize(N + 1); factinv.resize(N + 1);
fact[0] = 1;
rer(i, 1, N) fact[i] = fact[i - 1] * i;
factinv[N] = fact[N].inverse();
for(int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
if(n >= mint::Mod)
return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
int main() {
int N;
while(~scanf("%d", &N)) {
vector<int> A(N);
vector<int> B(N);
for(int i = 0; i < N; ++ i)
scanf("%d%d", &A[i], &B[i]);
int X = max(*max_element(A.begin(), A.end()), *max_element(B.begin(), B.end())) + 1;
vector<vector<mint>> sum(X * 4 + 1, vector<mint>(X * 4 + 1));
rep(i, N)
++ sum[X * 2 - (A[i] + B[i])][X * 2 - A[i]].x;
rep(i, X * 4) rep(j, X * 4) {
mint x = sum[i][j];
if(x.x == 0) continue;
sum[i + 1][j] += x;
sum[i + 1][j + 1] += x;
}
nCr_computeFactinv(X * 4);
mint ans;
rep(i, N) {
ans += sum[X * 2 + A[i] + B[i]][X * 2 + A[i]];
ans -= nCr((A[i] + B[i]) * 2, A[i] * 2);
}
ans /= 2;
printf("%d\n", ans.get());
}
return 0;
}
| codenet | -1 | 3,342 |
s682231826 | p04051 | 1,545,158,887 | cpp | Accepted | 502 | 166,272 | # include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[5000][5000],b[200000];
string str, ss;
Pll a[210000];
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<LL>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void yn(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
struct Combination {
int mod;
vector< int64_t > mfact, rfact;
Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
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));
}
};
Combination comb(10000,MOD);
int main() {
cin >> n;
rep(i, n) {
cin >> a[i].fir >> a[i].sec;
dp[2000 - a[i].fir][2000 - a[i].sec] += 1;
}
rep(i, n) {
sum += comb.C((a[i].fir + a[i].sec) * 2, a[i].fir * 2);
sum %= MOD;
}
rep(i, 4100)rep(j, 4100) {
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[2000 + a[i].fir][2000 + a[i].sec];
ans %= MOD;
}
cout << ((ans - sum + MOD) % MOD)*comb.inv(2) % MOD << endl;
return 0;
}
| codenet | -1 | 3,420 |
s128712809 | p04051 | 1,551,833,449 | cpp | Accepted | 446 | 128,768 | #include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod
int modpow(int x, int n, int m){
int a = 1;
IREP(i, 64){
a = (a * a) % m;
if(((n >> i) & 1) == 1) a = (a * x) % m;
}
return a;
}
class Combination
{
public:
vec fact, invfact;
int MAX_N, mod;
Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
initialize();
}
void initialize(){
fact = vec(MAX_N + 1);
invfact = vec(MAX_N + 1);
fact[0] = 1;
FOR(i, 1, MAX_N + 1){
fact[i] = (fact[i - 1] * i) % mod;
}
invfact[MAX_N] = modpow(fact[MAX_N], mod - 2, mod);
IREP(i, MAX_N){
invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
}
}
int nCr(int n, int r){
if(r > n || r < 0 || n < 0) return 0;
if(n > MAX_N){
MAX_N = n;
initialize();
}
int a = fact[n];
a = (a * invfact[r]) % mod;
a = (a * invfact[n - r]) % mod;
return a;
}
int nPr(int n, int r){
if(r > n || r < 0 || n < 0) return 0;
if(n > MAX_N){
MAX_N = n;
initialize();
}
int a = fact[n];
a = (a * invfact[n - r]) % mod;
return a;
}
};
int dp[4001][4001] = {};
signed main(){
int N; cin >> N;
vec A(N), B(N);
REP(i, N){
cin >> A[i] >> B[i];
dp[2000 - A[i]][2000 - B[i]]++;
}
REP(i, 4001) REP(j, 4001){
if(i > 0) Add(dp[i][j], dp[i - 1][j]);
if(j > 0) Add(dp[i][j], dp[i][j - 1]);
}
int ans = 0;
REP(i, N) Add(ans, dp[2000 + A[i]][2000 + B[i]]);
int x = 0;
Combination C(5000, mod);
REP(i, N) Add(x, C.nCr(2 * (A[i] + B[i]), 2 * A[i]));
ans = (ans - x + mod) % mod;
Mult(ans, modpow(2, mod - 2, mod));
cout << ans << endl;
return 0;
}
| codenet | -1 | 3,546 |
s812627743 | p04051 | 1,490,218,523 | cpp | Accepted | 164 | 78,320 | #include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
const int mo=1e9+7;
int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}
int f[4444][4444];
int Z=2100;
int n;
vpii pp;
int fac[8888],ifac[8888];
int c(int a,int b){
int ans= 1ll*fac[a]*ifac[a-b]%mo*ifac[b]%mo;
return ans;
}
int main()
{
#ifdef JCVB
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int _time_jc=clock();
#endif
gn(n);
fac[0]=1;rep(i,1,8300)fac[i]=1ll*fac[i-1]*i%mo;
rep(i,0,8300)ifac[i]=qp(fac[i],mo-2);
rep(i,1,n+1){
int x,y;gn(x);gn(y);
pp.pb(mp(x,y));
f[Z-x][Z-y]++;
}
rep(i,1,4400)rep(j,1,4400)upmo(f[i][j],f[i-1][j]+f[i][j-1]);
int su=0;
rep(i,0,n)
upmo(su,f[Z+pp[i].fi][Z+pp[i].se]);
rep(i,0,n){
upmo(su,-c(2*pp[i].fi+2*pp[i].se,2*pp[i].fi));
}
su=1ll*su*qp(2,mo-2)%mo;
printf("%d\n",su);
#ifdef JCVB
debug("time: %d\n",int(clock()-_time_jc));
#endif
return 0;
} | codenet | -1 | 3,547 |
s459812352 | p04051 | 1,506,811,087 | cpp | Accepted | 176 | 96,384 | // Copyright (C) 2017 __debug.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
using std::pair;
using std::vector;
using std::string;
typedef long long LL;
typedef pair<int, int> Pii;
const int oo = 0x3f3f3f3f;
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
std::ifstream t("/proc/self/status");
return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
f = (ch == '-' ? -1 : 1);
for (x = 0; isdigit(ch); ch = getchar())
x = 10 * x + ch - '0';
return x *= f;
}
template<typename T> void write(T x)
{
if (x == 0) {
putchar('0');
return;
}
if (x < 0) {
putchar('-');
x = -x;
}
static char s[20];
int top = 0;
for (; x; x /= 10)
s[++top] = x % 10 + '0';
while (top)
putchar(s[top--]);
}
// EOT
const int MAXN = 2e5 + 5, RNG = 2e3 + 5;
const int MOD = 1e9 + 7;
int N;
Pii A[MAXN];
void input()
{
read(N);
for (int i = 1; i <= N; ++i) {
read(A[i].x); read(A[i].y);
}
}
int fac[RNG * 4], ifac[RNG * 4];
LL fpm(LL base, LL exp)
{
LL ret = 1;
for (; exp; exp >>= 1) {
if (exp & 1)
(ret *= base) %= MOD;
(base *= base) %= MOD;
}
return ret;
}
inline int C(int n, int k)
{
assert(0 <= k && k <= n);
return (LL)fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}
void solve()
{
fac[0] = 1;
for (int i = 1; i < RNG * 4; ++i) {
fac[i] = (LL)fac[i - 1] * i % MOD;
}
ifac[RNG * 4 - 1] = fpm(fac[RNG * 4 - 1], MOD - 2);
for (int i = RNG * 4 - 1; i >= 1; --i) {
ifac[i - 1] = (LL)ifac[i] * i % MOD;
}
static int dp[RNG * 2][RNG * 2];
static int cnt[RNG * 2][RNG * 2];
int ans = 0;
for (int i = 1; i <= N; ++i) {
dp[RNG - A[i].x][RNG - A[i].y] += 1;
cnt[RNG + A[i].x][RNG + A[i].y] += 1;
(ans += MOD - C(A[i].x * 2 + A[i].y * 2, A[i].x * 2)) %= MOD;
}
for (int i = 0; i < RNG * 2; ++i) {
for (int j = 0; j < RNG * 2; ++j) {
(dp[i][j] += (i ? dp[i - 1][j] : 0) + (j ? dp[i][j - 1] : 0)) %= MOD;
(ans += (LL)cnt[i][j] * dp[i][j] % MOD) %= MOD;
}
}
ans = (LL)ans * fpm(2, MOD - 2) % MOD;
printf("%d\n", ans);
}
int main()
{
#ifdef __DEBUG
freopen("E.in", "r", stdin);
freopen("E.out", "w", stdout);
#endif
input();
solve();
return 0;
}
// ๅฟตๅ
ฐๅ ็บข็๏ผๅฟ้ฟ็ฐ็ญ๏ผๅไบบๅๆณชใ
// -- ๆๆฎใๆผๅบญ็งยทๅซๆฅ้ณไฟกๅ้ใ
| codenet | -1 | 3,623 |
s910085976 | p04051 | 1,600,877,895 | cpp | Accepted | 124 | 30,788 | #include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
// modint: mod ่จ็ฎใ int ใๆฑใใใใซๆฑใใๆง้ ไฝ
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};
using mint = Fp<mod>;
const int MAX = 1001001;
long long 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;
}
}
// ไบ้
ไฟๆฐ่จ็ฎ
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll nPr(int n, int r) {
if (n < 0 || r < 0 || n < r) return 0;
return fac[n] * finv[n - r] % mod;
}
int main(){
COMinit();
ll n;cin>>n;
V a(n),b(n),c(n);
const int d=2000;
VV memo(2*d+1,V());
for (int i = 0; i < n; ++i) {
cin >>a[i]>>b[i];
c[i]=a[i]+b[i];
memo[c[i]].push_back(d-a[i]);
}
mint Y=0;
for (int i = 0; i < n; ++i) {
Y+=COM(2*c[i],2*a[i]);
}
// cout <<Y<<endl;//Y ok
mint X=0;
vector<mint>F(2*d+1,0);
for (int i =2*d; i>=0 ;--i){
//*(1+x)
auto nf=F;
for (int j = 1; j <=2*d; ++j) {
F[j]=nf[j]+nf[j-1];
}
// +x^(d-a)
if(memo[i].empty())continue;
for(auto x:memo[i])F[x]+=1;
}
mint x=0;
for (int i = 0; i <=2*d; ++i){
x+=F[i]*F[2*d-i];
}
mint ans=x-Y;
ans/=2;
cout <<ans <<endl;
} | codenet | -1 | 3,716 |
s457683975 | p04051 | 1,481,125,601 | cpp | Accepted | 588 | 72,704 | #include <bits/stdc++.h>
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define pb emplace_back
#define fi first
#define se second
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }
// head
struct Mod{
unsigned n;
Mod() : n(0){}
Mod( ll x ){
if( x < 0 ) n = x%MOD+MOD;
else n = x%MOD;
}
};
Mod operator + ( Mod a , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
Mod res = 1;
while( k ){
if( k & 1 ) res *= x;
k /= 2;
x *= x;
}
return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
ll d = a;
if( b != 0 ){
d = extgcd( b , a % b , y , x );
y -= a / b * x;
} else {
x = 1, y = 0;
}
return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }
struct Factorial{
vector<Mod> v;
Factorial( int max_n ){
v = vector<Mod>( max_n , 1 );
FOR( i , 1 , max_n ) v[i] = v[i-1] * i;
}
int size(){
return v.size();
}
Mod operator [] ( int id ){
return v[id];
}
};
struct Factorial_inv{
vector<Mod> v;
Factorial_inv( Factorial &f ){
v = vector<Mod>( f.size() );
REP( i , f.size() ) v[i] = inv( f[i] );
}
Mod operator [] ( int id ){
return v[id];
}
};
struct Combination{
Factorial *f;
Factorial_inv *finv;
Combination( Factorial &arg_f , Factorial_inv &arg_finv ){
f = &arg_f;
finv = &arg_finv;
}
Mod operator () ( int a , int b ){
return (*f)[a] * (*finv)[b] * (*finv)[a-b];
}
};
Factorial fact( 1000010 );
Factorial_inv finv( fact );
Combination comb( fact , finv );
int n;
int a[200010], b[200010];
Mod dp[4020*4020];
int p( int x , int y ){
x += 2010;
y += 2010;
return x * 4020 + y;
}
int main(){
n = in();
REP( i , n ){
a[i] = in();
b[i] = in();
dp[ p( -a[i] , -b[i] ) ] += 1;
}
FOR( i , -2005 , 2005 ){
FOR( j , -2005 , 2005 ){
dp[ p( i , j ) ] += dp[ p( i-1 , j ) ] + dp[ p( i , j-1 ) ];
}
}
Mod ans = 0;
REP( i , n ){
ans += dp[ p( a[i] , b[i] ) ];
}
REP( i , n ){
ans -= comb( 2 * ( a[i] + b[i] ) , 2 * a[i] );
}
ans /= 2;
cout << ans.n << endl;
return 0;
}
| codenet | -1 | 3,760 |
s814317345 | p04051 | 1,468,576,917 | cpp | Accepted | 417 | 127,360 | #include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 4005, C = 2002, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
// Mod int
const int mod = 1000000007;
struct mint;
mint ex(mint a, ll tms);
struct mint {
ll x;
mint():x(0){}
mint(ll x):x((x%mod+mod)%mod){}
// mint(ll x):x(x){}
mint& fix() { x = (x%mod+mod)%mod; return *this;}
mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
mint& operator/=(const mint& a){ (x*=ex(a,mod-2).x)%=mod; return *this;}
mint operator+(const mint& a)const{ return mint(*this) += a;}
mint operator-(const mint& a)const{ return mint(*this) -= a;}
mint operator*(const mint& a)const{ return mint(*this) *= a;}
mint operator/(const mint& a)const{ return mint(*this) /= a;}
bool operator<(const mint& a)const{ return x < a.x;}
bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
mint ex(mint a, ll tms) {
if(!tms) return 1;
mint res = ex(a,tms/2);
res *= res;
return (tms&1)?res*a:res;
}
struct comb {
vm f, g;
comb(){}
comb(int mx):f(mx+1),g(mx+1) {
f[0] = 1;
rrep(i,mx) f[i] = f[i-1]*i;
g[mx] = ex(f[mx],mod-2);
for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
}
mint c(int a, int b) {
if (a < b) return 0;
return f[a]*g[b]*g[a-b];
}
};
//
int main() {
int n;
scanf("%d",&n);
vi a(n), b(n);
rep(i,n) scanf("%d%d",&a[i],&b[i]);
vector<vm> d(MX,vm(MX));
rep(i,n) d[C-a[i]][C-b[i]] += 1;
rep(i,MX-1)rep(j,MX-1) d[i+1][j+1] += d[i][j+1]+d[i+1][j];
mint ans;
rep(i,n) ans += d[C+a[i]][C+b[i]];
comb c(MX*2);
rep(i,n) ans -= c.c(a[i]*2+b[i]*2,a[i]*2);
ans /= 2;
cout<<ans<<endl;
return 0;
}
| codenet | -1 | 3,779 |
s083289605 | p04051 | 1,528,754,029 | cpp | Accepted | 168 | 129,792 | /*
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5 + 10, INF = 1LL * 1e9 * 1e9;
struct E{
int u, v, val;
}edge[MAXN];
vector <int> adj[MAXN];
pair <int, int> p[MAXN][20];
bitset <MAXN> b;
int dis[MAXN], h[MAXN];
pair <int, int> lca(int a, int b) {
pair <int, int> res = {};
if (h[a] < h[b])
swap(a, b);
int delta = h[a] - h[b];
int t = 0;
for(;delta; delta >>= 1, ++t)
if (delta & 1) {
res.second = max(res.second, p[a][t].second);
a = p[a][t].first;
}
t = 20 - 1;
while(~(t--)) {
if (p[a][t].first != p[b][t].first) {
res.second = max(res.second, p[a][t].second);
res.second = max(res.second, p[b][t].second);
a = p[a][t].first;
b = p[b][t].first;
}
}
res.second =max(res.second, max(p[a][0].second, p[b][0].second));
res.first = p[a][0].first;
return res;
}//
int32_t main () {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m, sum = 0;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> edge[i].v >> edge[i].u >> edge[i].val;
adj[edge[i].v].push_back(i);
adj[edge[i].u].push_back(i);
}
set <pair <int, int>> s;
for (int i = 1; i <= n; ++i)
dis[i] = m;
edge[m].val = INF;
s.insert({0, 1});
while(!s.empty()) {
auto now = *s.begin();
s.erase(now);
int v = now.second, e = dis[v];
p[v][0] = {edge[e].v + edge[e].u - v, now.first};
sum += now.first;
// cout << v << ' ' << sum << '\n';
h[v] = h[p[v][0].first] + 1;
for (int i = 1; i < 20; ++i)
p[v][i] = {p[p[v][i - 1].first][i - 1].first, max(p[p[v][i - 1].first][i - 1].second, p[v][i - 1].second)};
b[v] = true;
for (auto i : adj[v]) {
int u = edge[i].v + edge[i].u - v;
if (!b[u] && edge[dis[u]].val > edge[i].val) {
s.erase({edge[dis[u]].val, u});
dis[u] = i;
s.insert({edge[dis[u]].val, u});
}
}
}
for (int i = 0; i < m; ++i)
cout << sum + edge[i].val - lca(edge[i].v, edge[i].u).second << '\n';
return 0;
}
/*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5 + 10, MAX = 2010, md = 1e9 + 7;
int dp[2 * MAX][2 * MAX], fact[4 * MAX], inv_fact[4 * MAX];
int combination(int k, int n) {
if (k > n)
return 0;
return (fact[n] * inv_fact[k] % md) * inv_fact[n - k] % md;
}
int power(int n, int p) {
int res = 1;
for (;p; p >>= 1, n = n * n % md)
if (p & 1)
res = res * n % md;
return res;
}
int a[MAXN], b[MAXN];
int32_t main () {
fact[0] = 1;
for (int i = 1; i < 4 * MAX; ++i)
fact[i] = fact[i - 1] * i % md;
inv_fact[4 * MAX - 1] = power(fact[4 * MAX - 1], md - 2);
for (int i = 4 * MAX - 1; i; --i)
inv_fact[i - 1] = inv_fact[i] * i % md;
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
for (int i = 0; i < n; ++i)
++dp[MAX - a[i]][MAX - b[i]];
for (int i = 0; i < 2 * MAX - 1; ++i)
for (int j = 0; j < 2 * MAX - 1; ++j) {
dp[i + 1][j] += dp[i][j];
dp[i][j + 1] += dp[i][j];
if (dp[i + 1][j] >= md)
dp[i + 1][j] %= md;
if (dp[i][j + 1] >= md)
dp[i][j + 1] %= md;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += (dp[MAX + a[i]][MAX + b[i]] + (md - 1) * combination(2 * a[i], 2 * b[i] + 2 * a[i])) % md;
if (ans >= md)
ans %= md;
}
cout << ans * power(2, md - 2) % md;
return 0;
} | codenet | -1 | 3,816 |
s282044568 | p04051 | 1,508,618,445 | cpp | Accepted | 531 | 252,672 | #include<bits/stdc++.h>
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;
#define xx first
#define yy second
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof(x.end())i=x.begin();i!=x.end();++i)
struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT}
I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;
const int N=200007,M=4007,P=1000000007;
int n,a[N],b[N],fac[M*2],fin[M*2],f[M*2][M*2];
inline int pow(int a,int b)
{
int r=1;
for(;b;b>>=1,a=(ll)a*a%P)
if(b&1)r=(ll)r*a%P;
return r;
}
inline int C(int a,int b)
{
return(ll)fac[a+b]*fin[a]%P*fin[b]%P;
}
int main()
{
fac[0]=1;
fo1(i,M*2-1)fac[i]=(ll)fac[i-1]*i%P;
fin[M*2-1]=pow(fac[M*2-1],P-2);
fd1(i,M*2-1)fin[i-1]=(ll)fin[i]*i%P;
in,n;
fo1(i,n)in,a[i],b[i];
fo1(i,n)f[M-a[i]][M-b[i]]++;
fo1(i,M*2-1)fo1(j,M*2-1)(f[i][j]+=f[i-1][j]+f[i][j-1])%=P;
int ans=0;
fo1(i,n)(ans+=f[M+a[i]][M+b[i]])%=P;
fo1(i,n)(ans+=P-C(a[i]*2,b[i]*2))%=P;
ans=(ll)ans*(P+1)/2%P;
out,ans,'\n';
} | codenet | -1 | 3,817 |
s691835546 | p04051 | 1,598,538,706 | cpp | Accepted | 241 | 130,440 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};
template<ll mod>
struct Mod_Int{
ll x;
Mod_Int() {}
Mod_Int(ll y) : x (y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
Mod_Int &operator += (const Mod_Int &p){
x = (x + p.x) % mod;
return *this;
}
Mod_Int &operator -= (const Mod_Int &p){
x = (x + mod - p.x) % mod;
return *this;
}
Mod_Int &operator *= (const Mod_Int &p){
x = (x * p.x) % mod;
return *this;
}
Mod_Int &operator /= (const Mod_Int &p){
*this *= p.inverse();
return *this;
}
Mod_Int &operator ++ () {return *this += Mod_Int(1);}
Mod_Int operator ++ (int){
Mod_Int tmp = *this;
++*this;
return tmp;
}
Mod_Int &operator -- () {return *this -= Mod_Int(1);}
Mod_Int operator -- (int){
Mod_Int tmp = *this;
--*this;
return tmp;
}
Mod_Int operator - () const {return Mod_Int(-x);}
Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}
Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}
Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}
Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}
bool operator == (const Mod_Int &p) const {return x == p.x;}
bool operator != (const Mod_Int &p) const {return x != p.x;}
Mod_Int inverse() const {
assert(*this != Mod_Int(0));
return pow(mod-2);
}
Mod_Int pow(ll k) const{
Mod_Int now = *this, ret = 1;
while(k){
if(k&1) ret *= now;
now *= now, k >>= 1;
}
return ret;
}
friend ostream &operator << (ostream &os, const Mod_Int &p){
return os << p.x;
}
friend istream &operator >> (istream &is, Mod_Int &p){
ll a;
is >> a;
p = Mod_Int<mod>(a);
return is;
}
};
using mint = Mod_Int<MOD>;
template<typename T>
struct combination{
vector<T> _fac, _ifac;
combination(int n){
_fac.resize(n+1), _ifac.resize(n+1);
_fac[0] = 1;
rep2(i, 1, n) _fac[i] = _fac[i-1]*i;
_ifac[n] = _fac[n].inverse();
rep3(i, n, 1) _ifac[i-1] = _ifac[i]*i;
}
T fac(int k) const {return _fac[k];}
T ifac(int k) const {return _ifac[k];}
T comb(int n, int k) const{
if(k < 0 || n < k) return 0;
return fac(n) * ifac(n-k) * ifac(k);
}
T perm(int n, int k) const{
if(k < 0 || n < k) return 0;
return fac(n) * ifac(n-k);
}
};
int main(){
int N;
cin >> N;
mint dp[4002][4002];
fill(dp[0], dp[4002], 0);
mint ans = 0;
combination<mint> c(10000);
int a[N], b[N];
rep(i, N){
cin >> a[i] >> b[i];
dp[2000-a[i]][2000-b[i]]++;
ans -= c.comb(2*(a[i]+b[i]), 2*a[i]);
}
rep2(i, 0, 4000){
rep2(j, 0, 4000){
dp[i+1][j] += dp[i][j], dp[i][j+1] += dp[i][j];
}
}
rep(i, N) ans += dp[2000+a[i]][2000+b[i]];
cout << ans/2 << endl;
} | codenet | -1 | 3,891 |
s056543382 | p04051 | 1,548,452,592 | cpp | Accepted | 196 | 127,360 | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
constexpr int zero = 2001;
constexpr lint MDO = 1000000007;
vector<vector<lint>> dp;
constexpr lint MOD = 1000000007;
vector<lint> fac, facInv, inv;
void facInit(int nmax)
{
fac = facInv = inv = vector<lint>(nmax + 1, 1);
for (int i = 2; i <= nmax; i++)
{
fac[i] = fac[i-1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
facInv[i] = facInv[i-1] * inv[i] % MOD;
}
}
lint nCr(int n, int r)
{
if (n<r || r<0) return 0;
if (n >= (int)fac.size()) facInit(n);
return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}
int main()
{
int N;
cin >> N;
vector<pint> AB(N);
REP(i, N) cin >> AB[i].first >> AB[i].second;
ndarray(dp, zero * 2 + 1, zero * 2 + 1);
REP(i, N) dp[zero - AB[i].first][zero - AB[i].second]++;
REP(i, zero * 2) REP(j, zero * 2)
{
if (i) dp[i][j] += dp[i - 1][j];
if (j) dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
facInit(8000);
lint ans = 0;
REP(i, N) ans += dp[zero + AB[i].first][zero + AB[i].second];
REP(i, N) ans += MOD - nCr((AB[i].first + AB[i].second) * 2, AB[i].first * 2);
ans = ans % MOD * ((1 + MOD) / 2) % MOD;
cout << ans << endl;
}
| codenet | -1 | 4,015 |
s367874621 | p04051 | 1,547,769,159 | cpp | Accepted | 264 | 42,112 |
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b) for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int long long
#define pb emplace_back
#define eb pb
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<tapu, Vtapu, greater<tapu> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 2e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
#define endl "\n" //ใคใณใฟใฉใฏใใฃใใงใฏๆถใ
//ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
ut N, M, K, L, Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
int A[SIZE],B[SIZE];
LL times[SIZE2][SIZE2];
LL fact[SIZE], gyaku[SIZE];
inline LL nCr(LL n, LL r) {
return fact[n] * gyaku[n - r]%p * gyaku[r]%p;
}
inline LL twin(LL a1, LL b1, LL a2, LL b2) {
return nCr(a1 + b1 + a2 + b2, a1 + a2);
}
LL modpow(LL n, LL r) {
if (r == 0) return 1;
LL ans = modpow(n*n%p, r / 2);
if (r % 2) ans *= n;
return ans % p;
}
LL rev(LL x) {
return modpow(x, p - 2);
}
LL solve() {
cin >> N;
fact[0] = 1;
gyaku[0] = 1;
EFOR(i, 1, SIZE2 * 4) fact[i] = fact[i - 1] * i%p;
EFOR(i, 1, SIZE2*4) gyaku[i] = gyaku[i - 1] * rev(i)%p;
// cout << nCr(8000, 4000) << endl;
REP(i, N) {
cin >> A[i] >> B[i];
times[A[i]][B[i]]++;
}
LL ans = 0;
RFOR(i,0,SIZE2*2) {
// cout << i << endl;
REP(a, i) {
LL b = i - a;
if (max(a, b) >= SIZE2) continue;
if (a <= 0 or b <= 0) continue;
times[a-1][b] += times[a][b];
times[a][b - 1] += times[a][b];
times[a - 1][b] %= p;
times[a][b - 1] %= p;
ans -= twin(a, b - 1, a - 1, b)*times[a][b]%p;
ans += p;
times[a][b] = 0;
ans %= p;
}
}
LL ansc = 0;
REP(i, SIZE2) REP(j, SIZE2) {
if (i == j) continue;
LL resa = twin(i, 0, j, 0);
LL resb = twin(i, 0, 0, j);
ansc += resa*times[i][0]%p*times[j][0]%p;
ansc += resb*times[i][0]%p*times[0][j]%p;
ansc += resb*times[0][i]%p*times[j][0]%p;
ansc += resa*times[0][i]%p*times[0][j]%p;
ansc %= p;
}
ans += gyaku[2] % p*ansc;
// cout << "OK" << endl;
REP(i, SIZE2){
ans += twin(i, 0, i, 0) % p*(times[i][0]*(times[i][0]-1)/2) % p;
ans += twin(0, i, 0, i) % p*(times[0][i]*(times[0][i]-1)/2) % p;
ans += twin(i, 0, 0, i) % p*times[i][0] % p*(times[0][i]) % p;
ans %= p;
}
cout << ans << endl;
return 0;
}
//!!!!!!!!!!!!!!!!!!!ๅฎ่ฃ
ใ่ฉฐใใ!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
solve();
cin >> N;
return 0;
}
| codenet | -1 | 4,044 |
s720340688 | p04051 | 1,585,190,809 | cpp | Accepted | 246 | 199,296 | // includes
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
// types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;
template<typename T>
T extgcd(T a, T b, T &x, T &y){
T d = a;
if(b != 0){
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}else{
x = 1, y = 0;
}
return d;
}
template <typename T>
T modinv(T a, T m){
long long x = 0, y = 0;
extgcd<long long>(a, m, x, y);
x %= m;
if(x < 0)x += m;
return x;
}
const int B = 2500;
ll dp[5010][5010];
ll fac[10010], inv[10010];
void construct(){
fac[0] = 1;
FOR(i, 1, 10001)fac[i] = fac[i-1] * i % mod;
inv[10000] = modinv<ll>(fac[10000], mod);
for(int i = 9999; i >= 0; i--){
inv[i] = inv[i+1] * (i+1) % mod;
}
}
int main(int argc, char const* argv[])
{
int n; cin >> n;
vector<ll> a(n), b(n); rep(i, n)cin >> a[i] >> b[i];
construct();
rep(i, n){
dp[B-a[i]][B-b[i]]++;
}
rep(i, 5000){
rep(j, 5000){
if(i > 0)(dp[i][j] += dp[i-1][j]) %= mod;
if(j > 0)(dp[i][j] += dp[i][j-1]) %= mod;
}
}
ll res = 0;
rep(i, n){
(res += dp[a[i]+B][b[i]+B]) %= mod;
(res -= fac[2*a[i]+2*b[i]] * (inv[2*a[i]] * inv[2*b[i]] % mod) % mod) %= mod;
}
if(res < 0)res += mod;
res = res * inv[2] % mod;
cout << res << endl;
return 0;
}
| codenet | -1 | 4,104 |
s524177306 | p04051 | 1,472,359,172 | cpp | Accepted | 1,523 | 190,208 | #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
const int MAX = 500000;
const int MOD = 1000000007;
int N;
int A[MAX], B[MAX];
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
struct Fp {
long long val;
Fp() : val(0) {}
Fp(long long val_) { this->val = mod(val_, MOD); }
Fp operator = (long long val_) { this->val = mod(val_, MOD); return *this; }
inline Fp operator - () { return mod(-val, MOD); }
inline const Fp& operator += (const Fp &x);
inline const Fp& operator -= (const Fp &x);
inline const Fp& operator *= (const Fp &x);
inline const Fp& operator /= (const Fp &x);
};
ostream &operator << (ostream &os, Fp x) { return os << x.val;}
istream &operator >> (istream &is, Fp &x) { is >> x; return is; }
bool operator == (Fp x, Fp y) { return mod(x.val, MOD) == mod(y.val, MOD); }
inline Fp operator + (Fp x, Fp y) { return mod(x.val + y.val, MOD); }
inline Fp operator - (Fp x, Fp y) { return mod(x.val - y.val, MOD); }
inline Fp operator * (Fp x, Fp y) { return mod(x.val * y.val, MOD); }
inline Fp operator / (Fp x, Fp y) {
long long a = y.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a/b;
a -= t*b; swap(a, b);
u -= t*v; swap(u, v);
}
return x * u;
}
inline Fp power(Fp a, long long n) {
if (n == 0) return Fp(1);
Fp t = power(a, n/2);
t = t * t; if (n & 1) t = t * a;
return t;
}
inline const Fp& Fp::operator += (const Fp &x) {*this = *this + x; return *this;}
inline const Fp& Fp::operator -= (const Fp &x) {*this = *this - x; return *this;}
inline const Fp& Fp::operator *= (const Fp &x) {*this = *this * x; return *this;}
inline const Fp& Fp::operator /= (const Fp &x) {*this = *this / x; return *this;}
int Com[4010][4010];
void calc_com() {
memset(Com, 0, sizeof(Com));
Com[0][0] = 1;
for (int i = 1; i < 4010; ++i) {
Com[i][0] = 1;
Com[0][i] = 1;
}
for (int i = 1; i < 4010; ++i) {
for (int j = 1; j < 4010; ++j) {
Com[i][j] = (Com[i][j-1] + Com[i-1][j]);
Com[i][j] %= MOD;
}
}
}
Fp dp[4010][4010];
long long solve() {
Fp res = 0;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < N; ++i) {
dp[2005-A[i]][2005-B[i]] += 1;
}
for (int i = 1; i < 4010; ++i) {
for (int j = 1; j < 4010; ++j) {
dp[i][j] += dp[i-1][j] + dp[i][j-1];
}
}
for (int i = 0; i < N; ++i) {
res += dp[2005+A[i]][2005+B[i]];
}
for (int i = 0; i < N; ++i) {
res -= Com[A[i]*2][B[i]*2];
//cout << i << ": " <<Com[ A[i]*2 + B[i]*2 ][ A[i] * 2 ] << endl;
}
res /= 2;
return res.val;
}
int main() {
calc_com();
while (cin >> N) {
for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
cout << solve() << endl;
}
}
| codenet | -1 | 4,159 |
s124887252 | p04051 | 1,560,510,504 | cpp | Accepted | 363 | 126,976 | #include <iostream>
#define MOD 1000000007
#define MAX_N 200000
#define MAX_AB 2000
#define MAX_FACT 2 * ( 2 * MAX_AB + 1 )
using namespace std;
namespace mod
{
template <uint_fast64_t mod>
struct Modint
{
private:
uint_fast64_t val;
public:
constexpr Modint( const uint_fast64_t val = 0 ) : val( val % mod ) {}
constexpr uint_fast64_t &value() noexcept { return val; }
constexpr const uint_fast64_t &value() const noexcept { return val; }
constexpr Modint operator+( const Modint &rhs ) const noexcept
{
return Modint( *this ) += rhs;
}
constexpr Modint operator-( const Modint &rhs ) const noexcept
{
return Modint( *this ) -= rhs;
}
constexpr Modint operator*( const Modint &rhs ) const noexcept
{
return Modint( *this ) *= rhs;
}
constexpr Modint operator/( const Modint &rhs ) const noexcept
{
return Modint( *this ) /= rhs;
}
constexpr Modint &operator+=( const Modint &rhs ) noexcept
{
val += rhs.val;
if ( val > mod ) val -= mod;
return *this;
}
constexpr Modint &operator-=( const Modint &rhs ) noexcept
{
if ( val < rhs.val ) val += mod;
val -= rhs.val;
return *this;
}
constexpr Modint &operator*=( const Modint &rhs ) noexcept
{
val *= rhs.val;
val %= mod;
return *this;
}
constexpr Modint &operator/=( const Modint &rhs ) noexcept
{
uint_fast64_t a = rhs.val;
uint_fast64_t b = mod;
uint_fast64_t x = 1;
uint_fast64_t y = 0;
while ( b > 0 )
{
uint_fast64_t q = a / b;
a -= q * b;
x -= q * y;
swap( a, b );
swap( x, y );
}
val *= ( x + mod ) % mod;
val %= mod;
return *this;
}
friend constexpr ostream &operator<<( ostream &o, const Modint &m )
{
return ( o << ( m.val ) );
}
friend constexpr istream &operator>>( istream &i, Modint &m )
{
return ( i >> ( m.val ) );
}
Modint pow( int n )
{
Modint res = 1;
Modint a = Modint( *this );
while ( n != 0 )
{
if ( n & 1 ) res *= a;
a *= a;
n >>= 1;
}
return res;
}
};
// Modint Womparer
template <uint_fast64_t mod>
inline bool const operator<( const Modint<mod> &l, const Modint<mod> &r )
{
return l.value() < r.value();
}
template <uint_fast64_t mod>
inline bool operator>( const Modint<mod> &l, const Modint<mod> &r )
{
return r < l;
}
template <uint_fast64_t mod>
inline bool operator<=( const Modint<mod> &l, const Modint<mod> &r )
{
return !( l > r );
}
template <uint_fast64_t mod>
inline bool operator>=( const Modint<mod> &l, const Modint<mod> &r )
{
return !( l < r );
}
// Modint Equality Womparer
template <uint_fast64_t mod>
inline bool operator==( const Modint<mod> &l, const Modint<mod> &r )
{
return l.value() == r.value();
}
template <uint_fast64_t mod>
inline bool operator!=( const Modint<mod> &l, const Modint<mod> &r )
{
return !( l == r );
}
} // namespace mod
using mint_t = mod::Modint<MOD>;
mint_t fact[MAX_FACT + 1];
void initFact()
{
fact[0] = 1;
for ( int i = 0; i < MAX_FACT; i++ ) fact[i + 1] = fact[i] * ( i + 1 );
}
mint_t comb( int n, int r ) { return fact[n] / fact[n - r] / fact[r]; }
int A[MAX_N];
int B[MAX_N];
mint_t f[2 * MAX_AB + 1][2 * MAX_AB + 1];
int main( int argc, char **argv )
{
initFact();
int N;
cin >> N;
for ( int i = 0; i < N; i++ ) cin >> A[i] >> B[i];
for ( int i = 0; i < N; i++ ) f[MAX_AB - A[i]][MAX_AB - B[i]] += 1;
for ( int i = 0; i < 2 * MAX_AB + 1; i++ )
{
for ( int j = 0; j < 2 * MAX_AB + 1; j++ )
{
if ( i > 0 ) f[i][j] += f[i - 1][j];
if ( j > 0 ) f[i][j] += f[i][j - 1];
}
}
mint_t ans = 0;
for ( int i = 0; i < N; i++ )
{
ans += f[2000 + A[i]][2000 + B[i]];
ans -= comb( A[i] + A[i] + B[i] + B[i], A[i] + A[i] );
}
ans /= 2;
cout << ans << endl;
return 0;
}
| codenet | -1 | 4,175 |
s268343882 | p04051 | 1,554,711,276 | cpp | Accepted | 598 | 172,672 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
before_main_function() {
cin.tie(0); ios::sync_with_stdio(0);
cout << setprecision(15) << fixed;
// #define endl "\n"
}
} before_main_function;
//------------------8<------------------------------------8<--------------------
template <int mod>
class ModInt {
public:
ModInt() : v(0) {}
ModInt(int x) : v((x+mod)%mod) {}
int value() const {return v;}
const ModInt operator+(const ModInt &r) const { return ModInt(this->v + r.v); }
const ModInt operator-(const ModInt &r) const { return ModInt(this->v + mod - r.v); }
const ModInt operator*(const ModInt &r) const { return ModInt(this->v * r.v); }
const ModInt operator/(const ModInt &r) const { return (*this * (~r)); }
const ModInt operator^(int k) const { return ModInt(bpow(this->v, k)); }
const ModInt operator~() const { return ModInt(bpow(this->v, mod-2)); }
bool operator==(const ModInt &r) const { return this->v == r.v; }
bool operator!=(const ModInt &r) const { return this->v != r.v; }
ModInt& operator+=(const ModInt &r) { return *this = *this + r; }
ModInt& operator-=(const ModInt &r) { return *this = *this - r; }
ModInt& operator*=(const ModInt &r) { return *this = *this * r; }
ModInt& operator/=(const ModInt &r) { return *this = *this * (~r); }
private:
int v;
int bpow(int a, int b) const {
int ret = 1;
while (b > 0) {
if (b & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ret;
}
};
using Mint = ModInt<1000000007>;
struct Factorial {
static constexpr int MAX_N = 2000006;
vector<Mint> fact, fact_inv;
Factorial(size_t size = MAX_N) : fact(size), fact_inv(size) {
fact[0] = fact_inv[0] = 1;
for (int i = 1; i < MAX_N; ++i) {
fact[i] = fact[i - 1] * i;
fact_inv[i] = ~fact[i];
}
}
Mint combination(int N, int R) {
if (N < R) return 0;
return fact[N] * fact_inv[N - R] * fact_inv[R];
}
static Mint bin_pow(Mint x, int p) {
if (x.value() == 0) return x;
Mint prod = 1;
while (p > 0) {
if (p & 1) prod *= x;
x *= x;
p >>= 1;
}
return prod;
}
};
signed main() {
int N;
cin >> N;
vector<int> A(N), B(N);
rep(i, 0, N) cin >> A[i] >> B[i];
vector<vector<Mint>> dp(4200, vector<Mint>(4200));
rep(i, 0, N) {
dp[2100-A[i]][2100-B[i]] += 1;
}
rep(i, 0, 4190) {
rep(j, 0, 4190) {
dp[i + 1][j] += dp[i][j];
dp[i][j + 1] += dp[i][j];
}
}
Factorial fact;
Mint ans = 0;
rep(i, 0, N) {
ans += dp[2100 + A[i]][2100 + B[i]];
ans -= fact.combination(2 * (A[i] + B[i]), 2 * B[i]);
}
ans /= 2;
cout << ans.value() << endl;
return (0^_^0);
}
| codenet | -1 | 4,248 |
s930815663 | p04051 | 1,598,005,552 | cpp | Accepted | 176 | 130,192 | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
cout << x << " ";
print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <uint_fast64_t Modulus>
struct ModInt {
using u64 = uint_fast64_t;
u64 a;
constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
constexpr u64 &value() noexcept {return a;}
constexpr const u64 &value() const noexcept {return a;}
constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
constexpr bool operator==(const ModInt &rhs) const noexcept {return a == rhs.a;}
constexpr bool operator!=(const ModInt &rhs) const noexcept {return a != rhs.a;}
constexpr ModInt &operator+=(const ModInt rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr ModInt &operator/=(ModInt rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp&1) *this *= rhs;
exp >>= 1;
rhs *= rhs;
}
return *this;
}
constexpr ModInt &operator^=(long long exp) noexcept {
ModInt rhs = a;
a = 1;
while (exp) {
if (exp&1) *this *= rhs;
exp >>= 1;
rhs *= rhs;
}
return *this;
}
friend ostream &operator<<(ostream& os, const ModInt& rhs) noexcept {return os << rhs.a;}
friend istream &operator>>(istream& is, ModInt& rhs) noexcept {long long a; is >> a; rhs = a; return is;}
};
using mint = ModInt<MOD>;
struct ModCombination {
vector<mint> Fac;
vector<mint> Facinv;
ModCombination(int x) {
Fac.resize(x+1);
Facinv.resize(x+1);
Fac[0] = 1;
for (int i = 0; i < x; ++i) Fac[i+1] = Fac[i]*(i+1);
Facinv[x] = Fac[0]/Fac[x];
for (int i = x; i > 0; --i) Facinv[i-1] = Facinv[i]*i;
}
mint get(int n, int k) {
if (k < 0 || k > n) return 0;
return Fac[n]*Facinv[k]*Facinv[n-k];
}
};
mint dp[4001][4001];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N; cin >> N;
vector<int> A(N),B(N);
rep(i,N) cin >> A[i] >> B[i];
rep(i,N) {
dp[2000-A[i]][2000-B[i]] += 1;
}
rep(i,4001) {
rep(j,4001) {
if (i < 4000) dp[i+1][j] += dp[i][j];
if (j < 4000) dp[i][j+1] += dp[i][j];
}
}
mint ans = 0;
rep(i,N) ans += dp[2000+A[i]][2000+B[i]];
ModCombination MC(8000);
rep(i,N) ans -= MC.get(A[i]*2+B[i]*2,A[i]*2);
ans /= 2;
cout << ans << ln;
}
| codenet | -1 | 4,288 |
s398157829 | p04051 | 1,558,207,003 | cpp | Accepted | 444 | 208,512 | #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};
template<class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
int MOD = fact_[0].getmod();
for(int i = 2; i < n; i++){
fact_[i] = fact_[i-1] * i;
inv_[i] = -inv_[MOD%i] * (MOD/i);
finv_[i] = finv_[i-1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0) return 0;
return fact_[n] * finv_[k] * finv_[n-k];
}
constexpr T fact(int n) const noexcept {
if (n < 0) return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0) return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0) return 0;
return finv_[n];
}
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
int main() {
BiCoef<mint> bc(11000);
int N; cin >> N;
using pint = pair<int,int>;
map<pint,int> ma;
for (int i = 0; i < N; ++i) {
int x, y; cin >> x >> y;
ma[pint(x, y)]++;
}
const int GETA = 2500;
vector<vector<mint> > dp(GETA*2, vector<mint>(GETA*2, 0));
for (auto it : ma)
dp[GETA - it.first.first][GETA - it.first.second] = it.second;
for (int i = 1; i < dp.size(); ++i)
for (int j = 1; j < dp[0].size(); ++j)
dp[i][j] += dp[i-1][j] + dp[i][j-1];
mint res = 0;
for (auto it : ma)
res += dp[it.first.first + GETA][it.first.second + GETA] * it.second;
for (auto it : ma)
res -= bc.com(it.first.first*2 + it.first.second*2, it.first.first*2) * it.second;
cout << res * bc.inv(2) << endl;
}
| codenet | -1 | 4,321 |
s598843101 | p04051 | 1,549,200,450 | cpp | Accepted | 146 | 64,512 | #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }
template<class Int> constexpr bool is_prime(Int n) {
if (n < 2 or n > 2 and ~n & 1) return false;
for (Int i = 3; i * i <= n; i += 2) if (n % i == 0) return false;
return true;
}
template<uint P> struct ModInt {
static_assert(is_prime(P), "template argument must be a prime number");
using M = ModInt;
uint v;
ModInt() : v(0) {}
template<class Int> ModInt(Int x) : v(x >= 0 ? x % P : -x % P ? P - -x % P : 0) {}
constexpr ModInt(uint v, int _) : v(v) {} // ็ดๆฅๅคใๅๆๅ
static constexpr uint p() { return P; }
M operator++(int) { M t = *this; if (++v == P) v = 0; return t; }
M operator--(int) { M t = *this; v = (v ? v : P) - 1; return t; }
M& operator++() { if (++v == P) v = 0; return *this; }
M& operator--() { v = (v ? v : P) - 1; return *this; }
M operator+() const { return *this; }
M operator-() const { return {v ? P - v : 0, 0}; }
explicit operator bool() const noexcept { return v; }
bool operator!() const noexcept { return !static_cast<bool>(*this); }
M operator*(M rhs) const { return M(*this) *= rhs; }
M operator/(M rhs) const { return M(*this) /= rhs; }
M operator+(M rhs) const { return M(*this) += rhs; }
M operator-(M rhs) const { return M(*this) -= rhs; }
bool operator==(M rhs) { return v == rhs.v; }
bool operator!=(M rhs) { return !(*this == rhs); }
M& operator*=(M rhs) { v = (ulint) v * rhs.v % P; return *this; }
M& operator/=(M rhs) { return *this *= rhs.inv(); }
M& operator+=(M rhs) { v = rhs.v < P - v ? v + rhs.v : v - (P - rhs.v); return *this; }
M& operator-=(M rhs) { v = rhs.v <= v ? v - rhs.v : v + (P - rhs.v); return *this; }
M inv() const {
assert(v);
#ifdef __linux__ // ACใจCFใงๅไฝใๅคใใใใใฎไปฎใฎๅฏพๅฆ
return pow(P - 2);
#else
int a = v, b = P, x = 1, u = 0;
while (b) {
int q = a / b;
swap(a -= q * b, b);
swap(x -= q * u, u);
}
return x;
#endif
}
template<class Int> M pow(Int n) const {
n = n >= 0 ? n % (P - 1) : P - 1 - -n % (P - 1);
M res = 1;
for (M a = *this; n > 0; a *= a, n >>= 1) if (n & 1) res *= a;
return res;
}
template<class Int> friend M operator*(Int lhs, M rhs) { return M(lhs) *= rhs; }
template<class Int> friend M operator/(Int lhs, M rhs) { return M(lhs) /= rhs; }
template<class Int> friend M operator+(Int lhs, M rhs) { return M(lhs) += rhs; }
template<class Int> friend M operator-(Int lhs, M rhs) { return M(lhs) -= rhs; }
friend ostream& operator<<(ostream& os, M rhs) { return os << rhs.v; }
friend istream& operator>>(istream& is, M& rhs) { lint x; is >> x; rhs = x; return is; }
template<class Int> friend bool operator==(Int lhs, M rhs) { return M(lhs) == rhs; }
template<class Int> friend bool operator!=(Int lhs, M rhs) { return !(lhs == rhs); }
};
using Mint = ModInt<static_cast<uint>(1e9 + 7)>;
V<Mint> fact, ifact;
void init(int n) {
assert(n >= 0);
fact.resize(n + 1);
fact[0] = 1;
for (int i = 1; i <= n; ++i) {
fact[i] = i * fact[i - 1];
}
ifact.resize(n + 1);
ifact[n] = fact[n].inv();
for (int i = n; i > 0; --i) {
ifact[i - 1] = i * ifact[i];
}
}
Mint comb(int n, int r) {
if (r < 0 or r > n) return 0;
assert(n < (int) fact.size());
return fact[n] * ifact[r] * ifact[n - r];
}
constexpr int N = 2000;
int main() {
cin.tie(nullptr); ios_base::sync_with_stdio(false);
int n; cin >> n;
V<> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
VV<Mint> dp; assign(dp, 2 * N + 1, 2 * N + 1, 0);
for (int i = 0; i < n; ++i) {
++dp[N - a[i]][N - b[i]];
}
for (int x = 0; x <= 2 * N; ++x) for (int y = 0; y <= 2 * N; ++y) {
if (x > 0) {
dp[x][y] += dp[x - 1][y];
}
if (y > 0) {
dp[x][y] += dp[x][y - 1];
}
}
Mint res = 0;
for (int i = 0; i < n; ++i) {
res += dp[N + a[i]][N + b[i]];
}
init(4 * N);
for (int i = 0; i < n; ++i) {
res -= comb(2 * (a[i] + b[i]), 2 * a[i]);
}
res /= 2;
cout << res << '\n';
} | codenet | -1 | 4,407 |
s058162660 | p04051 | 1,577,842,529 | cpp | Accepted | 1,893 | 144,256 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end
template<unsigned mod>struct Mint {
int val;
int inv() const{
int tmp,a=val,b=mod,x=1,y=0;
while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
if(x<0)x+=mod; return x;
}
Mint():val(0){}
Mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
Mint& operator/=(const Mint& x){val=(ll)val*x.inv()%mod; return *this;}
Mint operator+(const Mint& x)const{return Mint(*this)+=x;}
Mint operator-(const Mint& x)const{return Mint(*this)-=x;}
Mint operator*(const Mint& x)const{return Mint(*this)*=x;}
Mint operator/(const Mint& x)const{return Mint(*this)/=x;}
bool operator==(const Mint& x)const{return val==x.val;}
bool operator!=(const Mint& x)const{return val!=x.val;}
};
using mint=Mint<1000000007>;
struct factorial {
vector<mint> Fact, Finv;
public:
factorial(int maxx){
Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
Finv[maxx]=mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
}
mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
mint nPr(int n,int r){if(n<0||n<r||r<0)return mint(0);else return Fact[n]*Finv[n-r];}
mint nCr(int n,int r){if(n<0||n<r||r<0)return mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
struct C{
float x,y;
C(double _x=0,double _y=0):x(_x),y(_y){}
C operator~()const{return {x,-y};}
C operator+(const C& c)const{return {x+c.x,y+c.y};}
C operator-(const C& c)const{return {x-c.x,y-c.y};}
C operator*(const C& c)const{return {x*c.x-y*c.y,x*c.y+y*c.x};}
};
vector<C> rt;
void init(int lg=20){
rt.resize(1<<lg,1);
rep(k,1,lg){
int d=1<<k;
rep(i,0,d){
if(i&1)rt[d+i-1]=C(cos(2*M_PI*i/d),sin(2*M_PI*i/d));
else rt[d+i-1]=rt[(d+i)/2-1];
}
}
}
void fft(vector<C>& a,bool inv=0,int n=-1){
if(n==-1)n=a.size();
if(inv){
for(int i=1;i<n;i<<=1){
for(int j=0;j<n;j+=i*2){
rep(k,0,i){
a[i+j+k]=a[i+j+k]*~rt[i*2-1+k];
const C tmp=a[j+k]-a[i+j+k];
a[j+k]=a[j+k]+a[i+j+k]; a[i+j+k]=tmp;
}
}
}
//rep(i,0,n)a[i].x/=n,a[i].y/=n;
}
else{
for(int i=n>>1;i;i>>=1){
for(int j=0;j<n;j+=i*2){
rep(k,0,i){
const C tmp=a[j+k]-a[i+j+k];
a[j+k]=a[j+k]+a[i+j+k]; a[i+j+k]=tmp*rt[i*2-1+k];
}
}
}
}
} //need to initialize
int sz=1<<12; mint ans; factorial fact(8020);
vector<vector<C>> buf(sz,vector<C>(sz));
void fft2d(bool inv=0){
rep(i,0,(inv?sz:sz/2))fft(buf[i],inv);
rep(i,0,sz)rep(j,0,i)swap(buf[i][j],buf[j][i]);
rep(i,0,sz)fft(buf[i],inv);
if(inv)rep(i,0,sz)rep(j,0,sz)buf[i][j].x/=sz*sz;
}
map<pair<int,int>,int> mp;
void sub(){
for(auto p1:mp)for(auto p2:mp){
int a=p1.first.first,b=p1.first.second;
int c=p2.first.first,d=p2.first.second;
ans+=fact.nCr(a+b+c+d,a+c)*p1.second*p2.second;
}
ans/=2; printf("%d\n",ans.val); exit(0);
}
int main(){
init(15); int n; scanf("%d",&n);
rep(i,0,n){
int h,w; scanf("%d%d",&h,&w); mp[{h,w}]++;
buf[h][w].x+=1.0; ans-=fact.nCr((h+w)*2,h*2);
}
if(mp.size()<=10000)sub();
fft2d();
rep(i,0,sz)rep(j,0,sz)buf[i][j]=buf[i][j]*buf[i][j];
fft2d(1);
rep(i,0,sz)rep(j,0,sz){
mint tmp((ll)(buf[i][j].x+0.5));
ans+=fact.nCr(i+j,i)*tmp;
} ans/=2;
printf("%d\n",ans.val);
return 0;
} | codenet | -1 | 4,467 |
s486366273 | p04051 | 1,598,412,510 | cpp | Accepted | 288 | 51,420 | /*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace fastio{
char in[100000];
int itr=0,llen=0;
char get(){
if(itr==llen)llen=fread(in,1,100000,stdin),itr=0;
if(llen==0)return EOF;
return in[itr++];
}
char out[100000];
int itr2=0;
void put(char c){
out[itr2++]=c;
if(itr2==100000){
fwrite(out,1,100000,stdout);
itr2=0;
}
}
int clear(){
fwrite(out,1,itr2,stdout);
itr2=0;
return 0;
}
int getint(){
int ret=0;char ch=get();
if(ch=='-')return -getint();
while (ch<'0'||ch>'9'){
ch=get();if(ch=='-')return -getint();
}
while ('0'<=ch&&ch<='9'){
ret=ret*10-48+ch;
ch=get();
}
return ret;
}
string getstr(){
string ret="";
char ch=get();
while(ch==' '||ch=='\n')ch=get();
while(ch!=' '&&ch!='\n')ret.push_back(ch),ch=get();
return ret;
}
void putstr(string s){
for(int i=0;i<s.size();i++)put(s[i]);
}
void putint(int x){
if(x<0){
put('-');
putint(-x);
return;
}
if(x==0){
put('0');put(' ');
return;
}
char c[40];int pos=0;
while(x){
c[pos++]='0'+x%10;
x/=10;
}
for(int i=pos-1;i>=0;i--)put(c[i]);
put(' ');
}
void putln(int x){
if(x<0){
put('-');
putln(-x);
return;
}
if(x==0){
put('0');put('\n');
return;
}
char c[40];int pos=0;
while(x){
c[pos++]='0'+x%10;
x/=10;
}
for(int i=pos-1;i>=0;i--)put(c[i]);
put('\n');
}
}
using namespace fastio;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,a[200005],b[200005],s[200005];
int C[4005][4005],fact[8888],inv[8888],ind[200005],c[200005],d[200005],pos[4444];
ll sum[6666];
int comb(int nn,int mm){
return (ll)fact[nn]*inv[mm]%mod*inv[nn-mm]%mod;
}
bool cmp1(int x,int y){
return a[x]<a[y];
}
int main(){
fact[0]=1;
for(int i=1;i<8888;i++)fact[i]=(ll)fact[i-1]*i%mod;
for(int i=0;i<8888;i++)inv[i]=modpow(fact[i],mod-2);
n=getint();
// n=2e5;
for(int i=1;i<=n;i++){
// a[i]=rand()%2000+1;b[i]=rand()%2000+1;
a[i]=getint();b[i]=getint();
s[i]=a[i]+b[i];
}
C[0][0]=1;
for(int i=1;i<=4000;i++){
C[i][0]=C[i][i]=1;
for(int j=1;j<i;j++){
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
}
for(int i=1;i<=n;i++){
for(int j=-a[i];j<=b[i];j++){
sum[j+2222]+=C[s[i]][a[i]+j];
}
}
for(int j=-2000;j<=2000;j++){
sum[j+2222]%=mod;
}
/*
for(int i=1;i<=n;i++)ind[i]=i;
sort(ind+1,ind+n+1,cmp1);
for(int i=1;i<=n;i++){
c[i]=a[ind[i]];
d[i]=b[ind[i]];
}
memcpy(a,c,sizeof a);
memcpy(b,d,sizeof b);
int ans=0;
memset(pos,inf,sizeof pos);
for(int i=n;i>=1;i--){
pos[a[i]]=i;
s[i]=a[i]+b[i];
}
for(int i=2000;i>=0;i--)pos[i]=min(pos[i],pos[i+1]);
for(int delta=-2000;delta<=0;delta++){
register ll val=0;
for(int j=pos[-delta];j<=n;j++){
val+=C[s[j]][a[j]+delta];
}
sum[delta+2222]=val%mod;
}
for(int delta=1;delta<=2000;delta++){
register ll val=0;
for(int j=1;j<=n;j++){
val+=C[s[j]][a[j]+delta];
}
sum[delta+2222]=val%mod;
}*/
int ans=0;
for(int i=-2000;i<=2000;i++){
ans+=(ll)sum[i+2222]*sum[-i+2222]%mod;
ans%=mod;
}
for(int i=1;i<=n;i++){
ans-=comb(a[i]+a[i]+b[i]+b[i],a[i]+a[i]);
if(ans<0)ans+=mod;
}
ans=((ll)ans*(mod+1)/2)%mod;
cout<<ans<<endl;
return 0;
} | codenet | -1 | 4,525 |
s833720085 | p04051 | 1,584,503,417 | cpp | Accepted | 177 | 64,640 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int mod = MOD;
struct ModInt {
unsigned val;
ModInt(): val(0) {}
ModInt(ll x) : val(x >= 0 ? x % mod : x % mod + mod) {}
ModInt pow(ll exponent) {
ModInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1) res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
ModInt &operator+=(const ModInt &x) { if((val += x.val) >= mod) val -= mod; return *this; }
ModInt &operator-=(const ModInt &x) { if((val += mod - x.val) >= mod) val -= mod; return *this; }
ModInt &operator*=(const ModInt &x) { val = static_cast<unsigned long long>(val) * x.val % mod; return *this; }
ModInt &operator/=(const ModInt &x) {
// assert(__gcd(static_cast<int>(x.val), mod) == 1);
unsigned a = x.val, b = mod; int u = 1, v = 0;
while (b) {
unsigned tmp = a / b;
swap(a -= tmp * b, b);
swap(u -= tmp * v, v);
}
return *this *= u;
}
bool operator==(const ModInt &x) const { return val == x.val; }
bool operator!=(const ModInt &x) const { return val != x.val; }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator<=(const ModInt &x) const { return val <= x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
bool operator>=(const ModInt &x) const { return val >= x.val; }
ModInt &operator++() { if (++val == mod) val = 0; return *this; }
ModInt operator++(int) { ModInt res = *this; ++*this; return res; }
ModInt &operator--() { val = (val == 0 ? mod : val) - 1; return *this; }
ModInt operator--(int) { ModInt res = *this; --*this; return res; }
ModInt operator+() const { return *this; }
ModInt operator-() const { return ModInt(val ? mod - val : 0); }
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.val; }
friend istream &operator>>(istream &is, ModInt &x) { ll val; is >> val; x = ModInt(val); return is; }
};
ModInt abs(const ModInt &x) { return x; }
struct Combinatorics {
int val; // "val!" and "mod" must be disjoint.
vector<ModInt> fact, fact_inv, inv;
Combinatorics(int val = 10000000) : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
fact[0] = 1;
FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i;
fact_inv[val] = ModInt(1) / fact[val];
for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;
FOR(i, 1, val + 1) inv[i] = fact[i - 1] * fact_inv[i];
}
ModInt nCk(int n, int k) {
if (n < 0 || n < k || k < 0) return ModInt(0);
// assert(n <= val && k <= val);
return fact[n] * fact_inv[k] * fact_inv[n - k];
}
ModInt nPk(int n, int k) {
if (n < 0 || n < k || k < 0) return ModInt(0);
// assert(n <= val);
return fact[n] * fact_inv[n - k];
}
ModInt nHk(int n, int k) {
if (n < 0 || k < 0) return ModInt(0);
return (k == 0 ? ModInt(1) : nCk(n + k - 1, k));
}
};
int main() {
const int M = 2000;
Combinatorics com(M * 4);
int n; cin >> n;
vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];
vector<vector<ModInt> > dp(M * 2 + 1, vector<ModInt>(M * 2 + 1, 0));
REP(i, n) ++dp[M - a[i]][M - b[i]];
REP(i, M * 2 + 1) REP(j, M * 2 + 1) {
if (i + 1 <= M * 2) dp[i + 1][j] += dp[i][j];
if (j + 1 <= M * 2) dp[i][j + 1] += dp[i][j];
}
ModInt ans = 0;
REP(i, n) {
ans += dp[M + a[i]][M + b[i]];
ans -= com.fact[a[i] * 2 + b[i] * 2] * com.fact_inv[a[i] * 2] * com.fact_inv[b[i] * 2];
}
cout << ans / 2 << '\n';
return 0;
}
| codenet | -1 | 4,562 |
s833720085 | p04051 | 1,584,503,417 | cpp | Accepted | 177 | 64,640 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int mod = MOD;
struct ModInt {
unsigned val;
ModInt(): val(0) {}
ModInt(ll x) : val(x >= 0 ? x % mod : x % mod + mod) {}
ModInt pow(ll exponent) {
ModInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1) res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
ModInt &operator+=(const ModInt &x) { if((val += x.val) >= mod) val -= mod; return *this; }
ModInt &operator-=(const ModInt &x) { if((val += mod - x.val) >= mod) val -= mod; return *this; }
ModInt &operator*=(const ModInt &x) { val = static_cast<unsigned long long>(val) * x.val % mod; return *this; }
ModInt &operator/=(const ModInt &x) {
// assert(__gcd(static_cast<int>(x.val), mod) == 1);
unsigned a = x.val, b = mod; int u = 1, v = 0;
while (b) {
unsigned tmp = a / b;
swap(a -= tmp * b, b);
swap(u -= tmp * v, v);
}
return *this *= u;
}
bool operator==(const ModInt &x) const { return val == x.val; }
bool operator!=(const ModInt &x) const { return val != x.val; }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator<=(const ModInt &x) const { return val <= x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
bool operator>=(const ModInt &x) const { return val >= x.val; }
ModInt &operator++() { if (++val == mod) val = 0; return *this; }
ModInt operator++(int) { ModInt res = *this; ++*this; return res; }
ModInt &operator--() { val = (val == 0 ? mod : val) - 1; return *this; }
ModInt operator--(int) { ModInt res = *this; --*this; return res; }
ModInt operator+() const { return *this; }
ModInt operator-() const { return ModInt(val ? mod - val : 0); }
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.val; }
friend istream &operator>>(istream &is, ModInt &x) { ll val; is >> val; x = ModInt(val); return is; }
};
ModInt abs(const ModInt &x) { return x; }
struct Combinatorics {
int val; // "val!" and "mod" must be disjoint.
vector<ModInt> fact, fact_inv, inv;
Combinatorics(int val = 10000000) : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
fact[0] = 1;
FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i;
fact_inv[val] = ModInt(1) / fact[val];
for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;
FOR(i, 1, val + 1) inv[i] = fact[i - 1] * fact_inv[i];
}
ModInt nCk(int n, int k) {
if (n < 0 || n < k || k < 0) return ModInt(0);
// assert(n <= val && k <= val);
return fact[n] * fact_inv[k] * fact_inv[n - k];
}
ModInt nPk(int n, int k) {
if (n < 0 || n < k || k < 0) return ModInt(0);
// assert(n <= val);
return fact[n] * fact_inv[n - k];
}
ModInt nHk(int n, int k) {
if (n < 0 || k < 0) return ModInt(0);
return (k == 0 ? ModInt(1) : nCk(n + k - 1, k));
}
};
int main() {
const int M = 2000;
Combinatorics com(M * 4);
int n; cin >> n;
vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];
vector<vector<ModInt> > dp(M * 2 + 1, vector<ModInt>(M * 2 + 1, 0));
REP(i, n) ++dp[M - a[i]][M - b[i]];
REP(i, M * 2 + 1) REP(j, M * 2 + 1) {
if (i + 1 <= M * 2) dp[i + 1][j] += dp[i][j];
if (j + 1 <= M * 2) dp[i][j + 1] += dp[i][j];
}
ModInt ans = 0;
REP(i, n) {
ans += dp[M + a[i]][M + b[i]];
ans -= com.fact[a[i] * 2 + b[i] * 2] * com.fact_inv[a[i] * 2] * com.fact_inv[b[i] * 2];
}
cout << ans / 2 << '\n';
return 0;
}
| codenet | -1 | 4,562 |
s484938385 | p04051 | 1,585,583,760 | cpp | Accepted | 235 | 127,616 |
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return true;
}
return false;
}
template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return true;
}
return false;
}
// [l, r) from l to r
struct range {
struct itr {
int i;
constexpr itr(int i_): i(i_) { }
constexpr void operator ++ () { ++i; }
constexpr int operator * () const { return i; }
constexpr bool operator != (itr x) const { return i != x.i; }
};
const itr l, r;
constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
constexpr itr begin() const { return l; }
constexpr itr end() const { return r; }
};
// [l, r) from r to l
struct revrange {
struct itr {
int i;
constexpr itr(int i_): i(i_) { }
constexpr void operator ++ () { --i; }
constexpr int operator * () const { return i; }
constexpr bool operator != (itr x) const { return i != x.i; }
};
const itr r, l;
constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
constexpr itr begin() const { return r; }
constexpr itr end() const { return l; }
};
template <class T>
class modulo_int {
public:
static constexpr int mod = T::value;
static_assert(mod > 0, "mod must be positive");
private:
long long value;
constexpr void normalize() {
value %= mod;
if (value < 0) value += mod;
}
public:
constexpr modulo_int(long long value_ = 0): value(value_) { normalize(); }
constexpr modulo_int operator - () const { return modulo_int(mod - value); }
constexpr modulo_int operator ~ () const { return power(mod - 2); }
constexpr long long operator () () const { return value; }
constexpr modulo_int operator + (const modulo_int &rhs) const { return modulo_int(*this) += rhs; }
constexpr modulo_int &operator += (const modulo_int &rhs) {
if ((value += rhs.value) >= mod) value -= mod;
return (*this);
}
constexpr modulo_int operator - (const modulo_int &rhs) const { return modulo_int(*this) -= rhs; }
constexpr modulo_int &operator -= (const modulo_int &rhs) {
if ((value += mod - rhs.value) >= mod) value -= mod;
return (*this);
}
constexpr modulo_int operator * (const modulo_int &rhs) const { return modulo_int(*this) *= rhs; }
constexpr modulo_int &operator *= (const modulo_int &rhs) {
(value *= rhs.value) %= mod;
return (*this);
}
constexpr modulo_int operator / (const modulo_int &rhs) const { return modulo_int(*this) /= rhs; }
constexpr modulo_int &operator /= (const modulo_int &rhs) {
return (*this) *= ~rhs;
}
constexpr bool operator == (const modulo_int &rhs) const {
return value == rhs();
}
constexpr bool operator != (const modulo_int &rhs) const {
return value != rhs();
}
constexpr modulo_int power (unsigned long long pow) const {
modulo_int result(1), mult(*this);
while (pow > 0) {
if (pow & 1) result *= mult;
mult *= mult;
pow >>= 1;
}
return result;
}
friend std::istream &operator >> (std::istream &stream, modulo_int &lhs) {
stream >> lhs.value;
lhs.normalize();
return stream;
}
friend std::ostream &operator << (std::ostream &stream, const modulo_int &rhs) {
return stream << rhs.value;
}
};
template <class T>
class factorials {
public:
using value_type = T;
public:
std::vector<value_type> fact, fact_inv;
factorials(int size_ = 200000): fact(size_ + 1), fact_inv(size_ + 1) {
fact[0] = 1;
for (int i = 1; i <= size_; ++i) {
fact[i] = fact[i - 1] * value_type(i);
}
fact_inv[size_] = ~fact[size_];
for (int i = size_; i > 0; --i) {
fact_inv[i - 1] = fact_inv[i] * value_type(i);
}
}
value_type operator () (int n, int r) const {
return fact[n] * fact_inv[n - r] * fact_inv[r];
}
};
using modint = modulo_int<std::integral_constant<int, 1000000007>>;
constexpr int mx = 2005;
modint dp[mx * 2][mx * 2];
factorials<modint> fact(mx * 4);
int main() {
int N;
std::cin >> N;
std::vector<int> A(N), B(N);
for (int i: range(0, N)) {
std::cin >> A[i] >> B[i];
dp[mx - A[i]][mx - B[i]] += 1;
}
for (int i: range(0, mx * 2)) {
for (int j: range(0, mx * 2)) {
if (i > 0) dp[i][j] += dp[i - 1][j];
if (j > 0) dp[i][j] += dp[i][j - 1];
}
}
modint ans;
for (int i: range(0, N)) {
ans += dp[mx + A[i]][mx + B[i]];
ans -= fact(A[i] * 2 + B[i] * 2, A[i] * 2);
}
std::cout << ans / 2 << '\n';
return 0;
}
| codenet | -1 | 4,631 |
s490243036 | p04051 | 1,574,275,555 | cpp | Accepted | 414 | 127,104 | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
const long long int mod = 1000000007;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod( long long int base, long long int index, long long int modulo = mod ){
if( index == 0 ) return 1;
// O( log(index) )
if( index % 2 ){
return base * PowMod(base, index - 1, modulo) % modulo;
}else{
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// modint {{{
struct modint{
long long int a;
inline constexpr modint( long long int x = 0 ) noexcept : a(x % mod) {}
inline constexpr long long int &value() noexcept { return a; }
inline constexpr const long long int &value() const noexcept { return a; }
inline constexpr modint operator+(const modint rhs) const noexcept{ return modint(*this) += rhs; }
inline constexpr modint operator+(const int rhs) const noexcept{ return modint(*this) += rhs; }
inline constexpr modint operator+(const long long int rhs) const noexcept{ return modint(*this) += rhs; }
inline constexpr modint operator-(const modint rhs) const noexcept{ return modint(*this) -= rhs; }
inline constexpr modint operator-(const int rhs) const noexcept{ return modint(*this) -= rhs; }
inline constexpr modint operator-(const long long int rhs) const noexcept{ return modint(*this) -= rhs; }
inline constexpr modint operator*(const modint rhs) const noexcept{ return modint(*this) *= rhs; }
inline constexpr modint operator*(const int rhs) const noexcept{ return modint(*this) *= rhs; }
inline constexpr modint operator*(const long long int rhs) const noexcept{ return modint(*this) *= rhs; }
inline constexpr modint operator/(const modint rhs) const noexcept{ return modint(*this) /= rhs; }
inline constexpr modint operator/(const int rhs) const noexcept{ return modint(*this) /= rhs; }
inline constexpr modint operator/(const long long int rhs) const noexcept{ return modint(*this) /= rhs; }
inline constexpr modint operator+=(const modint rhs) noexcept{ a += rhs.a; if( a >= mod ) a -= mod; return *this; }
inline constexpr modint operator-=(const modint rhs) noexcept{ a -= rhs.a; if( a < 0 ) a += mod; return *this; }
inline constexpr modint operator*=(const modint rhs) noexcept{ a = a * rhs.a % mod ; return *this; }
inline constexpr modint operator/=(const modint rhs) noexcept{ a = a * PowMod(rhs.a,mod-2) % mod; return *this; }
};
// }}}
unsigned long long int rnd(){
static unsigned long long int x = time(0);
x = x ^ (x << 13); x = x ^ (x >> 7);
return x = x ^ (x << 17);
}
#define D 4000
int main() {
int N;
Scd(N);
vi A(N),C(N);
int a,b;
Rep(i,N){
Scd2(a,b);
// a = (rnd())%2000+1;
// b = (rnd())%2000+1;
A[i] = a; C[i] = a+b;
}
vector<modint> f(D*2+1,1);
Rep(i,D*2){
f[i+1] = f[i]*(i+1);
}
modint X=0,Y=0;
// ็ญใใฏ(X-Y)/2
// Yใใๆฑใใ
Rep(i,N){
Y += f[C[i]*2] / f[C[i]*2-A[i]*2] / f[A[i]*2];
}
vector<modint> ff(D*2+1);
vector<vector<modint>> fc(D+1,vector<modint>(D+1));
Rep(i,N){
fc[C[i]][D-A[i]] += 1;
}
RRep(ci,D+1){
// *= (1+x);
RRep(fi,D*2){
ff[fi+1] += ff[fi];
}
// += Fc[ci]
Rep(i,D+1){
ff[i] += fc[ci][i];
}
}
Rep(i,2*D+1){
X += ff[2*D-i]*ff[i];
}
printf ("%lld\n", (X-Y)/2 );
return 0;
}
| codenet | -1 | 4,717 |
s042112234 | p04051 | 1,478,630,062 | cpp | Accepted | 444 | 255,232 | #include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1ใฎๅพใใซv2ใๅ
ฅใใ*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);
class modint {
//MODใ็ด ๆฐใงใใใใจใๅๆใจใใฆๅฎ่ฃ
ใใฆใใใใใใฎๅคๅฎใฏใใฆใใชใใ
//ใใพใใๅบใใใใช้ค็ฎใใใฆใฏใใใชใใ
private:
static const int MOD = 1000000007;
public:
modint() {
//assert(is_prime(MOD));
this->number = 0;
}
modint(const int src) {
//assert(is_prime(MOD));
this->number = opposit(src);
}
modint(const modint &src) {
this->number = src.number;
}
modint& operator += (const modint& obj) {
this->number = san2(this->number + obj.number);
return *this;
}
modint& operator -= (const modint& obj) {
this->number = san2(this->number - obj.number + MOD);
return *this;
}
modint& operator *= (const modint& obj) {
this->number = (this->number * obj.number) % MOD;
return *this;
}
modint& operator /= (const modint& obj) {
this->number = (this->number * inverse(obj.number)) % MOD;
return *this;
}
modint& operator += (const int n) {
this->number = san2(this->number + opposit(n));
return *this;
}
modint& operator -= (const int n) {
this->number = san2(this->number - opposit(n) + MOD);
return *this;
}
modint& operator *= (const int n) {
this->number = (this->number * opposit(n)) % MOD;
return *this;
}
modint& operator /= (const int n) {
this->number = (this->number * inverse(n)) % MOD;
return *this;
}
modint operator + (const modint obj) { modint re(*this); return re += obj; }
modint operator - (const modint obj) { modint re(*this); return re -= obj; }
modint operator * (const modint obj) { modint re(*this); return re *= obj; }
modint operator / (const modint obj) { modint re(*this); return re /= obj; }
modint operator + (const int n) { modint re(*this); return re += n; }
modint operator - (const int n) { modint re(*this); return re -= n; }
modint operator * (const int n) { modint re(*this); return re *= n; }
modint operator / (const int n) { modint re(*this); return re /= n; }
modint operator = (const int n) {
this->number = opposit(n);
return *this;
}
int get() {
return number;
}
private:
int number;
int opposit(int n) {
if (n < 0)n = MOD - ((-n) % MOD);
return n % MOD;
}
int inverse(int n) {
n = opposit(n);
int result = 1;
for (int i = MOD - 2; i; i /= 2) {
if (i % 2)result = (result * n) % MOD;
n = (n * n) % MOD;
}
return result;
}
inline int san2(const int n) {
return MOD <= n ? n - MOD : n;
}
bool is_prime(int n) {
if (n <= 1)return false;
if (n == 2)return true;
if (n % 2 == 0) return false;
const int upperbound = int(sqrt(n));
for (int i = 3; i <= upperbound; i += 2) {
if (n % i == 0) return false;
}
return true;
}
};
struct combi {
public:
vector<modint>facto;
combi(const int N) :facto(N) {
facto[0] = 1;
REP(i, 1, N)facto[i] = facto[i - 1] * i;
}
modint get_combi(const int N, const int C) {
//combination(N,C)ใๆฑใใฆ่ฟใใ
assert(0 <= C && C <= N);
if (int(facto.size()) <= N) {
int a = facto.size();
facto.resize(N + 1);
REP(i, a, N + 1)facto[i] = facto[i - 1] * i;
}
return facto[N] / (facto[N - C] * facto[C]);
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
combi C(10000);
int N;
cin >> N;
vector<int>A(N), B(N);
rep(i, N)cin >> A[i] >> B[i];
modint X = 0;//่งฃ่ชฌใฎX
vector<vector<modint>>grid(4011, vector<modint>(4011, 0));
vector<vector<int>>goal(4010, vector<int>(4010, 0));
rep(i, N) {
grid[2005 - A[i]][2005 - B[i]] += 1;
goal[2005 + A[i]][2005 + B[i]]++;
}
rep(i, 4010)rep(j, 4010) {
if (goal[i][j])X += grid[i][j] * goal[i][j];
grid[i + 1][j] += grid[i][j];
grid[i][j + 1] += grid[i][j];
}
modint X_ii = 0;
rep(i, N) {
X_ii += C.get_combi((A[i] + B[i]) * 2, B[i] * 2);
}
cout << ((X - X_ii) / 2).get() << endl;
return 0;
} | codenet | -1 | 4,755 |
s488452186 | p04051 | 1,575,468,412 | cpp | Accepted | 154 | 128,640 | #include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> i) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= x; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
using namespace std;
#define PRINTARR(x, y) \
cerr << #x << "=\n"; \
for (auto itr = x; itr != y; itr++) cerr << *itr << " "; \
cerr << endl;
#define PRINTARR2(x, i0, i1) \
cerr << #x << "=\n"; \
for (int ii0 = 0; ii0 < i0; ii0++) { \
for (int ii1 = 0; ii1 < i1; ii1++) cerr << x[ii0][ii1] << " "; \
cerr << endl; \
}
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec) is >> x;
return is;
}
// pair
template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define DUMP(...)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int FACTSIZE = 10100;
int fact[FACTSIZE];
int revfact[FACTSIZE];
int binpow(int a, int b, int mo) {
int ans = 1;
do {
if (b & 1) ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
int ncr(int n, int r) {
if (n < r) return 0;
int rs = fact[n] * revfact[r];
if (rs >= MOD) rs %= MOD;
rs *= revfact[n - r];
if (rs >= MOD) rs %= MOD;
return rs;
}
void init() {
fact[0] = 1, revfact[0] = 1;
for (int i = 1; i < FACTSIZE; ++i) {
fact[i] = fact[i - 1] * i % MOD;
revfact[i] = binpow(fact[i], MOD - 2, MOD);
}
}
#define MAXN 200200
//----//
int N;
int a[MAXN];
int b[MAXN];
int dp[4001][4001];
signed main() {
init();
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cin >> N;
REP(i, N) cin >> a[i] >> b[i];
REP(i, N) { dp[2000 - a[i]][2000 - b[i]]++; }
// REP(i, N) { dp[2000 + a[i]][2000 + b[i]]++; }
REP(i, 4001) {
REP(j, 4001) {
// if (i > 0 && j > 0) dp[i][j] += dp[i - 1][j - 1];
if (i > 0) dp[i][j] += dp[i - 1][j];
if (j > 0) dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
int ans = 0;
REP(i, N) { ans += dp[2000 + a[i]][2000 + b[i]], ans %= MOD; }
// DUMP(dp[1999][1999], dp[2000][2000], ans);
int cnt = 0;
REP(i, N) cnt += ncr(2 * (a[i] + b[i]), 2 * a[i]), cnt %= MOD;
cnt = MOD - cnt;
ans += cnt;
ans %= MOD;
ans = ans * revfact[2];
ans %= MOD;
print(ans);
} | codenet | -1 | 4,873 |
s439259772 | p04051 | 1,487,435,974 | cpp | Accepted | 279 | 130,816 | #include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <utility>
using namespace std;
namespace {
using Integer = long long; //__int128;
template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator , (istream& is, T& val){ return is >> val;}
template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
template<class T> ostream& operator , (ostream& os, const T& val){ return os << " " << val;}
template<class H> void print(const H& head){ cout << head; }
template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }
template<class H> void eprint(const H& head){ cerr << head; }
template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }
class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator end(){ return range_iterator( end_, step_); } };
inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }
inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed
mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());
template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }
inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 9_ten + 7;
class combination_mod{
const long long mod;
const long long size;
vector<long long> fact; //n!
vector<long long> fact_inv; // (n!)^-1
void make_fact(){
fact[0] = 1;
for(long long i=1; i<size; i++){
fact[i] = fact[i-1]*i % mod;
}
}
void make_fact_inv(){
fact_inv[0] = fact_inv[1] = 1;
for(long long i=2; i<size; i++){
fact_inv[i] = fact_inv[mod%i] * (mod - mod/i) % mod; // x ^ -1
}
for(int i=2; i<size; i++){
fact_inv[i] = fact_inv[i-1] * fact_inv[i] % mod; // x! ^ -1
}
}
public:
combination_mod(long long mod_, long long size_ = 2000000) : mod(mod_), size(size_+1){
fact.resize(size);
fact_inv.resize(size);
make_fact();
make_fact_inv();
}
//nCk mod p O(1)
long long operator()(long long n, long long k){
if(k==0 || n==k) return 1;
long long ret = fact[n] * fact_inv[k] % mod * fact_inv[n-k] % mod;
return ret;
}
};
int main(){
int n;
cin >> n;
vector<int> a(n), b(n);
for(int i=0; i<n; i++){
cin >> a[i],b[i];
}
vector<vector<long long>> dp(4010, vector<long long>(4010, 0));
int geta = 2005;
for(int i=0; i<n; i++){
dp[ geta - a[i] ][ geta - b[i] ]++;
}
for(int i=0; i<4010; i++){
for(int j=0; j<4010; j++){
if(i) (dp[i][j] += dp[i-1][j]) %= mod;
if(j) (dp[i][j] += dp[i][j-1]) %= mod;
}
}
combination_mod cmb(mod, 200000);
long long ans = 0;
for(int i=0; i<n; i++){
ans += dp[ geta + a[i] ][ geta + b[i] ] - cmb(2*a[i]+2*b[i], 2*b[i]) + mod;
ans %= mod;
}
ans = ans * my_pow_mod(2, mod-2, mod) % mod;
println(ans);
return 0;
}
| codenet | -1 | 4,970 |
s086662812 | p04051 | 1,540,485,146 | cpp | Accepted | 145 | 131,328 | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LB long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>
#define LOWBIT(x) x & (-x)
// #define LOCAL true
const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=1e9+7;
const double eps=1e-10;
const double pi=acos(-1);
struct fastio
{
static const int S=1e7;
char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
fastio() {rpos=len=wpos=0;}
inline char Getchar()
{
if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
if (!len) return EOF;
return rbuf[rpos++];
}
template <class T> inline void Get(T &x)
{
char ch;bool f;T res;
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';
x=(f?res:-res);
}
inline void getstring(char *s)
{
char ch;
while ((ch=Getchar())<=32) {}
for (;ch>32;ch=Getchar()) *s++=ch;
*s='\0';
}
inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
inline void Writechar(char ch)
{
if (wpos==S) flush();
wbuf[wpos++]=ch;
}
template <class T> inline void Print(T x,char ch)
{
char s[20];int pt=0;
if (x==0) s[++pt]='0';
else
{
if (x<0) Writechar('-'),x=-x;
while (x) s[++pt]='0'+x%10,x/=10;
}
while (pt) Writechar(s[pt--]);
Writechar(ch);
}
inline void printstring(char *s)
{
int pt=1;
while (s[pt]!='\0') Writechar(s[pt++]);
}
}io;
template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);}
template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);}
template<typename T> inline T myabs(T x) {return x>=0?x:-x;}
template<typename T> inline T gcd(T x,T y) {return y==0?x:gcd(y,x%y);}
inline int add(int x) {if (x>=MOD) x-=MOD;return x;}
inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;}
inline int sub(int x) {if (x<0) x+=MOD;return x;}
inline int sub(int x,int MO) {if (x<0) x+=MO;return x;}
inline void Add(int &x,int y) {x=add(x+y);}
inline void Add(int &x,int y,int MO) {x=add(x+y,MO);}
inline void Sub(int &x,int y) {x=sub(x-y);}
inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);}
template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;}
template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;}
const int MAXN=2e5;
int n;
Pair a[MAXN+48];
Pair small[MAXN+48],big[MAXN+48];int stot,btot;
const int lim=100000;
int fac[lim+48],finv[lim+48];
inline void init_inv()
{
fac[0]=fac[1]=1;
for (register int i=2;i<=lim;i++) fac[i]=1ll*fac[i-1]*i%MOD;
finv[lim]=quick_pow(fac[lim],MOD-2);
for (register int i=lim-1;i>=0;i--) finv[i]=1ll*finv[i+1]*(i+1)%MOD;
}
inline int C(int x,int y)
{
if (x<y || y<0) return 0;
return 1ll*fac[x]*finv[y]%MOD*finv[x-y]%MOD;
}
int dp[5600][5600];
inline int calc_small()
{
int base=2748;
for (register int i=1;i<=stot;i++) Add(dp[base-small[i].x][base-small[i].y],1);
for (register int i=base-2748;i<=base+2748;i++)
for (register int j=base-2748;j<=base+2748;j++)
Add(dp[i+1][j],dp[i][j]),Add(dp[i][j+1],dp[i][j]);
int ans=0;
for (register int i=1;i<=stot;i++) Add(ans,dp[base+small[i].x][base+small[i].y]);
for (register int i=1;i<=stot;i++) Sub(ans,C(small[i].x*2+small[i].y*2,small[i].x*2));
return ans;
}
/* inline int calc_big()
{
int ans=0;
for (register int i=1;i<=btot-1;i++)
for (register int j=i+1;j<=btot;j++)
Add(ans,C(big[i].x+big[i].y+big[j].x+big[j].y,big[i].x+big[j].x));
return ans;
}
inline int calc_smallbig()
{
int ans=0,base=2748;
for (register int i=1;i<=btot;i++)
{
for (register int j=base-2748;j<=base;j++)
Add(ans,1ll*dp[base][j]*C(big[i].x-1+big[i].y-(j-base),big[i].x-1));
for (register int j=base;j>=base-2748;j--)
Add(ans,1ll*dp[j][base]*C(big[i].x-(j-base)+big[i].y-1,big[i].x-(j-base)));
}
return ans;
} */
int main ()
{
double TIME=clock();
#ifdef LOCAL
double TIME=clock();
freopen ("a.in","r",stdin);
freopen ("a.out","w",stdout);
cerr<<"Running..."<<endl;
#endif
// freopen ("gift.in","r",stdin);
// freopen ("gift.out","w",stdout);
io.Get(n);
for (register int i=1;i<=n;i++)
{
io.Get(a[i].x),io.Get(a[i].y);
if (a[i].x<=2700 && a[i].y<=2700) small[++stot]=a[i]; else big[++btot]=a[i];
}
init_inv();
cout<<1ll*calc_small()*finv[2]%MOD<<endl;
// io.Print(add(add(calc_small()+calc_big())+calc_smallbig()),'\n');
io.flush();
#ifdef LOCAL
cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl;
#endif
return 0;
} | codenet | -1 | 5,113 |
s386966305 | p04051 | 1,567,567,403 | cpp | Accepted | 172 | 128,896 | // includes
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
// types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;
template <typename T>
T power(T a, T n, T mod) {
T res = 1;
T tmp = n;
T curr = a;
while(tmp){
if(tmp % 2 == 1){
res = (T)(res * curr % mod);
}
curr = (T)(curr * curr % mod);
tmp >>= 1;
}
return res;
}
struct Factorial{
int n = 0;
static const long long mod_default = 1e9 + 7;
long long MOD = mod_default;
vector<long long> fac;
vector<long long> inv_;
explicit Factorial(){}
explicit Factorial(int n, long long mod_=mod_default): n(n), MOD(mod_){
assert(MOD > 0 && n < MOD);
fac.resize(n + 1);
inv_.resize(n + 1);
calc_factorial();
calc_inv();
}
void calc_factorial(){
fac[0] = 1;
for(int i = 1; i <= n; i++){
fac[i] = i * fac[i-1] % MOD;
}
}
void calc_inv(){
inv_[n] = power<long long>(fac[n], MOD - 2, MOD);
for(int i = n - 1; i >= 0; i--){
inv_[i] = (i + 1) * inv_[i+1] % MOD;
}
}
long long& operator[](size_t i){
if((int)i > n){
cerr << "list index out of range" << endl;
abort();
}
return fac[i];
}
long long inv(size_t i){
if((int)i > n){
cerr << "list index out of range" << endl;
abort();
}
return inv_[i];
}
long long comb(int n, int k){
if(n < 0 || k < 0 || n < k)return 0;
long long res = fac[n];
res = res * inv_[n-k] % MOD;
res = res * inv_[k] % MOD;
return res;
}
long long perm(int n, int k){
if(n < 0 || k < 0 || n < k)return 0;
long long res = fac[n];
res = res * inv_[n-k] % MOD;
return res;
}
long long h(int n, int k){
if(n == 0 && k == 0)return 1;
return comb(n + k - 1, k);
}
};
ll dp[4010][4010];
const int B = 2000;
int main(int argc, char const* argv[])
{
int n;
cin >> n;
vector<ll> a(n), b(n);
rep(i, n)cin >> a[i] >> b[i];
Factorial fac(5 * B);
rep(i, n){
dp[B-a[i]][B-b[i]]++;
}
rep(i, 2 * B + 1){
rep(j, 2 * B + 1){
if(i > 0)(dp[i][j] += dp[i-1][j]) %= mod;
if(j > 0)(dp[i][j] += dp[i][j-1]) %= mod;
}
}
ll res = 0;
rep(i, n){
res = (res + dp[B+a[i]][B+b[i]]) % mod;
res = (res - fac.comb(2 * a[i] + 2 * b[i], 2 * a[i])) % mod;
if(res < 0)res += mod;
}
res = res * fac.inv(2) % mod;
cout << res << endl;
return 0;
}
| codenet | -1 | 5,117 |
s761371668 | p04051 | 1,530,612,969 | cpp | Accepted | 305 | 112,000 | /*
Author: isaf27 (Ivan Safonov)
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()
//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
const int fr = 4;
//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
if (k == 0) return 1;
ll t = power(a, k >> 1);
t = (t * t) % MOD;
if (k & 1) t = (t * a) % MOD;
return t;
}
//random
mt19937 rnd(239);
//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 2010;
const int X2 = 2 * X;
const int MD = 1e9 + 7;
int c[X2][X2], n, m, a[M], b[M], d[X][X];
ll f[X][X];
int main()
{
#ifdef ONPC
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastIO;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
m = 0;
for (int i = 0; i < n; i++)
{
m = max(m, a[i]);
m = max(m, b[i]);
}
for (int i = 0; i <= 2 * m; i++)
{
c[i][0] = 1;
c[0][i] = 1;
}
for (int s = 2; s <= 4 * m; s++)
for (int i = 1; i < min(2 * m + 1, s); i++)
{
int j = s - i;
if (j <= 0 || j > 2 * m) continue;
c[i][j] = c[i - 1][j] + c[i][j - 1];
if (c[i][j] >= MD) c[i][j] -= MD;
}
/*for (int i = 0; i <= 2 * m; i++, cerr << "\n")
for (int j = 0; j <= 2 * m; j++, cerr << " ")
cerr << c[i][j];*/
memset(d, 0, sizeof(d));
for (int i = 0; i < n; i++)
d[a[i]][b[i]]++;
for (int s = 2 * m; s >= 2; s--)
for (int i = 1; i < min(s, m + 1); i++)
{
int j = s - i;
if (j <= 0 || j > m) continue;
d[i - 1][j] += d[i][j];
if (d[i - 1][j] >= MD) d[i - 1][j] -= MD;
d[i][j - 1] += d[i][j];
if (d[i][j - 1] >= MD) d[i][j - 1] -= MD;
d[i][j] = 0;
}
/*for (int i = 0; i <= m; i++, cerr << "\n")
for (int j = 0; j <= m; j++, cerr << " ")
cerr << d[i][j];*/
for (int j = 0; j <= m; j++) // (0, j)
{
f[0][j] = 0;
for (int x = 0; x <= m; x++) // (x, 0) -- > (x + j, j)
if (d[x][0] != 0)
{
f[0][j] += (ll)d[x][0] * (ll)c[x][j];
if (f[0][j] >= MOD2) f[0][j] -= MOD2;
}
for (int x = 1; x <= m; x++) // (0, x) -- > (x + j, 0)
if (d[0][x] != 0)
{
f[0][j] += d[0][x];
if (f[0][j] >= MOD2) f[0][j] -= MOD2;
}
f[0][j] %= MOD;
}
for (int j = 0; j <= m; j++) // (j, 0)
{
f[j][0] = 0;
for (int x = 0; x <= m; x++) // (x, 0) -- > (x + j, 0)
if (d[x][0] != 0)
{
f[j][0] += d[x][0];
if (f[j][0] >= MOD2) f[j][0] -= MOD2;
}
for (int x = 1; x <= m; x++) // (0, x) -- > (x + j, x)
if (d[0][x] != 0)
{
f[j][0] += (ll)d[0][x] * (ll)c[x][j];
if (f[j][0] >= MOD2) f[j][0] -= MOD2;
}
f[j][0] %= MOD;
}
for (int s = 2; s <= 2 * m; s++)
for (int i = 1; i < min(m + 1, s); i++)
{
int j = s - i;
if (j <= 0 || j > m) continue;
f[i][j] = f[i - 1][j] + f[i][j - 1];
if (f[i][j] >= MD) f[i][j] -= MD;
}
ll ans = 0;
for (int i = 0; i < n; i++)
ans += f[a[i]][b[i]];
for (int i = 0; i < n; i++)
ans -= c[2 * a[i]][2 * b[i]];
ans %= MOD;
if (ans < 0) ans += MOD;
if (ans & 1)
ans = (ans + MOD) / 2;
else
ans /= 2;
cout << ans;
return 0;
} | codenet | -1 | 5,349 |