#P1192. Big Matrix

    ID: 193 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>湖南省第十八届大学生计算机程序设计竞赛(HNCPC2022)

Big Matrix

Description

Given two matrices A and B with the same size n × n, and parameters a1, a2, b1, b2, the two matrices are defined as:

  • A(i,j) = i × a1 + j × a2
  • B(i,j) = i × b1 + j × b2

where i, j are 0, 1, 2, ⋯, n − 1.

Calculate the sum of all elements of C = AB.

Input

No more than 10 test cases. For each case, n a1 a2 b1 b2 are given.

  • 1 ≤ n ≤ 1000
  • 1 ≤ a1, a2, b1, b2 ≤ 105

Output

The sum mod by 109 + 7.

2 1 1 1 1
4 1 2 3 4
10
3504