Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

NSC - Nuga chia kẹo

 

Candies

Mid-Fall Festival is coming, Nuga has bought a lot of candies for her sisters and brothers. Nuga has M candies in total, and she wants to give all of them to N children. We number the children from 1 to N.

Nuga knows that the i-th child is happy only if he or she get at least Ai candies. However one’s parents don’t want their child to eat more than Bi candies (to avoid dental caries). So, Nuga has to give the i-th child Xi candies that satisfies Ai ≤ Xi ≤ B­i.

Please help Nuga to calculate how many ways that she can divides M candies among N children and satisfy all conditions.

Input

- The first line contains 2 integers M, N.

- The second line contains N integers A1, A2, …, An.

- The third line contains N integers B1, B2, …, Bn

Constraint

- In 30% of the test cases, 1 ≤ N ≤ 5 và 0 ≤ Ai ≤ Bi ≤ M ≤ 20.

- In other test cases, 1 ≤ N ≤ 16 và 0 ≤ Ai ≤ Bi ≤ M ≤ 109.

Output

One line contains the number of satisfied ways.

Example

Input: 
6 3
0 0 0
3 2 4

Output:
9

 


Được gửi lên bởi:Race with time
Ngày:2009-07-16
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO PERL6 PYPY RUST SED
Nguồn bài:VNOI Marathon 2009
Round 4
Problem Setter: Phạm Lê Quang

hide comments
2014-12-25 15:52:26 [CHV] Bác Thợ Sãn
em đang phân vân là liệu có bị tràn số không nhỉ, có thánh nào làm chưa, tư vấn em với
2013-08-20 20:15:47 ‡■■Lãng du■■‡
P/s cho em hỏi code của em ID 9877965 sub bị WA hay TLE ạ!
2012-05-04 05:52:06 .
Hình đẹp quá
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.