# Input Format

• $1 \leq N \leq 2000$
• $0\leq A_i\leq 5000$
• $1 \leq \sum\limits^ n_{i=1} A_i \leq 5000$
• $0 \leq B_i \leq C_i \leq 5000$

2
2 2
1 1
3 3

5

# Sample Input 2

4
3 4 2 5
0 0 0 0
2000 2000 2000 2000

1333

# Hints

$X = [1, 1], [1,2], [1, 3], [2, 1], [2, 2]$ 是符合條件的所有可能
$[3, 1]$ 不符合條件因為 $X_1 > A_1$
$[2, 0]$ 不符合條件因為 $X_2 < B_2$

# Problem Source

No. Testdata Range Constraints Score
1 0~1 範例測資 0
2 0~15 $N \leq 500$, $\sum\limits^ n_{i=1} A_i \leq 500$ 32
3 16~27 $B_i = 0$, $C_i = 5000$ 29
4 0~38 無額外限制 39

# Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 262144 65536 1 2 4
1 1000 262144 65536 1 2 4
2 1000 262144 65536 2 4
3 1000 262144 65536 2 4
4 1000 262144 65536 2 4
5 1000 262144 65536 2 4
6 1000 262144 65536 2 4
7 1000 262144 65536 2 4
8 1000 262144 65536 2 4
9 1000 262144 65536 2 4
10 1000 262144 65536 2 4
11 1000 262144 65536 2 4
12 1000 262144 65536 2 4
13 1000 262144 65536 2 4
14 1000 262144 65536 2 4
15 1000 262144 65536 2 4
16 1000 262144 65536 3 4
17 1000 262144 65536 3 4
18 1000 262144 65536 3 4
19 1000 262144 65536 3 4
20 1000 262144 65536 3 4
21 1000 262144 65536 3 4
22 1000 262144 65536 3 4
23 1000 262144 65536 3 4
24 1000 262144 65536 3 4
25 1000 262144 65536 3 4
26 1000 262144 65536 3 4
27 1000 262144 65536 3 4
28 1000 262144 65536 4
29 1000 262144 65536 4
30 1000 262144 65536 4
31 1000 262144 65536 4
32 1000 262144 65536 4
33 1000 262144 65536 4
34 1000 262144 65536 4
35 1000 262144 65536 4
36 1000 262144 65536 4
37 1000 262144 65536 4
38 1000 262144 65536 4