Potential energy

3

2 votes
Algorithms, Approved, FFT, Fast Fourier transform, Medium
Problem

There are N electrons present in the coordinate plane. For each electron, you have been given three values Xi,Yi and Ki, where Xi and Yi denotes X coordinate and Y coordinates of electron in the plane and Ki denotes the self - potential energy of ith electron if other electron weren't present in the plane. You have to calculate potential energy of this system of electrons which is given by following formula: i=Ni=1j=Nj=1KiKjDIST(i,j)
DIST(i,j) denotes floor of euclidean distance between ith and jth electron. That is, DIST(i,j)=(XiXj)2+(YiYj)2 where denotes floor function.

Since electrons are very small in size, there can be more than one electron present at a point.

INPUT:
First line will consists of integer N denoting total number of electrons. Next N lines will consists of three integers Xi,Yi,Ki.

OUTPUT:
Output potential energy of this system of electrons. Since output can be large print it modulo 109+7.

CONSTRAINTS:
1N106
1Xi,Yi,Ki500

Sample Input
3
1 1 2
2 2 2
3 3 2
Sample Output
32
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The potential energy of this system of electrons =
(K1K10)+(K1K21)+ (K1K32)+(K2K11)+ (K2K20)+(K2K31)+ (K3K12)+(K3K21)+ (K3K30)=32.

Editor Image

?