Limited Permutation

TimeLimit:2000MS  MemoryLimit:131072KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

As to a permutation p1,p2,,pn from 1 to n, it is uncomplicated for each 1in to calculate (li,ri) meeting the condition that min(pL,pL+1,,pR)=pi if and only if liLiRri for each 1LRn.

Given the positive integers n, (li,ri) (1in), you are asked to calculate the number of possible permutations p1,p2,,pn from 1 to n, meeting the above condition.

The answer may be very large, so you only need to give the value of answer modulo 109+7.

Input

The input contains multiple test cases.

For each test case:

The first line contains one positive integer n, satisfying 1n106.

The second line contains n positive integers l1,l2,,ln, satisfying 1lii for each 1in.

The third line contains n positive integers r1,r2,,rn, satisfying irin for each 1in.

It's guaranteed that the sum of n in all test cases is not larger than 3106.

Warm Tips for C/C++: input data is so large (about 38 MiB) that we recommend to use fread() for buffering friendly.

size_t fread(void *buffer, size_t size, size_t count, FILE *stream); // reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by buffer; the total number of elements successfully read is returned.

 


Output

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.

 


SampleInput
3
1 1 3
1 3 3
5
1 2 2 4 5
5 2 5 5 5
SampleOutput
Case #1: 2
Case #2: 3
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: