#P13973. [VKOSHP 2024] Nightmare Sum

[VKOSHP 2024] Nightmare Sum

题目描述

Given an array aa of length nn, consisting of distinct positive integers. Compute

$$\sum\limits_{l=1}^{n} \sum\limits_{r=l}^{n} \left\lfloor\frac{\max(a_{l},a_{l+1},\ldots,a_{r})}{\min(a_{l},a_{l+1},\ldots,a_{r})}\right\rfloor $$

Here, x\lfloor x \rfloor denotes xx rounded down to the nearest integer.

Thus, it is necessary to compute the sum of the results of integer division of the maximum by the minimum over all subarrays of the array aa.

输入格式

The first line of input contains a single integer nn~--- the length of the array (1n300000)(1 \leq n \leq 300\,000).

The second line of input contains nn integers~--- the array aa (1ai300000)(1 \leq a_{i} \leq 300\,000).

It is guaranteed that all numbers in the array aa are distinct.

输出格式

Output a single number --- the desired sum.

6
1 3 6 4 2 5
56

提示

Let's consider the example in more detail:

:::align{center} :::