let s = read_line ()
let f c = try String.index s c |> ignore; 1 with _ -> 0
let _ = print_endline @@ if f 'N' - f 'S' + f 'E' - f 'W' = 0 then "Yes" else "No"

Score : 200 points

Problem Statement

Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip.
At the beginning of Day 1, he is at home. His plan is described in a string S of length N.
On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction:

North if the i-th letter of S is N

West if the i-th letter of S is W

South if the i-th letter of S is S

East if the i-th letter of S is E

He has not decided each day's travel distance. Determine whether it is possible to set each day's travel distance so that he will be back at home at the end of Day N.

Constraints

1 ≦ | S | ≦ 1000

S consists of the letters N, W, S, E.

Input

The input is given from Standard Input in the following format:

S

Output

Print Yes if it is possible to set each day's travel distance so that he will be back at home at the end of Day N. Otherwise, print No.

Sample Input 1

SENW

Sample Output 1

Yes

If Snuke travels a distance of 1 on each day, he will be back at home at the end of day 4.

Sample Input 2

NSNNSNSN

Sample Output 2

Yes

Sample Input 3

NNEW

Sample Output 3

No

Sample Input 4

W

Sample Output 4

No


Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let f x = if x >= 0 then x / 2 else 0 in

    let rec loop i r0 r1 =
        if i = n then max r0 r1 else
            if a.(i) = 0 then loop (i + 1) r0 0 else
                let r0a = max (r0 + f a.(i))       (r1 + f (a.(i) - 1)) in
                let r1a = max (r0 + f (a.(i) - 1)) (r1 + f (a.(i) - 2)) in
                loop (i + 1) r0a r1a
    in
    loop 1 (f a.(0)) (f (a.(0) - 1)) |> Printf.printf "%d\n"
)

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 400 points

Problem Statement

Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.
He has A_i cards with an integer i.

Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.

Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the maximum number of pairs that Snuke can create.

Sample Input 1

4
4
0
3
2

Sample Output 1

4

For example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).

Sample Input 2

8
2
0
1
6
0
8
2
1

Sample Output 2

9

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d\n" (fun a -> a)) in
  Array.fold_left (fun (acc, prev) a ->
    if prev && 1 <= a then (acc + 1 + (a - 1) / 2, (a - 1) mod 2 = 1)
    else (acc + a / 2, a mod 2 = 1)) (0, false) as_
  |> fst
  |> Printf.printf "%d\n"


Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i =
        if i = n - 1 then -1, -1 else
            if i < n - 2 && s.[i] = s.[i + 2] then i + 1, i + 3 else
                if s.[i] = s.[i + 1] then i + 1, i + 2 else
                    loop (i + 1)
    in
    let a, b = loop 0 in
    Printf.printf "%d %d\n" a b
)

Score : 400 points

Problem Statement

Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

Constraints

2 ≦ |s| ≦ 10^5

s consists of lowercase letters.

Partial Score

200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.

Input

The input is given from Standard Input in the following format:

s

Output

If there exists no unbalanced substring of s, print -1 -1.

If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.

Sample Input 1

needed

Sample Output 1

2 5

The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

Sample Input 2

atcoder

Sample Output 2

-1 -1

The string atcoder contains no unbalanced substring.


let n = Scanf.scanf "%d" (fun x -> x)
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))
let calc c = a
  |> Array.map (fun v -> (v - c) * (v - c))
  |> Array.fold_left (+) 0
let () = Array.init 210 (fun v -> calc (v-105))
  |> Array.fold_left min 10101010101010
  |> Printf.printf "%d\n"

Score : 200 points

Problem Statement

Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.

He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).

Find the minimum total cost to achieve his objective.

Constraints

1≦N≦100

-100≦a_i≦100

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum total cost to achieve Evi's objective.

Sample Input 1

2
4 8

Sample Output 1

8

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

Sample Input 2

3
1 1 3

Sample Output 2

3

Transforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.

Sample Input 3

3
4 2 5

Sample Output 3

5

Leaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.

Sample Input 4

4
-100 -100 -100 -100

Sample Output 4

0

Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.


let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xys = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let rs, bs = Array.(make n false, make n 1)
let _ = rs.(0) <- true; Array.(iteri (fun i (x, y) -> rs.(y) <- rs.(y) || rs.(x); bs.(x) <- bs.(x) - 1; if bs.(x) = 0 then rs.(x) <- false; bs.
(y) <- bs.(y) + 1) xys; Printf.printf "%d\n" @@ fold_left (fun c b -> c + if b then 1 else 0) 0 rs)

Problem Statement

We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.

Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i.

Find the number of boxes that may contain the red ball after all operations are performed.

Constraints

2≤N≤10^5

1≤M≤10^5

1≤x_i,y_i≤N

x_i≠y_i

Just before the i-th operation is performed, box x_i contains at least 1 ball.

Input

The input is given from Standard Input in the following format:

N M
x_1 y_1
:
x_M y_M

Output

Print the number of boxes that may contain the red ball after all operations are performed.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

2

Just after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.

Now, consider the second operation. If Snuke picks the red ball from box 2, the red ball will go into box 3. If he picks the white ball instead, the red ball will stay in box 2.
Thus, the number of boxes that may contain the red ball after all operations, is 2.

Sample Input 2

3 3
1 2
2 3
2 3

Sample Output 2

1

All balls will go into box 3.

Sample Input 3

4 4
1 2
2 3
4 1
3 4

Sample Output 3

3


module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let inf = int_of_float 1e18
let eps = 1e-11

module S = struct
  include String
  let of_array a = String.init (A.length a) (A.get a)
  let to_array s = A.init (String.length s) (String.get s)
end;;

let _ =
  let n = read_int () in
  let len = read_int () in
  let a = read_array read_int n in
  let (max_len, pos) = A.init (n - 1) (fun x -> x) |>
                         A.map (fun i -> (a.(i) + a.(i + 1), i)) |>
                         A.fold_left max (0, 0) in
  if max_len >= len
  then A.append (A.init pos (fun x -> x+1)) (A.init (n-pos-1) (fun x -> n-x-1)) |>
         ( print_endline "Possible";
           A.iter (fun x -> string_of_int x |> print_endline) )
  else print_endline "Impossible"

Problem Statement

We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i.

At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:

Choose a (connected) rope with a total length of at least L, then untie one of its knots.

Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.

Constraints

2≤N≤10^5

1≤L≤10^9

1≤a_i≤10^9

All input values are integers.

Input

The input is given from Standard Input in the following format:

N L
a_1 a_2 ... a_n

Output

If it is not possible to untie all of the N-1 knots, print Impossible.

If it is possible to untie all of the knots, print Possible, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i.

If there is more than one solution, output any.

Sample Input 1

3 50
30 20 10

Sample Output 1

Possible
2
1

If the knot 1 is untied first, the knot 2 will become impossible to untie.

Sample Input 2

2 21
10 10

Sample Output 2

Impossible

Sample Input 3

5 50
10 20 30 40 50

Sample Output 3

Possible
1
2
3
4

Another example of a possible solution is 3, 4, 1, 2.


let n = Scanf.scanf "%d\n" (fun x -> x)

let rec read_ints acc = function
  | 0 ->  acc
  | k -> read_ints (Scanf.scanf " %d" (fun x -> x) :: acc) (k-1)

let al = List.sort (fun x y -> compare y x) (read_ints [] n)

let parity k =
  let rec aux acc = function
    | [] -> acc
    | hd :: tl -> if hd != k then acc else aux (not acc) tl in
  aux false

let rec solve i k = function
  | [] -> true
  | hd :: tl -> if hd > i then solve (i+1) (hd - i) tl else
  k mod 2 = 1 || hd != i || parity k tl

let () = print_endline (if solve 1 0 al then "First" else "Second")

Problem Statement

There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.

Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:

Choose a pile with the largest number of candies remaining, then eat all candies of that pile.

From each pile with one or more candies remaining, eat one candy.

The player who eats the last candy on the table, loses the game. Determine which player will win if both players play the game optimally.

Constraints

1≤N≤10^5

1≤a_i≤10^9

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 … a_N

Output

If Snuke will win, print First. If Ciel will win, print Second.

Sample Input 1

2
1 3

Sample Output 1

First

At the beginning of the game, pile 2 contains the most candies. If Snuke eats all candies of this pile, Ciel has no choice but to eat the last candy.

Sample Input 2

3
1 2 1

Sample Output 2

First

If Snuke eats one candy from each pile, Ciel is again left with the last candy.

Sample Input 3

3
1 2 3

Sample Output 3

Second


module IntSet = Set.Make (struct type t = int let compare = compare end)

let rec tabulate n f =
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let rec solve ds = function
  | 0 -> (0, false)
  | n ->
      let m, n = n mod 10, n / 10 in
      if IntSet.mem m ds then
        match solve ds n with
        | (n, false) -> (10 * n + m, false)
        | (n, true) -> (10 * n + IntSet.min_elt ds, true)
      else
        tabulate 10 (fun n -> n)
        |> List.filter (fun n -> IntSet.mem n ds && m < n)
        |> (function
            | [] -> (10 * fst (solve ds (n + 1)) + IntSet.min_elt ds, true)
            | m :: _ ->
                match solve ds n with
                | (n, false) -> (10 * n + m, true)
                | (n, true) -> (10 * n + IntSet.min_elt ds, true))

let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let ds =
    IntSet.diff
      (IntSet.of_list (tabulate 10 (fun k -> k)))
      (IntSet.of_list (tabulate k (fun _ -> Scanf.scanf "%d " (fun d -> d)))) in
  Printf.printf "%d\n" (fst (solve ds n))

Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

1 ≦ N < 10000

1 ≦ K < 10

0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999


open Scanf
open Printf

let () = scanf "%d %d %d" (fun a b c ->
  if a = 7 || b = 5 || c = 5 then "YES"
  else if a = 5 || b = 7 || c = 5 then "YES"
  else if a = 5 || b = 5 || c = 7 then "YES"
  else "NO"
  ) |> printf "%s\n"

Score : 100 points

Problem Statement

Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Constraints

1≦A,B,C≦10

Input

The input is given from Standard Input in the following format:

A B C

Output

If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.

Sample Input 1

5 5 7

Sample Output 1

YES

Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.

Sample Input 2

7 7 5

Sample Output 2

NO


let r_long () = Int64.of_int (Scanf.scanf " %d" (fun x -> x)) ;;
let r_int () = Scanf.scanf " %d" (fun x -> x) ;;
let a=r_int() in
let b=r_int() in
let c=r_int() in
if (a=7 && b=5 && c=5) || (a=5 && b=7 && c=5) || (a=5 && b=5 && c=7) then
begin
print_string "YES";
end
else
begin
print_string "NO";
end
;
print_newline();


let _ =
    let p = Scanf.scanf "%d %d %d\n" (fun a b c ->
        List.sort compare [a;b;c]) in
    let f = function
        true -> print_endline "YES"
        | false -> print_endline "NO" in
    f ((List.nth p 0) == 5 && (List.nth p 1) == 5 && (List.nth p 2) == 7)


let main = Scanf.sscanf (read_line()) "%d %d %d" (fun a b c ->
    if a * b * c = 175
    then print_string "YES\n"
    else print_string "NO\n"
)


let rec h n a = if n = 0 then a else h (n / 10) (n mod 10 :: a)
let ns, ds = Scanf.(scanf " %d %d" @@ fun n k -> h n [], Array.(to_list @@ init k @@ fun _ -> scanf " %d" (+) 0))
let rec f n = if n > 9 then 10 * f 1 + if f 0 = 0 then 0 else f 1 else if List.mem n ds then f (n + 1) else n
let rec g b a = function [] -> a | n :: ns -> g (b || f n > n) ((if b then f 0 else f n) :: a) ns
let rec k b a = function [] -> a | n :: ns -> let m = if b then f (n + 1) else n in k (m > 9) ((if m > 9 && ns <> [] then f 0 else m) :: a) ns
let ns = g false [] ns |> k false [] |> List.fold_left (fun a n -> 10 * a + n) 0 |> Printf.printf "%d\n"


let split_nums str =
  Str.split (Str.regexp " ") str
  |> List.map int_of_string

let odd_indexed xs =
  let os, es = List.fold_left (fun (l,r) x -> x :: r, l) ([], []) xs
  in es

let sum_list = List.fold_left (+) 0

let answer xs =
  List.sort (-) xs
  |> odd_indexed
  |> sum_list

let () =
  let _ = read_int () in
  read_line ()
  |> split_nums
  |> answer
  |> Printf.printf "%d\n";

Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135


let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1);
  done;
  let d = Array.make_matrix n n min_int in
  for s = 0 to n - 1 do
    let rec dfs v =
      List.iter (fun u ->
        if d.(s).(u) < 0 then
          (d.(s).(u) <- 1 + d.(s).(v); dfs u)) es.(v) in
    d.(s).(s) <- 0; dfs s
  done;
  Printf.printf "%d\n" @@ ( - ) n @@ Array.fold_left max min_int @@ Array.init n @@ fun u ->
    let (vs, ws) = Array.fold_left (fun (vs, ws) v ->
      (if d.(u).(v) = k then v :: vs else vs),
      (if d.(u).(v) <= k then v :: ws else ws)) ([], []) @@
      Array.init n @@ fun v -> v in
    if
      List.for_all (fun v ->
        List.for_all (fun w ->
          d.(v).(w) <= k) ws) vs
    then List.length ws
    else min_int

Score : 600 points

Problem Statement

Given an undirected tree, let the distance between vertices u and v be the
number of edges on the simple path from u to v.
The diameter of a tree is the maximum among the distances between any two vertices.
We will call a tree good if and only if its diameter is at most K.

You are given an undirected tree with N vertices numbered 1 through N.
For each i (1≦i≦N-1), there is an edge connecting vertices A_i and B_i.

You want to remove zero or more vertices from the tree, so that the resulting tree is good.
When a vertex is removed, all incident edges will also be removed.
The resulting graph must be connected.

Find the minimum number of vertices that you need to remove in order to produce a good tree.

Constraints

2≦N≦2000

1≦K≦N-1

1≦A_i≦N, 1≦B_i≦N

The graph defined by A_i and B_i is a tree.

Input

The input is given from Standard Input in the following format:

N K
A_1 B_1
A_2 B_2
:
A_{N-1} B_{N-1}

Output

Print the minimum number of vertices that you need to remove in order to produce a good tree.

Sample Input 1

6 2
1 2
3 2
4 2
1 6
5 6

Sample Output 1

2

The tree is shown below. Removing vertices 5 and 6 will result in a good tree with the diameter of 2.

Sample Input 2

6 5
1 2
3 2
4 2
1 6
5 6

Sample Output 2

0

Since the given tree is already good, you do not need to remove any vertex.


let id x = x

let s = 1000000007
let inv2 = 500000004

let repeat f =
  let rec aux accu = function
    | 0 -> accu
    | n -> aux (f () :: accu) (n - 1) in
  aux []

let pow k =
  let rec aux accu k = function
  | 0 -> accu
  | n when n mod 2 == 0 -> aux accu (k*k mod s) (n/2)
  | n -> aux (accu*k mod s) (k*k mod s) (n/2) in
  aux 1 k

let inv k = pow k (s-2)

let () =
  let n = Scanf.scanf "%d\n" id in
  let l = repeat (fun () -> Scanf.scanf "%d %d\n" (fun a b -> (a,b))) n in
  let (maxa, maxb) = List.fold_left (fun (c,d) (a,b) -> (max a c, max d b)) (0, 0) l in
  let factbl = Array.make (2*maxa+2*maxb+1) 1 in
    for i = 1 to 2*maxa+2*maxb do Array.unsafe_set factbl i ((Array.unsafe_get factbl (i-1)) * i mod s) done;
  let ifactbl = Array.make (2*maxa+2*maxb+1) 0 in
    ifactbl.(2*maxa+2*maxb) <- inv factbl.(2*maxa+2*maxb);
    for i = 2*maxa+2*maxb-1 downto 0 do Array.unsafe_set ifactbl i ((Array.unsafe_get ifactbl (i+1)) * (i+1) mod s) done;
  let bc n k = ((factbl.(n)*ifactbl.(k) mod s) * ifactbl.(n-k) mod s) in
  let sal = List.sort (fun (a,b) (c,d) -> compare c a) l in
  let dp = Array.make (1 + 2 * maxb) 0 in
  let update () = for i = 1 to 2 * maxb do Array.unsafe_set dp i ((Array.unsafe_get dp i + Array.unsafe_get dp (i-1)) mod s) done in
  let rec solve sl m =
    if m > maxa then ()
      else match sl with
           | (a, b) :: tl when a = maxa-m -> dp.(maxb-b) <- ((dp.(maxb-b) +1) mod s); solve tl m
           | _ -> update (); solve sl (m+1) in
  solve sal 0;
  let rec accum accu = function
    | 0 -> accu + dp.(0)*dp.(2*maxb) mod s
    | k -> accum ((accu + ((s+dp.(k)-dp.(k-1)) mod s)*dp.(2*maxb-k) mod s) mod s) (k-1) in
  let sum = accum 0 (2*maxb) in
  let x = List.fold_left (fun x (a,b) -> (x + bc (2*a+2*b) (2*a)) mod s) 0 l in
    print_int ((s+sum - x)*inv2 mod s)

Score : 1400 points

Problem Statement

Snuke is having another barbeque party.

This time, he will make one serving of Skewer Meal.

He has a stock of N Skewer Meal Packs. The i-th Skewer Meal Pack contains one skewer, A_i pieces of beef and B_i pieces of green pepper.
All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.

To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper.
(Remaining Skewer Meal Packs will not be used.)
Then, all those pieces of food are threaded onto both skewers, one by one, in any order.

(See the image in the Sample section for better understanding.)

In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different.
Since this number can be extremely large, find it modulo 10^9+7.

Constraints

2≦N≦200,000

1≦A_i≦2000, 1≦B_i≦2000

Input

The input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo 10^9+7.

Sample Input 1

3
1 1
1 1
2 1

Sample Output 1

26

The 26 ways of making a Skewer Meal are shown below.
Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer.
Brown and green rectangles represent pieces of beef and green pepper, respectively.