PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000237. Tổng các tổng hình chữ nhật con (Sum of All Subrectangle Sums)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng các tổng hình chữ nhật con (Sum of All Subrectangle Sums)

Sum of All Subrectangle Sums

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer matrix of size n×mn\times m, sum the elements of every nonempty axis-aligned subrectangle and add all those sums. Different boundaries define distinct rectangles. Do not take a modulus. The exact answer may be negative or exceed signed 64-bit range.

Input

The first line contains n,mn,m, followed by nn rows of mm integers.

Output

Print the exact integer in decimal notation.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤101\le n,m\le 10; ∣ai,j∣≤106|a_{i,j}|\le 10^6.
  • Subtask 2 (30 points): 1≤n,m≤8001\le n,m\le 800; ∣ai,j∣≤106|a_{i,j}|\le 10^6; n=1n=1 or m=1m=1.
  • Subtask 3 (50 points): 1≤n,m≤8001\le n,m\le 800; ∣ai,j∣≤106|a_{i,j}|\le 10^6.

Example 1

Input

2 2
1 2
3 4

Output

40

Explanation

Each cell belongs to four subrectangles; the answer is 4×(1+2+3+4)=40.

Example 2

Input

1 2
-4 1

Output

-6

Explanation

The three segments sum to −4,1,−3; their total is −6.