407274: GYM102740 H E. Gadd's Ghost Zapper

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. E. Gadd's Ghost Zappertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

To help Luigi get rid of the spooky scary ghosts in the mansion, E. Gadd has created a new gadget, the Ghost Zapper '85. This gadget is able to automatically zap any ghost any distance away from it. The only catch is that zapping a ghost $$$x$$$ meters of distance away from the zapper consumes $$$x^{2}$$$ Watt-hours of energy. In addition, a zapper can zap as many ghost as necessary, but the energy requirements add up; zapping two ghosts, one distance $$$x$$$ away from the zapper and the other distance $$$z$$$ away, will consume $$$x^{2} + z^{2}$$$ Watt-hours of energy in total.

To test this out, E. Gadd will mount a Zapper unit on top of every light fixture in a very long hallway. Using another gadget, he has also determined the location of every ghost along the hallway. Calculate the amount of energy needed to zap every ghost in the hallway, mod $$$10^9 + 7$$$.

Input

Two integers, $$$1 \leq n \le 10^5$$$, and $$$1 \leq m \le 10^5$$$, separated by spaces on the first line.

$$$n$$$ denotes the number of zappers mounted, and $$$m$$$ denotes the number of ghosts in the hallway.

$$$n$$$ lines each containing an integer $$$0 \leq z_{i} \le 10^7$$$ where $$$z_{i}$$$ represents the location of the $$$i$$$th zapper, and location is defined as meters away from the start of the hallway.

$$$m$$$ lines each containing an integer $$$0 \leq x_{j} \le 10^7$$$ where $$$x_{j}$$$ represents the location of the $$$j$$$th ghost.

Output

The total energy required to zap every ghost in the hallway, mod $$$10^9 + 7$$$.

ExamplesInput
4 4
4
1
11
7
2
9
6
15
Output
22
Input
2 4
10
5
7
0
5
100
Output
8129
Note

In example 1, there are four zappers, at locations 4, 1, 11, and 7. The first ghost at location 2 can be zapped by the zapper at location 1, costing 1 Wh. The second ghost at location 9 can be zapped by the zapper at location 7 or the one at location 11, either costing 4 Wh. The third ghost at 6 can be zapped by the zapper at 7, costing 1 Wh. The fourth ghost at 15 can be zapped by the zapper at 11, costing 16 Wh. This yields a total of 22 Wh for all ghosts.

In example 2, The first ghost can be zapped by zapper 2 yielding a cost of $$$(7 - 5)^2 = 4$$$. The second ghost can be zapped by zapper 2 yielding a cost of $$$(5 - 0)^2 = 25$$$. The third ghost can be zapped by zapper 2 with a cost of $$$(5 - 5)^2 = 0$$$. The fourth ghost can be zapped by zapper 1, yielding a cost of $$$(100 - 10)^2 = 8100$$$. The total adds up to $$$8129$$$ Wh of energy.

加入题单

算法标签: