eolymp
bolt
Try our new interface for solving problems
Problems

Triangle

Triangle

On the plane, located the \textbf{N} (\textbf{3} ≤ \textbf{N}) points. Of these, randomly selected three points, which are then connected by segments. Required to determine the expectation of the perimeter of a triangle, provided that each set of three points can be chosen with equal probability, and the resulting triangle can be degenerate. \InputFile The first line of the input file contains two numbers \textbf{H} and \textbf{W} (\textbf{1} ≤ \textbf{H}, \textbf{W} ≤ \textbf{700}). This is followed by lines of \textbf{H} characters. \textbf{j}-th symbol of the \textbf{i}-th row is equal to '\textbf{1}' if there is a point with coordinates (\textbf{i}, \textbf{j}), otherwise the corresponding position is a symbol of '\textbf{0}'. It is guaranteed that the input data are presented as at least three points. \OutputFile The output file output a single number - the expectation of the perimeter of a triangle. The answer must differ from the correct no more than \textbf{10^\{-6\}}.
Time limit 6 seconds
Memory limit 256 MiB
Input example #1
11 20
10000000001000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
10000000000000000000
Output example #1
34.142135624
Author Dmitriy Zukov
Source Winter School, Kharkov, 2011, Day 2