#P13973. [VKOSHP 2024] Nightmare Sum

[VKOSHP 2024] Nightmare Sum

Description

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.

Input Format

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 Format

Output a single number --- the desired sum.

6
1 3 6 4 2 5
56

Hint

Let's consider the example in more detail:

:::align{center} :::