Squared Error

AtCoder
IDabc194_c
Time2000ms
Memory256MB
Difficulty
Given is a number sequence $A$ of length $N$. Find the sum of squared differences of every pair of elements: $\displaystyle \sum_{i = 2}^{N} \sum_{j = 1}^{i - 1} (A_i - A_j)^2$. ## Constraints * $2 \le N \le 3 \times 10^5$ * $|A_i| \le 200$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $A_3$ $\cdots$ $A_N$ [samples]
Samples
Input #1
3
2 8 4
Output #1
56

We have $\sum_{i = 2}^{N} \sum_{j = 1}^{i - 1} (A_i - A_j)^2 = (8 - 2)^2 + (4 - 2) ^ 2 + (4 - 8) ^ 2 = 56$.
Input #2
5
-5 8 9 -4 -3
Output #2
950
API Response (JSON)
{
  "problem": {
    "name": "Squared Error",
    "description": {
      "content": "Given is a number sequence $A$ of length $N$.   Find the sum of squared differences of every pair of elements: $\\displaystyle \\sum_{i = 2}^{N} \\sum_{j = 1}^{i - 1} (A_i - A_j)^2$.",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc194_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a number sequence $A$ of length $N$.  \nFind the sum of squared differences of every pair of elements: $\\displaystyle \\sum_{i = 2}^{N} \\sum_{j = 1}^{i - 1} (A_i - A_j)^2$.\n\n## Constraints\n\n*  ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments