#P8253. Sum of Array Function Values

    ID: 21432 Type: Default 1000ms 256MiB

Sum of Array Function Values

Sum of Array Function Values

You are given an m × n array \(a_{{i,j}}\). For each pair of columns \(i\) and \(j\) (\(1 \le i,j \le n\)), define:

\[ f(i,j)=\min_{k=1}^m\bigl(a_{k,i}+a_{k,j}\bigr) + \max_{k=1}^m\bigl(a_{k,i}+a_{k,j}\bigr) \]

Your task is to compute the sum

\[ \sum_{i=1}^n\sum_{j=1}^n f(i,j) \]

Please note that indices \(i\) and \(j\) correspond to the columns of the given array.

inputFormat

The first line contains two integers m and n (the number of rows and columns respectively).

Then follow m lines, each with n integers, representing the array \(a\).

outputFormat

Output a single number which is the sum of \(f(i,j)\) for all \(1 \le i, j \le n\).

sample

1 1
2
4