cswork / OAOpen practice workspace

AmazonOA #243

Group 1 Win Count

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersBinary Search

Each of two teams has n people. For each same-index pair i<j, the first team wins if the skill sum of its two people is strictly greater than that of the corresponding two people on the second team; a tie is not a win. Count the wins modulo 1000000007.

Input

The first line contains n, the second line the first team's skills, and the third line the second team's skills. 2≤n≤100000; all skills are in 1..10^9.

Output

Output a single integer, the answer.

Example 1

Input:

3
1 2 3
3 2 1

Output:

1

Example 2

Input:

2
5 5
5 5

Output:

0

Example 3

Input:

3
2 2 2
1 1 1

Output:

3

Example notes

The answers are 1, 0 and 3. You cannot sort the two teams separately and then subtract.

Editorial

Loading solution…