This page is still under construction.

Parts of this page are still being built. What you see may change.

Determinant Strikes Back

Time limit2sMemory limit512 MB

Summary
Find the determinant modulo 1e9+7 of an n by n matrix whose entries are a_i*b_j, with x added on the diagonal.
Level

Medium7 of 10

Topics
Math, Matrix, Combinatorics, Implementation
Solved
No attempts yet

Problem

Dinara has an integer xx and two arrays of length nn, a1,…,ana_1, \dots, a_n and b1,…,bnb_1, \dots, b_n. She builds an n×nn \times n matrix MM as follows.

Mi,j={x+aibjwhen i=jaibjotherwiseM_{i, j} = \left\{\begin{matrix} x + a_i b_j & \mathrm{when}\ i = j \\ a_i b_j & \mathrm{otherwise} \end{matrix}\right.

Find the determinant of MM modulo (109+7)(10^9+7).

Input

The input consists of several test cases, terminated by end-of-file.

The first line of each test case contains two integers nn and xx. The second line contains nn integers a1,…,ana_1, \dots, a_n. The third line contains nn integers b1,…,bnb_1, \dots, b_n.

Output

For each test case, print one integer, the result, on a line.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5
  • 0≤x,ai,bi≤1090 \leq x, a_i, b_i \leq 10^9
  • The sum of nn does not exceed 10610^6.

Examples1

  1. Example 1

    Input
    2 1
    0 0
    0 0
    2 1
    1000000000 1000000000
    1000000000 1000000000
    3 2
    2 3 3
    2 3 3
    
    Expected output
    1
    99
    96