|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +class Main { |
| 7 | + |
| 8 | + // IO field |
| 9 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 11 | + static StringTokenizer st; |
| 12 | + |
| 13 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 14 | + static int nextInt() {return Integer.parseInt(st.nextToken());} |
| 15 | + static long nextLong() {return Long.parseLong(st.nextToken());} |
| 16 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 17 | + |
| 18 | + // Additional field |
| 19 | + |
| 20 | + static int N; |
| 21 | + static long ans = 1; |
| 22 | + static long[] fac = new long[600001]; |
| 23 | + static final long mod = (long)1e9 + 7; |
| 24 | + |
| 25 | + |
| 26 | + public static void main(String[] args) throws Exception { |
| 27 | + |
| 28 | + ready(); |
| 29 | + solve(); |
| 30 | + |
| 31 | + bwEnd(); |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + static void ready() throws Exception{ |
| 36 | + |
| 37 | + N = Integer.parseInt(br.readLine()); |
| 38 | + fac[0] = 1; |
| 39 | + for(int i=1;i<=600000;i++) fac[i] = (fac[i-1] * i) % mod; |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + static void solve() throws Exception{ |
| 44 | + |
| 45 | + while(N-- > 0) { |
| 46 | + nextLine(); |
| 47 | + int a = nextInt(), b = nextInt(); |
| 48 | + ans = (ans * (comb(a+b,a) + mod - 1)) % mod; |
| 49 | + } |
| 50 | + bw.write(ans + "\n"); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + static long comb(int x, int y) { |
| 55 | + |
| 56 | + return fac[x] * power(fac[x-y], mod-2) % mod * power(fac[y], mod-2) % mod; |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + // x^p % mod |
| 61 | + static long power(long x, long p) { |
| 62 | + if(p == 0) return 1; |
| 63 | + if(p == 1) return x % mod; |
| 64 | + long half = power(x,p>>1) % mod; |
| 65 | + half = half * half % mod; |
| 66 | + if(p%2==0) return half; |
| 67 | + return half * x % mod; |
| 68 | + } |
| 69 | + |
| 70 | +} |
| 71 | + |
| 72 | +``` |
0 commit comments